Documentation ¶
Overview ¶
Copyright 2016 The go-ethereum Authors This file is part of the go-ethereum library.
The go-ethereum library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
The go-ethereum library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 协议处理
Index ¶
- Constants
- Variables
- func Label(e *entry) string
- func LogAddrs(nns [][]byte) string
- func NewPeerPotMap(neighbourhoodSize 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) 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 CacheItem
- type ExpirableCache
- type Fetcher
- type FetcherFactory
- type HandshakeMsg
- type Health
- type Hive
- func (h *Hive) CheckNode(n *enode.Node) bool
- func (h *Hive) ID() string
- func (h *Hive) NodeInfo() interface{}
- func (h *Hive) OnNewReceipts(address common.Address, id enode.ID, length int)
- func (h *Hive) PeerInfo(id enode.ID) interface{}
- func (h *Hive) Run(p *BzzPeer) error
- func (h *Hive) Start(server *p2p.Server) error
- func (h *Hive) Stop() error
- type HiveParams
- type KadParams
- type Kademlia
- func (k *Kademlia) BaseAddr() []byte
- func (k *Kademlia) CanProcPing(id enode.ID) bool
- func (k *Kademlia) CanProcPong(id enode.ID) bool
- func (k *Kademlia) CanSendPing(id enode.ID) bool
- func (k *Kademlia) CanStartConnect(id enode.ID) bool
- func (k *Kademlia) ClearDelay(id enode.ID, inbound bool)
- func (k *Kademlia) CloseAddrCountC()
- func (k *Kademlia) CloseNeighbourhoodDepthC()
- 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) GetConnectedNodes() (int, int)
- func (k *Kademlia) GetHealthInfo(pp *PeerPot) *Health
- func (k *Kademlia) GetIntendBinInfo(nodeAddr *BzzAddr) (int, int)
- func (k *Kademlia) IsBlocked(id enode.ID, inbound bool) bool
- func (k *Kademlia) ListKnown() []*BzzAddr
- func (k *Kademlia) NeighbourhoodDepth() (depth int)
- func (k *Kademlia) NeighbourhoodDepthC() <-chan int
- func (k *Kademlia) Off(p *Peer)
- func (k *Kademlia) On(p *Peer) (depth uint8, changed bool, err error)
- func (k *Kademlia) PeerChangedC() <-chan int
- func (k *Kademlia) Register(peers ...*BzzAddr) error
- func (k *Kademlia) Saturation() int
- func (k *Kademlia) SetDelay(id enode.ID, inbound bool)
- func (k *Kademlia) SetFilter(chain *p2p.FilterChain)
- func (k *Kademlia) ShouldAcceptConn(id enode.ID) bool
- func (k *Kademlia) String() string
- func (k *Kademlia) SuggestPeer() (suggestedPeer *BzzAddr, saturationDepth int, changed bool)
- type Peer
- type PeerPot
- type Request
- type RequestCenterFunc
- type RequestFunc
- type UDEF
Constants ¶
const (
DefaultNetworkID = 3
)
const MaxPoBin = 16
Variables ¶
var BzzSpec = &protocols.Spec{ Name: "bzz", Version: 8, MaxMsgSize: 10 * 1024 * 1024, Messages: []interface{}{ HandshakeMsg{}, }, }
BzzSpec is the spec of the generic swarm handshake
var DiscoverySpec = &protocols.Spec{
Name: "hive",
Version: 8,
MaxMsgSize: 10 * 1024 * 1024,
Messages: []interface{}{
peersMsg{},
subPeersMsg{},
},
}
DiscoverySpec is the spec for the bzz discovery subprotocols
var Pof = pot.DefaultPof(256)
var RequestTimeout = 3100 * time.Millisecond
Time to consider peer to be skipped. Also used in stream delivery.
Functions ¶
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 将新连接的Peer,通知到目前KAD桶中的所有Peer
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 NodeType uint8 BzzAccount [20]byte }
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 NewBzzPeer ¶
type ExpirableCache ¶
type ExpirableCache struct {
// contains filtered or unexported fields
}
func NewExpirableCache ¶
func NewExpirableCache(timeout time.Duration) *ExpirableCache
func (*ExpirableCache) Close ¶
func (e *ExpirableCache) Close()
func (*ExpirableCache) OnExpired ¶
func (e *ExpirableCache) OnExpired(onExpired func(string))
func (*ExpirableCache) Reset ¶
func (e *ExpirableCache) Reset(key string)
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 ¶
func NewFetcher(ctx context.Context, addr storage.Address, rf RequestFunc, crf RequestCenterFunc, 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, requestFromCenter RequestCenterFunc, 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 Account [20]byte NodeType uint8 // 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) 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 RefreshPeers time.Duration }
Hive is the logistic manager of the swarm
When the hive is started, a forever loop is launched that asks the kademlia nodetable to suggest peers to bootstrap connectivity
* Hive是节点启动器 Hive是swarm的对数距离管理器,当HIVE启动后,启动一个无限循环,请求Kademlia节点表,寻找一个启动的连接
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) CloseAddrCountC ¶
func (k *Kademlia) CloseAddrCountC()
CloseAddrCountC closes the channel returned by AddrCountC and stops sending address count change.
func (*Kademlia) CloseNeighbourhoodDepthC ¶
func (k *Kademlia) CloseNeighbourhoodDepthC()
CloseNeighbourhoodDepthC closes the channel returned by NeighbourhoodDepthC and stops sending neighbourhood change.
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) GetConnectedNodes ¶
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) GetIntendBinInfo ¶
func (*Kademlia) NeighbourhoodDepth ¶
NeighbourhoodDepth returns the depth for the pot, see depthForPot
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. TODO: Why is this exported, and if it should be; why can't we have more subscribers than one?
func (*Kademlia) PeerChangedC ¶
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) 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) SetFilter ¶
func (k *Kademlia) SetFilter(chain *p2p.FilterChain)
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 新节点地址A报告给连接点B
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.
type RequestFunc ¶
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 |
sync
|
sync |