本文整理汇总了Golang中github.com/jbenet/go-ipfs/peer.Peer.SetLatency方法的典型用法代码示例。如果您正苦于以下问题:Golang Peer.SetLatency方法的具体用法?Golang Peer.SetLatency怎么用?Golang Peer.SetLatency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jbenet/go-ipfs/peer.Peer
的用法示例。
在下文中一共展示了Peer.SetLatency方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Ping
// Ping a peer, log the time it took
func (dht *IpfsDHT) Ping(p *peer.Peer, timeout time.Duration) error {
// Thoughts: maybe this should accept an ID and do a peer lookup?
u.DOut("Enter Ping.\n")
pmes := Message{ID: swarm.GenerateMessageID(), Type: PBDHTMessage_PING}
mes := swarm.NewMessage(p, pmes.ToProtobuf())
before := time.Now()
responseChan := dht.listener.Listen(pmes.ID, 1, time.Minute)
dht.netChan.Outgoing <- mes
tout := time.After(timeout)
select {
case <-responseChan:
roundtrip := time.Since(before)
p.SetLatency(roundtrip)
u.DOut("Ping took %s.\n", roundtrip.String())
return nil
case <-tout:
// Timed out, think about removing peer from network
u.DOut("[%s] Ping peer [%s] timed out.", dht.self.ID.Pretty(), p.ID.Pretty())
dht.listener.Unlisten(pmes.ID)
return u.ErrTimeout
}
}