Commit cdb461d2 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

dht: update on every received message

i made a separate function because we may want to update our
routing table based on "closer peers". maybe not-- these could
all be lies.
parent 61cdef35
......@@ -34,8 +34,9 @@ func (dht *IpfsDHT) handleNewMessage(s inet.Stream) {
log.Error("Error unmarshaling data")
return
}
// update the peer (on valid msgs only)
dht.Update(ctx, mPeer)
dht.updateFromMessage(ctx, mPeer, pmes)
log.Event(ctx, "foo", dht.self, mPeer, pmes)
......@@ -103,6 +104,9 @@ func (dht *IpfsDHT) sendRequest(ctx context.Context, p peer.ID, pmes *pb.Message
return nil, errors.New("no response to request")
}
// update the peer (on valid msgs only)
dht.updateFromMessage(ctx, p, rpmes)
dht.peerstore.RecordLatency(p, time.Since(start))
log.Event(ctx, "dhtReceivedMessage", dht.self, p, rpmes)
return rpmes, nil
......@@ -129,3 +133,8 @@ func (dht *IpfsDHT) sendMessage(ctx context.Context, p peer.ID, pmes *pb.Message
log.Debugf("%s done", dht.self)
return nil
}
func (dht *IpfsDHT) updateFromMessage(ctx context.Context, p peer.ID, mes *pb.Message) error {
dht.Update(ctx, p)
return nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment