Add Private Network protector to swarm

parent 4e991e68
......@@ -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,13 @@ type Swarm struct {
bwc metrics.Reporter
limiter *dialLimiter
protec ipnet.Protector
}
// 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 NewSwarm(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 {
......@@ -130,7 +133,8 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
bwc: bwc,
fdRateLimit: make(chan struct{}, concurrentFdDials),
Filters: filter.NewFilters(),
dialer: conn.NewDialer(local, peers.PrivKey(local), wrap),
dialer: conn.NewDialer(local, peers.PrivKey(local), protec, wrap),
protec: protec,
}
s.dsync = NewDialSync(s.doDial)
......@@ -158,7 +162,7 @@ func NewBlankSwarm(ctx context.Context, id peer.ID, privkey ci.PrivKey, pstpt ps
notifs: make(map[inet.Notifiee]ps.Notifiee),
fdRateLimit: make(chan struct{}, concurrentFdDials),
Filters: filter.NewFilters(),
dialer: conn.NewDialer(id, privkey, nil),
dialer: conn.NewDialer(id, privkey, nil, nil),
}
// configure Swarm
......
......@@ -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.WrapTransportListener(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"
......@@ -19,9 +20,9 @@ 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) {
peers pstore.Peerstore, protec ipnet.Protector, bwc metrics.Reporter) (*Network, error) {
s, err := NewSwarm(ctx, listen, local, peers, bwc)
s, err := NewSwarm(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