log what arrives: one line per sync and per minute of gossip, every listing at debug; --log-level
A sync with a peer logs one info line when it brought something new (new and updated counts, per region). Listings that arrive by gossip are summed up once a minute. At debug level every stored listing gets a line with its id, region, outcome and the peer it came from. A duplicate is not news and logs nothing. --log-level takes debug, info, warn or error. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
+11
-2
@@ -296,6 +296,11 @@ func (n *Node) syncSoon(p peer.ID) {
|
||||
// does not know digests (an older node) is caught up the original way, by
|
||||
// paging through everything it holds.
|
||||
func (n *Node) SyncFrom(ctx context.Context, p peer.ID) error {
|
||||
// One info line says what this sync brought in, however it ends.
|
||||
got := &tally{}
|
||||
ctx = withTally(ctx, got)
|
||||
defer got.log(n.log, "synced listings", "peer", p)
|
||||
|
||||
n.mu.Lock()
|
||||
regions := append([]string(nil), n.subscribed...)
|
||||
n.mu.Unlock()
|
||||
@@ -403,8 +408,10 @@ func (n *Node) pullListings(ctx context.Context, p peer.ID, region string) error
|
||||
if json.Unmarshal(line, &l) != nil || listing.Region(l.Geohash) != region {
|
||||
return
|
||||
}
|
||||
if _, err := n.cfg.Store.Put(ctx, &l); err != nil {
|
||||
if out, err := n.cfg.Store.Put(ctx, &l); err != nil {
|
||||
n.log.Debug("sync: listing rejected", "peer", p, "err", err)
|
||||
} else {
|
||||
n.noteListing(ctx, &l, out, "sync", p)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
@@ -565,8 +572,10 @@ func (n *Node) syncRegion(ctx context.Context, p peer.ID, region string) error {
|
||||
if listing.Region(l.Geohash) != region {
|
||||
return // peer sent something we did not ask for
|
||||
}
|
||||
if _, err := n.cfg.Store.Put(ctx, &l); err != nil {
|
||||
if out, err := n.cfg.Store.Put(ctx, &l); err != nil {
|
||||
n.log.Debug("sync: listing rejected", "peer", p, "err", err)
|
||||
} else {
|
||||
n.noteListing(ctx, &l, out, "sync", p)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user