utp

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2015 License: MIT, MIT Imports: 14 Imported by: 0

README

utp

μTP (Micro Transport Protocol) implementation

Build status Build Status GoDoc

http://www.bittorrent.org/beps/bep_0029.html

warning: This is a buggy alpha version.

Benchmark History

Benchmark status

Installation

go get github.com/h2so5/utp

Example

Echo server

package main

import (
	"time"

	"github.com/h2so5/utp"
)

func main() {
	ln, _ := utp.Listen("utp", ":11000")
	defer ln.Close()

	conn, _ := ln.AcceptUTP()
	conn.SetKeepAlive(time.Minute)
	defer conn.Close()
	
	for {
		var buf [1024]byte
		l, err := conn.Read(buf[:])
		if err != nil {
			break
		}
		_, err = conn.Write(buf[:l])
		if err != nil {
			break
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialer

type Dialer struct {
	// Timeout is the maximum amount of time a dial will wait for
	// a connect to complete. If Deadline is also set, it may fail
	// earlier.
	//
	// The default is no timeout.
	//
	// With or without a timeout, the operating system may impose
	// its own earlier timeout. For instance, TCP timeouts are
	// often around 3 minutes.
	Timeout time.Duration

	// LocalAddr is the local address to use when dialing an
	// address. The address must be of a compatible type for the
	// network being dialed.
	// If nil, a local address is automatically chosen.
	LocalAddr net.Addr
}

A Dialer contains options for connecting to an address.

The zero value for each field is equivalent to dialing without that option. Dialing with the zero value of Dialer is therefore equivalent to just calling the Dial function.

func (*Dialer) Dial

func (d *Dialer) Dial(n, addr string) (*UTPConn, error)

Dial connects to the address on the named network.

See func Dial for a description of the network and address parameters.

type UTPAddr

type UTPAddr struct {
	net.Addr
}

func ResolveUTPAddr

func ResolveUTPAddr(n, addr string) (*UTPAddr, error)

func (UTPAddr) Network

func (a UTPAddr) Network() string

type UTPConn

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

func Dial

func Dial(n, addr string) (*UTPConn, error)

func DialUTP

func DialUTP(n string, laddr, raddr *UTPAddr) (*UTPConn, error)

func DialUTPTimeout

func DialUTPTimeout(n string, laddr, raddr *UTPAddr, timeout time.Duration) (*UTPConn, error)

func (*UTPConn) Close

func (c *UTPConn) Close() error

func (*UTPConn) LocalAddr

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

func (*UTPConn) Read

func (c *UTPConn) Read(b []byte) (int, error)

func (*UTPConn) RemoteAddr

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

func (*UTPConn) SetDeadline

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

func (*UTPConn) SetKeepAlive

func (c *UTPConn) SetKeepAlive(d time.Duration) error

func (*UTPConn) SetReadDeadline

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

func (*UTPConn) SetWriteDeadline

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

func (*UTPConn) Write

func (c *UTPConn) Write(b []byte) (int, error)

type UTPListener

type UTPListener struct {
	// RawConn represents an out-of-band connection.
	// This allows a single socket to handle multiple protocols.
	RawConn net.PacketConn
	// contains filtered or unexported fields
}

func Listen

func Listen(n, laddr string) (*UTPListener, error)

func ListenUTP

func ListenUTP(n string, laddr *UTPAddr) (*UTPListener, error)

func (*UTPListener) Accept

func (l *UTPListener) Accept() (net.Conn, error)

func (*UTPListener) AcceptUTP

func (l *UTPListener) AcceptUTP() (*UTPConn, error)

func (*UTPListener) Addr

func (l *UTPListener) Addr() net.Addr

func (*UTPListener) Close

func (l *UTPListener) Close() error

func (*UTPListener) SetDeadline

func (l *UTPListener) SetDeadline(t time.Time) error

Directories

Path Synopsis
package ucat provides an implementation of netcat using the go utp package.
package ucat provides an implementation of netcat using the go utp package.

Jump to

Keyboard shortcuts

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