mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 12:05:23 +00:00
use source routes in the dht (when available)
This commit is contained in:
parent
428789f24c
commit
0ba2ad74fe
@ -28,6 +28,7 @@ type dhtInfo struct {
|
|||||||
recv time.Time // When we last received a message
|
recv time.Time // When we last received a message
|
||||||
pings int // Time out if at least 3 consecutive maintenance pings drop
|
pings int // Time out if at least 3 consecutive maintenance pings drop
|
||||||
throttle time.Duration
|
throttle time.Duration
|
||||||
|
path []byte // source route the destination, learned from response rpath
|
||||||
dirty bool // Set to true if we've used this node in ping responses (for queries about someone other than the person doing the asking, i.e. real searches) since the last time we heard from the node
|
dirty bool // Set to true if we've used this node in ping responses (for queries about someone other than the person doing the asking, i.e. real searches) since the last time we heard from the node
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,9 +92,14 @@ func (t *dht) reconfigure() {
|
|||||||
func (t *dht) reset() {
|
func (t *dht) reset() {
|
||||||
for _, info := range t.table {
|
for _, info := range t.table {
|
||||||
if t.isImportant(info) {
|
if t.isImportant(info) {
|
||||||
|
t.ping(info, nil) // This will source route if a path is already known
|
||||||
|
if info.path != nil {
|
||||||
|
// In case the source route died, but the dest coords are still OK...
|
||||||
|
info.path = nil
|
||||||
t.ping(info, nil)
|
t.ping(info, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
t.table = make(map[crypto.NodeID]*dhtInfo)
|
t.table = make(map[crypto.NodeID]*dhtInfo)
|
||||||
t.imp = nil
|
t.imp = nil
|
||||||
}
|
}
|
||||||
@ -116,6 +122,9 @@ func (t *dht) lookup(nodeID *crypto.NodeID, everything bool) []*dhtInfo {
|
|||||||
results = newRes
|
results = newRes
|
||||||
results = results[:dht_lookup_size]
|
results = results[:dht_lookup_size]
|
||||||
}
|
}
|
||||||
|
for _, info := range results {
|
||||||
|
info.dirty = true
|
||||||
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +252,7 @@ func (t *dht) addCallback(rq *dhtReqKey, callback func(*dhtRes)) {
|
|||||||
|
|
||||||
// Reads a lookup response, checks that we had sent a matching request, and processes the response info.
|
// Reads a lookup response, checks that we had sent a matching request, and processes the response info.
|
||||||
// This mainly consists of updating the node we asked in our DHT (they responded, so we know they're still alive), and deciding if we want to do anything with their responses
|
// This mainly consists of updating the node we asked in our DHT (they responded, so we know they're still alive), and deciding if we want to do anything with their responses
|
||||||
func (t *dht) handleRes(res *dhtRes) {
|
func (t *dht) handleRes(res *dhtRes, rpath []byte) {
|
||||||
rq := dhtReqKey{res.Key, res.Dest}
|
rq := dhtReqKey{res.Key, res.Dest}
|
||||||
if callbacks, isIn := t.callbacks[rq]; isIn {
|
if callbacks, isIn := t.callbacks[rq]; isIn {
|
||||||
for _, callback := range callbacks {
|
for _, callback := range callbacks {
|
||||||
@ -259,6 +268,7 @@ func (t *dht) handleRes(res *dhtRes) {
|
|||||||
rinfo := dhtInfo{
|
rinfo := dhtInfo{
|
||||||
key: res.Key,
|
key: res.Key,
|
||||||
coords: res.Coords,
|
coords: res.Coords,
|
||||||
|
path: switch_reverseCoordBytes(rpath),
|
||||||
}
|
}
|
||||||
if t.isImportant(&rinfo) {
|
if t.isImportant(&rinfo) {
|
||||||
t.insert(&rinfo)
|
t.insert(&rinfo)
|
||||||
@ -290,6 +300,10 @@ func (t *dht) sendReq(req *dhtReq, dest *dhtInfo) {
|
|||||||
Nonce: *nonce,
|
Nonce: *nonce,
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
}
|
}
|
||||||
|
if dest.path != nil {
|
||||||
|
p.Coords = append([]byte{0}, dest.path...)
|
||||||
|
p.Offset += 1
|
||||||
|
}
|
||||||
packet := p.encode()
|
packet := p.encode()
|
||||||
t.router.out(packet)
|
t.router.out(packet)
|
||||||
rq := dhtReqKey{dest.key, req.Dest}
|
rq := dhtReqKey{dest.key, req.Dest}
|
||||||
|
@ -206,7 +206,7 @@ func (r *router) _handleProto(packet []byte) {
|
|||||||
case wire_DHTLookupRequest:
|
case wire_DHTLookupRequest:
|
||||||
r._handleDHTReq(bs, &p.FromKey, p.RPath)
|
r._handleDHTReq(bs, &p.FromKey, p.RPath)
|
||||||
case wire_DHTLookupResponse:
|
case wire_DHTLookupResponse:
|
||||||
r._handleDHTRes(bs, &p.FromKey)
|
r._handleDHTRes(bs, &p.FromKey, p.RPath)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,13 +237,13 @@ func (r *router) _handleDHTReq(bs []byte, fromKey *crypto.BoxPubKey, rpath []byt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decodes dht responses and passes them to dht.handleRes to update the DHT table and further pass them to the search code (if applicable).
|
// Decodes dht responses and passes them to dht.handleRes to update the DHT table and further pass them to the search code (if applicable).
|
||||||
func (r *router) _handleDHTRes(bs []byte, fromKey *crypto.BoxPubKey) {
|
func (r *router) _handleDHTRes(bs []byte, fromKey *crypto.BoxPubKey, rpath []byte) {
|
||||||
res := dhtRes{}
|
res := dhtRes{}
|
||||||
if !res.decode(bs) {
|
if !res.decode(bs) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res.Key = *fromKey
|
res.Key = *fromKey
|
||||||
r.dht.handleRes(&res)
|
r.dht.handleRes(&res, rpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decodes nodeinfo request
|
// Decodes nodeinfo request
|
||||||
|
Loading…
Reference in New Issue
Block a user