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: 4, MaxMsgSize: 10 * 1024 * 1024, Messages: []interface{}{ HandshakeMsg{}, }, }
BzzSpec is the spec of the generic swarm handshake
var DiscoverySpec = &protocols.Spec{
Name: "hive",
Version: 4,
MaxMsgSize: 10 * 1024 * 1024,
Messages: []interface{}{
peersMsg{},
subPeersMsg{},
},
}
DiscoverySpec is the spec for the bzz discovery subprotocols
Functions ¶
func NewNodeIDFromAddr ¶
NewNodeIDFromAddr transforms the underlay address to an adapters.NodeID
func NewPeerPotMap ¶
NewPeerPotMap creates a map of pot record of OverlayAddr with keys as hexadecimal representations of the address.
func NotifyDepth ¶
NotifyDepth sends a message to all connections if depth of saturation is changed
func NotifyPeer ¶
func NotifyPeer(p OverlayAddr, k Overlay)
NotifyPeer informs all peers about a newly added node
func ToOverlayAddr ¶
ToOverlayAddr creates an overlayaddress from a byte slice
Types ¶
type Addr ¶
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 ¶
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 ¶
APIs returns the APIs offered by bzz * hive Bzz implements the node.Service interface
func (*Bzz) GetHandshake ¶
func (b *Bzz) GetHandshake(peerID discover.NodeID) (*HandshakeMsg, bool)
GetHandshake returns the bzz handhake that the remote peer with peerID sent
func (*Bzz) NodeInfo ¶
func (b *Bzz) NodeInfo() interface{}
NodeInfo returns the node's overlay address
func (*Bzz) Protocols ¶
Protocols return the protocols swarm offers Bzz implements the node.Service interface * handshake/hive * discovery
func (*Bzz) RunProtocol ¶
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 ¶
UpdateLocalAddr updates underlayaddress of the running node
type BzzAddr ¶
BzzAddr implements the PeerAddr interface
func NewAddrFromNodeID ¶
NewAddrFromNodeID constucts a BzzAddr from a discover.NodeID the overlay address is derived as the hash of the nodeID
func NewAddrFromNodeIDAndPort ¶
NewAddrFromNodeIDAndPort constucts a BzzAddr from a discover.NodeID and port uint16 the overlay address is derived as the hash of the nodeID
func RandomAddr ¶
func RandomAddr() *BzzAddr
RandomAddr is a utility method generating an address from a public key
func (*BzzAddr) Update ¶
func (a *BzzAddr) Update(na OverlayAddr) OverlayAddr
Update updates the underlay address of a peer record
type BzzConfig ¶
type BzzConfig struct { OverlayAddr []byte // base address of the overlay network UnderlayAddr []byte // node's underlay address HiveParams *HiveParams NetworkID uint64 }
BzzConfig captures the config params used by the hive
type BzzPeer ¶
type BzzPeer struct { *protocols.Peer // represents the connection for online peers *BzzAddr // remote address -> implements Addr interface = protocols.Peer // 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 (*BzzPeer) LastActive ¶
LastActive returns the time the peer was last active
func (*BzzPeer) Off ¶
func (p *BzzPeer) Off() OverlayAddr
Off returns the overlay peer record for offline persistence
type Conn ¶
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(interface{}) error // can send messages Drop(error) // disconnect this peer Run(func(interface{}) error) error // the run function to run a protocol Off() OverlayAddr }
Conn interface represents an live peer connection
type HandshakeMsg ¶
type HandshakeMsg struct { Version uint64 NetworkID uint64 Addr *BzzAddr // 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 ¶
func (bh *HandshakeMsg) String() string
String pretty prints the handshake
type Health ¶
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 ¶
func (h *Hive) NodeInfo() interface{}
NodeInfo function is used by the p2p.server RPC interface to display protocol specific node information
func (*Hive) PeerInfo ¶
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 ¶
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 ¶
func NewKadParams() *KadParams
NewKadParams returns a params struct with default values
type Kademlia ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Healthy reports the health state of the kademlia connectivity returns a Health struct
func (*Kademlia) NeighbourhoodDepthC ¶
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 ¶
func (k *Kademlia) Off(p OverlayConn)
Off removes a peer from among live peers
func (*Kademlia) On ¶
func (k *Kademlia) On(p OverlayConn) (uint8, bool)
On inserts the peer as a kademlia peer into the live peers
func (*Kademlia) Register ¶
func (k *Kademlia) Register(peers []OverlayAddr) error
Register enters each OverlayAddr as kademlia peer record into the database of known peer addresses
func (*Kademlia) SuggestPeer ¶
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 ¶
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 ¶
type OverlayAddr interface { OverlayPeer Update(OverlayAddr) OverlayAddr // returns the updated version of the original }
OverlayAddr represents a kademlia peer record
type OverlayConn ¶
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 ¶
type OverlayPeer interface {
Address() []byte
}
OverlayPeer interface captures the common aspect of view of a peer from the Overlay topology driver