Documentation ¶
Index ¶
- Constants
- Variables
- func Label(e *entry) string
- func LogAddrs(nns [][]byte) string
- func NewNodeIDFromAddr(addr Addr) discover.NodeID
- func NewPeerPotMap(kadMinProxSize int, addrs [][]byte) map[string]*PeerPot
- func NotifyDepth(depth uint8, h Overlay)
- func NotifyPeer(p OverlayAddr, k Overlay)
- func ToOverlayAddr(id []byte) []byte
- type Addr
- type Bzz
- func (b *Bzz) APIs() []rpc.API
- func (b *Bzz) GetHandshake(peerID discover.NodeID) (*HandshakeMsg, bool)
- func (b *Bzz) NodeInfo() interface{}
- func (b *Bzz) Protocols() []p2p.Protocol
- func (b *Bzz) RunProtocol(spec *protocols.Spec, run func(*BzzPeer) error) func(*p2p.Peer, p2p.MsgReadWriter) error
- func (b *Bzz) UpdateLocalAddr(byteaddr []byte) *BzzAddr
- type BzzAddr
- type BzzConfig
- type BzzPeer
- type Conn
- type HandshakeMsg
- type Health
- type Hive
- type HiveParams
- type KadParams
- type Kademlia
- func (k *Kademlia) AddrCountC() <-chan int
- func (k *Kademlia) BaseAddr() []byte
- func (k *Kademlia) EachAddr(base []byte, o int, f func(OverlayAddr, int, bool) bool)
- func (k *Kademlia) EachBin(base []byte, pof pot.Pof, o int, ...)
- func (k *Kademlia) EachConn(base []byte, o int, f func(OverlayConn, int, bool) bool)
- func (k *Kademlia) Healthy(pp *PeerPot) *Health
- func (k *Kademlia) NeighbourhoodDepthC() <-chan int
- func (k *Kademlia) Off(p OverlayConn)
- func (k *Kademlia) On(p OverlayConn) (uint8, bool)
- func (k *Kademlia) Register(peers []OverlayAddr) error
- func (k *Kademlia) String() string
- func (k *Kademlia) SuggestPeer() (a OverlayAddr, o int, want bool)
- type Overlay
- type OverlayAddr
- type OverlayConn
- type OverlayPeer
- type Peer
- type PeerPot
Constants ¶
const ( DefaultNetworkID = 3 // ProtocolMaxMsgSize maximum allowed message size ProtocolMaxMsgSize = 10 * 1024 * 1024 )
Variables ¶
var BzzSpec = &protocols.Spec{ Name: "bzz", Version: 5, MaxMsgSize: 10 * 1024 * 1024, Messages: []interface{}{ HandshakeMsg{}, }, }
BzzSpec is the spec of the generic swarm handshake
var DiscoverySpec = &protocols.Spec{
Name: "hive",
Version: 5,
MaxMsgSize: 10 * 1024 * 1024,
Messages: []interface{}{
peersMsg{},
subPeersMsg{},
},
}
DiscoverySpec is the spec for the bzz discovery subprotocols
Functions ¶
func Label ¶ added in v1.8.12
func Label(e *entry) string
Label is a short tag for the entry for debug
func NewNodeIDFromAddr ¶ added in v1.8.12
NewNodeIDFromAddr transforms the underlay address to an adapters.NodeID
func NewPeerPotMap ¶ added in v1.8.12
NewPeerPotMap creates a map of pot record of OverlayAddr with keys as hexadecimal representations of the address.
func NotifyDepth ¶ added in v1.8.12
NotifyDepth sends a message to all connections if depth of saturation is changed
func NotifyPeer ¶ added in v1.8.12
func NotifyPeer(p OverlayAddr, k Overlay)
NotifyPeer informs all peers about a newly added node
func ToOverlayAddr ¶ added in v1.8.12
ToOverlayAddr creates an overlayaddress from a byte slice
Types ¶
type Addr ¶ added in v1.8.12
type Addr interface { OverlayPeer Over() []byte Under() []byte String() string Update(OverlayAddr) OverlayAddr }
Addr interface that peerPool needs
type Bzz ¶
Bzz is the swarm protocol bundle
func NewBzz ¶ added in v1.8.12
func NewBzz(config *BzzConfig, kad Overlay, store state.Store, streamerSpec *protocols.Spec, streamerRun func(*BzzPeer) error) *Bzz
NewBzz is the swarm protocol constructor arguments * bzz config * overlay driver * peer store
func (*Bzz) APIs ¶ added in v1.8.12
APIs returns the APIs offered by bzz * hive Bzz implements the node.Service interface
func (*Bzz) GetHandshake ¶ added in v1.8.12
func (b *Bzz) GetHandshake(peerID discover.NodeID) (*HandshakeMsg, bool)
GetHandshake returns the bzz handhake that the remote peer with peerID sent
func (*Bzz) NodeInfo ¶ added in v1.8.12
func (b *Bzz) NodeInfo() interface{}
NodeInfo returns the node's overlay address
func (*Bzz) Protocols ¶ added in v1.8.12
Protocols return the protocols swarm offers Bzz implements the node.Service interface * handshake/hive * discovery
func (*Bzz) RunProtocol ¶ added in v1.8.12
func (b *Bzz) RunProtocol(spec *protocols.Spec, run func(*BzzPeer) error) func(*p2p.Peer, p2p.MsgReadWriter) error
RunProtocol is a wrapper for swarm subprotocols returns a p2p protocol run function that can be assigned to p2p.Protocol#Run field arguments:
- p2p protocol spec
- run function taking BzzPeer as argument this run function is meant to block for the duration of the protocol session on return the session is terminated and the peer is disconnected
the protocol waits for the bzz handshake is negotiated the overlay address on the BzzPeer is set from the remote handshake
func (*Bzz) UpdateLocalAddr ¶ added in v1.8.12
UpdateLocalAddr updates underlayaddress of the running node
type BzzAddr ¶ added in v1.8.12
BzzAddr implements the PeerAddr interface
func NewAddrFromNodeID ¶ added in v1.8.12
NewAddrFromNodeID constucts a BzzAddr from a discover.NodeID the overlay address is derived as the hash of the nodeID
func NewAddrFromNodeIDAndPort ¶ added in v1.8.12
NewAddrFromNodeIDAndPort constucts a BzzAddr from a discover.NodeID and port uint16 the overlay address is derived as the hash of the nodeID
func RandomAddr ¶ added in v1.8.12
func RandomAddr() *BzzAddr
RandomAddr is a utility method generating an address from a public key
func ToAddr ¶ added in v1.8.12
func ToAddr(pa OverlayPeer) *BzzAddr
ToAddr returns the serialisable version of u
func (*BzzAddr) Address ¶ added in v1.8.12
Address implements OverlayPeer interface to be used in Overlay
func (*BzzAddr) Update ¶ added in v1.8.12
func (a *BzzAddr) Update(na OverlayAddr) OverlayAddr
Update updates the underlay address of a peer record
type BzzConfig ¶ added in v1.8.12
type BzzConfig struct { OverlayAddr []byte // base address of the overlay network UnderlayAddr []byte // node's underlay address HiveParams *HiveParams NetworkID uint64 LightNode bool }
BzzConfig captures the config params used by the hive
type BzzPeer ¶ added in v1.8.12
type BzzPeer struct { *protocols.Peer // represents the connection for online peers *BzzAddr // remote address -> implements Addr interface = protocols.Peer LightNode bool // contains filtered or unexported fields }
BzzPeer is the bzz protocol view of a protocols.Peer (itself an extension of p2p.Peer) implements the Peer interface and all interfaces Peer implements: Addr, OverlayPeer
func NewBzzTestPeer ¶ added in v1.8.12
func (*BzzPeer) LastActive ¶ added in v1.8.12
LastActive returns the time the peer was last active
func (*BzzPeer) Off ¶ added in v1.8.12
func (p *BzzPeer) Off() OverlayAddr
Off returns the overlay peer record for offline persistence
type Conn ¶ added in v1.8.12
type Conn interface { ID() discover.NodeID // the key that uniquely identifies the Node for the peerPool Handshake(context.Context, interface{}, func(interface{}) error) (interface{}, error) // can send messages Send(context.Context, interface{}) error // can send messages Drop(error) // disconnect this peer Run(func(context.Context, interface{}) error) error // the run function to run a protocol Off() OverlayAddr }
Conn interface represents an live peer connection
type HandshakeMsg ¶ added in v1.8.12
type HandshakeMsg struct { Version uint64 NetworkID uint64 Addr *BzzAddr LightNode bool // contains filtered or unexported fields }
Handshake
* Version: 8 byte integer version of the protocol * NetworkID: 8 byte integer network identifier * Addr: the address advertised by the node including underlay and overlay connecctions
func (*HandshakeMsg) String ¶ added in v1.8.12
func (bh *HandshakeMsg) String() string
String pretty prints the handshake
type Health ¶ added in v1.8.12
type Health struct { KnowNN bool // whether node knows all its nearest neighbours GotNN bool // whether node is connected to all its nearest neighbours CountNN int // amount of nearest neighbors connected to CulpritsNN [][]byte // which known NNs are missing Full bool // whether node has a peer in each kademlia bin (where there is such a peer) Hive string }
Health state of the Kademlia
type Hive ¶
type Hive struct { *HiveParams // settings Overlay // the overlay connectiviy driver Store state.Store // storage interface to save peers across sessions // contains filtered or unexported fields }
Hive manages network connections of the swarm node
func NewHive ¶
func NewHive(params *HiveParams, overlay Overlay, store state.Store) *Hive
NewHive constructs a new hive HiveParams: config parameters Overlay: connectivity driver using a network topology StateStore: to save peers across sessions
func (*Hive) NodeInfo ¶ added in v1.8.12
func (h *Hive) NodeInfo() interface{}
NodeInfo function is used by the p2p.server RPC interface to display protocol specific node information
func (*Hive) PeerInfo ¶ added in v1.8.12
PeerInfo function is used by the p2p.server RPC interface to display protocol specific information any connected peer referred to by their NodeID
type HiveParams ¶
type HiveParams struct { Discovery bool // if want discovery of not PeersBroadcastSetSize uint8 // how many peers to use when relaying MaxPeersPerRequest uint8 // max size for peer address batches KeepAliveInterval time.Duration }
HiveParams holds the config options to hive
func NewHiveParams ¶
func NewHiveParams() *HiveParams
NewHiveParams returns hive config with only the
type KadParams ¶ added in v1.8.12
type KadParams struct { // adjustable parameters MaxProxDisplay int // number of rows the table shows MinProxBinSize int // nearest neighbour core minimum cardinality MinBinSize int // minimum number of peers in a row MaxBinSize int // maximum number of peers in a row before pruning RetryInterval int64 // initial interval before a peer is first redialed RetryExponent int // exponent to multiply retry intervals with MaxRetries int // maximum number of redial attempts // function to sanction or prevent suggesting a peer Reachable func(OverlayAddr) bool }
KadParams holds the config params for Kademlia
func NewKadParams ¶ added in v1.8.12
func NewKadParams() *KadParams
NewKadParams returns a params struct with default values
type Kademlia ¶ added in v1.8.12
type Kademlia struct { *KadParams // Kademlia configuration parameters // contains filtered or unexported fields }
Kademlia is a table of live peers and a db of known peers (node records)
func NewKademlia ¶ added in v1.8.12
NewKademlia creates a Kademlia table for base address addr with parameters as in params if params is nil, it uses default values
func (*Kademlia) AddrCountC ¶ added in v1.8.12
AddrCountC returns the channel that sends a new address count value on each change. Not receiving from the returned channel will block Register function when address count value changes.
func (*Kademlia) EachAddr ¶ added in v1.8.12
EachAddr called with (base, po, f) is an iterator applying f to each known peer that has proximity order po or less as measured from the base if base is nil, kademlia base address is used
func (*Kademlia) EachConn ¶ added in v1.8.12
EachConn is an iterator with args (base, po, f) applies f to each live peer that has proximity order po or less as measured from the base if base is nil, kademlia base address is used
func (*Kademlia) Healthy ¶ added in v1.8.12
Healthy reports the health state of the kademlia connectivity returns a Health struct
func (*Kademlia) NeighbourhoodDepthC ¶ added in v1.8.12
NeighbourhoodDepthC returns the channel that sends a new kademlia neighbourhood depth on each change. Not receiving from the returned channel will block On function when the neighbourhood depth is changed.
func (*Kademlia) Off ¶ added in v1.8.12
func (k *Kademlia) Off(p OverlayConn)
Off removes a peer from among live peers
func (*Kademlia) On ¶ added in v1.8.12
func (k *Kademlia) On(p OverlayConn) (uint8, bool)
On inserts the peer as a kademlia peer into the live peers
func (*Kademlia) Register ¶ added in v1.8.12
func (k *Kademlia) Register(peers []OverlayAddr) error
Register enters each OverlayAddr as kademlia peer record into the database of known peer addresses
func (*Kademlia) String ¶ added in v1.8.12
String returns kademlia table + kaddb table displayed with ascii
func (*Kademlia) SuggestPeer ¶ added in v1.8.12
func (k *Kademlia) SuggestPeer() (a OverlayAddr, o int, want bool)
SuggestPeer returns a known peer for the lowest proximity bin for the lowest bincount below depth naturally if there is an empty row it returns a peer for that
type Overlay ¶ added in v1.8.12
type Overlay interface { // suggest peers to connect to SuggestPeer() (OverlayAddr, int, bool) // register and deregister peer connections On(OverlayConn) (depth uint8, changed bool) Off(OverlayConn) // register peer addresses Register([]OverlayAddr) error // iterate over connected peers EachConn([]byte, int, func(OverlayConn, int, bool) bool) // iterate over known peers (address records) EachAddr([]byte, int, func(OverlayAddr, int, bool) bool) // pretty print the connectivity String() string // base Overlay address of the node itself BaseAddr() []byte // connectivity health check used for testing Healthy(*PeerPot) *Health }
Overlay is the interface for kademlia (or other topology drivers)
type OverlayAddr ¶ added in v1.8.12
type OverlayAddr interface { OverlayPeer Update(OverlayAddr) OverlayAddr // returns the updated version of the original }
OverlayAddr represents a kademlia peer record
type OverlayConn ¶ added in v1.8.12
type OverlayConn interface { OverlayPeer Drop(error) // call to indicate a peer should be expunged Off() OverlayAddr // call to return a persitent OverlayAddr }
OverlayConn represents a connected peer
type OverlayPeer ¶ added in v1.8.12
type OverlayPeer interface {
Address() []byte
}
OverlayPeer interface captures the common aspect of view of a peer from the Overlay topology driver
Directories ¶
Path | Synopsis |
---|---|
You can run this simulation using go run ./swarm/network/simulations/overlay.go
|
You can run this simulation using go run ./swarm/network/simulations/overlay.go |