Documentation ¶
Overview ¶
Package gossip 实现了gossip网络拓扑
Package gossip ...
Index ¶
- Constants
- Variables
- func New(mgr *p2p.Manager, subCfg []byte) p2p.IP2P
- type AddrBook
- func (a *AddrBook) AddAddress(addr *NetAddress, ka *KnownAddress)
- func (a *AddrBook) AddOurAddress(addr *NetAddress)
- func (a *AddrBook) Close()
- func (a *AddrBook) GetAddrs() []string
- func (a *AddrBook) GetPeerStat(addr string) *KnownAddress
- func (a *AddrBook) GetPeers() []*NetAddress
- func (a *AddrBook) GetPrivPubKey() (string, string)
- func (a *AddrBook) ISOurAddress(addr *NetAddress) bool
- func (a *AddrBook) IsOurStringAddress(addr string) bool
- func (a *AddrBook) RemoveAddr(peeraddr string)
- func (a *AddrBook) ResetPeerkey(privkey, pubkey string)
- func (a *AddrBook) Save()
- func (a *AddrBook) Size() int
- func (a *AddrBook) Start() error
- type BlackList
- type Cli
- func (m *Cli) BlockBroadcast(msg *queue.Message, taskindex int64)
- func (m *Cli) BroadCastTx(msg *queue.Message, taskindex int64)
- func (m *Cli) CheckPeerNatOk(addr string, info *NodeInfo) bool
- func (m *Cli) CheckSelf(addr string, nodeinfo *NodeInfo) bool
- func (m *Cli) GetAddr(peer *Peer) ([]string, error)
- func (m *Cli) GetAddrList(peer *Peer) (map[string]int64, error)
- func (m *Cli) GetBlockHeight(nodeinfo *NodeInfo) (int64, error)
- func (m *Cli) GetBlocks(msg *queue.Message, taskindex int64)
- func (m *Cli) GetHeaders(msg *queue.Message, taskindex int64)
- func (m *Cli) GetInPeersNum(peer *Peer) (int, error)
- func (m *Cli) GetMemPool(msg *queue.Message, taskindex int64)
- func (m *Cli) GetNetInfo(msg *queue.Message, taskindex int64)
- func (m *Cli) GetPeerInfo(msg *queue.Message, taskindex int64)
- func (m *Cli) SendPing(peer *Peer, nodeinfo *NodeInfo) error
- func (m *Cli) SendVersion(peer *Peer, nodeinfo *NodeInfo) (string, error)
- type Comm
- func (Comm) AddrRouteble(addrs []string, version int32, creds credentials.TransportCredentials) []string
- func (c Comm) BytesToInt32(b []byte) int32
- func (c Comm) CheckSign(in *types.P2PPing) bool
- func (c Comm) CollectPeerStat(err error, peer *Peer)
- func (c Comm) GenPrivPubkey() ([]byte, []byte, error)
- func (c Comm) GetLocalAddr() string
- func (c Comm) GrpcConfig() grpc.ServiceConfig
- func (c Comm) Int32ToBytes(n int32) []byte
- func (c Comm) NewPingData(nodeInfo *NodeInfo) (*types.P2PPing, error)
- func (c Comm) Pubkey(key string) (string, error)
- func (c Comm) RandStr(n int) string
- func (c Comm) Signature(key string, in *types.P2PPing) (*types.P2PPing, error)
- type DownloadJob
- type EventInterface
- type Invs
- type KnownAddress
- type Listener
- type MConnection
- type NetAddress
- type Node
- func (n *Node) AddCachePeer(pr *Peer)
- func (n *Node) CacheBoundsSize() int
- func (n *Node) Close()
- func (n *Node) GetActivePeers() (map[string]*Peer, map[string]*types.Peer)
- func (n *Node) GetCacheBounds() []*Peer
- func (n *Node) GetRegisterPeer(paddr string) *Peer
- func (n *Node) GetRegisterPeers() []*Peer
- func (n *Node) Has(paddr string) bool
- func (n *Node) HasCacheBound(addr string) bool
- func (n *Node) RemoveCachePeer(addr string)
- func (n *Node) SetQueueClient(client queue.Client)
- func (n *Node) Size() int
- func (n *Node) Start()
- type NodeInfo
- func (nf *NodeInfo) FetchPeerInfo(n *Node)
- func (nf *NodeInfo) Get() *NodeInfo
- func (nf *NodeInfo) GetExternalAddr() *NetAddress
- func (nf *NodeInfo) GetListenAddr() *NetAddress
- func (nf *NodeInfo) IsNatDone() bool
- func (nf *NodeInfo) IsOutService() bool
- func (nf *NodeInfo) OutSide() bool
- func (nf *NodeInfo) ServiceTy() int32
- func (nf *NodeInfo) Set(n *NodeInfo)
- func (nf *NodeInfo) SetExternalAddr(addr *NetAddress)
- func (nf *NodeInfo) SetListenAddr(addr *NetAddress)
- func (nf *NodeInfo) SetNatDone()
- func (nf *NodeInfo) SetNetSide(ok bool)
- func (nf *NodeInfo) SetServiceTy(ty int32)
- type NormalInterface
- type P2p
- type P2pserver
- func (s *P2pserver) BroadCastBlock(ctx context.Context, in *pb.P2PBlock) (*pb.Reply, error)
- func (s *P2pserver) BroadCastTx(ctx context.Context, in *pb.P2PTx) (*pb.Reply, error)
- func (s *P2pserver) Close()
- func (s *P2pserver) CollectInPeers(ctx context.Context, in *pb.P2PPing) (*pb.PeerList, error)
- func (s *P2pserver) CollectInPeers2(ctx context.Context, in *pb.P2PPing) (*pb.PeersReply, error)
- func (s *P2pserver) GetAddr(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2PAddr, error)
- func (s *P2pserver) GetAddrList(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2PAddrList, error)
- func (s *P2pserver) GetBlocks(ctx context.Context, in *pb.P2PGetBlocks) (*pb.P2PInv, error)
- func (s *P2pserver) GetData(in *pb.P2PGetData, stream pb.P2Pgservice_GetDataServer) error
- func (s *P2pserver) GetHeaders(ctx context.Context, in *pb.P2PGetHeaders) (*pb.P2PHeaders, error)
- func (s *P2pserver) GetMemPool(ctx context.Context, in *pb.P2PGetMempool) (*pb.P2PInv, error)
- func (s *P2pserver) GetPeerInfo(ctx context.Context, in *pb.P2PGetPeerInfo) (*pb.P2PPeerInfo, error)
- func (s *P2pserver) IsClose() bool
- func (s *P2pserver) Ping(ctx context.Context, in *pb.P2PPing) (*pb.P2PPong, error)
- func (s *P2pserver) ServerStreamRead(stream pb.P2Pgservice_ServerStreamReadServer) error
- func (s *P2pserver) ServerStreamSend(in *pb.P2PPing, stream pb.P2Pgservice_ServerStreamSendServer) error
- func (s *P2pserver) SoftVersion(ctx context.Context, in *pb.P2PPing) (*pb.Reply, error)
- func (s *P2pserver) Start()
- func (s *P2pserver) Version(ctx context.Context, in *pb.P2PVersion) (*pb.P2PVerAck, error)
- func (s *P2pserver) Version2(ctx context.Context, in *pb.P2PVersion) (*pb.P2PVersion, error)
- type Peer
- func (p *Peer) Addr() string
- func (p *Peer) Close()
- func (p *Peer) GetInBouns() int32
- func (p *Peer) GetPeerInfo() (*pb.P2PPeerInfo, error)
- func (p *Peer) GetPeerName() string
- func (p *Peer) GetRunning() bool
- func (p *Peer) IsPersistent() bool
- func (p *Peer) MakePersistent()
- func (p *Peer) SetAddr(addr *NetAddress)
- func (p *Peer) SetPeerName(name string)
- func (p *Peer) Start()
- type PeerInfos
- type Stat
- type Version
Constants ¶
const ( DefaultLtTxBroadCastTTL = 3 DefaultMaxTxBroadCastTTL = 25 )
TTL
const ( PeerAddrCacheNum = 1000 //接收的交易哈希过滤缓存设为mempool最大接收交易量 TxRecvFilterCacheNum = 10240 BlockFilterCacheNum = 50 //发送过滤主要用于发送时冗余检测, 发送完即可以被删除, 维护较小缓存数 TxSendFilterCacheNum = 500 BlockCacheNum = 10 MaxBlockCacheByteSize = 100 * 1024 * 1024 )
P2pCacheTxSize p2pcache size of transaction
const P2PTypeName = "gossip"
P2PTypeName p2p plugin name for gossip
const ( // Service service number Service int32 = nodeBloom + nodeNetwork + nodeGetUTXO )
const VERSION = lightBroadCastVersion
VERSION number
Variables ¶
var ( UpdateState = 2 * time.Second PingTimeout = 14 * time.Second DefaultSendTimeout = 10 * time.Second DialTimeout = 5 * time.Second StreamPingTimeout = 20 * time.Second MonitorPeerInfoInterval = 10 * time.Second MonitorPeerNumInterval = 30 * time.Second MonitorReBalanceInterval = 15 * time.Minute GetAddrFromAddrBookInterval = 5 * time.Second GetAddrFromOnlineInterval = 5 * time.Second GetAddrFromGitHubInterval = 5 * time.Minute CheckActivePeersInterVal = 5 * time.Second CheckBlackListInterVal = 30 * time.Second CheckCfgSeedsInterVal = 1 * time.Minute )
time limit for timeout
var MainNetSeeds = []string{
"39.105.112.116:9675",
"101.200.37.68:9675",
}
MainNetSeeds built-in list of seed
var TestNetSeeds = []string{
"47.97.223.101:9675",
}
TestNetSeeds test seeds of net
Functions ¶
Types ¶
type AddrBook ¶
type AddrBook struct { Quit chan struct{} // contains filtered or unexported fields }
AddrBook peer address manager
func NewAddrBook ¶
NewAddrBook create a addrbook
func (*AddrBook) AddAddress ¶
func (a *AddrBook) AddAddress(addr *NetAddress, ka *KnownAddress)
AddAddress add a address for ours NOTE: addr must not be nil
func (*AddrBook) AddOurAddress ¶
func (a *AddrBook) AddOurAddress(addr *NetAddress)
AddOurAddress add a address for ours
func (*AddrBook) GetPeerStat ¶
func (a *AddrBook) GetPeerStat(addr string) *KnownAddress
GetPeerStat get peer stat
func (*AddrBook) GetPrivPubKey ¶
GetPrivPubKey return privkey and pubkey
func (*AddrBook) ISOurAddress ¶
func (a *AddrBook) ISOurAddress(addr *NetAddress) bool
ISOurAddress determine if the address is ours
func (*AddrBook) IsOurStringAddress ¶
IsOurStringAddress determine if the address is ours
func (*AddrBook) RemoveAddr ¶
RemoveAddr remove address
func (*AddrBook) ResetPeerkey ¶
ResetPeerkey reset priv,pub key
type BlackList ¶
type BlackList struct {
// contains filtered or unexported fields
}
BlackList badpeers list
func (*BlackList) GetBadPeers ¶
GetBadPeers reurn black list peers
type Cli ¶
type Cli struct {
// contains filtered or unexported fields
}
Cli p2p client
func (*Cli) BlockBroadcast ¶
BlockBroadcast block broadcast
func (*Cli) BroadCastTx ¶
BroadCastTx broadcast transactions
func (*Cli) CheckPeerNatOk ¶
CheckPeerNatOk check peer is ok or not
func (*Cli) GetAddrList ¶
GetAddrList return a map for address-prot
func (*Cli) GetBlockHeight ¶
GetBlockHeight return block height
func (*Cli) GetHeaders ¶
GetHeaders get headers information
func (*Cli) GetInPeersNum ¶
GetInPeersNum return normal number of peers
func (*Cli) GetMemPool ¶
GetMemPool get mempool contents
func (*Cli) GetNetInfo ¶
GetNetInfo get network information
func (*Cli) GetPeerInfo ¶
GetPeerInfo return peer information
type Comm ¶
type Comm struct{}
Comm information
var P2pComm Comm
P2pComm p2p communication
func (Comm) AddrRouteble ¶
func (Comm) AddrRouteble(addrs []string, version int32, creds credentials.TransportCredentials) []string
AddrRouteble address router ,return enbale address
func (Comm) BytesToInt32 ¶
BytesToInt32 bytes to int32 type
func (Comm) CollectPeerStat ¶
CollectPeerStat collect peer stat and report
func (Comm) GenPrivPubkey ¶
GenPrivPubkey return key and pubkey in bytes
func (Comm) GetLocalAddr ¶
GetLocalAddr get local address ,return address
func (Comm) Int32ToBytes ¶
Int32ToBytes int32 to bytes type
func (Comm) NewPingData ¶
NewPingData get ping node ,return p2pping
type DownloadJob ¶
type DownloadJob struct { MaxJob int32 // contains filtered or unexported fields }
DownloadJob defines download job type
func NewDownloadJob ¶
func NewDownloadJob(p2pcli *Cli, peers []*Peer) *DownloadJob
NewDownloadJob create a downloadjob object
func (*DownloadJob) CancelJob ¶
func (d *DownloadJob) CancelJob()
CancelJob cancel the downloadjob object
func (*DownloadJob) DownloadBlock ¶
DownloadBlock download the block
func (*DownloadJob) GetFreePeer ¶
func (d *DownloadJob) GetFreePeer(blockHeight int64) *Peer
GetFreePeer get free peer ,return peer
func (*DownloadJob) ResetDownloadPeers ¶
func (d *DownloadJob) ResetDownloadPeers(peers []*Peer)
ResetDownloadPeers reset download peers
type EventInterface ¶
type EventInterface interface { BroadCastTx(msg *queue.Message, taskindex int64) GetMemPool(msg *queue.Message, taskindex int64) GetPeerInfo(msg *queue.Message, taskindex int64) GetHeaders(msg *queue.Message, taskindex int64) GetBlocks(msg *queue.Message, taskindex int64) BlockBroadcast(msg *queue.Message, taskindex int64) GetNetInfo(msg *queue.Message, taskindex int64) }
EventInterface p2p subscribe to the event hander interface
type KnownAddress ¶
type KnownAddress struct { Addr *NetAddress `json:"addr"` Attempts uint `json:"attempts"` LastAttempt time.Time `json:"lastattempt"` LastSuccess time.Time `json:"lastsuccess"` // contains filtered or unexported fields }
KnownAddress defines known address type
func (*KnownAddress) GetAttempts ¶
func (ka *KnownAddress) GetAttempts() uint
GetAttempts return attempts
type MConnection ¶
type MConnection struct {
// contains filtered or unexported fields
}
MConnection contains node, grpc client, p2pgserviceClient, netaddress, peer
func NewMConnection ¶
func NewMConnection(conn *grpc.ClientConn, remote *NetAddress, peer *Peer) *MConnection
NewMConnection wraps net.Conn and creates multiplex connection
type NetAddress ¶
NetAddress defines information about a peer on the network including its IP address, and port.
func NewNetAddress ¶
func NewNetAddress(addr net.Addr) *NetAddress
NewNetAddress returns a new NetAddress using the provided TCP address.
func NewNetAddressIPPort ¶
func NewNetAddressIPPort(ip net.IP, port uint16) *NetAddress
NewNetAddressIPPort returns a new NetAddress using the provided IP and port number.
func NewNetAddressString ¶
func NewNetAddressString(addr string) (*NetAddress, error)
NewNetAddressString returns a new NetAddress using the provided address in the form of "IP:Port". Also resolves the host if host is not an IP.
func NewNetAddressStrings ¶
func NewNetAddressStrings(addrs []string) ([]*NetAddress, error)
NewNetAddressStrings returns an array of NetAddress'es build using the provided strings.
func (*NetAddress) DialTimeout ¶
func (na *NetAddress) DialTimeout(version int32, creds credentials.TransportCredentials) (*grpc.ClientConn, error)
DialTimeout dial timeout
func (*NetAddress) Equals ¶
func (na *NetAddress) Equals(other interface{}) bool
Equals reports whether na and other are the same addresses.
func (*NetAddress) Less ¶
func (na *NetAddress) Less(other interface{}) bool
Less reports whether na and other are the less addresses
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node attribute
func (*Node) AddCachePeer ¶
AddCachePeer add cacheBound map by addr
func (*Node) CacheBoundsSize ¶
CacheBoundsSize return node cachebount size
func (*Node) GetActivePeers ¶
GetActivePeers return activities of the peers and infos
func (*Node) GetCacheBounds ¶
GetCacheBounds get node cachebounds
func (*Node) GetRegisterPeer ¶
GetRegisterPeer return one peer according to paddr
func (*Node) GetRegisterPeers ¶
GetRegisterPeers return peers
func (*Node) HasCacheBound ¶
HasCacheBound peer whether exists according to address
func (*Node) RemoveCachePeer ¶
RemoveCachePeer remove cacheBound by addr
func (*Node) SetQueueClient ¶
SetQueueClient return client for nodeinfo
type NodeInfo ¶
type NodeInfo struct { ServiceType int32 // contains filtered or unexported fields }
NodeInfo is interface object of the node
func NewNodeInfo ¶
NewNodeInfo new a node object
func (*NodeInfo) FetchPeerInfo ¶
FetchPeerInfo get peerinfo by node
func (*NodeInfo) GetExternalAddr ¶
func (nf *NodeInfo) GetExternalAddr() *NetAddress
GetExternalAddr return external address
func (*NodeInfo) GetListenAddr ¶
func (nf *NodeInfo) GetListenAddr() *NetAddress
GetListenAddr return listen address
func (*NodeInfo) IsOutService ¶
IsOutService return true and false for out service
func (*NodeInfo) SetExternalAddr ¶
func (nf *NodeInfo) SetExternalAddr(addr *NetAddress)
SetExternalAddr modidy address of the nodeinfo
func (*NodeInfo) SetListenAddr ¶
func (nf *NodeInfo) SetListenAddr(addr *NetAddress)
SetListenAddr modify listen address
func (*NodeInfo) SetServiceTy ¶
SetServiceTy set service type
type NormalInterface ¶
type NormalInterface interface { GetAddr(peer *Peer) ([]string, error) SendVersion(peer *Peer, nodeinfo *NodeInfo) (string, error) SendPing(peer *Peer, nodeinfo *NodeInfo) error GetBlockHeight(nodeinfo *NodeInfo) (int64, error) CheckPeerNatOk(addr string, nodeInfo *NodeInfo) bool GetAddrList(peer *Peer) (map[string]int64, error) GetInPeersNum(peer *Peer) (int, error) CheckSelf(addr string, nodeinfo *NodeInfo) bool }
NormalInterface subscribe to the event hander interface
func NewNormalP2PCli ¶
func NewNormalP2PCli() NormalInterface
NewNormalP2PCli produce a normal client
type P2pserver ¶
type P2pserver struct {
// contains filtered or unexported fields
}
P2pserver object information
func (*P2pserver) BroadCastBlock ¶
BroadCastBlock broadcast block of p2pserver
func (*P2pserver) BroadCastTx ¶
BroadCastTx broadcast transactions of p2pserver
func (*P2pserver) CollectInPeers ¶
CollectInPeers collect external network nodes of connect their own
func (*P2pserver) CollectInPeers2 ¶
CollectInPeers2 collect external network nodes of connect their own
func (*P2pserver) GetAddrList ¶
func (s *P2pserver) GetAddrList(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2PAddrList, error)
GetAddrList get address list , and height of address
func (*P2pserver) GetData ¶
func (s *P2pserver) GetData(in *pb.P2PGetData, stream pb.P2Pgservice_GetDataServer) error
GetData get data of p2pserver
func (*P2pserver) GetHeaders ¶
func (s *P2pserver) GetHeaders(ctx context.Context, in *pb.P2PGetHeaders) (*pb.P2PHeaders, error)
GetHeaders ger headers of p2pServer
func (*P2pserver) GetMemPool ¶
GetMemPool p2pserver queries the local mempool
func (*P2pserver) GetPeerInfo ¶
func (s *P2pserver) GetPeerInfo(ctx context.Context, in *pb.P2PGetPeerInfo) (*pb.P2PPeerInfo, error)
GetPeerInfo get peer information of p2pServer
func (*P2pserver) ServerStreamRead ¶
func (s *P2pserver) ServerStreamRead(stream pb.P2Pgservice_ServerStreamReadServer) error
ServerStreamRead server stream read of p2pserver
func (*P2pserver) ServerStreamSend ¶
func (s *P2pserver) ServerStreamSend(in *pb.P2PPing, stream pb.P2Pgservice_ServerStreamSendServer) error
ServerStreamSend serverstream send of p2pserver
func (*P2pserver) SoftVersion ¶
SoftVersion software version
func (*P2pserver) Version2 ¶
func (s *P2pserver) Version2(ctx context.Context, in *pb.P2PVersion) (*pb.P2PVersion, error)
Version2 p2pserver version
type Peer ¶
type Peer struct { IsMaxInbouds bool // contains filtered or unexported fields }
Peer object information
func NewPeer ¶
func NewPeer(conn *grpc.ClientConn, node *Node, remote *NetAddress) *Peer
NewPeer produce a peer object
func (*Peer) GetPeerInfo ¶
func (p *Peer) GetPeerInfo() (*pb.P2PPeerInfo, error)
GetPeerInfo get peer information of peer
func (*Peer) IsPersistent ¶
IsPersistent returns true if the peer is persitent, false otherwise.
func (*Peer) MakePersistent ¶
func (p *Peer) MakePersistent()
MakePersistent marks the peer as persistent.
type PeerInfos ¶
type PeerInfos struct {
// contains filtered or unexported fields
}
PeerInfos encapsulation peer information
func (*PeerInfos) FlushPeerInfos ¶
FlushPeerInfos flush peer information
func (*PeerInfos) GetPeerInfo ¶
GetPeerInfo return a infos by key
func (*PeerInfos) GetPeerInfos ¶
GetPeerInfos return a map for peerinfos
func (*PeerInfos) SetPeerInfo ¶
SetPeerInfo modify peer infos
type Version ¶
type Version struct {
// contains filtered or unexported fields
}
Version version object information
func (*Version) SetSupport ¶
SetSupport set support of version