Commit e272315e authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub

Merge pull request #8 from libp2p/feat/pnet

Introduce changes required for Private Netowrk support
parents 4e991e68 b2d941fc
......@@ -81,9 +81,9 @@
},
{
"author": "whyrusleeping",
"hash": "QmU1YMnktAuCPBC7TqhbZRkpZ7KCiekv7SZtaLU5zpTgqb",
"hash": "QmV7iorvAUv766HnS5gZrsYAkFqKdTTF73kGvUDu5XFzCb",
"name": "go-libp2p-conn",
"version": "1.4.0"
"version": "1.5.0"
},
{
"author": "whyrusleeping",
......
......@@ -18,6 +18,7 @@ import (
addrutil "github.com/libp2p/go-addr-util"
conn "github.com/libp2p/go-libp2p-conn"
ci "github.com/libp2p/go-libp2p-crypto"
ipnet "github.com/libp2p/go-libp2p-interface-pnet"
metrics "github.com/libp2p/go-libp2p-metrics"
mconn "github.com/libp2p/go-libp2p-metrics/conn"
inet "github.com/libp2p/go-libp2p-net"
......@@ -98,11 +99,18 @@ type Swarm struct {
bwc metrics.Reporter
limiter *dialLimiter
protec ipnet.Protector
}
func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr, local peer.ID,
peers pstore.Peerstore, bwc metrics.Reporter) (*Swarm, error) {
return NewSwarmWithProtector(ctx, listenAddrs, local, peers, nil, bwc)
}
// NewSwarm constructs a Swarm, with a Chan.
func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
local peer.ID, peers pstore.Peerstore, bwc metrics.Reporter) (*Swarm, error) {
func NewSwarmWithProtector(ctx context.Context, listenAddrs []ma.Multiaddr, local peer.ID,
peers pstore.Peerstore, protec ipnet.Protector, bwc metrics.Reporter) (*Swarm, error) {
listenAddrs, err := filterAddrs(listenAddrs)
if err != nil {
......@@ -131,7 +139,9 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
fdRateLimit: make(chan struct{}, concurrentFdDials),
Filters: filter.NewFilters(),
dialer: conn.NewDialer(local, peers.PrivKey(local), wrap),
protec: protec,
}
s.dialer.Protector = protec
s.dsync = NewDialSync(s.doDial)
s.limiter = newDialLimiter(s.dialAddr)
......
......@@ -83,7 +83,7 @@ func (s *Swarm) addListener(tptlist transport.Listener) error {
log.Warning("Listener not given PrivateKey, so WILL NOT SECURE conns.")
}
list, err := conn.WrapTransportListener(s.Context(), tptlist, s.local, sk)
list, err := conn.WrapTransportListenerWithProtector(s.Context(), tptlist, s.local, sk, s.protec)
if err != nil {
return err
}
......
......@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/jbenet/goprocess"
ipnet "github.com/libp2p/go-libp2p-interface-pnet"
metrics "github.com/libp2p/go-libp2p-metrics"
inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer"
......@@ -17,11 +18,17 @@ import (
// to implement inet.Network.
type Network Swarm
// NewNetwork constructs a new network and starts listening on given addresses.
func NewNetwork(ctx context.Context, listen []ma.Multiaddr, local peer.ID,
peers pstore.Peerstore, bwc metrics.Reporter) (*Network, error) {
s, err := NewSwarm(ctx, listen, local, peers, bwc)
return NewNetworkWithProtector(ctx, listen, local, peers, nil, bwc)
}
// NewNetwork constructs a new network and starts listening on given addresses.
func NewNetworkWithProtector(ctx context.Context, listen []ma.Multiaddr, local peer.ID,
peers pstore.Peerstore, protec ipnet.Protector, bwc metrics.Reporter) (*Network, error) {
s, err := NewSwarmWithProtector(ctx, listen, local, peers, protec, bwc)
if err != nil {
return nil, err
}
......
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