Skip to content

Commit

Permalink
Merge pull request #204 from libp2p/feat/connmgr
Browse files Browse the repository at this point in the history
Feat/connmgr
  • Loading branch information
whyrusleeping authored Jul 12, 2017
2 parents dfaa021 + f9e0e73 commit 2308756
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.4.1: QmapADMpK4e5kFGBxC2aHreaDqKP9vmMng5f91MA14Ces9
4.4.2: QmNoCFYrmNFZxpv4KRGHujfsX2QqC3gH4bLJfkizZHFdUS
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ os:
language: go

go:
- 1.7
- 1.8

install: true

Expand Down
18 changes: 18 additions & 0 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

logging "github.com/ipfs/go-log"
goprocess "github.com/jbenet/goprocess"
connmgr "github.com/libp2p/go-libp2p-connmgr"
metrics "github.com/libp2p/go-libp2p-metrics"
mstream "github.com/libp2p/go-libp2p-metrics/stream"
inet "github.com/libp2p/go-libp2p-net"
Expand Down Expand Up @@ -58,6 +59,7 @@ type BasicHost struct {
ids *identify.IDService
natmgr NATManager
addrs AddrsFactory
cmgr connmgr.ConnManager

negtimeout time.Duration

Expand Down Expand Up @@ -92,6 +94,9 @@ type HostOpts struct {

//
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.
Expand Down Expand Up @@ -131,6 +136,13 @@ func NewHost(net inet.Network, opts *HostOpts) *BasicHost {
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 {
if h.natmgr != nil {
h.natmgr.Close()
Expand Down Expand Up @@ -161,6 +173,8 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
hostopts.BandwidthReporter = o
case AddrsFactory:
hostopts.AddrsFactory = AddrsFactory(o)
case connmgr.ConnManager:
hostopts.ConnManager = o
}
}

Expand Down Expand Up @@ -411,6 +425,10 @@ func (h *BasicHost) dialPeer(ctx context.Context, p peer.ID) error {
return nil
}

func (h *BasicHost) ConnManager() connmgr.ConnManager {
return h.cmgr
}

// Addrs returns listening addresses that are safe to announce to the network.
// The output is the same as AllAddrs, but processed by AddrsFactory.
func (h *BasicHost) Addrs() []ma.Multiaddr {
Expand Down
4 changes: 4 additions & 0 deletions p2p/host/routed/routed.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
host "github.com/libp2p/go-libp2p-host"

logging "github.com/ipfs/go-log"
connmgr "github.com/libp2p/go-libp2p-connmgr"
lgbl "github.com/libp2p/go-libp2p-loggables"
inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer"
Expand Down Expand Up @@ -124,5 +125,8 @@ func (rh *RoutedHost) Close() error {
// no need to close IpfsRouting. we dont own it.
return rh.host.Close()
}
func (rh *RoutedHost) ConnManager() connmgr.ConnManager {
return rh.host.ConnManager()
}

var _ (host.Host) = (*RoutedHost)(nil)
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@
},
{
"author": "whyrusleeping",
"hash": "QmZy7c24mmkEHpNJndwgsEE3wcVxHd8yB969yTnAJFVw7f",
"hash": "QmRNyPNJGNCaZyYonJj7owciWTsMd9gRfEKmZY3o6xwN3h",
"name": "go-libp2p-host",
"version": "1.3.15"
"version": "1.3.16"
},
{
"author": "whyrusleeping",
Expand All @@ -229,16 +229,16 @@
},
{
"author": "whyrusleeping",
"hash": "QmQoFme2KBiCZmCwKDLoCVZShkYGjPt4YR7ihZK5c3vtzH",
"hash": "QmbQXcWAa9ZbTH74m6yroexY8QjTS4oivLNEFwjamZCJTU",
"name": "go-libp2p-blankhost",
"version": "0.1.14"
"version": "0.1.15"
}
],
"gxVersion": "0.4.0",
"language": "go",
"license": "MIT",
"name": "go-libp2p",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "4.4.1"
"version": "4.4.2"
}

0 comments on commit 2308756

Please sign in to comment.