Documentation ¶
Index ¶
- Constants
- Variables
- func Label(e *entry) string
- func LogAddrs(nns [][]byte) string
- func NewEnode(params *EnodeParams) (*enode.Node, error)
- func NewEnodeRecord(params *EnodeParams) (*enr.Record, error)
- func NewPeerPotMap(neighbourhoodSize int, addrs [][]byte) map[string]*PeerPot
- func NotifyDepth(depth uint8, kad *Kademlia)
- func NotifyPeer(p *BzzAddr, k *Kademlia)
- func PrivateKeyToBzzKey(prvKey *ecdsa.PrivateKey) []byte
- type Bzz
- func (b *Bzz) APIs() []rpc.API
- func (b *Bzz) GetOrCreateHandshake(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 ENRAddrEntry
- type ENRBootNodeEntry
- type ENRLightNodeEntry
- type EnodeParams
- type Fetcher
- type FetcherFactory
- type HandshakeMsg
- type Health
- type Hive
- type HiveParams
- type KadParams
- type Kademlia
- func (k *Kademlia) BaseAddr() []byte
- func (k *Kademlia) EachAddr(base []byte, o int, f func(*BzzAddr, int) bool)
- func (k *Kademlia) EachConn(base []byte, o int, f func(*Peer, int) bool)
- func (k *Kademlia) GetHealthInfo(pp *PeerPot) *Health
- func (k *Kademlia) ListKnown() []*BzzAddr
- func (k *Kademlia) NeighbourhoodDepth() 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) Saturation() int
- func (k *Kademlia) String() string
- func (k *Kademlia) SubscribeToNeighbourhoodDepthChange() (c <-chan struct{}, unsubscribe func())
- func (k *Kademlia) SuggestPeer() (suggestedPeer *BzzAddr, saturationDepth int, changed bool)
- type Peer
- type PeerPot
- type Request
- type RequestFunc
Constants ¶
const (
DefaultNetworkID = 4
)
Variables ¶
var BzzSpec = &protocols.Spec{ Name: "bzz", Version: 10, MaxMsgSize: 10 * 1024 * 1024, Messages: []interface{}{ HandshakeMsg{}, }, }
BzzSpec is the spec of the generic swarm handshake
var DefaultTestNetworkID = rand.Uint64()
var DiscoverySpec = &protocols.Spec{
Name: "hive",
Version: 9,
MaxMsgSize: 10 * 1024 * 1024,
Messages: []interface{}{
peersMsg{},
subPeersMsg{},
},
}
DiscoverySpec is the spec for the bzz discovery subprotocols
var Pof = pot.DefaultPof(256)
var RequestTimeout = 10 * time.Second
Time to consider peer to be skipped. Also used in stream delivery.
Functions ¶
func NewEnodeRecord ¶
func NewEnodeRecord(params *EnodeParams) (*enr.Record, error)
func NewPeerPotMap ¶
NewPeerPotMap creates a map of pot record of *BzzAddr with keys as hexadecimal representations of the address. the NeighbourhoodSize of the passed kademlia is used used for testing only TODO move to separate testing tools file
func NotifyDepth ¶
NotifyDepth sends a message to all connections if depth of saturation is changed
func NotifyPeer ¶
NotifyPeer informs all peers about a newly added node
func PrivateKeyToBzzKey ¶
func PrivateKeyToBzzKey(prvKey *ecdsa.PrivateKey) []byte
Types ¶
type Bzz ¶
Bzz is the swarm protocol bundle
func NewBzz ¶
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 ¶
APIs returns the APIs offered by bzz * hive Bzz implements the node.Service interface
func (*Bzz) GetOrCreateHandshake ¶
func (b *Bzz) GetOrCreateHandshake(peerID enode.ID) (*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 RandomAddr ¶
func RandomAddr() *BzzAddr
RandomAddr is a utility method generating an address from a public key
type BzzConfig ¶
type BzzConfig struct { OverlayAddr []byte // base address of the overlay network UnderlayAddr []byte // node's underlay address HiveParams *HiveParams NetworkID uint64 LightNode bool BootnodeMode bool }
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 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 ¶
type ENRAddrEntry ¶
type ENRAddrEntry struct {
// contains filtered or unexported fields
}
ENRAddrEntry is the entry type to store the bzz key in the enode
func NewENRAddrEntry ¶
func NewENRAddrEntry(addr []byte) *ENRAddrEntry
func (ENRAddrEntry) Address ¶
func (b ENRAddrEntry) Address() []byte
type ENRBootNodeEntry ¶
type ENRBootNodeEntry bool
func (ENRBootNodeEntry) ENRKey ¶
func (b ENRBootNodeEntry) ENRKey() string
type ENRLightNodeEntry ¶
type ENRLightNodeEntry bool
func (ENRLightNodeEntry) ENRKey ¶
func (b ENRLightNodeEntry) ENRKey() string
type EnodeParams ¶
type EnodeParams struct { PrivateKey *ecdsa.PrivateKey EnodeKey *ecdsa.PrivateKey Lightnode bool Bootnode bool }
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 because the requester cancelled/timed out
Fetcher self destroys itself after it is completed. TODO: cancel all forward requests after termination
func NewFetcher ¶
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, peers *sync.Map) storage.NetFetcher
New constructs 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 ¶
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 ¶
func (bh *HandshakeMsg) String() string
String pretty prints the handshake
type Health ¶
type Health struct { KnowNN bool // whether node knows all its neighbours CountKnowNN int // amount of neighbors known MissingKnowNN [][]byte // which neighbours we should have known but we don't ConnectNN bool // whether node is connected to all its neighbours CountConnectNN int // amount of neighbours connected to MissingConnectNN [][]byte // which neighbours we should have been connected to but we're not // Saturated: if in all bins < depth number of connections >= MinBinsize or, // if number of connections < MinBinSize, to the number of available peers in that bin Saturated bool 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 ¶
func (h *Hive) NodeInfo() interface{}
NodeInfo function is used by the p2p.server RPC interface to display protocol specific node information
func (*Hive) Peer ¶
Peer returns a bzz peer from the Hive. If there is no peer with the provided enode id, a nil value is returned.
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 NeighbourhoodSize 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 `json:"-"` }
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) EachAddr ¶
EachAddr called with (base, po, f) is an iterator applying f to each known peer that has proximity order o 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) GetHealthInfo ¶
GetHealthInfo reports the health state of the kademlia connectivity
The PeerPot argument provides an all-knowing view of the network The resulting Health object is a result of comparisons between what is the actual composition of the kademlia in question (the receiver), and what SHOULD it have been when we take all we know about the network into consideration.
used for testing only
func (*Kademlia) NeighbourhoodDepth ¶
NeighbourhoodDepth returns the value calculated by depthForPot function in setNeighbourhoodDepth method.
func (*Kademlia) Register ¶
Register enters each address as kademlia peer record into the database of known peer addresses
func (*Kademlia) Saturation ¶
Saturation returns the smallest po value in which the node has less than MinBinSize peers if the iterator reaches neighbourhood radius, then the last bin + 1 is returned
func (*Kademlia) SubscribeToNeighbourhoodDepthChange ¶
func (k *Kademlia) SubscribeToNeighbourhoodDepthChange() (c <-chan struct{}, unsubscribe func())
SubscribeToNeighbourhoodDepthChange returns the channel that signals when neighbourhood depth value is changed. The current neighbourhood depth is returned by NeighbourhoodDepth method. Returned function unsubscribes the channel from signaling and releases the resources. Returned function is safe to be called multiple times.
type Peer ¶
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 ¶
PeerPot keeps info about expected nearest neighbours used for testing only TODO move to separate testing tools file
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 |