Commit 0fa1c254 authored by vyzo's avatar vyzo
Browse files

ping service in basic host

parent a768598c
......@@ -14,6 +14,7 @@ import (
pstore "github.com/libp2p/go-libp2p-peerstore"
protocol "github.com/libp2p/go-libp2p-protocol"
identify "github.com/libp2p/go-libp2p/p2p/protocol/identify"
ping "github.com/libp2p/go-libp2p/p2p/protocol/ping"
ma "github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns"
msmux "github.com/multiformats/go-multistream"
......@@ -56,6 +57,7 @@ type BasicHost struct {
network inet.Network
mux *msmux.MultistreamMuxer
ids *identify.IDService
pings *ping.PingService
natmgr NATManager
addrs AddrsFactory
maResolver *madns.Resolver
......@@ -96,6 +98,9 @@ type HostOpts struct {
// ConnManager is a libp2p connection manager
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.
......@@ -149,6 +154,10 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost,
net.Notify(h.cmgr.Notifee())
}
if opts.EnablePing {
h.pings = ping.NewPingService(h)
}
net.SetConnHandler(h.newConnHandler)
net.SetStreamHandler(h.newStreamHandler)
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