Commit 665234f6 authored by Jeromy's avatar Jeromy
Browse files

WIP: add ConnManager interface method

parent dfaa021c
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
goprocess "github.com/jbenet/goprocess" goprocess "github.com/jbenet/goprocess"
connmgr "github.com/libp2p/go-libp2p-connmgr"
metrics "github.com/libp2p/go-libp2p-metrics" metrics "github.com/libp2p/go-libp2p-metrics"
mstream "github.com/libp2p/go-libp2p-metrics/stream" mstream "github.com/libp2p/go-libp2p-metrics/stream"
inet "github.com/libp2p/go-libp2p-net" inet "github.com/libp2p/go-libp2p-net"
...@@ -58,6 +59,7 @@ type BasicHost struct { ...@@ -58,6 +59,7 @@ type BasicHost struct {
ids *identify.IDService ids *identify.IDService
natmgr NATManager natmgr NATManager
addrs AddrsFactory addrs AddrsFactory
cmgr connmgr.ConnManager
negtimeout time.Duration negtimeout time.Duration
...@@ -92,6 +94,9 @@ type HostOpts struct { ...@@ -92,6 +94,9 @@ type HostOpts struct {
// //
BandwidthReporter metrics.Reporter BandwidthReporter metrics.Reporter
// ConnManager is a libp2p connection manager
ConnManager connmgr.ConnManager
} }
// 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.
...@@ -131,6 +136,13 @@ func NewHost(net inet.Network, opts *HostOpts) *BasicHost { ...@@ -131,6 +136,13 @@ func NewHost(net inet.Network, opts *HostOpts) *BasicHost {
h.ids.Reporter = opts.BandwidthReporter h.ids.Reporter = opts.BandwidthReporter
} }
if opts.ConnManager == nil {
// create 'disabled' conn manager for now
h.cmgr = connmgr.NewConnManager(0, 0, 0)
} else {
h.cmgr = opts.ConnManager
}
h.proc = goprocess.WithTeardown(func() error { h.proc = goprocess.WithTeardown(func() error {
if h.natmgr != nil { if h.natmgr != nil {
h.natmgr.Close() h.natmgr.Close()
...@@ -161,6 +173,8 @@ func New(net inet.Network, opts ...interface{}) *BasicHost { ...@@ -161,6 +173,8 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
hostopts.BandwidthReporter = o hostopts.BandwidthReporter = o
case AddrsFactory: case AddrsFactory:
hostopts.AddrsFactory = AddrsFactory(o) hostopts.AddrsFactory = AddrsFactory(o)
case connmgr.ConnManager:
hostopts.ConnManager = o
} }
} }
...@@ -411,6 +425,10 @@ func (h *BasicHost) dialPeer(ctx context.Context, p peer.ID) error { ...@@ -411,6 +425,10 @@ func (h *BasicHost) dialPeer(ctx context.Context, p peer.ID) error {
return nil return nil
} }
func (h *BasicHost) ConnManager() connmgr.ConnManager {
return h.cmgr
}
// Addrs returns listening addresses that are safe to announce to the network. // Addrs returns listening addresses that are safe to announce to the network.
// The output is the same as AllAddrs, but processed by AddrsFactory. // The output is the same as AllAddrs, but processed by AddrsFactory.
func (h *BasicHost) Addrs() []ma.Multiaddr { func (h *BasicHost) Addrs() []ma.Multiaddr {
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
host "github.com/libp2p/go-libp2p-host" host "github.com/libp2p/go-libp2p-host"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
connmgr "github.com/libp2p/go-libp2p-connmgr"
lgbl "github.com/libp2p/go-libp2p-loggables" lgbl "github.com/libp2p/go-libp2p-loggables"
inet "github.com/libp2p/go-libp2p-net" inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer" peer "github.com/libp2p/go-libp2p-peer"
...@@ -124,5 +125,8 @@ func (rh *RoutedHost) Close() error { ...@@ -124,5 +125,8 @@ func (rh *RoutedHost) Close() error {
// no need to close IpfsRouting. we dont own it. // no need to close IpfsRouting. we dont own it.
return rh.host.Close() return rh.host.Close()
} }
func (rh *RoutedHost) ConnManager() connmgr.ConnManager {
return rh.host.ConnManager()
}
var _ (host.Host) = (*RoutedHost)(nil) var _ (host.Host) = (*RoutedHost)(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