@cryptotaxi247 / kubo / commits / 6b1f1ec1b

send record fixes to peers who send outdated records

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Nov 19, 2015 at 11:24 UTC 6b1f1ec1ba57cc95da686809d6996308556325b1
2 files changed +14 -2
routing/dht/dht.go
+3 -1
@@ -173,7 +173,9 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.ID,
173 err = dht.verifyRecordOnline(ctx, record)
174 if err != nil {
175 log.Info("Received invalid record! (discarded)")
176 - return nil, nil, err
176 + // still return a non-nil record to signify that we received
177 + // a bad record from this peer
178 + record = new(pb.Record)
179 }
180 return record, peers, nil
181 }
routing/dht/routing.go
+11 -1
@@ -91,7 +91,9 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key key.Key) ([]byte, error) {
91
92 var recs [][]byte
93 for _, v := range vals {
94 - recs = append(recs, v.Val)
94 + if v.Val != nil {
95 + recs = append(recs, v.Val)
96 + }
97 }
98
99 i, err := dht.Selector.BestRecord(key, recs)
@@ -170,6 +172,14 @@ func (dht *IpfsDHT) GetValues(ctx context.Context, key key.Key, nvals int) ([]ro
172
173 rec, peers, err := dht.getValueOrPeers(ctx, p, key)
174 if err != nil {
175 + if err == routing.ErrNotFound {
176 + // in this case, they responded with nothing,
177 + // still send a notification
178 + notif.PublishQueryEvent(parent, &notif.QueryEvent{
179 + Type: notif.PeerResponse,
180 + ID: p,
181 + })
182 + }
183 return nil, err
184 }
185