本文整理汇总了Golang中github.com/jbenet/go-ipfs/peer.Peer.Key方法的典型用法代码示例。如果您正苦于以下问题:Golang Peer.Key方法的具体用法?Golang Peer.Key怎么用?Golang Peer.Key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jbenet/go-ipfs/peer.Peer
的用法示例。
在下文中一共展示了Peer.Key方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getLedger
func (bs *BitSwap) getLedger(p *peer.Peer) *Ledger {
l, ok := bs.partners[p.Key()]
if ok {
return l
}
l = new(Ledger)
l.Strategy = bs.strategy
l.Partner = p
bs.partners[p.Key()] = l
return l
}
示例2: Dial
// Dial connects to a peer.
//
// The idea is that the client of Swarm does not need to know what network
// the connection will happen over. Swarm can use whichever it choses.
// This allows us to use various transport protocols, do NAT traversal/relay,
// etc. to achive connection.
//
// For now, Dial uses only TCP. This will be extended.
func (s *Swarm) Dial(peer *peer.Peer) (*Conn, error) {
k := peer.Key()
// check if we already have an open connection first
s.connsLock.RLock()
conn, found := s.conns[k]
s.connsLock.RUnlock()
if found {
return conn, nil
}
// open connection to peer
conn, err := Dial("tcp", peer)
if err != nil {
return nil, err
}
// add to conns
s.connsLock.Lock()
s.conns[k] = conn
s.connsLock.Unlock()
// kick off reader goroutine
go s.fanIn(conn)
return conn, nil
}
示例3: Dial
// Dial connects to a peer.
//
// The idea is that the client of Swarm does not need to know what network
// the connection will happen over. Swarm can use whichever it choses.
// This allows us to use various transport protocols, do NAT traversal/relay,
// etc. to achive connection.
//
// For now, Dial uses only TCP. This will be extended.
func (s *Swarm) Dial(peer *peer.Peer) (*Conn, error, bool) {
k := peer.Key()
// check if we already have an open connection first
s.connsLock.RLock()
conn, found := s.conns[k]
s.connsLock.RUnlock()
if found {
return conn, nil, true
}
// open connection to peer
conn, err := Dial("tcp", peer)
if err != nil {
return nil, err, false
}
return conn, nil, false
}