Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 69e3672

Browse files
committedDec 29, 2015
Merge pull request #1977 from ipfs/fix/record-accounting
send record fixes to peers who send outdated records
2 parents 9e9aa4c + 0a649c7 commit 69e3672

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed
 

‎routing/dht/dht.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ func (dht *IpfsDHT) putProvider(ctx context.Context, p peer.ID, skey string) err
150150
return nil
151151
}
152152

153+
var errInvalidRecord = errors.New("received invalid record")
154+
153155
// getValueOrPeers queries a particular peer p for the value for
154156
// key. It returns either the value or a list of closer peers.
155157
// NOTE: it will update the dht's peerstore with any new addresses
@@ -173,9 +175,11 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.ID,
173175
err = dht.verifyRecordOnline(ctx, record)
174176
if err != nil {
175177
log.Info("Received invalid record! (discarded)")
176-
return nil, nil, err
178+
// return a sentinal to signify an invalid record was received
179+
err = errInvalidRecord
180+
record = new(pb.Record)
177181
}
178-
return record, peers, nil
182+
return record, peers, err
179183
}
180184

181185
if len(peers) > 0 {

‎routing/dht/routing.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key key.Key) ([]byte, error) {
9191

9292
var recs [][]byte
9393
for _, v := range vals {
94-
recs = append(recs, v.Val)
94+
if v.Val != nil {
95+
recs = append(recs, v.Val)
96+
}
9597
}
9698

9799
i, err := dht.Selector.BestRecord(key, recs)
@@ -169,13 +171,26 @@ func (dht *IpfsDHT) GetValues(ctx context.Context, key key.Key, nvals int) ([]ro
169171
})
170172

171173
rec, peers, err := dht.getValueOrPeers(ctx, p, key)
172-
if err != nil {
174+
switch err {
175+
case routing.ErrNotFound:
176+
// in this case, they responded with nothing,
177+
// still send a notification so listeners can know the
178+
// request has completed 'successfully'
179+
notif.PublishQueryEvent(parent, &notif.QueryEvent{
180+
Type: notif.PeerResponse,
181+
ID: p,
182+
})
183+
return nil, err
184+
default:
173185
return nil, err
186+
187+
case nil, errInvalidRecord:
188+
// in either of these cases, we want to keep going
174189
}
175190

176191
res := &dhtQueryResult{closerPeers: peers}
177192

178-
if rec.GetValue() != nil {
193+
if rec.GetValue() != nil || err == errInvalidRecord {
179194
rv := routing.RecvdVal{
180195
Val: rec.GetValue(),
181196
From: p,

0 commit comments

Comments
 (0)
Please sign in to comment.