本文整理匯總了Golang中github.com/ethereum/go-ethereum/p2p.Peer類的典型用法代碼示例。如果您正苦於以下問題:Golang Peer類的具體用法?Golang Peer怎麽用?Golang Peer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Peer類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newPeer
func newPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer {
id := p.ID()
return &peer{
Peer: p,
rw: rw,
version: version,
id: fmt.Sprintf("%x", id[:8]),
knownTxs: set.New(),
knownBlocks: set.New(),
}
}
示例2: newPeerInfo
func newPeerInfo(peer *p2p.Peer) *PeerInfo {
var caps []string
for _, cap := range peer.Caps() {
caps = append(caps, cap.String())
}
return &PeerInfo{
ID: peer.ID().String(),
Name: peer.Name(),
Caps: strings.Join(caps, ", "),
RemoteAddress: peer.RemoteAddr().String(),
LocalAddress: peer.LocalAddr().String(),
}
}
示例3: newPeer
func newPeer(protv, netid int, genesis, recentHash common.Hash, td *big.Int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer {
id := p.ID()
return &peer{
Peer: p,
rw: rw,
genesis: genesis,
ourHash: recentHash,
ourTd: td,
protv: protv,
netid: netid,
id: fmt.Sprintf("%x", id[:8]),
txHashes: set.New(),
blockHashes: set.New(),
}
}
示例4: NewPeer
func NewPeer(peer *p2p.Peer) *Peer {
var caps []string
for _, cap := range peer.Caps() {
caps = append(caps, fmt.Sprintf("%s/%d", cap.Name, cap.Version))
}
return &Peer{
ref: peer,
Ip: fmt.Sprintf("%v", peer.RemoteAddr()),
Version: fmt.Sprintf("%v", peer.ID()),
Caps: fmt.Sprintf("%v", caps),
}
}