dispatcher

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const HandshakeDeadline = 5 * time.Second

HandshakeDeadline is the maximum amount of time allowed for a handshake read or write.

Variables

This section is empty.

Functions

func GlobalDownloadCap

func GlobalDownloadCap(bytesPerSecond int) func(*Dispatcher) error

GlobalDownloadCap sets the maximum download speed of the dispatcher. Default is no limit.

func GlobalUploadCap

func GlobalUploadCap(bytesPerSecond int) func(*Dispatcher) error

GlobalUploadCap sets the maximum upload speed of the dispatcher. Default is no limit.

func LogTo

func LogTo(logger *slog.Logger) func(*Dispatcher) error

LogTo sets the logger the dispatcher should use. Default discards logs.

func PortRange

func PortRange(from, to uint32) func(*Dispatcher) error

PortRange sets the available ports to listen on to the specified range. Default is to let the system choose a random port.

func SendTorrentHandshake

func SendTorrentHandshake(conn net.Conn, extensions ProtocolExtensions, infoHash tfs.InfoHash, clientID PeerID) error

SendTorrentHandshake sends the torrent protocol handshake.

func UseNATPMP

func UseNATPMP(d *Dispatcher) error

UseNATPMP sets the dispatcher to use NatPMP to route traffic through the external gateway.

Types

type ConnectionHandler

type ConnectionHandler interface {
	HandleConnection(conn net.Conn, log *slog.Logger, extensions ProtocolExtensions, infoHash tfs.InfoHash, sendHandshake bool)
}

ConnectionHandler defines the interface for handling torrent connections.

type Dispatcher

type Dispatcher struct {
	InRate  rate.Limiter
	OutRate rate.Limiter
	// contains filtered or unexported fields
}

Dispatcher holds a dispatcher for bit torrent connections.

func NewDispatcher

func NewDispatcher(options ...func(*Dispatcher) error) (*Dispatcher, error)

NewDispatcher creates a new dispatcher and starts listening for connections.

func (*Dispatcher) Deregister

func (d *Dispatcher) Deregister(infoHash tfs.InfoHash)

Deregister a connection handler from this dispatcher.

func (*Dispatcher) ExternalIP added in v1.0.3

func (d *Dispatcher) ExternalIP() string

ExternalIP returns our external IP address.

func (*Dispatcher) ExternalPort

func (d *Dispatcher) ExternalPort() uint32

ExternalPort returns the external port that we're listening on.

func (*Dispatcher) GateKeeper

func (d *Dispatcher) GateKeeper() *GateKeeper

GateKeeper returns the GateKeeper being used by this dispatcher.

func (*Dispatcher) InternalPort

func (d *Dispatcher) InternalPort() uint32

InternalPort returns the internal port that we're listening on.

func (*Dispatcher) Logger

func (d *Dispatcher) Logger() *slog.Logger

Logger returns the logger being used by this dispatcher.

func (*Dispatcher) Register

func (d *Dispatcher) Register(infoHash tfs.InfoHash, handler ConnectionHandler)

Register a connection handler with this dispatcher.

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

Stop accepting connections and shutdown.

type GateKeeper

type GateKeeper struct {
	// contains filtered or unexported fields
}

GateKeeper controls whether peers with a given address may connect with us.

func NewGateKeeper

func NewGateKeeper() *GateKeeper

NewGateKeeper creates a new GateKeeper.

func (*GateKeeper) BlockAddress

func (r *GateKeeper) BlockAddress(addr net.Addr)

BlockAddress adds the specified address to the incoming blocked list.

func (*GateKeeper) BlockAddressString

func (r *GateKeeper) BlockAddressString(addr string)

BlockAddressString adds the specified address to the incoming blocked list.

func (*GateKeeper) Close

func (r *GateKeeper) Close()

Close shuts this GateKeeper down.

func (*GateKeeper) IsAddressBlocked

func (r *GateKeeper) IsAddressBlocked(addr net.Addr) bool

IsAddressBlocked returns true if the address is blocked.

func (*GateKeeper) IsAddressStringBlocked

func (r *GateKeeper) IsAddressStringBlocked(addr string) bool

IsAddressStringBlocked returns true if the address is blocked.

type PeerID

type PeerID [20]byte

PeerID holds a peer's ID.

type ProtocolExtensions

type ProtocolExtensions [8]byte

ProtocolExtensions holds any protocol extensions.

func ReceiveTorrentHandshake

func ReceiveTorrentHandshake(conn net.Conn) (extensions ProtocolExtensions, infoHash tfs.InfoHash, err error)

ReceiveTorrentHandshake reads the torrent protocol handshake.

Jump to

Keyboard shortcuts

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