本文整理汇总了Golang中github.com/ipfs/go-libp2p/p2p/net.Conn.LocalMultiaddr方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.LocalMultiaddr方法的具体用法?Golang Conn.LocalMultiaddr怎么用?Golang Conn.LocalMultiaddr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ipfs/go-libp2p/p2p/net.Conn
的用法示例。
在下文中一共展示了Conn.LocalMultiaddr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: consumeObservedAddress
func (ids *IDService) consumeObservedAddress(observed []byte, c inet.Conn) {
if observed == nil {
return
}
maddr, err := ma.NewMultiaddrBytes(observed)
if err != nil {
log.Debugf("error parsing received observed addr for %s: %s", c, err)
return
}
// we should only use ObservedAddr when our connection's LocalAddr is one
// of our ListenAddrs. If we Dial out using an ephemeral addr, knowing that
// address's external mapping is not very useful because the port will not be
// the same as the listen addr.
ifaceaddrs, err := ids.Host.Network().InterfaceListenAddresses()
if err != nil {
log.Infof("failed to get interface listen addrs", err)
return
}
log.Debugf("identify identifying observed multiaddr: %s %s", c.LocalMultiaddr(), ifaceaddrs)
if !addrInAddrs(c.LocalMultiaddr(), ifaceaddrs) {
// not in our list
return
}
// ok! we have the observed version of one of our ListenAddresses!
log.Debugf("added own observed listen addr: %s --> %s", c.LocalMultiaddr(), maddr)
ids.observedAddrs.Add(maddr, c.RemoteMultiaddr())
}