link

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CircuitReceiver added in v0.1.5

type CircuitReceiver struct {
	Cells chan cell.Cell
	Done  <-chan struct{}
	// contains filtered or unexported fields
}

CircuitReceiver receives raw cells routed to a circuit by the link read loop.

func (*CircuitReceiver) ReadCell added in v0.1.5

func (cr *CircuitReceiver) ReadCell() (cell.Cell, error)

ReadCell reads a cell from the circuit's channel. This satisfies the circuit.CellReader interface.

type Link struct {
	Version uint16
	Reader  *cell.Reader
	Writer  *cell.Writer
	// RelayIdentityEd25519 is the relay's Ed25519 identity key from CERTS validation.
	RelayIdentityEd25519 []byte
	// RelayAddr is the relay's IP:port we connected to.
	RelayAddr string
	// CircIDs tracks allocated circuit IDs on this link to prevent collisions.
	CircIDs map[uint32]bool
	// contains filtered or unexported fields
}

Link represents an established Tor link connection.

func Handshake

func Handshake(addr string, logger *slog.Logger) (*Link, error)

Handshake connects to a Tor relay and performs the full link handshake. Returns a ready Link or an error.

func HandshakeWithPinning added in v0.1.6

func HandshakeWithPinning(addr string, expectedEd25519 []byte, logger *slog.Logger) (*Link, error)

HandshakeWithPinning connects to a Tor relay and performs the full link handshake. If expectedEd25519 is non-nil, the relay's Ed25519 identity key from the CERTS cell is compared using constant-time comparison; a mismatch returns an error.

func NewTestLink(reader *cell.Reader, writer *cell.Writer) *Link

NewTestLink creates a Link suitable for testing with the given cell reader and writer. It initializes the circuits map and done channel so that RegisterCircuit, StartReadLoop, etc. work correctly.

func (*Link) ClaimCircID

func (l *Link) ClaimCircID(id uint32) bool

ClaimCircID registers a circuit ID on this link. Returns false if already in use.

func (*Link) Close

func (l *Link) Close() error

Close closes the underlying TLS connection.

func (*Link) LinkDone added in v0.1.5

func (l *Link) LinkDone() <-chan struct{}

LinkDone returns the link's done channel for detecting link death. Returns nil if the link has no done channel (e.g., test links).

func (*Link) RegisterCircuit added in v0.1.5

func (l *Link) RegisterCircuit(circID uint32) (*CircuitReceiver, error)

RegisterCircuit creates and stores a CircuitReceiver for the given circuit ID. Returns an error if the ID is already registered or the link is dead.

func (*Link) ReleaseCircID

func (l *Link) ReleaseCircID(id uint32)

ReleaseCircID removes a circuit ID from this link's tracking.

func (*Link) SetDeadline

func (l *Link) SetDeadline(t time.Time) error

SetDeadline sets a deadline on the underlying connection.

func (*Link) StartReadLoop added in v0.1.5

func (l *Link) StartReadLoop()

StartReadLoop starts the background read loop goroutine (idempotent via sync.Once).

func (*Link) UnregisterCircuit added in v0.1.5

func (l *Link) UnregisterCircuit(circID uint32)

UnregisterCircuit removes a circuit from the dispatch table and signals Done. It does NOT close cr.Cells - the cells channel is only closed in cleanupAllCircuits (on link death) to avoid a race with runReadLoop sending to the channel.

Jump to

Keyboard shortcuts

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