v1.0.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: BSD-2-Clause Imports: 17 Imported by: 1




View Source
const (
	DefaultKCPSendWindowSize    int = 65535
	DefaultKCPReceiveWindowSize int = 65535
	DefaultKCPReadBuffer        int = 16 * 1024 * 1024
	DefaultKCPWriteBuffer       int = 16 * 1024 * 1024
View Source
const MaxHopPort = 65535
View Source
const MaxUDPLen uint = 65507
View Source
const MinHopPort = 49152


View Source
var (
	ErrCannotDial = errors.New("cannot dial")
View Source
var PortHopRange = MaxHopPort - MinHopPort


func GetKCPDialer

func GetKCPDialer(kcpConfig KCPConfig, logger func(format string, a ...interface{})) func(network, address string) (net.Conn, error)

func NewServerState

func NewServerState(stateDir string) error

NewServerState will create all the state (node-id, private-key, public-key, drbg-seed, iat-mode) that the OBFS4 server needs to function. It will write it into the passed stateDir folder.

func ReadTCPFrameUDP

func ReadTCPFrameUDP(tcpConn net.Conn, datagramBuffer []byte, lengthBuffer []byte) ([]byte, error)

ReadTCPFrameUDP reads from a tcp connection and returns a framed UDP buffer

func ReadUDPFrameTCP

func ReadUDPFrameTCP(udpConn *net.UDPConn, datagramBuffer []byte) ([]byte, *net.UDPAddr, error)

ReadUDPFrameTCP reads from a udp connection and returns a framed TCP buffer


type Dialer

type Dialer struct {
	Dialer net.Dialer

	NodeID    *ntor.NodeID
	PublicKey *ntor.PublicKey
	IATMode   IATMode
	DialFunc  func(string, string) (net.Conn, error)
	// contains filtered or unexported fields

Dialer contains options for connecting to an address and obfuscating traffic with the obfs4 protocol. It performs the ntor handshake on all dialed connections.

func NewDialerFromArgs

func NewDialerFromArgs(args pt.Args) (*Dialer, error)

NewDialerFromArgs creates a dialer from existing pluggable transport arguments.

func NewDialerFromCert

func NewDialerFromCert(cert string) (*Dialer, error)

NewDialerFromCert creates a dialer from a node certificate.

func (*Dialer) Args

func (d *Dialer) Args() pt.Args

Args returns the dialers options as pluggable transport arguments. The args include valid args for the "new" (version >= 0.0.3) bridge lines that use a unified "cert" argument as well as the legacy lines that use a separate Node ID and Public Key.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial creates an outbound net.Conn and performs the ntor handshake.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext creates an outbound net.Conn and performs the ntor handshake.

type IATMode

type IATMode int

IATMode determines the amount of time sent between packets.

const (
	IATNone IATMode = iota

Valid IAT modes.

type KCPConfig

type KCPConfig struct {
	Enabled           bool
	SendWindowSize    int
	ReceiveWindowSize int
	ReadBuffer        int
	WriteBuffer       int

func DefaultKCPConfig

func DefaultKCPConfig() *KCPConfig

type ListenConfig

type ListenConfig struct {
	ListenConfig net.ListenConfig
	KCPConfig    KCPConfig

	NodeID     *ntor.NodeID
	PrivateKey *ntor.PrivateKey
	PublicKey  string
	Seed       [ntor.KeySeedLength]byte
	StateDir   string

ListenConfig contains options for listening to an address. If Seed is not set it defaults to a randomized value. If StateDir is not set the current working directory is used.

func NewListenConfig

func NewListenConfig(nodeIDStr, privKeyStr, pubKeyStr, seedStr, stateDir string, kcpConfig KCPConfig) (*ListenConfig, error)

NewListenConfig returns a ListenConfig and any error during the initialization. perhaps this is redundant, but using the same json format than ss for debug.

func NewListenConfigCert

func NewListenConfigCert(cert string) (*ListenConfig, error)

NewListenConfigCert creates a listener config by unpacking the node ID from its certificate. The private key must still be specified.

func (*ListenConfig) Listen

func (lc *ListenConfig) Listen(ctx context.Context, kcpConfig KCPConfig, address string) (*Listener, error)

Listen listens on the local network address. See func net.Dial for a description of the network and address parameters.

func (*ListenConfig) Wrap

func (lc *ListenConfig) Wrap(ctx context.Context, ln net.Listener) (*Listener, error)

Wrap takes an existing net.Listener and wraps it in a listener that is configured to perform the ntor handshake and copy data through the obfuscated conn. Values from the inner net.ListenConfig are ignored.

type Listener

type Listener struct {
	// contains filtered or unexported fields

Listener is a network listener that accepts obfuscated connections and performs the ntor handshake on them.

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the listener's network address.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the listener. Any blocked Accept operations will be unblocked and return errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL