本文整理汇总了Golang中github.com/ipfs/go-libp2p/p2p/net.Network类的典型用法代码示例。如果您正苦于以下问题:Golang Network类的具体用法?Golang Network怎么用?Golang Network使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Network类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: printConns
func printConns(n inet.Network) string {
s := fmt.Sprintf("Connections in %s:\n", n)
for _, c := range n.Conns() {
s = s + fmt.Sprintf("- %s\n", c)
}
return s
}
开发者ID:wemeetagain,项目名称:go-libp2p,代码行数:7,代码来源:swarm_net_test.go
示例2: NetworkConns
func (p *printer) NetworkConns(ni inet.Network) {
fmt.Fprintf(p.w, "%s connected to:\n", ni.LocalPeer())
for _, c := range ni.Conns() {
fmt.Fprintf(p.w, "\t%s (addr: %s)\n", c.RemotePeer(), c.RemoteMultiaddr())
}
fmt.Fprintf(p.w, "\n")
}
开发者ID:harlantwood,项目名称:go-libp2p,代码行数:8,代码来源:mock_printer.go
示例3: expectConnectedness
func expectConnectedness(t *testing.T, a, b inet.Network, expected inet.Connectedness) {
es := "%s is connected to %s, but Connectedness incorrect. %s %s"
if a.Connectedness(b.LocalPeer()) != expected {
t.Errorf(es, a, b, printConns(a), printConns(b))
}
// test symmetric case
if b.Connectedness(a.LocalPeer()) != expected {
t.Errorf(es, b, a, printConns(b), printConns(a))
}
}
开发者ID:wemeetagain,项目名称:go-libp2p,代码行数:11,代码来源:swarm_net_test.go
示例4: New
// New constructs and sets up a new *BasicHost with given Network
func New(net inet.Network, opts ...interface{}) *BasicHost {
h := &BasicHost{
network: net,
mux: msmux.NewMultistreamMuxer(),
bwc: metrics.NewBandwidthCounter(),
}
h.proc = goprocess.WithTeardown(func() error {
if h.natmgr != nil {
h.natmgr.Close()
}
return h.Network().Close()
})
// setup host services
h.ids = identify.NewIDService(h)
muxh := h.Mux().Handle
handle := func(s inet.Stream) {
muxh(s)
}
h.relay = relay.NewRelayService(h, handle)
for _, o := range opts {
switch o := o.(type) {
case Option:
switch o {
case NATPortMap:
h.natmgr = newNatManager(h)
}
case metrics.Reporter:
h.bwc = o
}
}
net.SetConnHandler(h.newConnHandler)
net.SetStreamHandler(h.newStreamHandler)
return h
}
开发者ID:harlantwood,项目名称:go-libp2p,代码行数:42,代码来源:basic_host.go
示例5: LinksBetweenNets
func (mn *mocknet) LinksBetweenNets(n1, n2 inet.Network) []Link {
return mn.LinksBetweenPeers(n1.LocalPeer(), n2.LocalPeer())
}
开发者ID:diasdavid,项目名称:go-libp2p,代码行数:3,代码来源:mock_net.go
示例6: DisconnectNets
func (mn *mocknet) DisconnectNets(n1, n2 inet.Network) error {
return n1.ClosePeer(n2.LocalPeer())
}
开发者ID:diasdavid,项目名称:go-libp2p,代码行数:3,代码来源:mock_net.go
示例7: ConnectNets
func (mn *mocknet) ConnectNets(a, b inet.Network) (inet.Conn, error) {
return a.DialPeer(mn.ctx, b.LocalPeer())
}
开发者ID:diasdavid,项目名称:go-libp2p,代码行数:3,代码来源:mock_net.go
示例8: UnlinkNets
func (mn *mocknet) UnlinkNets(n1, n2 inet.Network) error {
return mn.UnlinkPeers(n1.LocalPeer(), n2.LocalPeer())
}
开发者ID:diasdavid,项目名称:go-libp2p,代码行数:3,代码来源:mock_net.go
示例9: Disconnected
func (nn *metricsNotifiee) Disconnected(n inet.Network, v inet.Conn) {
peersTotalGauge(n.LocalPeer()).Set(float64(len(n.Conns())))
}
开发者ID:tilgovi,项目名称:go-libp2p,代码行数:3,代码来源:swarm.go
示例10: DivulgeAddresses
func DivulgeAddresses(a, b inet.Network) {
id := a.LocalPeer()
addrs := a.Peerstore().Addrs(id)
b.Peerstore().AddAddrs(id, addrs, peer.PermanentAddrTTL)
}
开发者ID:diasdavid,项目名称:go-libp2p,代码行数:5,代码来源:util.go
注:本文中的github.com/ipfs/go-libp2p/p2p/net.Network类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论