conn

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SecioTag        = "/secio/1.0.0"
	NoEncryptionTag = "/plaintext/1.0.0"
)

Variables

View Source
var AcceptTimeout = 60 * time.Second

AcceptTimeout is the maximum duration an Accept is allowed to take. This includes the time between accepting the raw network connection, protocol selection as well as the handshake, if applicable.

View Source
var DialTimeout = 60 * time.Second

DialTimeout is the maximum duration a Dial is allowed to take. This includes the time between dialing the raw network connection, protocol selection as well the handshake, if applicable.

Functions

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 appropriate global buffer pool based on its capacity.

func WrapTransportListener

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

WrapTransportListener wraps a raw transport.Listener in an iconn.Listener. If sk is not provided, transport encryption is disabled.

The Listener will accept connections in the background and attempt to negotiate the protocol before making the wrapped connection available to Accept. If the negotiation and handshake take more than AcceptTimeout, the connection is dropped. However, note that once a connection handshake succeeds, it will wait indefinitely for an Accept call to service it (possibly consuming a goroutine).

The context covers the listener and its background activities, but not the connections once returned from Accept. Calling Close and canceling the context are equivalent.

The returned Listener implements ListenerConnWrapper.

func WrapTransportListenerWithProtector

func WrapTransportListenerWithProtector(ctx context.Context, ml transport.Listener, local peer.ID,
	sk ic.PrivKey, protec ipnet.Protector) (iconn.Listener, error)

Types

type ConnWrapper

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 ci.PrivKey

	// Protector makes dialer part of a private network.
	// It includes implementation details how connection are protected.
	// Can be nil, then dialer is in public network.
	Protector ipnet.Protector

	// Wrapper to wrap the raw connection. Can be nil.
	Wrapper ConnWrapper
	// contains filtered or unexported fields
}

Dialer is an object with a peer identity that can open connections.

NewDialer must be used to instantiate new Dialer objects.

func NewDialer

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

NewDialer creates a new Dialer object.

Before any calls to Dial are made, underlying dialers must be added with AddDialer, and Protector (if any) must be set.

func (*Dialer) AddDialer

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

AddDialer adds a sub-dialer usable by this dialer. Dialers added first will be selected first, based on the address.

func (*Dialer) Dial

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

Dial connects to a peer over a particular address. The remote peer ID is only verified if secure connections are in use. It returns once the connection is established, the protocol negotiated, and the handshake complete (if applicable).

func (*Dialer) String

func (d *Dialer) String() string

String returns the string representation of this Dialer.

type ListenerConnWrapper

type ListenerConnWrapper interface {
	// SetConnWrapper assigns a ConnWrapper to wrap all raw incoming
	// connections with. It must be called before any call to Accept.
	SetConnWrapper(ConnWrapper)
}

Jump to

Keyboard shortcuts

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