p2p: a node asks its peers for its own listings after losing its database
Sync kind 'author': everything a peer holds from one author key, any region. A node asks the first 3 peers it syncs with per run. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
+24
-2
@@ -55,6 +55,7 @@ type syncRequest struct {
|
||||
AfterID string `json:"after_id,omitempty"` // listings
|
||||
AfterHash string `json:"after_hash,omitempty"` // messages
|
||||
Limit int `json:"limit,omitempty"`
|
||||
Author string `json:"author,omitempty"` // "author": whose listings
|
||||
}
|
||||
|
||||
// --- server ---------------------------------------------------------------
|
||||
@@ -74,7 +75,7 @@ func (n *Node) handleSync(s network.Stream) {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
if n.oldSync && (req.Kind == "digest" || req.Kind == "inventory" || req.Kind == "fetch" || req.Kind == "reports" || req.Kind == "peers") {
|
||||
if n.oldSync && (req.Kind == "digest" || req.Kind == "inventory" || req.Kind == "fetch" || req.Kind == "reports" || req.Kind == "peers" || req.Kind == "author") {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
@@ -198,6 +199,27 @@ func (n *Node) handleSync(s network.Stream) {
|
||||
return
|
||||
}
|
||||
}
|
||||
case "author":
|
||||
// Everything we hold from one author, whatever the region.
|
||||
if !validAuthor(req.Author) {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
limit := req.Limit
|
||||
if limit <= 0 || limit > n.cfg.SyncPageSize {
|
||||
limit = n.cfg.SyncPageSize
|
||||
}
|
||||
items, err := n.cfg.Store.AuthorListings(n.ctx, req.Author, req.AfterID, limit)
|
||||
if err != nil {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
for _, l := range items {
|
||||
if !write(l.Bytes()) {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
}
|
||||
case "inventory":
|
||||
if !listing.ValidRegion(req.Region) {
|
||||
_ = s.Reset()
|
||||
@@ -353,7 +375,7 @@ func (n *Node) SyncFrom(ctx context.Context, p peer.ID) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return n.recoverOwn(ctx, p)
|
||||
}
|
||||
|
||||
func (n *Node) digest(ctx context.Context, p peer.ID, region string, out *digestReply) error {
|
||||
|
||||
Reference in New Issue
Block a user