ptx

package
v3.12.0-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package ptx contains code to use pluggable transports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeDialer

type FakeDialer struct {
	// Address is the real destination address.
	Address string
}

FakeDialer is a fake pluggable transport dialer. It actually just creates a TCP connection with the given address.

func (*FakeDialer) AsBridgeArgument

func (d *FakeDialer) AsBridgeArgument() string

AsBridgeArgument returns the argument to be passed to the tor command line to declare this bridge.

func (*FakeDialer) DialContext

func (d *FakeDialer) DialContext(ctx context.Context) (net.Conn, error)

DialContext establishes a TCP connection with d.Address.

func (*FakeDialer) Name

func (d *FakeDialer) Name() string

Name returns the pluggable transport name.

type Listener

type Listener struct {
	// PTDialer is the MANDATORY pluggable transports dialer
	// to use. Both SnowflakeDialer and OBFS4Dialer implement this
	// interface and can be thus safely used here.
	PTDialer PTDialer

	// Logger is the optional logger. When not set, this library
	// will not emit logs. (But the underlying pluggable transport
	// may still emit its own log messages.)
	Logger Logger
	// contains filtered or unexported fields
}

Listener is a generic pluggable transports listener. Make sure you fill the mandatory fields before using it. Do not modify public fields after you called Start, since this causes data races.

func (*Listener) Addr

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

Addr returns the listening address. This function should not be called after you have called the Stop method or before the Start method has successfully returned. When invoked in such conditions, this function may return nil. Otherwise, it will return the valid net.Addr where we are listening.

func (*Listener) AsClientTransportPluginArgument

func (lst *Listener) AsClientTransportPluginArgument() string

AsClientTransportPluginArgument converts the current configuration of the pluggable transport to a ClientTransportPlugin argument to be passed to the tor daemon command line. This function must be called after Start and before Stop so that we have a valid Addr.

Assuming that we are listening at 127.0.0.1:12345, then this function will return the following string:

obfs4 socks5 127.0.0.1:12345

The correct configuration line for the `torrc` would be:

ClientTransportPlugin obfs4 socks5 127.0.0.1:12345

Since we pass configuration to tor using the command line, it is more convenient to us to avoid including ClientTransportPlugin in the returned string. In fact, ClientTransportPlugin and its arguments need to be two consecutive argv strings.

func (*Listener) Start

func (lst *Listener) Start() error

Start starts the pluggable transport Listener. The pluggable transport will run in a background goroutine until txp.Stop is called. Attempting to call Start when the pluggable transport is already running is a no-op causing no error and no data races.

func (*Listener) Stop

func (lst *Listener) Stop()

Stop stops the pluggable transport. This method is idempotent and asks the background goroutine(s) to stop just once. Also, this method is safe to call from any goroutine.

type Logger

type Logger interface {
	// Debugf formats and emits a debug message.
	Debugf(format string, v ...interface{})

	// Infof formats and emits an informational message.
	Infof(format string, v ...interface{})

	// Warnf formats and emits a warning message.
	Warnf(format string, v ...interface{})
}

Logger allows us to log messages.

type OBFS4Dialer

type OBFS4Dialer struct {
	// Address contains the MANDATORY proxy address.
	Address string

	// Cert contains the MANDATORY certificate parameter.
	Cert string

	// DataDir is the MANDATORY directory where to store obfs4 data.
	DataDir string

	// Fingerprint is the MANDATORY bridge fingerprint.
	Fingerprint string

	// IATMode contains the MANDATORY iat-mode parameter.
	IATMode string

	// UnderlyingDialer is the optional underlying dialer to
	// use. If not set, we will use &net.Dialer{}.
	UnderlyingDialer UnderlyingDialer
}

OBFS4Dialer is a dialer for obfs4. Make sure you fill all the fields marked as mandatory before using.

func DefaultTestingOBFS4Bridge

func DefaultTestingOBFS4Bridge() *OBFS4Dialer

DefaultTestingOBFS4Bridge is a factory that returns you an OBFS4Dialer configured for the bridge we use by default when testing. Of course, given the nature of obfs4, it's not wise to use this bridge in general. But, feel free to use this bridge for integration testing of this code.

func (*OBFS4Dialer) AsBridgeArgument

func (d *OBFS4Dialer) AsBridgeArgument() string

AsBridgeArgument returns the argument to be passed to the tor command line to declare this bridge.

func (*OBFS4Dialer) DialContext

func (d *OBFS4Dialer) DialContext(ctx context.Context) (net.Conn, error)

DialContext establishes a connection with the given obfs4 proxy. The context argument allows to interrupt this operation midway.

func (*OBFS4Dialer) Name

func (d *OBFS4Dialer) Name() string

Name returns the pluggable transport name.

type PTDialer

type PTDialer interface {
	// DialContext establishes a connection to the pluggable
	// transport backend according to PT-specific configuration
	// and returns you such a connection.
	DialContext(ctx context.Context) (net.Conn, error)

	// AsBridgeArgument returns the argument to be passed to
	// the tor command line to declare this bridge.
	AsBridgeArgument() string

	// Name returns the pluggable transport name.
	Name() string
}

PTDialer is a generic pluggable transports dialer.

type SnowflakeDialer

type SnowflakeDialer struct {
	// BrokerURL is the optional broker URL. If not specified,
	// we will be using a sensible default value.
	BrokerURL string

	// FrontDomain is the domain to use for fronting. If not
	// specified, we will be using a sensible default.
	FrontDomain string

	// ICEAddresses contains the addresses to use for ICE. If not
	// specified, we will be using a sensible default.
	ICEAddresses []string

	// MaxSnowflakes is the maximum number of snowflakes we
	// should create per dialer. If negative or zero, we will
	// be using a sensible default.
	MaxSnowflakes int
	// contains filtered or unexported fields
}

SnowflakeDialer is a dialer for snowflake. When optional fields are not specified, we use defaults from the snowflake repository.

func (*SnowflakeDialer) AsBridgeArgument

func (d *SnowflakeDialer) AsBridgeArgument() string

AsBridgeArgument returns the argument to be passed to the tor command line to declare this bridge.

func (*SnowflakeDialer) DialContext

func (d *SnowflakeDialer) DialContext(ctx context.Context) (net.Conn, error)

DialContext establishes a connection with the given SF proxy. The context argument allows to interrupt this operation midway.

func (*SnowflakeDialer) Name

func (d *SnowflakeDialer) Name() string

Name returns the pluggable transport name.

type UnderlyingDialer

type UnderlyingDialer interface {
	// DialContext behaves like net.Dialer.DialContext.
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

UnderlyingDialer is the underlying dialer used for dialing.

Jump to

Keyboard shortcuts

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