Documentation ¶
Index ¶
- Constants
- Variables
- func Label(e *entry) string
- func LogAddrs(nns [][]byte) string
- func NewPeerPotMap(kadMinProxSize int, addrs [][]byte) map[string]*PeerPot
- func NotifyDepth(depth uint8, kad *Kademlia)
- func NotifyPeer(p *BzzAddr, k *Kademlia)
- type Bzz
- func (b *Bzz) APIs() []rpc.API
- func (b *Bzz) GetHandshake(peerID enode.ID) (*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 Fetcher
- type FetcherFactory
- 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(*BzzAddr, int, bool) bool)
- func (k *Kademlia) EachBin(base []byte, pof pot.Pof, o int, eachBinFunc func(conn *Peer, po int) bool)
- func (k *Kademlia) EachConn(base []byte, o int, f func(*Peer, int, bool) bool)
- func (k *Kademlia) Healthy(pp *PeerPot) *Health
- func (k *Kademlia) NeighbourhoodDepthC() <-chan int
- func (k *Kademlia) Off(p *Peer)
- func (k *Kademlia) On(p *Peer) (uint8, bool)
- func (k *Kademlia) Register(peers ...*BzzAddr) error
- func (k *Kademlia) String() string
- func (k *Kademlia) SuggestPeer() (a *BzzAddr, o int, want bool)
- type Peer
- type PeerPot
- type Request
- type RequestFunc
Constants ¶
const ( DefaultNetworkID = 3 // ProtocolMaxMsgSize maximum allowed message size ProtocolMaxMsgSize = 10 * 1024 * 1024 )
Variables ¶
var BzzSpec = &protocols.Spec{ Name: "bzz", Version: 7, MaxMsgSize: 10 * 1024 * 1024, Messages: []interface{}{ HandshakeMsg{}, }, }
BzzSpec is the spec of the generic swarm handshake
var DiscoverySpec = &protocols.Spec{
Name: "hive",
Version: 6,
MaxMsgSize: 10 * 1024 * 1024,
Messages: []interface{}{
peersMsg{},
subPeersMsg{},
},
}
DiscoverySpec is the spec for the bzz discovery subprotocols
var RequestTimeout = 10 * time.Second
Time to consider peer to be skipped. Also used in stream delivery.
Functions ¶
func Label ¶ added in v1.8.12
func Label(e *entry) string
Label is a short tag for the entry for debug
func NewPeerPotMap ¶ added in v1.8.12
NewPeerPotMap creates a map of pot record of *BzzAddr with keys as hexadecimal representations of the address. used for testing only
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
NotifyPeer informs all peers about a newly added node
Types ¶
type Bzz ¶
Bzz is the swarm protocol bundle
func NewBzz ¶ added in v1.8.12
func NewBzz(config *BzzConfig, kad *Kademlia, 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 enode.ID) (*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 RandomAddr ¶ added in v1.8.12
func RandomAddr() *BzzAddr
RandomAddr is a utility method generating an address from a public key
func (*BzzAddr) Address ¶ added in v1.8.12
Address implements OverlayPeer interface to be used in Overlay.
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 NewBzzPeer ¶
func (*BzzPeer) LastActive ¶ added in v1.8.12
LastActive returns the time the peer was last active
type Fetcher ¶
type Fetcher struct {
// contains filtered or unexported fields
}
Fetcher is created when a chunk is not found locally. It starts a request handler loop once and keeps it alive until all active requests are completed. This can happen:
- either because the chunk is delivered
- or becuse the requestor cancelled/timed out
Fetcher self destroys itself after it is completed. TODO: cancel all forward requests after termination
func NewFetcher ¶
func NewFetcher(addr storage.Address, rf RequestFunc, skipCheck bool) *Fetcher
NewFetcher creates a new Fetcher for the given chunk address using the given request function.
type FetcherFactory ¶
type FetcherFactory struct {
// contains filtered or unexported fields
}
FetcherFactory is initialised with a request function and can create fetchers
func NewFetcherFactory ¶
func NewFetcherFactory(request RequestFunc, skipCheck bool) *FetcherFactory
NewFetcherFactory takes a request function and skip check parameter and creates a FetcherFactory
func (*FetcherFactory) New ¶
func (f *FetcherFactory) New(ctx context.Context, source storage.Address, peersToSkip *sync.Map) storage.NetFetcher
New contructs a new Fetcher, for the given chunk. All peers in peersToSkip are not requested to deliver the given chunk. peersToSkip should always contain the peers which are actively requesting this chunk, to make sure we don't request back the chunks from them. The created Fetcher is started and returned.
type HandshakeMsg ¶ added in v1.8.12
type HandshakeMsg struct { Version uint64 NetworkID uint64 ShardId uint16 Addr *BzzAddr LightNode bool // contains filtered or unexported fields }
Handshake
* Version: 8 byte integer version of the protocol * NetworkID: 8 byte integer network identifier * ShardId: 2 byte integer shard identifier 0xFFFF for master node * 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 used for testing only
type Hive ¶
type Hive struct { *HiveParams // settings *Kademlia // 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, kad *Kademlia, store state.Store) *Hive
NewHive constructs a new hive HiveParams: config parameters Kademlia: 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(*BzzAddr) 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 used for testing only
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) Register ¶ added in v1.8.12
Register enters each address as kademlia peer record into the database of known peer addresses
type Peer ¶ added in v1.8.12
type Peer struct { *BzzPeer // contains filtered or unexported fields }
Peer wraps BzzPeer and embeds Kademlia overlay connectivity driver
func (*Peer) NotifyDepth ¶
NotifyDepth sends a subPeers Msg to the receiver notifying them about a change in the depth of saturation
func (*Peer) NotifyPeer ¶
NotifyPeer notifies the remote node (recipient) about a peer if the peer's PO is within the recipients advertised depth OR the peer is closer to the recipient than self unless already notified during the connection session
type PeerPot ¶ added in v1.8.12
PeerPot keeps info about expected nearest neighbours and empty bins used for testing only
type Request ¶
type Request struct { Addr storage.Address // chunk address Source *enode.ID // nodeID of peer to request from (can be nil) SkipCheck bool // whether to offer the chunk first or deliver directly HopCount uint8 // number of forwarded requests (hops) // contains filtered or unexported fields }
func NewRequest ¶
NewRequest returns a new instance of Request based on chunk address skip check and a map of peers to skip.
Source Files ¶
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 |