transport

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Unlicense Imports: 28 Imported by: 0

Documentation

Overview

Package transport provides a set of definitions of abstractions that layer above the implementation enabling the use of simple functions that interact on channels to queue and receive messages from the tpt.Transport of which several variants are here implemented.

Index

Constants

View Source
const (
	// LocalhostZeroIPv4TCP is the default localhost to bind to any address. Used in
	// tests.
	LocalhostZeroIPv4TCP = "/ip4/127.0.0.1/tcp/0"

	// LocalhostZeroIPv6TCP is the default localhost to bind to any address. Used in
	// tests.
	LocalhostZeroIPv6TCP = "/ip6/::1/tcp/0"

	// DefaultMTU is the default maximum size for a packet.
	DefaultMTU = 1382

	// ConnBufs is the number of buffers to use in message dispatch channels.
	ConnBufs = 8192

	// IndraLibP2PID is the indra protocol identifier.
	IndraLibP2PID = "/indra/relay/" + indra.SemVer
)

Variables

View Source
var (
	DefaultUserAgent = "/indra:" + indra.SemVer + "/"
)

Functions

func BadgerStore added in v0.1.19

func BadgerStore(dataPath string) (datastore.Batching, func())

BadgerStore creates a new badger database backed persistence engine for keys and values used in the peer information database.

func Discover

func Discover(ctx context.Context, h host.Host, dht *dht.IpfsDHT,
	rendezvous []multiaddr.Multiaddr)

Discover uses the DHT to share and distribute peer lists between nodes on Indranet.

func GetHostFirstMultiaddr added in v0.1.20

func GetHostFirstMultiaddr(ha host.Host) string

GetHostFirstMultiaddr returns the multiaddr string encoding of a host.Host's network listener.

func GetHostMultiaddrs added in v0.1.20

func GetHostMultiaddrs(ha host.Host) (addrs []string)

GetHostMultiaddrs returns the multiaddr strings encoding of a host.Host's network listener.

This includes (the repeated) p2p key sections of the peer identity key.

func GetHostOnlyFirstMultiaddr added in v0.1.20

func GetHostOnlyFirstMultiaddr(ha host.Host) string

GetHostOnlyFirstMultiaddr returns the multiaddr string without the p2p key.

func GetHostOnlyMultiaddrs added in v0.1.20

func GetHostOnlyMultiaddrs(ha host.Host) (addrs []string)

GetHostOnlyMultiaddrs returns the multiaddr string without the p2p key.

func NewDHT

func NewDHT(ctx context.Context, host host.Host,
	bootstrapPeers []multiaddr.Multiaddr) (d *dht.IpfsDHT, e error)

NewDHT sets up a DHT for use in searching and propagating peer information.

func SetUserAgent added in v0.1.16

func SetUserAgent(s string)

SetUserAgent changes the user agent. Note that this will only have an effect before a new listener is created.

func Tick added in v0.1.20

func Tick(h host.Host, rendezvous []multiaddr.Multiaddr,
	peers <-chan peer.AddrInfo, disco *routing.RoutingDiscovery,
	ctx context.Context) (e error)

Types

type ByteChan

type ByteChan chan slice.Bytes

ByteChan is the most primitive form of an atomic FIFO queue used to dispatch jobs to a network I/O handler.

func NewByteChan

func NewByteChan(bufs int) ByteChan

NewByteChan creates a new ByteChan with a specified number of buffers.

func (ByteChan) Receive

func (s ByteChan) Receive() <-chan slice.Bytes

Receive returns the receiving side of the simplex ByteChan.

func (ByteChan) Send

func (s ByteChan) Send(b slice.Bytes) error

Send the provided buffer to the ByteChan.

type Conn

type Conn struct {

	// Conn is the actual network connection, which is a ReaderWriterCloser.
	network.Conn

	// MTU is the size of packet segments handled on the connection.
	MTU int

	// RemoteKey is the receiver public key messages should be encrypted to.
	//
	// todo: this is also handled by the dispatcher for key changes etc?
	RemoteKey *crypto.Pub

	// MultiAddr is the multiaddr.Multiaddr of the other side of the connection.
	MultiAddr multiaddr.Multiaddr

	// Host is the libp2p host implementing the Conn.
	Host host.Host

	// Transport is the duplex channel that is given to calling code to dispatch
	// messages through the Conn.
	Transport *DuplexByteChan

	// Mutex to prevent concurrent read/write of shared data.
	sync.Mutex

	// C can be closed to shut down the connection, and closes the Conn.
	qu.C
	// contains filtered or unexported fields
}

Conn is a wrapper around the bidirectional connection established between two peers via the libp2p API.

func (*Conn) GetMTU

func (c *Conn) GetMTU() int

GetMTU returns the Maximum Transmission Unit (MTU) of the Conn.

func (*Conn) GetRecv

func (c *Conn) GetRecv() tpt.Transport

GetRecv returns the Transport that is functioning as receiver, used to receive messages.

func (*Conn) GetRemoteKey

func (c *Conn) GetRemoteKey() (remoteKey *crypto.Pub)

GetRemoteKey ruturns the current remote receiver public key we want to encrypt to (with ECDH).

func (*Conn) GetSend

func (c *Conn) GetSend() tpt.Transport

GetSend returns the Transport that is functioning as sender, used to send messages.

func (*Conn) SetMTU

func (c *Conn) SetMTU(mtu int)

SetMTU defines the size of the packets messages will be segmented into.

func (*Conn) SetRemoteKey

func (c *Conn) SetRemoteKey(remoteKey *crypto.Pub)

SetRemoteKey changes the key that should be used with ECDH to generate message encryption secrets. This will be called in response to the other side sending a key change message.

type DuplexByteChan

type DuplexByteChan struct {
	// Receiver and Sender can send and receive in parallel.
	Receiver, Sender tpt.Transport
}

DuplexByteChan is intended to be connected up in chains with other processing steps as a pipeline. The send and receive functions send bytes to their respective send and receive channels, and the processing is added by a consuming type by listening to the send channel for requests to send, and forwarding data from the upstream to the recieve channel.

func NewDuplexByteChan

func NewDuplexByteChan(bufs int) *DuplexByteChan

NewDuplexByteChan creates a new DuplexByteChan with each of the two channels given a specified number of buffer queue slots.

func NewSimDuplex

func NewSimDuplex(bufs int, ctx context.Context) (d *DuplexByteChan)

NewSimDuplex creates a DuplexByteChan that behaves like a single ByteChan by forwarding from the send channel to the receiver channel. This creates something like a virtual in memory packet connection, as used in many of the Onion tests for testing correct forwarding without a full network.

A network-using version of the same tests should also work exactly the same.

func (*DuplexByteChan) Receive

func (d *DuplexByteChan) Receive() (C <-chan slice.Bytes)

Receive messages from the receiver channel of the DuplexByteChan.

func (*DuplexByteChan) Send

func (d *DuplexByteChan) Send(b slice.Bytes) (e error)

Send messages to the sender channel of the DuplexByteChan.

type Listener

type Listener struct {

	// The DHT is used by peer discovery and peer information gossip to provide
	// information to clients to enable them to set up sessions and then send traffic
	// through them.
	DHT *dht.IpfsDHT

	// MTU is the size of the packets that should be used by the dispatcher, which
	// should be the same as the Path MTU between the node and its routeable internet
	// address.
	MTU int

	// Host is the libp2p peer management system and provides access to all the
	// connectivity and related services provided by libp2p.
	Host host.Host

	// Keys are this node's identity keys, used for identification and authentication
	// of peer advertisements.
	*crypto.Keys

	// Context here allows listener processes to be signalled to shut down.
	context.Context

	// Mutex because any number of threads can be handling Listener work.
	sync.Mutex
	// contains filtered or unexported fields
}

Listener is a libp2p connected network transport with a DHT and peer information gossip exchange system that carries the advertisements for services and relays providing access to them.

func NewListener

func NewListener(rendezvous, multiAddr []string, storePath string,
	keys *crypto.Keys, ctx context.Context, mtu int) (c *Listener,
	e error)

NewListener creates a new Listener with the given parameters.

func (*Listener) Accept

func (l *Listener) Accept() <-chan *Conn

Accept waits on inbound connections and hands them out to listeners on the returned channel.

func (*Listener) AddConn

func (l *Listener) AddConn(d *Conn)

AddConn adds a new connection, including dispatching it to any callers of Accept.

func (*Listener) DelConn

func (l *Listener) DelConn(d *Conn)

DelConn closes and removes the connection from the Listener.

func (*Listener) Dial

func (l *Listener) Dial(multiAddr string) (d *Conn)

Dial creates a new Conn as an outbound connection.

func (*Listener) FindConn

func (l *Listener) FindConn(multiAddr string) (d *Conn)

FindConn searches a Listener's collection of connections for the one matching a given multiaddr string.

func (*Listener) GetConnRecv

func (l *Listener) GetConnRecv(multiAddr string) (recv tpt.Transport)

GetConnRecv searches a Listener's collection of connections for the one matching a given multiaddr string, and returns the transport for receiving messages.

func (*Listener) GetConnSend

func (l *Listener) GetConnSend(multiAddr string) (send tpt.Transport)

GetConnSend searches a Listener's collection of connections for the one matching a given multiaddr string, and returns the transport for sending messages.

func (*Listener) ProtocolsAvailable added in v0.1.19

func (l *Listener) ProtocolsAvailable() (p protocols.NetworkProtocols)

func (*Listener) SetMTU

func (l *Listener) SetMTU(mtu int)

SetMTU sets the packet segment size to be used for future connections.

Jump to

Keyboard shortcuts

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