Documentation ¶
Overview ¶
Package utp implements uTP, the micro transport protocol as used with Bittorrent. It opts for simplicity and reliability over strict adherence to the (poor) spec. It allows using the underlying OS-level transport despite dispatching uTP on top to allow for example, shared socket use with DHT. Additionally, multiple uTP connections can share the same OS socket, to truly realize uTP's claim to be light on system and network switching resources.
Socket is a wrapper of net.PacketConn, and performs dispatching of uTP packets to attached uTP Conns. Dial and Accept is done via Socket. Conn implements net.Conn over uTP, via aforementioned Socket.
Index ¶
- Constants
- Variables
- func IsAckTimeout(err error) bool
- func IsTimeout(err error) bool
- func WriteStatus(w io.Writer)
- type Conn
- func (c *Conn) Close() (err error)
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(b []byte) (n int, err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) String() string
- func (c *Conn) Write(p []byte) (n int, err error)
- type ConnOption
- type ErrTimeout
- type Socket
- func (s *Socket) Accept() (net.Conn, error)
- func (s *Socket) Addr() net.Addr
- func (s *Socket) Close() error
- func (s *Socket) CloseNow() error
- func (s *Socket) DialContext(ctx context.Context, addr net.Addr) (nc net.Conn, err error)
- func (s *Socket) LocalAddr() net.Addr
- func (s *Socket) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (c *Socket) SetDeadline(t time.Time) error
- func (c *Socket) SetReadDeadline(t time.Time) error
- func (c *Socket) SetWriteDeadline(t time.Time) error
- func (s *Socket) WriteTo(b []byte, addr net.Addr) (n int, err error)
- type SocketOption
- func WithBackground(ctx context.Context) SocketOption
- func WithBacklogLen(n int) SocketOption
- func WithConnOption(o ConnOption) SocketOption
- func WithInitialLatency(d time.Duration) SocketOption
- func WithPacketReadTimeout(d time.Duration) SocketOption
- func WithWriteTimeout(d time.Duration) SocketOption
Constants ¶
const (
DefaultBacklogLen = 50
)
Variables ¶
var (
ErrClosed = net.ErrClosed
)
Functions ¶
func IsAckTimeout ¶
func WriteStatus ¶
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a uTP stream and implements net.Conn. It owned by a Socket, which handles dispatching packets to and from Conns.
func (*Conn) RemoteAddr ¶
func (*Conn) SetDeadline ¶
func (*Conn) SetReadDeadline ¶
func (*Conn) SetWriteDeadline ¶
type ConnOption ¶
type ConnOption func(*connConfig)
ConnOption is used to configure Conn specific options
type ErrTimeout ¶
func (ErrTimeout) Error ¶
func (e ErrTimeout) Error() string
func (ErrTimeout) Temporary ¶
func (e ErrTimeout) Temporary() bool
func (ErrTimeout) Timeout ¶
func (e ErrTimeout) Timeout() bool
type Socket ¶
type Socket struct { // If a read error occurs on the underlying net.PacketConn, it is put // here. This is because reading is done in its own goroutine to dispatch // to uTP Conns. ReadErr error // contains filtered or unexported fields }
A Socket wraps a net.PacketConn, diverting uTP packets to its child uTP Conns.
func NewSocket ¶
func NewSocket(pc net.PacketConn, opts ...SocketOption) *Socket
NewSocket creates a net.PacketConn with the given network and address, and returns a Socket dispatching on it. Create a Socket, using the provided net.PacketConn. If you want to retain use of the net.PacketConn after the Socket closes it, override the net.PacketConn's Close method, or use NetSocketFromPacketConnNoClose.
func (*Socket) DialContext ¶
func (*Socket) SetDeadline ¶
func (*Socket) SetReadDeadline ¶
func (*Socket) SetWriteDeadline ¶
type SocketOption ¶
type SocketOption func(*socketConfig)
SocketOption configures a Socket
func WithBackground ¶
func WithBackground(ctx context.Context) SocketOption
WithBackground sets the background context. This can be used to enable instrumentation with the stdctx library.
func WithBacklogLen ¶
func WithBacklogLen(n int) SocketOption
Maximum received SYNs that haven't been accepted. If more SYNs are received, a pseudo randomly selected SYN is replied to with a reset to make room.
func WithConnOption ¶
func WithConnOption(o ConnOption) SocketOption
func WithInitialLatency ¶
func WithInitialLatency(d time.Duration) SocketOption
This is the latency we assume on new connections. It should be higher than the latency we expect on most connections to prevent excessive resending to peers that take a long time to respond, before we've got a better idea of their actual latency.
func WithPacketReadTimeout ¶
func WithPacketReadTimeout(d time.Duration) SocketOption
func WithWriteTimeout ¶
func WithWriteTimeout(d time.Duration) SocketOption
If a write isn't acked within this period, destroy the connection.