Documentation ¶
Overview ¶
Package p2p provides the peer-to-peer abstractions used across different protocols in Bee.
Index ¶
- Constants
- Variables
- func Discover(ctx context.Context, addr ma.Multiaddr, f func(ma.Multiaddr) (bool, error)) (bool, error)
- func NewBlockPeerError(duration time.Duration, err error) error
- func NewConnectionBackoffError(err error, tryAfter time.Time) error
- func NewDisconnectError(err error) error
- func NewSwarmStreamName(protocol, version, stream string) string
- func WithBlocklistStreams(dur time.Duration, spec ProtocolSpec)
- func WithDisconnectStreams(spec ProtocolSpec)
- type BlockPeerError
- type Blocklister
- type ConnectionBackoffError
- type DebugService
- type DisconnectError
- type Disconnecter
- type Halter
- type HandlerFunc
- type HandlerMiddleware
- type Headers
- type HeadlerFunc
- type IncompatibleStreamError
- type Notifier
- type Peer
- type Picker
- type PickyNotifier
- type Pinger
- type ProtocolSpec
- type ReachabilityStatus
- type ReachabilityUpdater
- type ReachableNotifier
- type Reacher
- type Service
- type Stream
- type StreamSpec
- type Streamer
- type StreamerDisconnecter
- type StreamerPinger
Constants ¶
const ( ReachabilityStatusUnknown = ReachabilityStatus(network.ReachabilityUnknown) ReachabilityStatusPublic = ReachabilityStatus(network.ReachabilityPublic) ReachabilityStatusPrivate = ReachabilityStatus(network.ReachabilityPrivate) )
const (
DefaultBlocklistTime = 1 * time.Minute
)
const (
HeaderNameTracingSpanContext = "tracing-span-context"
)
Common header names.
Variables ¶
var ( // ErrPeerNotFound should be returned by p2p service methods when the requested // peer is not found. ErrPeerNotFound = errors.New("peer not found") // ErrAlreadyConnected is returned if connect was called for already connected node. ErrAlreadyConnected = errors.New("already connected") // ErrDialLightNode is returned if connect was attempted to a light node. ErrDialLightNode = errors.New("target peer is a light node") // ErrPeerBlocklisted is returned if peer is on blocklist ErrPeerBlocklisted = errors.New("peer blocklisted") )
var ErrUnexpected = errors.New("unexpected request while in light mode")
Functions ¶
func NewBlockPeerError ¶ added in v0.3.0
NewBlockPeerError wraps error and creates a special error that is treated specially by p2p. It causes peer to be disconnected and blocks any new connection for this peer for the provided duration.
func NewConnectionBackoffError ¶
NewConnectionBackoffError creates new `ConnectionBackoffError` with provided underlying error and `tryAfter` timestamp.
func NewDisconnectError ¶
NewDisconnectError wraps error and creates a special error that is treated specially by p2p. It causes peer to disconnect.
func NewSwarmStreamName ¶
NewSwarmStreamName constructs a libp2p compatible stream name out of protocol name and version and stream name.
func WithBlocklistStreams ¶ added in v0.6.0
func WithBlocklistStreams(dur time.Duration, spec ProtocolSpec)
WithBlocklistStreams will mutate the given spec and replace the handler with a always erroring one.
func WithDisconnectStreams ¶ added in v0.6.0
func WithDisconnectStreams(spec ProtocolSpec)
WithDisconnectStreams will mutate the given spec and replace the handler with a always erroring one.
Types ¶
type BlockPeerError ¶ added in v0.3.0
type BlockPeerError struct {
// contains filtered or unexported fields
}
func (*BlockPeerError) Duration ¶ added in v0.3.0
func (e *BlockPeerError) Duration() time.Duration
Duration represents the period for which the peer will be blocked. 0 duration is treated as infinity
func (*BlockPeerError) Error ¶ added in v0.3.0
func (e *BlockPeerError) Error() string
Error implements function of the standard go error interface.
func (*BlockPeerError) Unwrap ¶ added in v0.3.0
func (e *BlockPeerError) Unwrap() error
Unwrap returns an underlying error.
type Blocklister ¶ added in v1.2.0
type ConnectionBackoffError ¶
type ConnectionBackoffError struct {
// contains filtered or unexported fields
}
ConnectionBackoffError indicates that connection calls will not be executed until `tryAfter` timetamp. The reason is provided in the wrappped error.
func (*ConnectionBackoffError) Error ¶
func (e *ConnectionBackoffError) Error() string
Error implements function of the standard go error interface.
func (*ConnectionBackoffError) TryAfter ¶
func (e *ConnectionBackoffError) TryAfter() time.Time
TryAfter returns a tryAfter timetamp.
func (*ConnectionBackoffError) Unwrap ¶
func (e *ConnectionBackoffError) Unwrap() error
Unwrap returns an underlying error.
type DebugService ¶ added in v0.2.0
type DebugService interface { Service SetWelcomeMessage(val string) error GetWelcomeMessage() string }
DebugService extends the Service with method used for debugging.
type DisconnectError ¶
type DisconnectError struct {
// contains filtered or unexported fields
}
DisconnectError is an error that is specifically handled inside p2p. If returned by specific protocol handler it causes peer disconnect.
func (*DisconnectError) Error ¶
func (e *DisconnectError) Error() string
Error implements function of the standard go error interface.
func (*DisconnectError) Unwrap ¶
func (e *DisconnectError) Unwrap() error
Unwrap returns an underlying error.
type Disconnecter ¶ added in v0.4.0
type Disconnecter interface { Disconnect(overlay swarm.Address, reason string) error Blocklister }
type Halter ¶ added in v0.6.2
type Halter interface {
// Halt new incoming connections while shutting down
Halt()
}
type HandlerFunc ¶
HandlerFunc handles a received Stream from a Peer.
type HandlerMiddleware ¶
type HandlerMiddleware func(HandlerFunc) HandlerFunc
HandlerMiddleware decorates a HandlerFunc by returning a new one.
type HeadlerFunc ¶
HeadlerFunc is returning response headers based on the received request headers.
type IncompatibleStreamError ¶
type IncompatibleStreamError struct {
// contains filtered or unexported fields
}
IncompatibleStreamError is the error that should be returned by p2p service NewStream method when the stream or its version is not supported.
func NewIncompatibleStreamError ¶
func NewIncompatibleStreamError(err error) *IncompatibleStreamError
NewIncompatibleStreamError wraps the error that is the cause of stream incompatibility with IncompatibleStreamError that it can be detected and returns it.
func (*IncompatibleStreamError) Error ¶
func (e *IncompatibleStreamError) Error() string
Error implements function of the standard go error interface.
func (*IncompatibleStreamError) Unwrap ¶
func (e *IncompatibleStreamError) Unwrap() error
Unwrap returns an underlying error.
type PickyNotifier ¶ added in v0.5.3
type PickyNotifier interface { Picker Notifier ReachabilityUpdater ReachableNotifier }
PickyNotifier can decide whether a peer should be picked
type Pinger ¶ added in v1.1.0
type Pinger interface {
Ping(ctx context.Context, addr ma.Multiaddr) (rtt time.Duration, err error)
}
Pinger interface is used to ping a underlay address which is not yet known to the bee node. It uses libp2p's default ping protocol. This is different from the PingPong protocol as this is meant to be used before we know a particular underlay and we can consider it useful
type ProtocolSpec ¶
type ProtocolSpec struct { Name string Version string StreamSpecs []StreamSpec ConnectIn func(context.Context, Peer) error ConnectOut func(context.Context, Peer) error DisconnectIn func(Peer) error DisconnectOut func(Peer) error }
ProtocolSpec defines a collection of Stream specifications with handlers.
type ReachabilityStatus ¶ added in v1.4.0
type ReachabilityStatus network.Reachability
ReachabilityStatus represents the node reachability status.
func (ReachabilityStatus) String ¶ added in v1.4.0
func (rs ReachabilityStatus) String() string
String implements the fmt.Stringer interface.
type ReachabilityUpdater ¶ added in v1.4.0
type ReachabilityUpdater interface {
UpdateReachability(ReachabilityStatus)
}
type ReachableNotifier ¶ added in v1.4.0
type ReachableNotifier interface {
Reachable(swarm.Address, ReachabilityStatus)
}
type Service ¶
type Service interface { AddProtocol(ProtocolSpec) error // Connect to a peer but do not notify topology about the established connection. Connect(ctx context.Context, addr ma.Multiaddr) (address *bzz.Address, err error) Disconnecter Peers() []Peer BlocklistedPeers() ([]Peer, error) Addresses() ([]ma.Multiaddr, error) SetPickyNotifier(PickyNotifier) Halter }
Service provides methods to handle p2p Peers and Protocols.
type Stream ¶
type Stream interface { io.ReadWriter io.Closer ResponseHeaders() Headers Headers() Headers FullClose() error Reset() error }
Stream represent a bidirectional data Stream.
type StreamSpec ¶
type StreamSpec struct { Name string Handler HandlerFunc Headler HeadlerFunc }
StreamSpec defines a Stream handling within the protocol.
type Streamer ¶
type Streamer interface {
NewStream(ctx context.Context, address swarm.Address, h Headers, protocol, version, stream string) (Stream, error)
}
Streamer is able to create a new Stream.
type StreamerDisconnecter ¶ added in v0.4.0
type StreamerDisconnecter interface { Streamer Disconnecter }
type StreamerPinger ¶ added in v1.1.0
Directories ¶
Path | Synopsis |
---|---|
internal/handshake/pb
Package pb holds only Protocol Buffer definitions and generated code.
|
Package pb holds only Protocol Buffer definitions and generated code. |
internal/headers/pb
Package pb holds only Protocol Buffer definitions and generated code.
|
Package pb holds only Protocol Buffer definitions and generated code. |
internal/reacher
Package reacher runs a background worker that will ping peers from an internal queue and report back the reachability to the notifier.
|
Package reacher runs a background worker that will ping peers from an internal queue and report back the reachability to the notifier. |
internal/pb
Package pb holds only Protocol Buffer definitions and generated code for testing purposes.
|
Package pb holds only Protocol Buffer definitions and generated code for testing purposes. |