control

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 19 Imported by: 16

Documentation

Overview

Package control implements a low-level client for the Tor control spec version 1.

The primary entrypoint is the Conn struct, instantiated with NewConn. This is the low-level layer to the control port of an already-running Tor instance. Most developers will prefer the tor package adjacent to this one for a higher level abstraction over the process and this connection.

Some of this code is lifted from https://github.com/yawning/bulb with thanks.

Index

Constants

View Source
const (
	StatusOk            = 250
	StatusOkUnnecessary = 251

	StatusErrResourceExhausted      = 451
	StatusErrSyntaxError            = 500
	StatusErrUnrecognizedCmd        = 510
	StatusErrUnimplementedCmd       = 511
	StatusErrSyntaxErrorArg         = 512
	StatusErrUnrecognizedCmdArg     = 513
	StatusErrAuthenticationRequired = 514
	StatusErrBadAuthentication      = 515
	StatusErrUnspecifiedTorError    = 550
	StatusErrInternalError          = 551
	StatusErrUnrecognizedEntity     = 552
	StatusErrInvalidConfigValue     = 553
	StatusErrInvalidDescriptor      = 554
	StatusErrUnmanagedEntity        = 555

	StatusAsyncEvent = 650
)

The various control port StatusCode constants.

Variables

View Source
var ErrEventWaitSynchronousResponseOccurred = errors.New("Synchronous event occurred during EventWait")

ErrEventWaitSynchronousResponseOccurred is returned from EventWait (see docs)

Functions

This section is empty.

Types

type AddOnionRequest

type AddOnionRequest struct {
	// Key is the key to use or GenKey if Tor should generate it.
	Key Key
	// Flags are ADD_ONION flags.
	Flags []string
	// MaxStreams is ADD_ONION MaxStreams.
	MaxStreams int
	// Ports are ADD_ONION Port values. Key is virtual port, Val is target
	// port (or can be empty to use virtual port).
	Ports []*KeyVal
	// ClientAuths are ADD_ONION ClientAuth values. If value is empty string,
	// Tor will generate the password.
	ClientAuths map[string]string
}

AddOnionRequest is a set of request params for AddOnion.

type AddOnionResponse

type AddOnionResponse struct {
	// ServiceID is the ADD_ONION response ServiceID value.
	ServiceID string
	// Key is the ADD_ONION response PrivateKey value.
	Key Key
	// ClientAuths are the ADD_ONION response ClientAuth values.
	ClientAuths map[string]string
	// RawResponse is the raw ADD_ONION response.
	RawResponse *Response
}

AddOnionResponse is the response for AddOnion.

type AddrMapEvent

type AddrMapEvent struct {
	Raw        string
	Address    string
	NewAddress string
	ErrorCode  string
	// Zero if no expire
	Expires time.Time
	// Sans double quotes
	Cached string
}

AddrMapEvent is ADDRMAP in spec.

func ParseAddrMapEvent

func ParseAddrMapEvent(raw string) *AddrMapEvent

ParseAddrMapEvent parses the event.

func (*AddrMapEvent) Code

func (*AddrMapEvent) Code() EventCode

Code implements Event.Code

type BandwidthEvent

type BandwidthEvent struct {
	Raw          string
	BytesRead    int64
	BytesWritten int64
}

BandwidthEvent is BW in spec.

func ParseBandwidthEvent

func ParseBandwidthEvent(raw string) *BandwidthEvent

ParseBandwidthEvent parses the event.

func (*BandwidthEvent) Code

func (*BandwidthEvent) Code() EventCode

Code implements Event.Code

type BuildTimeoutSetEvent

type BuildTimeoutSetEvent struct {
	Raw          string
	Type         string
	TotalTimes   int
	Timeout      time.Duration
	Xm           int
	Alpha        float32
	Quantile     float32
	TimeoutRate  float32
	CloseTimeout time.Duration
	CloseRate    float32
}

BuildTimeoutSetEvent is BUILDTIMEOUT_SET in spec.

func ParseBuildTimeoutSetEvent

func ParseBuildTimeoutSetEvent(raw string) *BuildTimeoutSetEvent

ParseBuildTimeoutSetEvent parses the event.

func (*BuildTimeoutSetEvent) Code

Code implements Event.Code

type CellStatsEvent

type CellStatsEvent struct {
	Raw             string
	CircuitID       string
	InboundQueueID  string
	InboundConnID   string
	InboundAdded    map[string]int
	InboundRemoved  map[string]int
	InboundTime     map[string]int
	OutboundQueueID string
	OutboundConnID  string
	OutboundAdded   map[string]int
	OutboundRemoved map[string]int
	OutboundTime    map[string]int
}

CellStatsEvent is CELL_STATS in spec.

func ParseCellStatsEvent

func ParseCellStatsEvent(raw string) *CellStatsEvent

ParseCellStatsEvent parses the event.

func (*CellStatsEvent) Code

func (*CellStatsEvent) Code() EventCode

Code implements Event.Code

type CircuitBandwidthEvent

type CircuitBandwidthEvent struct {
	Raw          string
	CircuitID    string
	BytesRead    int64
	BytesWritten int64
	Time         time.Time
}

CircuitBandwidthEvent is CIRC_BW in spec.

func ParseCircuitBandwidthEvent

func ParseCircuitBandwidthEvent(raw string) *CircuitBandwidthEvent

ParseCircuitBandwidthEvent parses the event.

func (*CircuitBandwidthEvent) Code

Code implements Event.Code

type CircuitEvent

type CircuitEvent struct {
	Raw           string
	CircuitID     string
	Status        string
	Path          []string
	BuildFlags    []string
	Purpose       string
	HSState       string
	RendQuery     string
	TimeCreated   time.Time
	Reason        string
	RemoteReason  string
	SocksUsername string
	SocksPassword string
}

CircuitEvent is CIRC in spec.

func ParseCircuitEvent

func ParseCircuitEvent(raw string) *CircuitEvent

ParseCircuitEvent parses the event.

func (*CircuitEvent) Code

func (*CircuitEvent) Code() EventCode

Code implements Event.Code

type CircuitMinorEvent

type CircuitMinorEvent struct {
	Raw         string
	CircuitID   string
	Event       string
	Path        []string
	BuildFlags  []string
	Purpose     string
	HSState     string
	RendQuery   string
	TimeCreated time.Time
	OldPurpose  string
	OldHSState  string
}

CircuitMinorEvent is CIRC_MINOR in spec.

func ParseCircuitMinorEvent

func ParseCircuitMinorEvent(raw string) *CircuitMinorEvent

ParseCircuitMinorEvent parses the event.

func (*CircuitMinorEvent) Code

func (*CircuitMinorEvent) Code() EventCode

Code implements Event.Code

type ClientsSeenEvent

type ClientsSeenEvent struct {
	Raw            string
	TimeStarted    time.Time
	CountrySummary map[string]int
	IPVersions     map[string]int
}

ClientsSeenEvent is CLIENTS_SEEN in spec.

func ParseClientsSeenEvent

func ParseClientsSeenEvent(raw string) *ClientsSeenEvent

ParseClientsSeenEvent parses the event.

func (*ClientsSeenEvent) Code

func (*ClientsSeenEvent) Code() EventCode

Code implements Event.Code

type ConfChangedEvent

type ConfChangedEvent struct {
	Raw []string
}

ConfChangedEvent is CONF_CHANGED in spec.

func ParseConfChangedEvent

func ParseConfChangedEvent(raw []string) *ConfChangedEvent

ParseConfChangedEvent parses the event.

func (*ConfChangedEvent) Code

func (*ConfChangedEvent) Code() EventCode

Code implements Event.Code

type Conn

type Conn struct {
	// DebugWriter is the writer that debug logs for this library (not Tor
	// itself) will be written to. If nil, no debug logs are generated/written.
	DebugWriter io.Writer

	// True if Authenticate has been called successfully.
	Authenticated bool
	// contains filtered or unexported fields
}

Conn is the connection to the Tor control port.

func NewConn

func NewConn(conn *textproto.Conn) *Conn

NewConn creates a Conn from the given textproto connection.

func (*Conn) AddEventListener

func (c *Conn) AddEventListener(ch chan<- Event, events ...EventCode) error

AddEventListener adds the given channel as an event listener for the given events. Then Tor is notified about which events should be listened to. Callers are expected to call RemoveEventListener for the channel and all event codes used here before closing the channel. If no events are provided, this is essentially a no-op. The EventCodeUnrecognized event code can be used to listen for unrecognized events.

func (*Conn) AddOnion

func (c *Conn) AddOnion(req *AddOnionRequest) (*AddOnionResponse, error)

AddOnion invokes ADD_ONION and returns its response.

func (*Conn) AttachStream

func (c *Conn) AttachStream(streamID string, circuitID string, hopNum int) error

AttachStream invokes ATTACHSTREAM.

func (*Conn) Authenticate

func (c *Conn) Authenticate(password string) error

Authenticate authenticates with the Tor instance using the "best" possible authentication method if not already authenticated and sets the Authenticated field. The password argument is optional, and will only be used if the "SAFECOOKIE" and "NULL" authentication methods are not available and "HASHEDPASSWORD" is.

func (*Conn) Close

func (c *Conn) Close() error

Close sends a QUIT and closes the underlying Tor connection. This does not error if the QUIT is not accepted but does relay any error that occurs while closing the underlying connection.

func (*Conn) CloseCircuit

func (c *Conn) CloseCircuit(circuitID string, flags []string) error

CloseCircuit invokes CLOSECIRCUIT.

func (*Conn) CloseStream

func (c *Conn) CloseStream(streamID string, reason string) error

CloseStream invokes CLOSESTREAM.

func (*Conn) DelOnion

func (c *Conn) DelOnion(serviceID string) error

DelOnion invokes DELONION.

func (*Conn) DropGuards

func (c *Conn) DropGuards() error

DropGuards invokes DROPGUARDS.

func (*Conn) EventWait

func (c *Conn) EventWait(
	ctx context.Context, events []EventCode, predicate func(Event) (bool, error),
) (Event, error)

EventWait waits for the predicate to be satisified or a non-event message to come through. If a non-event comes through, the error ErrEventWaitSynchronousResponseOccurred is returned. If there is an error in the predicate or if the context completes or there is an error internally handling the event, the error is returned. Otherwise, the event that true was returned from the predicate for is returned.

func (*Conn) ExtendCircuit

func (c *Conn) ExtendCircuit(circuitID string, path []string, purpose string) (string, error)

ExtendCircuit invokes EXTENDCIRCUIT and returns the circuit ID on success.

func (*Conn) GetConf

func (c *Conn) GetConf(keys ...string) ([]*KeyVal, error)

GetConf invokes GETCONF and returns the values for the requested keys.

func (*Conn) GetHiddenServiceDescriptorAsync

func (c *Conn) GetHiddenServiceDescriptorAsync(address string, server string) error

GetHiddenServiceDescriptorAsync invokes HSFETCH.

func (*Conn) GetInfo

func (c *Conn) GetInfo(keys ...string) ([]*KeyVal, error)

GetInfo invokes GETINTO and returns values for requested keys.

func (*Conn) HandleEvents

func (c *Conn) HandleEvents(ctx context.Context) error

HandleEvents loops until the context is closed dispatching async events. Can dispatch events even after context is done and of course during synchronous request. This will always end with an error, either from ctx.Done() or from an error reading/handling the event.

func (*Conn) HandleNextEvent

func (c *Conn) HandleNextEvent() error

HandleNextEvent attempts to read and handle the next event. It will return on first message seen, event or not. Otherwise it will wait until there is a message read.

func (*Conn) LoadConf

func (c *Conn) LoadConf(conf string) error

LoadConf invokes LOADCONF.

func (*Conn) MapAddresses

func (c *Conn) MapAddresses(addresses ...*KeyVal) ([]*KeyVal, error)

MapAddresses invokes MAPADDRESS and returns mapped addresses.

func (*Conn) PostDescriptor

func (c *Conn) PostDescriptor(descriptor string, purpose string, cache string) error

PostDescriptor invokes POSTDESCRIPTOR.

func (*Conn) PostHiddenServiceDescriptorAsync

func (c *Conn) PostHiddenServiceDescriptorAsync(desc string, servers []string, address string) error

PostHiddenServiceDescriptorAsync invokes HSPOST.

func (*Conn) ProtocolInfo

func (c *Conn) ProtocolInfo() (*ProtocolInfo, error)

ProtocolInfo invokes PROTOCOLINFO on first invocation and returns a cached result on all others.

func (*Conn) Quit

func (c *Conn) Quit() error

Quit invokes QUIT.

func (*Conn) ReadResponse

func (c *Conn) ReadResponse() (*Response, error)

ReadResponse returns the next response object.

func (*Conn) RedirectStream

func (c *Conn) RedirectStream(streamID string, address string, port int) error

RedirectStream invokes REDIRECTSTREAM.

func (*Conn) RemoveEventListener

func (c *Conn) RemoveEventListener(ch chan<- Event, events ...EventCode) error

RemoveEventListener removes the given channel from being sent to by the given event codes. It is not an error to remove a channel from events AddEventListener was not called for. Tor is notified about events which may no longer be listened to. If no events are provided, this is essentially a no-op.

func (*Conn) ResetConf

func (c *Conn) ResetConf(entries ...*KeyVal) error

ResetConf invokes RESETCONF.

func (*Conn) ResolveAsync

func (c *Conn) ResolveAsync(address string, reverse bool) error

ResolveAsync invokes RESOLVE.

func (*Conn) SaveConf

func (c *Conn) SaveConf(force bool) error

SaveConf invokes SAVECONF.

func (*Conn) SendRequest

func (c *Conn) SendRequest(format string, args ...interface{}) (*Response, error)

SendRequest sends a synchronous request to Tor and awaits the response. If the response errors, the error result will be set, but the response will be set also. This is usually not directly used by callers, but instead called by higher-level methods.

func (*Conn) SetCircuitPurpose

func (c *Conn) SetCircuitPurpose(circuitID string, purpose string) error

SetCircuitPurpose invokes SETCIRCUITPURPOSE.

func (*Conn) SetConf

func (c *Conn) SetConf(entries ...*KeyVal) error

SetConf invokes SETCONF.

func (*Conn) Signal

func (c *Conn) Signal(signal string) error

Signal invokes SIGNAL.

func (*Conn) TakeOwnership

func (c *Conn) TakeOwnership() error

TakeOwnership invokes TAKEOWNERSHIP.

func (*Conn) UseFeatures

func (c *Conn) UseFeatures(features ...string) error

UseFeatures invokes USEFEATURE.

type ConnBandwidthEvent

type ConnBandwidthEvent struct {
	Raw          string
	ConnID       string
	ConnType     string
	BytesRead    int64
	BytesWritten int64
}

ConnBandwidthEvent is CONN_BW in spec.

func ParseConnBandwidthEvent

func ParseConnBandwidthEvent(raw string) *ConnBandwidthEvent

ParseConnBandwidthEvent parses the event.

func (*ConnBandwidthEvent) Code

func (*ConnBandwidthEvent) Code() EventCode

Code implements Event.Code

type DescChangedEvent

type DescChangedEvent struct {
	Raw string
}

DescChangedEvent is DESCCHANGED in spec.

func ParseDescChangedEvent

func ParseDescChangedEvent(raw string) *DescChangedEvent

ParseDescChangedEvent parses the event.

func (*DescChangedEvent) Code

func (*DescChangedEvent) Code() EventCode

Code implements Event.Code

type ED25519Key

type ED25519Key struct{ ed25519.KeyPair }

ED25519Key is a Key for AddOnion that is a ed25519 key (i.e. v3).

func ED25519KeyFromBlob

func ED25519KeyFromBlob(blob string) (*ED25519Key, error)

ED25519KeyFromBlob creates a ED25519Key for the given response blob.

func (*ED25519Key) Blob

func (e *ED25519Key) Blob() string

Blob implements Key.Blob.

func (*ED25519Key) Type

func (*ED25519Key) Type() KeyType

Type implements Key.Type.

type Event

type Event interface {
	Code() EventCode
}

Event is the base interface for all known asynchronous events.

func ParseEvent

func ParseEvent(code EventCode, raw string, dataArray []string) Event

ParseEvent returns an Event for the given code and data info. Raw is the raw single line if it is a single-line event (even if it has newlines), dataArray is the array of lines for multi-line events. Only one of the two needs to be set. The response is never nil, but may be UnrecognizedEvent. Format errors are ignored per the Tor spec.

type EventCode

type EventCode string

EventCode represents an asynchronous event code (ref control spec 4.1).

const (
	EventCodeAddrMap           EventCode = "ADDRMAP"
	EventCodeBandwidth         EventCode = "BW"
	EventCodeBuildTimeoutSet   EventCode = "BUILDTIMEOUT_SET"
	EventCodeCellStats         EventCode = "CELL_STATS"
	EventCodeCircuit           EventCode = "CIRC"
	EventCodeCircuitBandwidth  EventCode = "CIRC_BW"
	EventCodeCircuitMinor      EventCode = "CIRC_MINOR"
	EventCodeClientsSeen       EventCode = "CLIENTS_SEEN"
	EventCodeConfChanged       EventCode = "CONF_CHANGED"
	EventCodeConnBandwidth     EventCode = "CONN_BW"
	EventCodeDescChanged       EventCode = "DESCCHANGED"
	EventCodeGuard             EventCode = "GUARD"
	EventCodeHSDesc            EventCode = "HS_DESC"
	EventCodeHSDescContent     EventCode = "HS_DESC_CONTENT"
	EventCodeLogDebug          EventCode = "DEBUG"
	EventCodeLogErr            EventCode = "ERR"
	EventCodeLogInfo           EventCode = "INFO"
	EventCodeLogNotice         EventCode = "NOTICE"
	EventCodeLogWarn           EventCode = "WARN"
	EventCodeNetworkLiveness   EventCode = "NETWORK_LIVENESS"
	EventCodeNetworkStatus     EventCode = "NS"
	EventCodeNewConsensus      EventCode = "NEWCONSENSUS"
	EventCodeNewDesc           EventCode = "NEWDESC"
	EventCodeORConn            EventCode = "ORCONN"
	EventCodeSignal            EventCode = "SIGNAL"
	EventCodeStatusClient      EventCode = "STATUS_CLIENT"
	EventCodeStatusGeneral     EventCode = "STATUS_GENERAL"
	EventCodeStatusServer      EventCode = "STATUS_SERVER"
	EventCodeStream            EventCode = "STREAM"
	EventCodeStreamBandwidth   EventCode = "STREAM_BW"
	EventCodeTokenBucketEmpty  EventCode = "TB_EMPTY"
	EventCodeTransportLaunched EventCode = "TRANSPORT_LAUNCHED"
)

Event codes

var EventCodeUnrecognized EventCode = "<unrecognized>"

EventCodeUnrecognized is a special event code that is only used with AddEventListener and RemoveEventListener to listen for events that are unrecognized by this library (i.e. UnrecognizedEvent).

func EventCodes

func EventCodes() []EventCode

EventCodes returns a new slice of all event codes that are recognized (i.e. does not include EventCodeUnrecognized).

type GenKey

type GenKey KeyAlgo

GenKey is a Key for AddOnion that asks Tor to generate a key for the given algorithm.

func GenKeyFromBlob

func GenKeyFromBlob(blob string) GenKey

GenKeyFromBlob creates a GenKey for the given response blob which is a KeyAlgo.

func (GenKey) Blob

func (g GenKey) Blob() string

Blob implements Key.Blob.

func (GenKey) Type

func (GenKey) Type() KeyType

Type implements Key.Type.

type GuardEvent

type GuardEvent struct {
	Raw    string
	Type   string
	Name   string
	Status string
}

GuardEvent is GUARD in spec.

func ParseGuardEvent

func ParseGuardEvent(raw string) *GuardEvent

ParseGuardEvent parses the event.

func (*GuardEvent) Code

func (*GuardEvent) Code() EventCode

Code implements Event.Code

type HSDescContentEvent

type HSDescContentEvent struct {
	Raw        string
	Address    string
	DescID     string
	HSDir      string
	Descriptor string
}

HSDescContentEvent is HS_DESC_CONTENT in spec.

func ParseHSDescContentEvent

func ParseHSDescContentEvent(raw string) *HSDescContentEvent

ParseHSDescContentEvent parses the event.

func (*HSDescContentEvent) Code

func (*HSDescContentEvent) Code() EventCode

Code implements Event.Code

type HSDescEvent

type HSDescEvent struct {
	Raw        string
	Action     string
	Address    string
	AuthType   string
	HSDir      string
	DescID     string
	Reason     string
	Replica    int
	HSDirIndex string
}

HSDescEvent is HS_DESC in spec.

func ParseHSDescEvent

func ParseHSDescEvent(raw string) *HSDescEvent

ParseHSDescEvent parses the event.

func (*HSDescEvent) Code

func (*HSDescEvent) Code() EventCode

Code implements Event.Code

type Key

type Key interface {
	// Type is the KeyType for AddOnion.
	Type() KeyType
	// Blob is the serialized key for AddOnion.
	Blob() string
}

Key is a type of key to use for AddOnion. Implementations include GenKey, RSAKey, and ED25519Key.

func KeyFromString

func KeyFromString(str string) (Key, error)

KeyFromString creates a Key for AddOnion based on a response string.

type KeyAlgo

type KeyAlgo string

KeyAlgo is a key algorithm for GenKey on AddOnion.

const (
	// KeyAlgoBest is BEST.
	KeyAlgoBest KeyAlgo = "BEST"
	// KeyAlgoRSA1024 is RSA1024.
	KeyAlgoRSA1024 KeyAlgo = "RSA1024"
	// KeyAlgoED25519V3 is ED25519-V3.
	KeyAlgoED25519V3 KeyAlgo = "ED25519-V3"
)

type KeyType

type KeyType string

KeyType is a key type for Key in AddOnion.

const (
	// KeyTypeNew is NEW.
	KeyTypeNew KeyType = "NEW"
	// KeyTypeRSA1024 is RSA1024.
	KeyTypeRSA1024 KeyType = "RSA1024"
	// KeyTypeED25519V3 is ED25519-V3.
	KeyTypeED25519V3 KeyType = "ED25519-V3"
)

type KeyVal

type KeyVal struct {
	// Key is the always-present key
	Key string

	// Val is the value. If it's an empty string and nils are accepted/supported
	// where this is used, it means nil unless ValSetAndEmpty is true.
	Val string

	// ValSetAndEmpty is true when Val is an empty string, the associated
	// command supports nils, and Val should NOT be treated as nil. False
	// otherwise.
	ValSetAndEmpty bool
}

KeyVal is a simple key-value struct. In cases where Val can be nil, an empty string represents that unless ValSetAndEmpty is true.

func KeyVals

func KeyVals(keysAndVals ...string) []*KeyVal

KeyVals creates multiple new key-value pairs from the given strings. The provided set of strings must have a length that is a multiple of 2.

func NewKeyVal

func NewKeyVal(key string, val string) *KeyVal

NewKeyVal creates a new key-value pair.

func (*KeyVal) ValSet

func (k *KeyVal) ValSet() bool

ValSet returns true if Val is either non empty or ValSetAndEmpty is true.

type LogEvent

type LogEvent struct {
	Severity EventCode
	Raw      string
}

LogEvent is DEBUG, ERR, INFO, NOTICE, and WARN in spec.

func ParseLogEvent

func ParseLogEvent(severity EventCode, raw string) *LogEvent

ParseLogEvent parses the event.

func (*LogEvent) Code

func (l *LogEvent) Code() EventCode

Code implements Event.Code

type NetworkLivenessEvent

type NetworkLivenessEvent struct {
	Raw string
}

NetworkLivenessEvent is NETWORK_LIVENESS in spec.

func ParseNetworkLivenessEvent

func ParseNetworkLivenessEvent(raw string) *NetworkLivenessEvent

ParseNetworkLivenessEvent parses the event.

func (*NetworkLivenessEvent) Code

Code implements Event.Code

type NetworkStatusEvent

type NetworkStatusEvent struct {
	Raw string
}

NetworkStatusEvent is NS in spec.

func ParseNetworkStatusEvent

func ParseNetworkStatusEvent(raw string) *NetworkStatusEvent

ParseNetworkStatusEvent parses the event.

func (*NetworkStatusEvent) Code

func (*NetworkStatusEvent) Code() EventCode

Code implements Event.Code

type NewConsensusEvent

type NewConsensusEvent struct {
	Raw string
}

NewConsensusEvent is NEWCONSENSUS in spec.

func ParseNewConsensusEvent

func ParseNewConsensusEvent(raw string) *NewConsensusEvent

ParseNewConsensusEvent parses the event.

func (*NewConsensusEvent) Code

func (*NewConsensusEvent) Code() EventCode

Code implements Event.Code

type NewDescEvent

type NewDescEvent struct {
	Raw   string
	Descs []string
}

NewDescEvent is NEWDESC in spec.

func ParseNewDescEvent

func ParseNewDescEvent(raw string) *NewDescEvent

ParseNewDescEvent parses the event.

func (*NewDescEvent) Code

func (*NewDescEvent) Code() EventCode

Code implements Event.Code

type ORConnEvent

type ORConnEvent struct {
	Raw         string
	Target      string
	Status      string
	Reason      string
	NumCircuits int
	ConnID      string
}

ORConnEvent is ORCONN in spec.

func ParseORConnEvent

func ParseORConnEvent(raw string) *ORConnEvent

ParseORConnEvent parses the event.

func (*ORConnEvent) Code

func (*ORConnEvent) Code() EventCode

Code implements Event.Code

type ProtocolInfo

type ProtocolInfo struct {
	AuthMethods []string
	CookieFile  string
	TorVersion  string
	RawResponse *Response
}

ProtocolInfo is the protocol info result of Conn.ProtocolInfo.

func (*ProtocolInfo) HasAuthMethod

func (p *ProtocolInfo) HasAuthMethod(authMethod string) bool

HasAuthMethod checks if ProtocolInfo contains the requested auth method.

type RSAKey

type RSAKey struct{ *rsa.PrivateKey }

RSAKey is a Key for AddOnion that is a RSA-1024 key (i.e. v2).

func RSA1024KeyFromBlob

func RSA1024KeyFromBlob(blob string) (*RSAKey, error)

RSA1024KeyFromBlob creates a RSAKey for the given response blob.

func (*RSAKey) Blob

func (r *RSAKey) Blob() string

Blob implements Key.Blob.

func (*RSAKey) Type

func (*RSAKey) Type() KeyType

Type implements Key.Type.

type Response

type Response struct {
	// Err is the status code and string representation associated with a
	// response. Responses that have completed successfully will also have Err
	// set to indicate such.
	Err *textproto.Error

	// Reply is the text on the EndReplyLine of the response.
	Reply string

	// Data is the MidReplyLines/DataReplyLines of the response. Dot encoded
	// data is "decoded" and presented as a single string (terminal ".CRLF"
	// removed, all intervening CRs stripped).
	Data []string

	// RawLines is all of the lines of a response, without CRLFs.
	RawLines []string
}

Response is a response to a control port command or an asynchronous event.

func (*Response) DataWithReply

func (r *Response) DataWithReply() []string

DataWithReply returns a combination of Data and Reply to give a full set of the lines of the response.

func (*Response) IsAsync

func (r *Response) IsAsync() bool

IsAsync returns true if the response is an asynchronous event.

func (*Response) IsOk

func (r *Response) IsOk() bool

IsOk returns true if the response status code indicates success or an asynchronous event.

type SignalEvent

type SignalEvent struct {
	Raw string
}

SignalEvent is SIGNAL in spec.

func ParseSignalEvent

func ParseSignalEvent(raw string) *SignalEvent

ParseSignalEvent parses the event.

func (*SignalEvent) Code

func (*SignalEvent) Code() EventCode

Code implements Event.Code

type StatusEvent

type StatusEvent struct {
	Raw       string
	Type      EventCode
	Severity  string
	Action    string
	Arguments map[string]string
}

StatusEvent is STATUS_CLIENT, STATUS_GENERAL, and STATUS_SERVER in spec.

func ParseStatusEvent

func ParseStatusEvent(typ EventCode, raw string) *StatusEvent

ParseStatusEvent parses the event.

func (*StatusEvent) Code

func (s *StatusEvent) Code() EventCode

Code implements Event.Code

type StreamBandwidthEvent

type StreamBandwidthEvent struct {
	Raw          string
	BytesRead    int64
	BytesWritten int64
	Time         time.Time
}

StreamBandwidthEvent is STREAM_BW in spec.

func ParseStreamBandwidthEvent

func ParseStreamBandwidthEvent(raw string) *StreamBandwidthEvent

ParseStreamBandwidthEvent parses the event.

func (*StreamBandwidthEvent) Code

Code implements Event.Code

type StreamEvent

type StreamEvent struct {
	Raw           string
	StreamID      string
	Status        string
	CircuitID     string
	TargetAddress string
	TargetPort    int
	Reason        string
	RemoteReason  string
	Source        string
	SourceAddress string
	SourcePort    int
	Purpose       string
}

StreamEvent is STREAM in spec.

func ParseStreamEvent

func ParseStreamEvent(raw string) *StreamEvent

ParseStreamEvent parses the event.

func (*StreamEvent) Code

func (*StreamEvent) Code() EventCode

Code implements Event.Code

type TokenBucketEmptyEvent

type TokenBucketEmptyEvent struct {
	Raw              string
	BucketName       string
	ConnID           string
	ReadBucketEmpty  time.Duration
	WriteBucketEmpty time.Duration
	LastRefil        time.Duration
}

TokenBucketEmptyEvent is TB_EMPTY in spec.

func ParseTokenBucketEmptyEvent

func ParseTokenBucketEmptyEvent(raw string) *TokenBucketEmptyEvent

ParseTokenBucketEmptyEvent parses the event.

func (*TokenBucketEmptyEvent) Code

Code implements Event.Code

type TransportLaunchedEvent

type TransportLaunchedEvent struct {
	Raw     string
	Type    string
	Name    string
	Address string
	Port    int
}

TransportLaunchedEvent is TRANSPORT_LAUNCHED in spec.

func ParseTransportLaunchedEvent

func ParseTransportLaunchedEvent(raw string) *TransportLaunchedEvent

ParseTransportLaunchedEvent parses the event.

func (*TransportLaunchedEvent) Code

Code implements Event.Code

type UnrecognizedEvent

type UnrecognizedEvent struct {
	EventCode     EventCode
	RawSingleLine string
	RawMultiLine  []string
}

UnrecognizedEvent is any unrecognized event code.

func ParseUnrecognizedEvent

func ParseUnrecognizedEvent(eventCode EventCode, rawSingleLine string, rawMultiLine []string) *UnrecognizedEvent

ParseUnrecognizedEvent creates an unrecognized event with the given values.

func (*UnrecognizedEvent) Code

func (u *UnrecognizedEvent) Code() EventCode

Code implements Event.Code

Jump to

Keyboard shortcuts

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