conn

package
Version: v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2016 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EncryptConnections = true

EncryptConnections is a global parameter because it should either be enabled or _completely disabled_. I.e. a node should only be able to talk to proper (encrypted) networks if it is encrypting all its transports. Running a node with disabled transport encryption is useful to debug the protocols, achieve implementation interop, or for private networks which -- for whatever reason -- _must_ run unencrypted.

Functions

func ID

func ID(c Conn) string

ID returns the ID of a given Conn.

func MultiaddrNetMatch

func MultiaddrNetMatch(tgt ma.Multiaddr, srcs []ma.Multiaddr) ma.Multiaddr

MultiaddrNetMatch returns the first Multiaddr found to match network.

func MultiaddrProtocolsMatch

func MultiaddrProtocolsMatch(a, b ma.Multiaddr) bool

MultiaddrProtocolsMatch returns whether two multiaddrs match in protocol stacks.

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 {
	PeerConn

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

	// can't just say "net.Conn" cause we have duplicate methods.
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	SetDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error

	msgio.Reader
	msgio.Writer
}

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

type ConnWrapper added in v0.3.2

type ConnWrapper func(transport.Conn) transport.Conn

ConnWrapper is any function that wraps a raw multiaddr connection

type Dialer

type Dialer struct {
	// LocalPeer is the identity of the local Peer.
	LocalPeer peer.ID

	// Dialers are the sub-dialers usable by this dialer
	// selected in order based on the address being dialed
	Dialers []transport.Dialer

	// PrivateKey used to initialize a secure connection.
	// Warning: if PrivateKey is nil, connection will not be secured.
	PrivateKey ic.PrivKey

	// Wrapper to wrap the raw connection (optional)
	Wrapper WrapFunc
}

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 NewDialer added in v0.3.10

func NewDialer(p peer.ID, pk ci.PrivKey, wrap WrapFunc) *Dialer

func (*Dialer) AddDialer added in v0.3.10

func (d *Dialer) AddDialer(pd transport.Dialer)

func (*Dialer) Dial

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

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

func (*Dialer) String

func (d *Dialer) String() string

String returns the string rep of d.

type Listener

type Listener interface {

	// Accept waits for and returns the next connection to the listener.
	Accept() (net.Conn, error)

	// Addr is the local address
	Addr() net.Addr

	// Multiaddr is the local multiaddr address
	Multiaddr() ma.Multiaddr

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

	SetAddrFilters(*filter.Filters)

	// 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 WrapTransportListener added in v0.3.10

func WrapTransportListener(ctx context.Context, ml transport.Listener, local peer.ID, sk ic.PrivKey) (Listener, error)

type ListenerConnWrapper added in v0.3.2

type ListenerConnWrapper interface {
	SetConnWrapper(ConnWrapper)
}

type Map

type Map map[key.Key]Conn

Map maps Keys (Peer.IDs) to Connections.

type PeerConn

type PeerConn interface {
	io.Closer

	// LocalPeer (this side) ID, PrivateKey, and Address
	LocalPeer() peer.ID
	LocalPrivateKey() ic.PrivKey
	LocalMultiaddr() ma.Multiaddr

	// RemotePeer ID, PublicKey, and Address
	RemotePeer() peer.ID
	RemotePublicKey() ic.PubKey
	RemoteMultiaddr() ma.Multiaddr
}

type WrapFunc added in v0.3.10

type WrapFunc func(transport.Conn) transport.Conn

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