more debugging

This commit is contained in:
Arceliar 2018-10-20 16:27:01 -05:00
parent 1720dff476
commit 02f0611dde
3 changed files with 33 additions and 7 deletions

View File

@ -415,10 +415,10 @@ func main() {
} }
fmt.Println("Test") fmt.Println("Test")
Util_testAddrIDMask() Util_testAddrIDMask()
idxstore := makeStoreSquareGrid(4) //idxstore := makeStoreSquareGrid(4)
//idxstore := makeStoreStar(256) //idxstore := makeStoreStar(256)
//idxstore := loadGraph("misc/sim/hype-2016-09-19.list") //idxstore := loadGraph("misc/sim/hype-2016-09-19.list")
//idxstore := loadGraph("misc/sim/fc00-2017-08-12.txt") idxstore := loadGraph("misc/sim/fc00-2017-08-12.txt")
//idxstore := loadGraph("skitter") //idxstore := loadGraph("skitter")
kstore := getKeyedStore(idxstore) kstore := getKeyedStore(idxstore)
//* //*

View File

@ -233,6 +233,7 @@ func (c *Core) DEBUG_getDHTSize() int {
c.router.doAdmin(func() { c.router.doAdmin(func() {
total = len(c.dht.table) total = len(c.dht.table)
}) })
fmt.Println("DEBUG_getDHTSize():", total)
return total return total
} }

View File

@ -66,6 +66,7 @@ func (t *dht) init(c *Core) {
} }
func (t *dht) reset() { func (t *dht) reset() {
fmt.Println("Resetting table:", t.nodeID)
t.reqs = make(map[boxPubKey]map[NodeID]time.Time) t.reqs = make(map[boxPubKey]map[NodeID]time.Time)
t.table = make(map[NodeID]*dhtInfo) t.table = make(map[NodeID]*dhtInfo)
} }
@ -98,7 +99,7 @@ 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 { if *info.getNodeID() == t.nodeID {
// This shouldn't happen, but don't crash or add it in case it does // This shouldn't happen, but don't add it in case it does
return return
panic("FIXME") panic("FIXME")
} }
@ -152,6 +153,7 @@ func (t *dht) handleReq(req *dhtReq) {
} }
// 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
t.insert(&info) t.insert(&info)
info.send = info.send.Add(-time.Minute)
} }
// Sends a lookup response to the specified node. // Sends a lookup response to the specified node.
@ -234,11 +236,19 @@ func (t *dht) handleRes(res *dhtRes) {
// 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()) {
t.ping(info, &t.nodeID) t.ping(info, &t.nodeID)
if successor != nil {
fmt.Println("pinging better successor", t.nodeID[:4], info.getNodeID()[:4], successor.getNodeID()[:4], len(t.table))
} else {
fmt.Println("pinging new successor", t.nodeID[:4], info.getNodeID()[:4], successor) 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) {
t.ping(info, &t.nodeID) t.ping(info, &t.nodeID)
fmt.Println("pinging new predecessor", t.nodeID[:4], info.getNodeID()[:4], predecessor) if predecessor != nil {
fmt.Println("pinging better predecessor", t.nodeID[:4], info.getNodeID()[:4], predecessor.getNodeID()[:4], len(t.table))
} else {
fmt.Println("pinging new predecessor", t.nodeID[:4], info.getNodeID()[:4])
}
} }
} }
// 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?)
@ -290,15 +300,30 @@ func (t *dht) doMaintenance() {
// Ping successor, asking for their predecessor, and clean up old/expired info // Ping successor, asking for their predecessor, and clean up old/expired info
var successor *dhtInfo var successor *dhtInfo
now := time.Now() now := time.Now()
size := len(t.table)
for infoID, info := range t.table { for infoID, info := range t.table {
/*
if now.Sub(info.recv) > time.Minute { if now.Sub(info.recv) > time.Minute {
delete(t.table, infoID) delete(t.table, infoID)
} else if successor == nil || dht_ordered(&t.nodeID, &infoID, successor.getNodeID()) { } else if successor == nil || dht_ordered(&t.nodeID, &infoID, successor.getNodeID()) {
successor = info successor = info
} }
*/
if successor == nil || dht_ordered(&t.nodeID, &infoID, successor.getNodeID()) {
successor = info
}
if now.Sub(info.recv) > time.Minute {
delete(t.table, infoID)
}
} }
if successor != nil && if successor != nil &&
now.Sub(successor.send) > 6*time.Second { now.Sub(successor.send) > 6*time.Second {
t.ping(successor, nil) t.ping(successor, nil)
} }
if successor != nil && t.table[*successor.getNodeID()] == nil {
fmt.Println("DEBUG: successor timed out:", t.nodeID[:4], successor.getNodeID()[:4])
}
if len(t.table) != size {
fmt.Println("DEBUG: timeouts:", t.nodeID[:4], size, len(t.table))
}
} }