Documentation
¶
Index ¶
- Constants
- Variables
- func CloseConns(conns ...Conn)
- func Handshake1(ctx context.Context, c Conn) error
- func Handshake3(ctx context.Context, c Conn) (*handshake.Handshake3Result, error)
- func ID(c Conn) string
- func ReleaseBuffer(b []byte)
- func String(c Conn, typ string) string
- type Conn
- type Dialer
- type Duplex
- type Listener
- type Map
- type MultiConn
- func (c *MultiConn) Add(conns ...Conn)
- func (c *MultiConn) BestConn() Conn
- func (c *MultiConn) GetError() error
- func (c *MultiConn) ID() string
- func (c *MultiConn) In() <-chan []byte
- func (c *MultiConn) LocalMultiaddr() ma.Multiaddr
- func (c *MultiConn) LocalPeer() peer.Peer
- func (c *MultiConn) Out() chan<- []byte
- func (c *MultiConn) RemoteMultiaddr() ma.Multiaddr
- func (c *MultiConn) RemotePeer() peer.Peer
- func (c *MultiConn) Remove(conns ...Conn)
- func (c *MultiConn) String() string
- type MultiConnMap
Constants ¶
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 ¶
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 ReleaseBuffer ¶
func ReleaseBuffer(b []byte)
ReleaseBuffer puts the given byte array back into the buffer pool, first verifying that it is the correct size
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)
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
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) 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) 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