Update for changed libp2p-conn

parent 5d1bbd52
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmU1YMnktAuCPBC7TqhbZRkpZ7KCiekv7SZtaLU5zpTgqb", "hash": "QmRJA93XFXJTVqFgC1mquPV4m1MkNrtTsfnRmFUy4Mhoih",
"name": "go-libp2p-conn", "name": "go-libp2p-conn",
"version": "1.4.0" "version": "1.4.0"
}, },
......
...@@ -103,8 +103,13 @@ type Swarm struct { ...@@ -103,8 +103,13 @@ type Swarm struct {
protec ipnet.Protector protec ipnet.Protector
} }
// NewSwarm constructs a Swarm, with a Chan.
func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr, local peer.ID, 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 NewSwarmWithProtector(ctx context.Context, listenAddrs []ma.Multiaddr, local peer.ID,
peers pstore.Peerstore, protec ipnet.Protector, bwc metrics.Reporter) (*Swarm, error) { peers pstore.Peerstore, protec ipnet.Protector, bwc metrics.Reporter) (*Swarm, error) {
listenAddrs, err := filterAddrs(listenAddrs) listenAddrs, err := filterAddrs(listenAddrs)
...@@ -133,9 +138,10 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr, local peer.ID, ...@@ -133,9 +138,10 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr, local peer.ID,
bwc: bwc, bwc: bwc,
fdRateLimit: make(chan struct{}, concurrentFdDials), fdRateLimit: make(chan struct{}, concurrentFdDials),
Filters: filter.NewFilters(), Filters: filter.NewFilters(),
dialer: conn.NewDialer(local, peers.PrivKey(local), protec, wrap), dialer: conn.NewDialer(local, peers.PrivKey(local), wrap),
protec: protec, protec: protec,
} }
s.dialer.Protector = protec
s.dsync = NewDialSync(s.doDial) s.dsync = NewDialSync(s.doDial)
s.limiter = newDialLimiter(s.dialAddr) s.limiter = newDialLimiter(s.dialAddr)
...@@ -162,7 +168,7 @@ func NewBlankSwarm(ctx context.Context, id peer.ID, privkey ci.PrivKey, pstpt ps ...@@ -162,7 +168,7 @@ func NewBlankSwarm(ctx context.Context, id peer.ID, privkey ci.PrivKey, pstpt ps
notifs: make(map[inet.Notifiee]ps.Notifiee), notifs: make(map[inet.Notifiee]ps.Notifiee),
fdRateLimit: make(chan struct{}, concurrentFdDials), fdRateLimit: make(chan struct{}, concurrentFdDials),
Filters: filter.NewFilters(), Filters: filter.NewFilters(),
dialer: conn.NewDialer(id, privkey, nil, nil), dialer: conn.NewDialer(id, privkey, nil),
} }
// configure Swarm // configure Swarm
......
...@@ -65,11 +65,11 @@ func TestFilterAddrs(t *testing.T) { ...@@ -65,11 +65,11 @@ func TestFilterAddrs(t *testing.T) {
ps := pstore.NewPeerstore() ps := pstore.NewPeerstore()
ctx := context.Background() ctx := context.Background()
if _, err := NewNetwork(ctx, bad, id, ps, metrics.NewBandwidthCounter()); err == nil { if _, err := NewNetwork(ctx, bad, id, ps, nil, metrics.NewBandwidthCounter()); err == nil {
t.Fatal("should have failed to create swarm") t.Fatal("should have failed to create swarm")
} }
if _, err := NewNetwork(ctx, goodAndBad, id, ps, metrics.NewBandwidthCounter()); err != nil { if _, err := NewNetwork(ctx, goodAndBad, id, ps, nil, metrics.NewBandwidthCounter()); err != nil {
t.Fatal("should have succeeded in creating swarm", err) t.Fatal("should have succeeded in creating swarm", err)
} }
} }
......
...@@ -83,7 +83,7 @@ func (s *Swarm) addListener(tptlist transport.Listener) error { ...@@ -83,7 +83,7 @@ func (s *Swarm) addListener(tptlist transport.Listener) error {
log.Warning("Listener not given PrivateKey, so WILL NOT SECURE conns.") log.Warning("Listener not given PrivateKey, so WILL NOT SECURE conns.")
} }
list, err := conn.WrapTransportListener(s.Context(), tptlist, s.local, sk, s.protec) list, err := conn.WrapTransportListenerWithProtector(s.Context(), tptlist, s.local, sk, s.protec)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -22,7 +22,7 @@ type Network Swarm ...@@ -22,7 +22,7 @@ type Network Swarm
func NewNetwork(ctx context.Context, listen []ma.Multiaddr, local peer.ID, func NewNetwork(ctx context.Context, listen []ma.Multiaddr, local peer.ID,
peers pstore.Peerstore, protec ipnet.Protector, bwc metrics.Reporter) (*Network, error) { peers pstore.Peerstore, protec ipnet.Protector, bwc metrics.Reporter) (*Network, error) {
s, err := NewSwarm(ctx, listen, local, peers, protec, bwc) s, err := NewSwarmWithProtector(ctx, listen, local, peers, protec, bwc)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -17,7 +17,7 @@ func GenSwarmNetwork(t *testing.T, ctx context.Context) *Network { ...@@ -17,7 +17,7 @@ func GenSwarmNetwork(t *testing.T, ctx context.Context) *Network {
ps := pstore.NewPeerstore() ps := pstore.NewPeerstore()
ps.AddPubKey(p.ID, p.PubKey) ps.AddPubKey(p.ID, p.PubKey)
ps.AddPrivKey(p.ID, p.PrivKey) ps.AddPrivKey(p.ID, p.PrivKey)
n, err := NewNetwork(ctx, []ma.Multiaddr{p.Addr}, p.ID, ps, nil) n, err := NewNetwork(ctx, []ma.Multiaddr{p.Addr}, p.ID, ps, nil, nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(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