Documentation ¶
Index ¶
- Constants
- Variables
- func NewDownloadJob(p2pcli *Cli, peers []*Peer) *downloadJob
- 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) 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) 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) []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 EventInterface
- type Filterdata
- type Listener
- type MConnConfig
- type MConnection
- type NetAddress
- func (na *NetAddress) Copy() *NetAddress
- func (na *NetAddress) DialTimeout(version int32) (*grpc.ClientConn, error)
- func (na *NetAddress) Equals(other interface{}) bool
- func (na *NetAddress) Less(other interface{}) bool
- func (na *NetAddress) Local() bool
- func (na *NetAddress) RFC1918() bool
- func (na *NetAddress) RFC3849() bool
- func (na *NetAddress) RFC3927() bool
- func (na *NetAddress) RFC3964() bool
- func (na *NetAddress) RFC4193() bool
- func (na *NetAddress) RFC4380() bool
- func (na *NetAddress) RFC4843() bool
- func (na *NetAddress) RFC4862() bool
- func (na *NetAddress) RFC6052() bool
- func (na *NetAddress) RFC6145() bool
- func (na *NetAddress) ReachabilityTo(o *NetAddress) int
- func (na *NetAddress) Routable() bool
- func (na *NetAddress) String() string
- func (na *NetAddress) Valid() bool
- 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(version int32) (*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 (
P2pCacheTxSize = 10240
)
const (
Service int32 = nodeBloom + nodeNetwork + nodeGetUTXO
)
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 = 2 * time.Minute GetAddrFromAddrBookInterval = 5 * time.Second GetAddrFromOnlineInterval = 5 * time.Second GetAddrFromGitHubInterval = 5 * time.Minute CheckActivePeersInterVal = 5 * time.Second CheckBlackListInterVal = 30 * time.Second )
var Filter = NewFilter()
var InnerSeeds = []string{
"39.107.234.240:13802",
"39.105.88.66:13802",
"39.105.87.114:13802",
"39.105.85.247:13802",
"39.105.87.106:13802",
"39.105.76.78:13802",
"39.105.82.4:13802",
"39.105.43.225:13802",
"39.107.239.248:13802",
"39.105.83.33:13802",
"120.27.234.254:13802",
"116.62.169.41:13802",
"47.97.169.229:13802",
"47.98.253.181:13802",
"47.98.252.73:13802",
"47.98.253.127:13802",
"47.98.251.119:13802",
"120.27.230.87:13802",
"47.98.59.24:13802",
"47.98.247.98:13802",
"39.108.133.129:13802",
"120.79.150.175:13802",
"39.108.97.52:13802",
"39.108.208.73:13802",
"120.78.154.251:13802",
"120.79.134.73:13802",
"120.79.174.247:13802",
"120.79.156.149:13802",
"120.78.135.23:13802",
"120.79.21.219:13802",
"47.74.248.233:13802",
"47.88.168.235:13802",
"47.74.229.169:13802",
"47.74.250.4:13802",
"47.74.157.48:13802",
"47.252.6.16:13802",
"47.90.247.202:13802",
"47.252.9.86:13802",
"47.252.13.153:13802",
"47.252.13.228:13802",
"47.254.129.47:13802",
"47.254.132.237:13802",
"47.254.150.129:13802",
"47.254.149.155:13802",
"47.254.145.252:13802",
"47.74.8.101:13802",
"47.91.19.21:13802",
"47.74.22.60:13802",
"47.74.22.86:13802",
"47.91.17.139:13802",
}
内置seed 列表
var (
LocalAddr string
)
var TestNetSeeds = []string{
"114.55.101.159:13802",
"47.104.125.151:13802",
"47.104.125.97:13802",
"47.104.125.177:13802",
}
var VERSION int32 = 119
Functions ¶
func NewDownloadJob ¶
Types ¶
type AddrBook ¶
type AddrBook struct { Quit chan struct{} // contains filtered or unexported fields }
peer address manager
func NewAddrBook ¶
func (*AddrBook) AddAddress ¶
func (a *AddrBook) AddAddress(addr *NetAddress, ka *knownAddress)
NOTE: addr must not be nil
func (*AddrBook) AddOurAddress ¶
func (a *AddrBook) AddOurAddress(addr *NetAddress)
func (*AddrBook) GetPeerStat ¶
func (*AddrBook) GetPeers ¶
func (a *AddrBook) GetPeers() []*NetAddress
func (*AddrBook) GetPrivPubKey ¶
func (*AddrBook) ISOurAddress ¶
func (a *AddrBook) ISOurAddress(addr *NetAddress) bool
func (*AddrBook) IsOurStringAddress ¶
func (*AddrBook) RemoveAddr ¶
type BlackList ¶
type BlackList struct {
// contains filtered or unexported fields
}
func (*BlackList) GetBadPeers ¶
type Cli ¶
type Cli struct {
// contains filtered or unexported fields
}
func (*Cli) CheckPeerNatOk ¶
type Comm ¶
type Comm struct{}
var P2pComm Comm
func (Comm) AddrRouteble ¶
func (Comm) BytesToInt32 ¶
func (Comm) CollectPeerStat ¶
func (Comm) GetLocalAddr ¶
func (Comm) GrpcConfig ¶
func (c Comm) GrpcConfig() grpc.ServiceConfig
func (Comm) Int32ToBytes ¶
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) }
p2p 订阅的事件处理函数接口
func NewP2PCli ¶
func NewP2PCli(network *P2p) EventInterface
type Filterdata ¶
type Filterdata struct {
// contains filtered or unexported fields
}
func NewFilter ¶
func NewFilter() *Filterdata
func (*Filterdata) Close ¶
func (f *Filterdata) Close()
func (*Filterdata) GetLock ¶
func (f *Filterdata) GetLock()
func (*Filterdata) ManageRecvFilter ¶
func (f *Filterdata) ManageRecvFilter()
func (*Filterdata) QueryRecvData ¶
func (f *Filterdata) QueryRecvData(key string) bool
func (*Filterdata) RegRecvData ¶
func (f *Filterdata) RegRecvData(key string) bool
func (*Filterdata) ReleaseLock ¶
func (f *Filterdata) ReleaseLock()
func (*Filterdata) RemoveRecvData ¶
func (f *Filterdata) RemoveRecvData(key string)
type MConnConfig ¶
type MConnConfig struct {
// contains filtered or unexported fields
}
MConnConfig is a MConnection configuration.
func DefaultMConnConfig ¶
func DefaultMConnConfig() *MConnConfig
DefaultMConnConfig returns the default config.
func NewTemMConnConfig ¶
func NewTemMConnConfig(gconn *grpc.ClientConn, gcli pb.P2PgserviceClient) *MConnConfig
type MConnection ¶
type MConnection struct {
// contains filtered or unexported fields
}
func NewMConnection ¶
func NewMConnection(conn *grpc.ClientConn, remote *NetAddress, peer *Peer) *MConnection
NewMConnection wraps net.Conn and creates multiplex connection
func NewMConnectionWithConfig ¶
func NewMConnectionWithConfig(cfg *MConnConfig) *MConnection
func (*MConnection) Close ¶
func (c *MConnection) Close()
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) Copy ¶
func (na *NetAddress) Copy() *NetAddress
func (*NetAddress) DialTimeout ¶
func (na *NetAddress) DialTimeout(version int32) (*grpc.ClientConn, error)
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
func (*NetAddress) Local ¶
func (na *NetAddress) Local() bool
Local returns true if it is a local address.
func (*NetAddress) RFC1918 ¶
func (na *NetAddress) RFC1918() bool
func (*NetAddress) RFC3849 ¶
func (na *NetAddress) RFC3849() bool
func (*NetAddress) RFC3927 ¶
func (na *NetAddress) RFC3927() bool
func (*NetAddress) RFC3964 ¶
func (na *NetAddress) RFC3964() bool
func (*NetAddress) RFC4193 ¶
func (na *NetAddress) RFC4193() bool
func (*NetAddress) RFC4380 ¶
func (na *NetAddress) RFC4380() bool
func (*NetAddress) RFC4843 ¶
func (na *NetAddress) RFC4843() bool
func (*NetAddress) RFC4862 ¶
func (na *NetAddress) RFC4862() bool
func (*NetAddress) RFC6052 ¶
func (na *NetAddress) RFC6052() bool
func (*NetAddress) RFC6145 ¶
func (na *NetAddress) RFC6145() bool
func (*NetAddress) ReachabilityTo ¶
func (na *NetAddress) ReachabilityTo(o *NetAddress) int
ReachabilityTo checks whenever o can be reached from na.
func (*NetAddress) Routable ¶
func (na *NetAddress) Routable() bool
Routable returns true if the address is routable.
func (*NetAddress) Valid ¶
func (na *NetAddress) Valid() bool
For IPv4 these are either a 0 or all bits set address. For IPv6 a zero address or one that matches the RFC3849 documentation address format.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func (*Node) AddCachePeer ¶
func (*Node) CacheBoundsSize ¶
func (*Node) GetActivePeers ¶
func (*Node) GetCacheBounds ¶
func (*Node) GetRegisterPeer ¶
func (*Node) GetRegisterPeers ¶
func (*Node) HasCacheBound ¶
func (*Node) RemoveCachePeer ¶
func (*Node) SetQueueClient ¶
type NodeInfo ¶
type NodeInfo struct { ServiceType int32 // contains filtered or unexported fields }
func NewNodeInfo ¶
func (*NodeInfo) FetchPeerInfo ¶
func (*NodeInfo) GetExternalAddr ¶
func (nf *NodeInfo) GetExternalAddr() *NetAddress
func (*NodeInfo) GetListenAddr ¶
func (nf *NodeInfo) GetListenAddr() *NetAddress
func (*NodeInfo) IsOutService ¶
func (*NodeInfo) SetExternalAddr ¶
func (nf *NodeInfo) SetExternalAddr(addr *NetAddress)
func (*NodeInfo) SetListenAddr ¶
func (nf *NodeInfo) SetListenAddr(addr *NetAddress)
func (*NodeInfo) SetNatDone ¶
func (nf *NodeInfo) SetNatDone()
func (*NodeInfo) SetNetSide ¶
func (*NodeInfo) SetServiceTy ¶
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) bool GetAddrList(peer *Peer) (map[string]int64, error) GetInPeersNum(peer *Peer) (int, error) CheckSelf(addr string, nodeinfo *NodeInfo) bool }
非p2p 订阅的事件处理函数接口
func NewNormalP2PCli ¶
func NewNormalP2PCli() NormalInterface
type P2p ¶
type P2p struct {
// contains filtered or unexported fields
}
func (*P2p) SetQueueClient ¶
type P2pServer ¶
type P2pServer struct {
// contains filtered or unexported fields
}
func NewP2pServer ¶
func NewP2pServer() *P2pServer
func (*P2pServer) BroadCastBlock ¶
func (*P2pServer) BroadCastTx ¶
func (*P2pServer) CollectInPeers ¶
func (*P2pServer) CollectInPeers2 ¶
func (*P2pServer) GetAddrList ¶
func (s *P2pServer) GetAddrList(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2PAddrList, error)
获取地址列表,包含地址高度
func (*P2pServer) GetData ¶
func (s *P2pServer) GetData(in *pb.P2PGetData, stream pb.P2Pgservice_GetDataServer) error
func (*P2pServer) GetHeaders ¶
func (s *P2pServer) GetHeaders(ctx context.Context, in *pb.P2PGetHeaders) (*pb.P2PHeaders, error)
func (*P2pServer) GetMemPool ¶
服务端查询本地mempool
func (*P2pServer) GetPeerInfo ¶
func (s *P2pServer) GetPeerInfo(ctx context.Context, in *pb.P2PGetPeerInfo) (*pb.P2PPeerInfo, error)
func (*P2pServer) ServerStreamRead ¶
func (s *P2pServer) ServerStreamRead(stream pb.P2Pgservice_ServerStreamReadServer) error
func (*P2pServer) ServerStreamSend ¶
func (*P2pServer) SoftVersion ¶
func (*P2pServer) Version2 ¶
func (s *P2pServer) Version2(ctx context.Context, in *pb.P2PVersion) (*pb.P2PVersion, error)
type Peer ¶
type Peer struct { IsMaxInbouds bool // contains filtered or unexported fields }
func NewPeer ¶
func NewPeer(conn *grpc.ClientConn, node *Node, remote *NetAddress) *Peer
func (*Peer) GetInBouns ¶
func (*Peer) GetPeerInfo ¶
func (p *Peer) GetPeerInfo(version int32) (*pb.P2PPeerInfo, error)
func (*Peer) GetPeerName ¶
func (*Peer) GetRunning ¶
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.
func (*Peer) SetAddr ¶
func (p *Peer) SetAddr(addr *NetAddress)
func (*Peer) SetPeerName ¶
type PeerInfos ¶
type PeerInfos struct {
// contains filtered or unexported fields
}
func (*PeerInfos) FlushPeerInfos ¶
func (*PeerInfos) SetPeerInfo ¶
type Version ¶
type Version struct {
// contains filtered or unexported fields
}