mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-24 18:45:21 +00:00
add some debug output and get things to start working in the sim
This commit is contained in:
parent
03a88fe304
commit
1720dff476
@ -229,14 +229,10 @@ func DEBUG_wire_encode_coords(coords []byte) []byte {
|
|||||||
// DHT, via core
|
// DHT, via core
|
||||||
|
|
||||||
func (c *Core) DEBUG_getDHTSize() int {
|
func (c *Core) DEBUG_getDHTSize() int {
|
||||||
total := 0
|
var total int
|
||||||
/* FIXME
|
c.router.doAdmin(func() {
|
||||||
for bidx := 0; bidx < c.dht.nBuckets(); bidx++ {
|
total = len(c.dht.table)
|
||||||
b := c.dht.getBucket(bidx)
|
})
|
||||||
total += len(b.peers)
|
|
||||||
total += len(b.other)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return total
|
return total
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package yggdrasil
|
package yggdrasil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -65,11 +66,11 @@ func (t *dht) init(c *Core) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *dht) reset() {
|
func (t *dht) reset() {
|
||||||
|
t.reqs = make(map[boxPubKey]map[NodeID]time.Time)
|
||||||
t.table = make(map[NodeID]*dhtInfo)
|
t.table = make(map[NodeID]*dhtInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *dht) lookup(nodeID *NodeID, allowWorse bool) []*dhtInfo {
|
func (t *dht) lookup(nodeID *NodeID, allowWorse bool) []*dhtInfo {
|
||||||
return nil
|
|
||||||
var results []*dhtInfo
|
var results []*dhtInfo
|
||||||
var successor *dhtInfo
|
var successor *dhtInfo
|
||||||
sTarget := t.nodeID.next()
|
sTarget := t.nodeID.next()
|
||||||
@ -96,6 +97,11 @@ func (t *dht) lookup(nodeID *NodeID, allowWorse bool) []*dhtInfo {
|
|||||||
|
|
||||||
// Insert into table, preserving the time we last sent a packet if the node was already in the table, otherwise setting that time to now
|
// Insert into table, preserving the time we last sent a packet if the node was already in the table, otherwise setting that time to now
|
||||||
func (t *dht) insert(info *dhtInfo) {
|
func (t *dht) insert(info *dhtInfo) {
|
||||||
|
if *info.getNodeID() == t.nodeID {
|
||||||
|
// This shouldn't happen, but don't crash or add it in case it does
|
||||||
|
return
|
||||||
|
panic("FIXME")
|
||||||
|
}
|
||||||
info.recv = time.Now()
|
info.recv = time.Now()
|
||||||
if oldInfo, isIn := t.table[*info.getNodeID()]; isIn {
|
if oldInfo, isIn := t.table[*info.getNodeID()]; isIn {
|
||||||
info.send = oldInfo.send
|
info.send = oldInfo.send
|
||||||
@ -139,14 +145,12 @@ func (t *dht) handleReq(req *dhtReq) {
|
|||||||
Infos: t.lookup(&req.Dest, false),
|
Infos: t.lookup(&req.Dest, false),
|
||||||
}
|
}
|
||||||
t.sendRes(&res, req)
|
t.sendRes(&res, req)
|
||||||
// Also (possibly) add them to our DHT
|
// Also add them to our DHT
|
||||||
info := dhtInfo{
|
info := dhtInfo{
|
||||||
key: req.Key,
|
key: req.Key,
|
||||||
coords: req.Coords,
|
coords: req.Coords,
|
||||||
}
|
}
|
||||||
// For bootstrapping to work, we need to add these nodes to the table
|
// For bootstrapping to work, we need to add these nodes to the table
|
||||||
// Using insertIfNew, they can lie about coords, but searches will route around them
|
|
||||||
// Using the mill would mean trying to block off the mill becomes an attack vector
|
|
||||||
t.insert(&info)
|
t.insert(&info)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +173,7 @@ func (t *dht) sendRes(res *dhtRes, req *dhtReq) {
|
|||||||
|
|
||||||
// Returns nodeID + 1
|
// Returns nodeID + 1
|
||||||
func (nodeID NodeID) next() NodeID {
|
func (nodeID NodeID) next() NodeID {
|
||||||
for idx := len(nodeID); idx >= 0; idx-- {
|
for idx := len(nodeID) - 1; idx >= 0; idx-- {
|
||||||
nodeID[idx] += 1
|
nodeID[idx] += 1
|
||||||
if nodeID[idx] != 0 {
|
if nodeID[idx] != 0 {
|
||||||
break
|
break
|
||||||
@ -180,7 +184,7 @@ func (nodeID NodeID) next() NodeID {
|
|||||||
|
|
||||||
// Returns nodeID - 1
|
// Returns nodeID - 1
|
||||||
func (nodeID NodeID) prev() NodeID {
|
func (nodeID NodeID) prev() NodeID {
|
||||||
for idx := len(nodeID); idx >= 0; idx-- {
|
for idx := len(nodeID) - 1; idx >= 0; idx-- {
|
||||||
nodeID[idx] -= 1
|
nodeID[idx] -= 1
|
||||||
if nodeID[idx] != 0xff {
|
if nodeID[idx] != 0xff {
|
||||||
break
|
break
|
||||||
@ -222,13 +226,19 @@ func (t *dht) handleRes(res *dhtRes) {
|
|||||||
if *info.getNodeID() == t.nodeID {
|
if *info.getNodeID() == t.nodeID {
|
||||||
continue
|
continue
|
||||||
} // Skip self
|
} // Skip self
|
||||||
|
if _, isIn := t.table[*info.getNodeID()]; isIn {
|
||||||
|
// TODO? don't skip if coords are different?
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Send a request to all better successors or predecessors
|
// Send a request to all better successors or predecessors
|
||||||
// We could try sending to only the best, but then packet loss matters more
|
// We could try sending to only the best, but then packet loss matters more
|
||||||
if successor == nil || dht_ordered(&t.nodeID, info.getNodeID(), successor.getNodeID()) {
|
if successor == nil || dht_ordered(&t.nodeID, info.getNodeID(), successor.getNodeID()) {
|
||||||
// ping
|
t.ping(info, &t.nodeID)
|
||||||
|
fmt.Println("pinging new successor", t.nodeID[:4], info.getNodeID()[:4], successor)
|
||||||
}
|
}
|
||||||
if predecessor == nil || dht_ordered(predecessor.getNodeID(), info.getNodeID(), &t.nodeID) {
|
if predecessor == nil || dht_ordered(predecessor.getNodeID(), info.getNodeID(), &t.nodeID) {
|
||||||
// ping
|
t.ping(info, &t.nodeID)
|
||||||
|
fmt.Println("pinging new predecessor", t.nodeID[:4], info.getNodeID()[:4], predecessor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO add everyting else to a rumor mill for later use? (when/how?)
|
// TODO add everyting else to a rumor mill for later use? (when/how?)
|
||||||
@ -288,7 +298,6 @@ func (t *dht) doMaintenance() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if successor != nil &&
|
if successor != nil &&
|
||||||
now.Sub(successor.recv) > 30*time.Second &&
|
|
||||||
now.Sub(successor.send) > 6*time.Second {
|
now.Sub(successor.send) > 6*time.Second {
|
||||||
t.ping(successor, nil)
|
t.ping(successor, nil)
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ func (s *searches) addToSearch(sinfo *searchInfo, res *dhtRes) {
|
|||||||
// Add responses to toVisit if closer to dest than the res node
|
// Add responses to toVisit if closer to dest than the res node
|
||||||
from := dhtInfo{key: res.Key, coords: res.Coords}
|
from := dhtInfo{key: res.Key, coords: res.Coords}
|
||||||
for _, info := range res.Infos {
|
for _, info := range res.Infos {
|
||||||
if sinfo.visited[*info.getNodeID()] {
|
if *info.getNodeID() == s.core.dht.nodeID || sinfo.visited[*info.getNodeID()] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if dht_ordered(from.getNodeID(), info.getNodeID(), &res.Dest) {
|
if dht_ordered(from.getNodeID(), info.getNodeID(), &res.Dest) {
|
||||||
|
Loading…
Reference in New Issue
Block a user