Skip to content

Commit

Permalink
fix: remove peerstore no-op
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumemichel committed Mar 6, 2025
1 parent 64ea67f commit 02dea23
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
27 changes: 10 additions & 17 deletions crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ type (
}
// DefaultCrawler provides a default implementation of Crawler.
DefaultCrawler struct {
parallelism int
connectTimeout time.Duration
queryTimeout time.Duration
host host.Host
dhtRPC *pb.ProtocolMessenger
dialAddressExtendDur time.Duration
parallelism int
connectTimeout time.Duration
queryTimeout time.Duration
host host.Host
dhtRPC *pb.ProtocolMessenger
}
)

Expand All @@ -59,12 +58,11 @@ func NewDefaultCrawler(host host.Host, opts ...Option) (*DefaultCrawler, error)
}

return &DefaultCrawler{
parallelism: o.parallelism,
connectTimeout: o.connectTimeout,
queryTimeout: 3 * o.connectTimeout,
host: host,
dhtRPC: pm,
dialAddressExtendDur: o.dialAddressExtendDur,
parallelism: o.parallelism,
connectTimeout: o.connectTimeout,
queryTimeout: 3 * o.connectTimeout,
host: host,
dhtRPC: pm,
}, nil
}

Expand Down Expand Up @@ -300,11 +298,6 @@ func (c *DefaultCrawler) queryPeer(ctx context.Context, nextPeer peer.AddrInfo)
logger.Debugf("could not connect to peer %v: %v", nextPeer.ID, err)
return &queryResult{nextPeer.ID, nil, err}
}
// Extend peerstore address ttl for addresses whose ttl is below
// c.dialAddressExtendDur. By now identify has already cleaned up addresses
// provided to Connect above and only kept the listen addresses advertised by
// the remote peer
c.host.Peerstore().AddAddrs(nextPeer.ID, c.host.Peerstore().Addrs(nextPeer.ID), c.dialAddressExtendDur)

localPeers := make(map[peer.ID]*peer.AddrInfo)
var retErr error
Expand Down
20 changes: 4 additions & 16 deletions crawler/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (
type Option func(*options) error

type options struct {
protocols []protocol.ID
parallelism int
connectTimeout time.Duration
perMsgTimeout time.Duration
dialAddressExtendDur time.Duration
protocols []protocol.ID
parallelism int
connectTimeout time.Duration
perMsgTimeout time.Duration
}

// defaults are the default crawler options. This option will be automatically
Expand All @@ -25,7 +24,6 @@ var defaults = func(o *options) error {
o.parallelism = 1000
o.connectTimeout = time.Second * 5
o.perMsgTimeout = time.Second * 5
o.dialAddressExtendDur = time.Minute * 30

return nil
}
Expand Down Expand Up @@ -61,13 +59,3 @@ func WithConnectTimeout(timeout time.Duration) Option {
return nil
}
}

// WithDialAddrExtendDuration sets the duration by which the TTL of dialed address in peer store are
// extended.
// Defaults to 30 minutes if unset.
func WithDialAddrExtendDuration(ext time.Duration) Option {
return func(o *options) error {
o.dialAddressExtendDur = ext
return nil
}
}
2 changes: 1 addition & 1 deletion fullrt/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func NewFullRT(h host.Host, protocolPrefix protocol.ID, options ...Option) (*Ful
}

if fullrtcfg.crawler == nil {
fullrtcfg.crawler, err = crawler.NewDefaultCrawler(h, crawler.WithParallelism(200), crawler.WithDialAddrExtendDuration(fullrtcfg.crawlInterval))
fullrtcfg.crawler, err = crawler.NewDefaultCrawler(h, crawler.WithParallelism(200))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 02dea23

Please sign in to comment.