"plugins/git@web.lueluesay.top:root/oh-my-zsh.git" did not exist on "7e8177b09443f942084f9e7f3bfb5b2c9ce1ba27"
Commit 0fa1c254 authored by vyzo's avatar vyzo
Browse files

ping service in basic host

parent a768598c
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
pstore "github.com/libp2p/go-libp2p-peerstore" pstore "github.com/libp2p/go-libp2p-peerstore"
protocol "github.com/libp2p/go-libp2p-protocol" protocol "github.com/libp2p/go-libp2p-protocol"
identify "github.com/libp2p/go-libp2p/p2p/protocol/identify" identify "github.com/libp2p/go-libp2p/p2p/protocol/identify"
ping "github.com/libp2p/go-libp2p/p2p/protocol/ping"
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns" madns "github.com/multiformats/go-multiaddr-dns"
msmux "github.com/multiformats/go-multistream" msmux "github.com/multiformats/go-multistream"
...@@ -56,6 +57,7 @@ type BasicHost struct { ...@@ -56,6 +57,7 @@ type BasicHost struct {
network inet.Network network inet.Network
mux *msmux.MultistreamMuxer mux *msmux.MultistreamMuxer
ids *identify.IDService ids *identify.IDService
pings *ping.PingService
natmgr NATManager natmgr NATManager
addrs AddrsFactory addrs AddrsFactory
maResolver *madns.Resolver maResolver *madns.Resolver
...@@ -96,6 +98,9 @@ type HostOpts struct { ...@@ -96,6 +98,9 @@ type HostOpts struct {
// ConnManager is a libp2p connection manager // ConnManager is a libp2p connection manager
ConnManager ifconnmgr.ConnManager ConnManager ifconnmgr.ConnManager
// EnablePing indicates whether to instantiate the ping service
EnablePing bool
} }
// NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network. // NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network.
...@@ -149,6 +154,10 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost, ...@@ -149,6 +154,10 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost,
net.Notify(h.cmgr.Notifee()) net.Notify(h.cmgr.Notifee())
} }
if opts.EnablePing {
h.pings = ping.NewPingService(h)
}
net.SetConnHandler(h.newConnHandler) net.SetConnHandler(h.newConnHandler)
net.SetStreamHandler(h.newStreamHandler) net.SetStreamHandler(h.newStreamHandler)
return h, nil return h, nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment