Documentation ¶
Index ¶
- Constants
- Variables
- func ParseListeners(addrs []string) ([]net.Addr, error)
- type BroadcastParams
- type ConnPeer
- func (cp *ConnPeer) GetBanScore() uint32
- func (cp *ConnPeer) GetDisableRelayTx() bool
- func (cp *ConnPeer) GetListenAddr() string
- func (cp *ConnPeer) GetShards() []shard.Index
- func (cp *ConnPeer) HandleNewMsg(pr peer.Reply, rmsg wire.Message, buf []byte)
- func (cp *ConnPeer) IsStorageNode() bool
- func (cp *ConnPeer) OnAddr(msg *wire.MsgAddr)
- func (cp *ConnPeer) OnGetAddr(msg *wire.MsgGetAddr)
- func (cp *ConnPeer) OnRead(bytesRead int, msg wire.Message, err error)
- func (cp *ConnPeer) OnUpdatePeerInfo(msg *wire.UpdatePeerInfoMessage)
- func (cp *ConnPeer) OnUpdateShardInfo(msg *wire.UpdatePeerInfoMessage)
- func (cp *ConnPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion)
- func (cp *ConnPeer) OnWrite(bytesWritten int, msg wire.Message, err error)
- func (cp *ConnPeer) RPCListenerAddress() string
- func (cp *ConnPeer) SendHash()
- type ConnServer
- func (s *ConnServer) AddBytesReceived(bytesReceived uint64)
- func (s *ConnServer) AddBytesSent(bytesSent uint64)
- func (s *ConnServer) AddPeer(cp *ConnPeer)
- func (s *ConnServer) BanPeer(cp *ConnPeer)
- func (s *ConnServer) BroadcastMessage(msg wire.Message, par *BroadcastParams)
- func (s *ConnServer) ConnectedCount() int32
- func (s *ConnServer) HandleMessage(msg wire.Message)
- func (s *ConnServer) NetTotals() (uint64, uint64)
- func (s *ConnServer) QueryChannel() chan interface{}
- func (s *ConnServer) QueryPeerShardCount() int32
- func (s *ConnServer) QueryShardPeersAddr(shard []shard.Index) []string
- func (s *ConnServer) QueryShardPeersCount() []int32
- func (s *ConnServer) RegisterChannels(dispatch *MessagesAndReceiver)
- func (s *ConnServer) SetEnabledShards(shards []shard.Index) bool
- func (s *ConnServer) Start()
- func (s *ConnServer) Stop() error
- func (s *ConnServer) UpdatePeerInfo(shards []shard.Index)
- type ConnectNodeMsg
- type Connector
- type DisconnectNodeMsg
- type GetAddedNodesMsg
- type GetConnCountMsg
- type GetPeerShardCountMsg
- type GetPeersMsg
- type GetShardPeersAddrMsg
- type GetShardPeersCountMsg
- type GossipNode
- type MessageAndReply
- type MessagesAndReceiver
- type Multiplexer
- type NAT
- type RemoveNodeMsg
- type Tag
Constants ¶
const ( // ToStorageNode defines the role that message should be sent to storage nodes. ToStorageNode toNodeType = iota // ToMinerNode defines the role that message should be sent to miner nodes. ToMinerNode // ToAllNode defines the role that message should be sent to all nodes. ToAllNode )
const ToAllShard shard.Index = params.GenesisNumberOfShards
ToAllShard defines that the message should go to all shard.
Variables ¶
var SelfPeer = &ConnPeer{}
SelfPeer means local peer.
Functions ¶
func ParseListeners ¶
ParseListeners determines whether each listen address is IPv4 and IPv6 and returns a slice of appropriate net.Addrs to listen on with TCP. It also properly detects addresses which apply to "all interfaces" and adds the address as both IPv4 and IPv6.
Types ¶
type BroadcastParams ¶
BroadcastParams defines the broadcast params.
type ConnPeer ¶
type ConnPeer struct { // The following variables must only be used atomically CpFeeFilter int64 *peer.Peer // The following chans are used to sync blockmanager and Server. ServerPeerHandle func(p peer.Reply, msg wire.Message, buf []byte) // contains filtered or unexported fields }
ConnPeer extends the peer to maintain state shared by the Server.
func (*ConnPeer) GetBanScore ¶
GetBanScore returns the current ban score.
func (*ConnPeer) GetDisableRelayTx ¶
GetDisableRelayTx get the disable relay tx.
func (*ConnPeer) GetListenAddr ¶
GetListenAddr returns the listen address.
func (*ConnPeer) HandleNewMsg ¶
HandleNewMsg handles the new incoming msg from other peers, dispatches it to appropriate logic or layer.
func (*ConnPeer) IsStorageNode ¶
IsStorageNode returns whether connpeer is storagenode.
func (*ConnPeer) OnAddr ¶
OnAddr is invoked when a peer receives an addr bitcoin message and is used to notify the Server about advertised addresses.
func (*ConnPeer) OnGetAddr ¶
func (cp *ConnPeer) OnGetAddr(msg *wire.MsgGetAddr)
OnGetAddr is invoked when a peer receives a getaddr bitcoin message and is used to provide the peer with known addresses from the address manager.
func (*ConnPeer) OnRead ¶
OnRead is invoked when a peer receives a message and it is used to update the bytes received by the Server.
func (*ConnPeer) OnUpdatePeerInfo ¶
func (cp *ConnPeer) OnUpdatePeerInfo(msg *wire.UpdatePeerInfoMessage)
OnUpdatePeerInfo update the connected peer info.
func (*ConnPeer) OnUpdateShardInfo ¶
func (cp *ConnPeer) OnUpdateShardInfo(msg *wire.UpdatePeerInfoMessage)
OnUpdateShardInfo just use for test. todo: remove, OnUpdateShardInfo just for test
func (*ConnPeer) OnVersion ¶
func (cp *ConnPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion)
OnVersion is invoked when a peer receives a version bitcoin message and is used to negotiate the protocol version details as well as kick start the communications.
func (*ConnPeer) OnWrite ¶
OnWrite is invoked when a peer sends a message and it is used to update the bytes sent by the Server.
func (*ConnPeer) RPCListenerAddress ¶
RPCListenerAddress returns the rpc listener address.
type ConnServer ¶
type ConnServer struct { ConnectToEnoughPeers chan struct{} // contains filtered or unexported fields }
ConnServer defines the data structure of connect server.
func NewConnServer ¶
func NewConnServer(listenAddrs []string, chainParams *chaincfg.Params, newPeersServer chan *ConnPeer, donePeersServer chan *ConnPeer, isStorageNode bool) (*ConnServer, error)
NewConnServer creates a connect server.
func (*ConnServer) AddBytesReceived ¶
func (s *ConnServer) AddBytesReceived(bytesReceived uint64)
AddBytesReceived adds the passed number of bytes to the total bytes received counter for the ConnServer. It is safe for concurrent access.
func (*ConnServer) AddBytesSent ¶
func (s *ConnServer) AddBytesSent(bytesSent uint64)
AddBytesSent adds the passed number of bytes to the total bytes sent counter for the Server. It is safe for concurrent access.
func (*ConnServer) AddPeer ¶
func (s *ConnServer) AddPeer(cp *ConnPeer)
AddPeer adds a new peer that has already been connected to the Server.
func (*ConnServer) BanPeer ¶
func (s *ConnServer) BanPeer(cp *ConnPeer)
BanPeer bans a peer that has already been connected to the Server by ip.
func (*ConnServer) BroadcastMessage ¶
func (s *ConnServer) BroadcastMessage(msg wire.Message, par *BroadcastParams)
BroadcastMessage sends msg to all peers currently connected to the Server except those in the passed peers to exclude.
func (*ConnServer) ConnectedCount ¶
func (s *ConnServer) ConnectedCount() int32
ConnectedCount returns the number of currently connected peers.
func (*ConnServer) HandleMessage ¶
func (s *ConnServer) HandleMessage(msg wire.Message)
HandleMessage handle messages sent to myself.
func (*ConnServer) NetTotals ¶
func (s *ConnServer) NetTotals() (uint64, uint64)
NetTotals returns the sum of all bytes received and sent across the network for all peers. It is safe for concurrent access.
func (*ConnServer) QueryChannel ¶
func (s *ConnServer) QueryChannel() chan interface{}
QueryChannel returns the channel that query message.
func (*ConnServer) QueryPeerShardCount ¶
func (s *ConnServer) QueryPeerShardCount() int32
QueryPeerShardCount returns the number of currently connected peers shards count.
func (*ConnServer) QueryShardPeersAddr ¶
func (s *ConnServer) QueryShardPeersAddr(shard []shard.Index) []string
QueryShardPeersAddr returns connected peers address belong to the shards.
func (*ConnServer) QueryShardPeersCount ¶
func (s *ConnServer) QueryShardPeersCount() []int32
QueryShardPeersCount returns the number of currently connected peers shards count.
func (*ConnServer) RegisterChannels ¶
func (s *ConnServer) RegisterChannels(dispatch *MessagesAndReceiver)
RegisterChannels is used to register handlers.
func (*ConnServer) SetEnabledShards ¶
func (s *ConnServer) SetEnabledShards(shards []shard.Index) bool
SetEnabledShards set the enabled shards and return whether the enabled shards is set.
func (*ConnServer) Start ¶
func (s *ConnServer) Start()
Start begins accepting connections from peers.
func (*ConnServer) Stop ¶
func (s *ConnServer) Stop() error
Stop gracefully shuts down the Server by stopping and disconnecting all peers and the main listener.
func (*ConnServer) UpdatePeerInfo ¶
func (s *ConnServer) UpdatePeerInfo(shards []shard.Index)
UpdatePeerInfo broadcast UpdatePeerInfoMessage when resharding
type ConnectNodeMsg ¶
ConnectNodeMsg defines a type of query request to return connected node message.
type DisconnectNodeMsg ¶
DisconnectNodeMsg defines a type of query request to Check inbound peers
type GetAddedNodesMsg ¶
type GetAddedNodesMsg struct {
Reply chan []*ConnPeer
}
GetAddedNodesMsg defines a type of query request to return a slice of the relevant peers.
type GetConnCountMsg ¶
type GetConnCountMsg struct {
Reply chan int32
}
GetConnCountMsg defines a type of query request to return the number of connected peer.
type GetPeerShardCountMsg ¶
type GetPeerShardCountMsg struct {
Reply chan int32
}
GetPeerShardCountMsg defines a type of query request to show how many shards miner has join.
type GetPeersMsg ¶
type GetPeersMsg struct {
Reply chan []*ConnPeer
}
GetPeersMsg defines a type of query request to return all the connected peer.
type GetShardPeersAddrMsg ¶
GetShardPeersAddrMsg defines a type of query request to show the list of miners' listen address.
type GetShardPeersCountMsg ¶
type GetShardPeersCountMsg struct {
Reply chan []int32
}
GetShardPeersCountMsg defines a type of query request to show how many miners in every shard.
type GossipNode ¶
type GossipNode interface { BroadcastMessage(msg wire.Message, par *BroadcastParams) RegisterChannels(dispatch *MessagesAndReceiver) HandleMessage(msg wire.Message) }
GossipNode defines an abstract node and its given method.
var GlobalConnServer GossipNode
GlobalConnServer is used to register handler.
type MessageAndReply ¶
MessageAndReply defines the data structure that the p2p network modules will send to other modules by channel.
type MessagesAndReceiver ¶
type MessagesAndReceiver struct { Tags []Tag Channels chan *MessageAndReply }
MessagesAndReceiver defines the data structure for Register handler.
type Multiplexer ¶
type Multiplexer struct {
// contains filtered or unexported fields
}
Multiplexer defines the data structure for handler.
func MakeMultiplexer ¶
func MakeMultiplexer() *Multiplexer
MakeMultiplexer creates an empty Multiplexer.
func (*Multiplexer) Handle ¶
Handle will find the channels which the message should be transmitted according to the command of message and the given shard index, and then put the message into the channels.
func (*Multiplexer) RegisterChannels ¶
func (m *Multiplexer) RegisterChannels(dispatch *MessagesAndReceiver)
RegisterChannels is used to register the channels for message reception to the Map so that the network provider can easily find the channel and then put the message into the channel and pass it to other modules.
type NAT ¶
type NAT interface { // Get the external address from outside the NAT. GetExternalAddress() (addr net.IP, err error) // Add a port mapping for protocol ("udp" or "tcp") from external port to // internal port with description lasting for timeout. AddPortMapping(protocol string, externalPort, internalPort int, description string, timeout int) (mappedExternalPort int, err error) // Remove a previously added port mapping from external port to // internal port. DeletePortMapping(protocol string, externalPort, internalPort int) (err error) }
NAT is an interface representing a NAT traversal options for example UPNP or NAT-PMP. It provides methods to query and manipulate this traversal to allow access to services.
type RemoveNodeMsg ¶
RemoveNodeMsg defines a type of query request to remove the connection if it's suitable for cmp.