Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(crawler): remove peerstore no-op #1063

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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