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.UDPConn, 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 ¶
- func Dial(addr string) (net.Conn, error)
- func DialContext(ctx context.Context, addr string) (nc net.Conn, err error)
- func Listen(laddr string) (net.Listener, error)
- 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 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) Dial(addr string) (net.Conn, error)
- func (s *Socket) DialContext(ctx context.Context, network, addr string) (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)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dial ¶
Attempt to connect to a remote uTP listener, creating a Socket just for this connection.
func DialContext ¶
Same as Dial with a timeout parameter. Creates a Socket just for the connection, which will be closed with the Conn is. To reuse another Socket, see Socket.Dial.
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 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 ¶
NewSocket creates a net.PacketConn with the given network and address, and returns a Socket dispatching on it.
func NewSocketFromPacketConn ¶
func NewSocketFromPacketConn(pc net.PacketConn) (s *Socket, err error)
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 NewSocketFromPacketConnNoClose ¶
func NewSocketFromPacketConnNoClose(pc net.PacketConn) (s *Socket, err error)
Create a Socket using the provided PacketConn, that doesn't close the PacketConn when the Socket is closed.