utp

package module
Version: v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2018 License: MPL-2.0 Imports: 17 Imported by: 97

README

utp

GoDoc CircleCI

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

  • There is no MTU path discovery.
  • A fixed 64 slot selective ack window is used in both sending and receiving.

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 DialContext

func DialContext(ctx context.Context, addr string) (nc net.Conn, err error)

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 Listen

func Listen(laddr string) (net.Listener, error)

Listen creates listener Socket to accept incoming connections.

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)

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.

func (*Socket) Accept

func (s *Socket) Accept() (net.Conn, 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) CloseNow

func (s *Socket) CloseNow() error

func (*Socket) Dial

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

func (*Socket) DialContext

func (s *Socket) DialContext(ctx context.Context, network, addr string) (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) (n int, err error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL