utp

package
v0.0.0-...-56cfde8 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MPL-2.0, MIT Imports: 14 Imported by: 0

README

utp

GoDoc Build Status

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.

Supported

  • Multiple uTP connections switched on a single PacketConn, including those initiated locally.
  • Raw access to the PacketConn for non-uTP purposes, like sharing the PacketConn with a DHT implementation.

Implementation characteristics

  • Receive window size is used to limit out of order packets received.
  • There is no MTU path discovery. The minimum size is always used.
  • A fixed 64 slot selective ack window is used in both sending and receiving.
  • All received non-ACK packets are ACKed in response.

Patches welcomed.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(addr string) (net.Conn, error)

Attempt to connect to a remote uTP listener, creating a Socket just for this connection.

func DialTimeout

func DialTimeout(addr string, timeout time.Duration) (nc net.Conn, err error)

Same as Dial with a timeout parameter.

func WriteStatus

func WriteStatus(w io.Writer)

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) Close

func (c *Conn) Close() (err error)

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) Read

func (c *Conn) Read(b []byte) (n int, err error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) String

func (c *Conn) String() string

func (*Conn) Write

func (c *Conn) Write(p []byte) (n int, err error)

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(network, addr string) (s *Socket, err error)

addr is used to create a listening UDP conn which becomes the underlying net.PacketConn for the Socket.

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 your net.PacketConn's Close method.

func (*Socket) Accept

func (s *Socket) Accept() (c net.Conn, err error)

Accept and return a new uTP connection.

func (*Socket) Addr

func (s *Socket) Addr() net.Addr

The address we're listening on for new uTP connections.

func (*Socket) Close

func (s *Socket) Close() error

func (*Socket) Dial

func (s *Socket) Dial(addr string) (net.Conn, error)

func (*Socket) DialTimeout

func (s *Socket) DialTimeout(addr string, timeout time.Duration) (nc net.Conn, err error)

func (*Socket) LocalAddr

func (s *Socket) LocalAddr() net.Addr

func (*Socket) ReadFrom

func (s *Socket) ReadFrom(p []byte) (n int, addr net.Addr, err error)

func (*Socket) SetDeadline

func (c *Socket) SetDeadline(t time.Time) error

func (*Socket) SetReadDeadline

func (c *Socket) SetReadDeadline(t time.Time) error

func (*Socket) SetWriteDeadline

func (c *Socket) SetWriteDeadline(t time.Time) error

func (*Socket) WriteTo

func (s *Socket) WriteTo(b []byte, addr net.Addr) (int, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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