networking

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxOCRMsgLength is the maximum allowed length for a data payload in bytes
	// This is exported as serialization tests depend on it.
	// NOTE: This is slightly larger than 2x of the largest message we can
	// possibly send, assuming N=31.
	MaxOCRMsgLength = 10000
)

Variables

This section is empty.

Functions

func NewPeer

func NewPeer(c PeerConfig) (*concretePeer, error)

NewPeer constructs a new peer, consisting of the v1 and/or v2 sub-peers depending on the networking stack requested in PeerConfig. Specifically: NetworkingStackV1: only the v1 peer is started NetworkingStackV2: only the v2 peer is started NetworkingStackV1V2: both v1 and v2 are started, and NewPeer will fail if either fails to start.

Users are expected to create (using the OCR*Factory() methods) and close endpoints and bootstrappers before calling Close() on the peer itself.

Types

type BinaryNetworkEndpointLimits

type BinaryNetworkEndpointLimits struct {
	MaxMessageLength          int
	MessagesRatePerOracle     float64
	MessagesCapacityPerOracle int
	BytesRatePerOracle        float64
	BytesCapacityPerOracle    int
}

type EndpointConfigV1

type EndpointConfigV1 struct {
	// IncomingMessageBufferSize is the per-remote number of incoming
	// messages to buffer. Any additional messages received on top of those
	// already in the queue will be dropped.
	IncomingMessageBufferSize int

	// OutgoingMessageBufferSize is the per-remote number of outgoing
	// messages to buffer. Any additional messages send on top of those
	// already in the queue will displace the oldest.
	// NOTE: OutgoingMessageBufferSize should be comfortably smaller than remote's
	// IncomingMessageBufferSize to give the remote enough space to process
	// them all in case we regained connection and now send a bunch at once
	OutgoingMessageBufferSize int

	// NewStreamTimeout is the maximum length of time to wait to open a
	// stream before we give up.
	// We shouldn't hit this in practice since libp2p will give up fast if
	// it can't get a connection, but it is here anyway as a failsafe.
	// Set to 0 to disable any timeout on top of what libp2p gives us by default.
	NewStreamTimeout time.Duration

	// DHTLookupInterval is the interval between which we do the expensive peer
	// lookup using DHT.
	//
	// Every DHTLookupInterval failures to open a stream to a peer, we will
	// attempt to lookup its IP from DHT
	DHTLookupInterval int

	// Interval at which nodes check connections to bootstrap nodes and reconnect if any of them is lost.
	// Setting this to a small value would allow newly joined bootstrap nodes to get more connectivity
	// more quickly, which helps to make bootstrap process faster. The cost of this operation is relatively
	// cheap. We set this to 1 minute during our test.
	BootstrapCheckInterval time.Duration
}

type EndpointConfigV2

type EndpointConfigV2 struct {
	// IncomingMessageBufferSize is the per-remote number of incoming
	// messages to buffer. Any additional messages received on top of those
	// already in the queue will be dropped.
	IncomingMessageBufferSize int

	// OutgoingMessageBufferSize is the per-remote number of outgoing
	// messages to buffer. Any additional messages send on top of those
	// already in the queue will displace the oldest.
	// NOTE: OutgoingMessageBufferSize should be comfortably smaller than remote's
	// IncomingMessageBufferSize to give the remote enough space to process
	// them all in case we regained connection and now send a bunch at once
	OutgoingMessageBufferSize int
}

type NetworkingStack

type NetworkingStack uint8
const (
	NetworkingStackV1 NetworkingStack
	NetworkingStackV2
	NetworkingStackV1V2
)

func (NetworkingStack) MarshalText

func (n NetworkingStack) MarshalText() (text []byte, err error)

func (NetworkingStack) String

func (n NetworkingStack) String() string

func (*NetworkingStack) UnmarshalText

func (n *NetworkingStack) UnmarshalText(text []byte) error

type PeerConfig

type PeerConfig struct {
	// NetworkingStack declares which network stack will be used: v1, v2 or both (prefer v2).
	NetworkingStack NetworkingStack
	PrivKey         p2pcrypto.PrivKey
	Logger          commontypes.Logger

	V1ListenIP   net.IP
	V1ListenPort uint16
	// V1AnnounceIP _should not_ be an unspecified IP (https://pkg.go.dev/net#IP.IsUnspecified), otherwise V1 peer
	// discovery will not work. V1ListenIP might be an unspecified IP, so be careful!
	// For auto-detection of the V1 announce IP and port based on V1ListenIP and V1ListenPort, you should leave both
	// V1AnnounceIP and V1AnnouncePort unspecified!
	V1AnnounceIP net.IP
	// V1AnnouncePort should be set if and only if V1AnnounceIP is also set.
	V1AnnouncePort uint16
	V1Peerstore    p2ppeerstore.Peerstore

	// This should be 0 most of times, but when needed (eg when counter is somehow rolled back)
	// users can bump this value to manually bump the counter.
	V1DHTAnnouncementCounterUserPrefix uint32

	// V2ListenAddresses contains the addresses the peer will listen to on the network in <ip>:<port> form as
	// accepted by net.Listen.
	V2ListenAddresses []string

	// V2AnnounceAddresses contains the addresses the peer will advertise on the network in <host>:<port> form as
	// accepted by net.Dial. The addresses should be reachable by peers of interest.
	// May be left unspecified, in which case the announce addresses are auto-detected based on V2ListenAddresses.
	V2AnnounceAddresses []string

	// Every V2DeltaReconcile a Reconcile message is sent to every peer.
	V2DeltaReconcile time.Duration

	// Dial attempts will be at least V2DeltaDial apart.
	V2DeltaDial time.Duration

	V2DiscovererDatabase nettypes.DiscovererDatabase

	V1EndpointConfig EndpointConfigV1
	V2EndpointConfig EndpointConfigV2
}

PeerConfig configures the peer. A peer can operate with the v1 or v2 or both networking stacks, depending on the NetworkingStack set. The options for each stack are clearly marked, those for v1 start with V1 and those for v2 start with V2. Only the options for the desired stack(s) need to be set.

Directories

Path Synopsis
Package knockingTLS is a wrapper around the TLS transport to provide server identity privacy from unauthorized clients.
Package knockingTLS is a wrapper around the TLS transport to provide server identity privacy from unauthorized clients.

Jump to

Keyboard shortcuts

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