Documentation ¶
Index ¶
- Constants
- func GlobalDownloadCap(bytesPerSecond int) func(*Dispatcher) error
- func GlobalUploadCap(bytesPerSecond int) func(*Dispatcher) error
- func LogTo(logger *slog.Logger) func(*Dispatcher) error
- func PortRange(from, to uint32) func(*Dispatcher) error
- func SendTorrentHandshake(conn net.Conn, extensions ProtocolExtensions, infoHash tfs.InfoHash, ...) error
- func UseNATPMP(d *Dispatcher) error
- type ConnectionHandler
- type Dispatcher
- func (d *Dispatcher) Deregister(infoHash tfs.InfoHash)
- func (d *Dispatcher) ExternalIP() string
- func (d *Dispatcher) ExternalPort() uint32
- func (d *Dispatcher) GateKeeper() *GateKeeper
- func (d *Dispatcher) InternalPort() uint32
- func (d *Dispatcher) Logger() *slog.Logger
- func (d *Dispatcher) Register(infoHash tfs.InfoHash, handler ConnectionHandler)
- func (d *Dispatcher) Stop()
- type GateKeeper
- type PeerID
- type ProtocolExtensions
Constants ¶
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.
type GateKeeper ¶
type GateKeeper struct {
// contains filtered or unexported fields
}
GateKeeper controls whether peers with a given address may connect with us.
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) 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 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.