connection

package
v0.0.0-...-4f0ab6e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2021 License: MIT Imports: 24 Imported by: 14

Documentation

Index

Constants

View Source
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
)

ToAllShard defines that the message should go to all shard.

Variables

View Source
var SelfPeer = &ConnPeer{}

SelfPeer means local peer.

Functions

func ParseListeners

func ParseListeners(addrs []string) ([]net.Addr, error)

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

type BroadcastParams struct {
	ToNode      toNodeType
	ToShard     shard.Index
	IncludeSelf bool
}

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

func (cp *ConnPeer) GetBanScore() uint32

GetBanScore returns the current ban score.

func (*ConnPeer) GetDisableRelayTx

func (cp *ConnPeer) GetDisableRelayTx() bool

GetDisableRelayTx get the disable relay tx.

func (*ConnPeer) GetListenAddr

func (cp *ConnPeer) GetListenAddr() string

GetListenAddr returns the listen address.

func (*ConnPeer) GetShards

func (cp *ConnPeer) GetShards() []shard.Index

GetShards gets all shardIndex.

func (*ConnPeer) HandleNewMsg

func (cp *ConnPeer) HandleNewMsg(pr peer.Reply, rmsg wire.Message, buf []byte)

HandleNewMsg handles the new incoming msg from other peers, dispatches it to appropriate logic or layer.

func (*ConnPeer) IsStorageNode

func (cp *ConnPeer) IsStorageNode() bool

IsStorageNode returns whether connpeer is storagenode.

func (*ConnPeer) OnAddr

func (cp *ConnPeer) OnAddr(msg *wire.MsgAddr)

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

func (cp *ConnPeer) OnRead(bytesRead int, msg wire.Message, err error)

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

func (cp *ConnPeer) OnWrite(bytesWritten int, msg wire.Message, err error)

OnWrite is invoked when a peer sends a message and it is used to update the bytes sent by the Server.

func (*ConnPeer) RPCListenerAddress

func (cp *ConnPeer) RPCListenerAddress() string

RPCListenerAddress returns the rpc listener address.

func (*ConnPeer) SendHash

func (cp *ConnPeer) SendHash()

SendHash 当新的 connpeer 启动时会启动 SendHash 协程, 负责消息发送缓冲的作用: 当缓冲区消息数大于设定缓冲数或发送超时时,节点会向相应节点发送消息.

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

type ConnectNodeMsg struct {
	Addr      string
	Permanent bool
	Reply     chan error
}

ConnectNodeMsg defines a type of query request to return connected node message.

type Connector

type Connector interface {
	UpdatePeerInfo([]shard.Index)
}

Connector is used for inject.

type DisconnectNodeMsg

type DisconnectNodeMsg struct {
	Cmp   func(*ConnPeer) bool
	Reply chan error
}

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

type GetShardPeersAddrMsg struct {
	Shard []shard.Index
	Reply chan []string
}

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

type MessageAndReply struct {
	Msg   wire.Message
	Reply peer.Reply
}

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

func (m *Multiplexer) Handle(message wire.Message, pr peer.Reply) bool

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.

func Discover

func Discover() (nat NAT, err error)

Discover searches the local network for a UPnP router returning a NAT for the network if so, nil if not.

type RemoveNodeMsg

type RemoveNodeMsg struct {
	Cmp   func(*ConnPeer) bool
	Reply chan error
}

RemoveNodeMsg defines a type of query request to remove the connection if it's suitable for cmp.

type Tag

type Tag struct {
	Msg   string
	Shard shard.Index
}

Tag is the key of multiplexer map.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL