dst

package module
v0.0.0-...-b85a0bf Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2015 License: MIT Imports: 15 Imported by: 1

README

dst

Latest Build API Documentation MIT License

DST is the Datagram Stream Transfer protocol. In principle it's yet another way to provide a reliable stream protocol on top of UDP, similar to uTP, RUDP, and DST.

In fact, it's mostly based on DST with some significant differences;

  • The packet format is simplified.

  • The keepalive mechanism has been removed to reduce complexity and bandwidth use. Applications can perform keepalives as desired.

  • Windowing and congestion control is simpler, with room for future improvement.

There's currently no protocol specification document apart from the code. One will be written once it's proven to work and the formats can be locked down.

The API follows the usual net conventions and should be familiar.

Documentation

http://godoc.org/github.com/calmh/dst

Documentation

Overview

Package dst implements the Datagram Stream Transfer protocol.

DST is a way to get reliable stream connections (like TCP) on top of UDP.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrClosedConn       = &Error{"operation on closed connection"}
	ErrClosedMux        = &Error{"operation on closed mux"}
	ErrHandshakeTimeout = &Error{"handshake timeout"}
	ErrNotDST           = &Error{"network is not dst"}
	ErrNotImplemented   = &Error{"not implemented"}
)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is an SDT connection carried over a Mux.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (*Conn) GetStatistics

func (c *Conn) GetStatistics() Statistics

GetStatistics returns a snapsht of the current connection statistics.

func (*Conn) LocalAddr

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

LocalAddr returns the local network address.

func (*Conn) Read

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

Read reads data from the connection. Read can be made to time out and return a Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline.

func (*Conn) RemoteAddr

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

RemoteAddr returns the remote network address.

func (*Conn) SetDeadline

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

SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future I/O, not just the immediately following call to Read or Write.

An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls.

A zero value for t means I/O operations will not time out.

BUG(jb): SetDeadline is not implemented.

func (*Conn) SetReadDeadline

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

SetReadDeadline sets the deadline for future Read calls. A zero value for t means Read will not time out.

BUG(jb): SetReadDeadline is not implemented.

func (*Conn) SetWriteDeadline

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

SetWriteDeadline sets the deadline for future Write calls. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.

BUG(jb): SetWriteDeadline is not implemented.

func (*Conn) String

func (c *Conn) String() string

String returns a string representation of the connection.

func (*Conn) Write

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

Write writes data to the connection. Write can be made to time out and return a Error with Timeout() == true after a fixed time limit; see SetDeadline and SetWriteDeadline.

type Error

type Error struct {
	Err string
}

Error represents the various dst-internal error conditions.

func (Error) Error

func (e Error) Error() string

Error returns a string representation of the error.

type Mux

type Mux struct {
	// contains filtered or unexported fields
}

Mux is a UDP multiplexer of DST connections.

func NewMux

func NewMux(conn net.PacketConn, packetSize int) *Mux

NewMux creates a new DST Mux on top of a packet connection.

func (*Mux) Accept

func (m *Mux) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

Example
package main

import (
	"net"

	"github.com/calmh/dst"
)

func main() {
	// Create an underlying UDP socket on a specified local port.
	udpConn, err := net.ListenUDP("udp", &net.UDPAddr{Port: 23458})
	if err != nil {
		panic(err)
	}

	// Create a DST mux around the packet connection with the default max
	// packet size.
	mux := dst.NewMux(udpConn, 0)

	// Accept new DST connections and handle them in a separate routine.
	for {
		conn, err := mux.Accept()
		if err != nil {
			panic(err)
		}
		go handleConn(conn)
	}
}

func handleConn(net.Conn) {}
Output:

func (*Mux) AcceptDST

func (m *Mux) AcceptDST() (*Conn, error)

AcceptDST waits for and returns the next connection to the listener.

func (*Mux) Addr

func (m *Mux) Addr() net.Addr

Addr returns the listener's network address.

func (*Mux) Close

func (m *Mux) Close() error

Close closes the listener. Any blocked Accept operations will be unblocked and return errors.

func (*Mux) Dial

func (m *Mux) Dial(network, addr string) (net.Conn, error)

Dial connects to the address on the named network.

Network must be "dst".

Addresses have the form host:port. If host is a literal IPv6 address or host name, it must be enclosed in square brackets as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80". The functions JoinHostPort and SplitHostPort manipulate addresses in this form.

Examples:

Dial("dst", "12.34.56.78:80")
Dial("dst", "google.com:http")
Dial("dst", "[2001:db8::1]:http")
Dial("dst", "[fe80::1%lo0]:80")
Example
package main

import (
	"net"

	"github.com/calmh/dst"
)

func main() {
	// Create an underlying UDP socket on a random local port.
	udpConn, err := net.ListenUDP("udp", &net.UDPAddr{})
	if err != nil {
		panic(err)
	}

	// Create a DST mux around the packet connection with the default max
	// packet size.
	mux := dst.NewMux(udpConn, 0)

	// Dial a DST connection. The address is that of a remote DST mux.
	conn, err := mux.Dial("dst", "192.0.2.42:23458")
	if err != nil {
		panic(err)
	}

	_, err = conn.Write([]byte("Hello via DST!"))
	if err != nil {
		panic(err)
	}
}
Output:

func (*Mux) DialDST

func (m *Mux) DialDST(network, addr string) (*Conn, error)

Dial connects to the address on the named network.

Network must be "dst".

Addresses have the form host:port. If host is a literal IPv6 address or host name, it must be enclosed in square brackets as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80". The functions JoinHostPort and SplitHostPort manipulate addresses in this form.

Examples:

Dial("dst", "12.34.56.78:80")
Dial("dst", "google.com:http")
Dial("dst", "[2001:db8::1]:http")
Dial("dst", "[fe80::1%lo0]:80")

func (*Mux) String

func (m *Mux) String() string

type Statistics

type Statistics struct {
	DataPacketsIn     int64
	DataPacketsOut    int64
	DataBytesIn       int64
	DataBytesOut      int64
	ResentPackets     int64
	DroppedPackets    int64
	OutOfOrderPackets int64
}

func (Statistics) String

func (s Statistics) String() string

String returns a printable represetnation of the Statistics.

Notes

Bugs

  • SetDeadline is not implemented.

  • SetReadDeadline is not implemented.

  • SetWriteDeadline is not implemented.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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