當前位置: 首頁>>代碼示例>>Golang>>正文


Golang go-libp2p-net.Network類代碼示例

本文整理匯總了Golang中github.com/libp2p/go-libp2p-net.Network的典型用法代碼示例。如果您正苦於以下問題:Golang Network類的具體用法?Golang Network怎麽用?Golang Network使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Network類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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:peckjerry,項目名稱:go-libp2p,代碼行數:8,代碼來源:mock_printer.go

示例2: 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(),
		NegotiateTimeout: NegotiateTimeout,
	}

	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
		}
	}

	h.ids.Reporter = h.bwc

	net.SetConnHandler(h.newConnHandler)
	net.SetStreamHandler(h.newStreamHandler)

	return h
}
開發者ID:libp2p,項目名稱:go-libp2p,代碼行數:44,代碼來源:basic_host.go

示例3: LinksBetweenNets

func (mn *mocknet) LinksBetweenNets(n1, n2 inet.Network) []Link {
	return mn.LinksBetweenPeers(n1.LocalPeer(), n2.LocalPeer())
}
開發者ID:peckjerry,項目名稱:go-libp2p,代碼行數:3,代碼來源:mock_net.go

示例4: DisconnectNets

func (mn *mocknet) DisconnectNets(n1, n2 inet.Network) error {
	return n1.ClosePeer(n2.LocalPeer())
}
開發者ID:peckjerry,項目名稱:go-libp2p,代碼行數:3,代碼來源:mock_net.go

示例5: ConnectNets

func (mn *mocknet) ConnectNets(a, b inet.Network) (inet.Conn, error) {
	return a.DialPeer(mn.ctx, b.LocalPeer())
}
開發者ID:peckjerry,項目名稱:go-libp2p,代碼行數:3,代碼來源:mock_net.go

示例6: UnlinkNets

func (mn *mocknet) UnlinkNets(n1, n2 inet.Network) error {
	return mn.UnlinkPeers(n1.LocalPeer(), n2.LocalPeer())
}
開發者ID:peckjerry,項目名稱:go-libp2p,代碼行數:3,代碼來源:mock_net.go

示例7: DivulgeAddresses

func DivulgeAddresses(a, b inet.Network) {
	id := a.LocalPeer()
	addrs := a.Peerstore().Addrs(id)
	b.Peerstore().AddAddrs(id, addrs, pstore.PermanentAddrTTL)
}
開發者ID:peckjerry,項目名稱:go-libp2p,代碼行數:5,代碼來源:util.go


注:本文中的github.com/libp2p/go-libp2p-net.Network類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。