1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 05:52:20 +08:00

send record fixes to peers who send outdated records

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2015-11-19 11:24:59 -08:00
parent f3f776067a
commit 6b1f1ec1ba
2 changed files with 14 additions and 2 deletions

View File

@ -173,7 +173,9 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.ID,
err = dht.verifyRecordOnline(ctx, record)
if err != nil {
log.Info("Received invalid record! (discarded)")
return nil, nil, err
// still return a non-nil record to signify that we received
// a bad record from this peer
record = new(pb.Record)
}
return record, peers, nil
}

View File

@ -91,7 +91,9 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key key.Key) ([]byte, error) {
var recs [][]byte
for _, v := range vals {
recs = append(recs, v.Val)
if v.Val != nil {
recs = append(recs, v.Val)
}
}
i, err := dht.Selector.BestRecord(key, recs)
@ -170,6 +172,14 @@ func (dht *IpfsDHT) GetValues(ctx context.Context, key key.Key, nvals int) ([]ro
rec, peers, err := dht.getValueOrPeers(ctx, p, key)
if err != nil {
if err == routing.ErrNotFound {
// in this case, they responded with nothing,
// still send a notification
notif.PublishQueryEvent(parent, &notif.QueryEvent{
Type: notif.PeerResponse,
ID: p,
})
}
return nil, err
}