conn

package
v0.0.0-...-e4696f9 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2014 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ChanBuffer is the size of the buffer in the Conn Chan
	ChanBuffer = 10

	// MaxMessageSize is the size of the largest single message
	MaxMessageSize = 1 << 20

	// HandshakeTimeout for when nodes first connect
	HandshakeTimeout = time.Second * 5
)

Variables

View Source
var BufferPool *sync.Pool

global static buffer pool for byte arrays of size MaxMessageSize

Functions

func CloseConns

func CloseConns(conns ...Conn)

CloseConns closes multiple connections in parallel, and waits for all to finish closing.

func Handshake1

func Handshake1(ctx context.Context, c Conn) error

Handshake1 exchanges local and remote versions and compares them closes remote and returns an error in case of major difference

func Handshake3

func Handshake3(ctx context.Context, c Conn) (*handshake.Handshake3Result, error)

Handshake3 exchanges local and remote service information

func ID

func ID(c Conn) string

ID returns the ID of a given Conn.

func ReleaseBuffer

func ReleaseBuffer(b []byte)

ReleaseBuffer puts the given byte array back into the buffer pool, first verifying that it is the correct size

func String

func String(c Conn, typ string) string

String returns the user-friendly String representation of a conn

Types

type Conn

type Conn interface {
	// implement ContextCloser too!
	ctxc.ContextCloser

	// ID is an identifier unique to this connection.
	ID() string

	// LocalMultiaddr is the Multiaddr on this side
	LocalMultiaddr() ma.Multiaddr

	// LocalPeer is the Peer on our side of the connection
	LocalPeer() peer.Peer

	// RemoteMultiaddr is the Multiaddr on the remote side
	RemoteMultiaddr() ma.Multiaddr

	// RemotePeer is the Peer on the remote side
	RemotePeer() peer.Peer

	// In returns a readable message channel
	In() <-chan []byte

	// Out returns a writable message channel
	Out() chan<- []byte

	// Get an error from this conn if one is available
	// TODO: implement a better error handling system
	GetError() error
}

Conn is a generic message-based Peer-to-Peer connection.

type Dialer

type Dialer struct {

	// LocalPeer is the identity of the local Peer.
	LocalPeer peer.Peer

	// Peerstore is the set of peers we know about locally. The Dialer needs it
	// because when an incoming connection is identified, we should reuse the
	// same peer objects (otherwise things get inconsistent).
	Peerstore peer.Peerstore
}

Dialer is an object that can open connections. We could have a "convenience" Dial function as before, but it would have many arguments, as dialing is no longer simple (need a peerstore, a local peer, a context, a network, etc)

func (*Dialer) Dial

func (d *Dialer) Dial(ctx context.Context, network string, remote peer.Peer) (Conn, error)

Dial connects to a particular peer, over a given network Example: d.Dial(ctx, "udp", peer)

func (*Dialer) DialAddr

func (d *Dialer) DialAddr(ctx context.Context, raddr ma.Multiaddr, remote peer.Peer) (Conn, error)

DialAddr connects to a peer over a particular address Ensures raddr is part of peer.Addresses() Example: d.DialAddr(ctx, peer.Addresses()[0], peer)

type Duplex

type Duplex struct {
	In  chan []byte
	Out chan []byte
}

Duplex is a simple duplex channel

type Listener

type Listener interface {

	// Accept waits for and returns the next connection to the listener.
	Accept() <-chan Conn

	// Multiaddr is the identity of the local Peer.
	Multiaddr() ma.Multiaddr

	// LocalPeer is the identity of the local Peer.
	LocalPeer() peer.Peer

	// Peerstore is the set of peers we know about locally. The Listener needs it
	// because when an incoming connection is identified, we should reuse the
	// same peer objects (otherwise things get inconsistent).
	Peerstore() peer.Peerstore

	// Close closes the listener.
	// Any blocked Accept operations will be unblocked and return errors.
	Close() error
}

Listener is an object that can accept connections. It matches net.Listener

func Listen

func Listen(ctx context.Context, addr ma.Multiaddr, local peer.Peer, peers peer.Peerstore) (Listener, error)

Listen listens on the particular multiaddr, with given peer and peerstore.

type Map

type Map map[u.Key]Conn

Map maps Keys (Peer.IDs) to Connections.

type MultiConn

type MultiConn struct {

	// for adding/removing connections concurrently
	sync.RWMutex
	ctxc.ContextCloser
	// contains filtered or unexported fields
}

MultiConn represents a single connection to another Peer (IPFS Node).

func NewMultiConn

func NewMultiConn(ctx context.Context, local, remote peer.Peer, conns []Conn) (*MultiConn, error)

NewMultiConn constructs a new connection

func (*MultiConn) Add

func (c *MultiConn) Add(conns ...Conn)

Add adds given Conn instances to multiconn.

func (*MultiConn) BestConn

func (c *MultiConn) BestConn() Conn

BestConn is the best connection in this MultiConn

func (*MultiConn) GetError

func (c *MultiConn) GetError() error

func (*MultiConn) ID

func (c *MultiConn) ID() string

ID is an identifier unique to this connection. In MultiConn, this is all the children IDs XORed together.

func (*MultiConn) In

func (c *MultiConn) In() <-chan []byte

In returns a readable message channel

func (*MultiConn) LocalMultiaddr

func (c *MultiConn) LocalMultiaddr() ma.Multiaddr

LocalMultiaddr is the Multiaddr on this side

func (*MultiConn) LocalPeer

func (c *MultiConn) LocalPeer() peer.Peer

LocalPeer is the Peer on this side

func (*MultiConn) Out

func (c *MultiConn) Out() chan<- []byte

Out returns a writable message channel

func (*MultiConn) RemoteMultiaddr

func (c *MultiConn) RemoteMultiaddr() ma.Multiaddr

RemoteMultiaddr is the Multiaddr on the remote side

func (*MultiConn) RemotePeer

func (c *MultiConn) RemotePeer() peer.Peer

RemotePeer is the Peer on the remote side

func (*MultiConn) Remove

func (c *MultiConn) Remove(conns ...Conn)

Remove removes given Conn instances from multiconn.

func (*MultiConn) String

func (c *MultiConn) String() string

type MultiConnMap

type MultiConnMap map[u.Key]*MultiConn

MultiConnMap is for shorthand

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳