Skip to content

Commit ca41a99

Browse files
refactor p2p host gater initialization, add new blocking gater to p2p host
1 parent 104cdca commit ca41a99

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

p2p/host.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,15 @@ func NewHost(cfg HostConfig) (Host, error) {
181181
if err := ps.AddPubKey(peerID, pub); err != nil {
182182
return nil, fmt.Errorf("failed to set up peerstore with pub key: %w", err)
183183
}
184-
var connGtr gating.BlockingConnectionGater
185-
connGtr, err = gating.NewBlockingConnectionGater(datastore)
184+
var connGtr gating.ExtendedConnectionGater
185+
connGtr, err = gating.NewExtendedConnectionGater(datastore)
186186
if err != nil {
187187
return nil, fmt.Errorf("failed to open connection gater: %w", err)
188188
}
189+
if cfg.DisablePrivateIPScan {
190+
// Prevent dialing of public addresses
191+
connGtr = gating.AddBlocking(connGtr, cfg.DisablePrivateIPScan)
192+
}
189193
connGtr = gating.AddBanExpiry(connGtr, ps, clock.SystemClock)
190194
connGtr = gating.AddMetering(connGtr)
191195

@@ -302,12 +306,6 @@ func NewHost(cfg HostConfig) (Host, error) {
302306
p2pHostConfig = append(p2pHostConfig, libp2p.ForceReachabilityPublic())
303307
}
304308

305-
// TODO: this should be moved to main gater
306-
if cfg.DisablePrivateIPScan {
307-
// Prevent dialing of public addresses
308-
p2pHostConfig = append(p2pHostConfig, libp2p.ConnectionGater(NewGater(cfg.DisablePrivateIPScan)))
309-
}
310-
311309
// create p2p host
312310
p2pHost, err := libp2p.New(p2pHostConfig...)
313311
if err != nil {

0 commit comments

Comments
 (0)