5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 08:21:36 +00:00

more debugging, trying to understand bootstrap issues

This commit is contained in:
Arceliar 2018-10-21 12:28:21 -05:00
parent 6c59ae862a
commit efe6cec11a
2 changed files with 73 additions and 33 deletions

View File

@ -57,7 +57,6 @@ type dht struct {
table map[NodeID]*dhtInfo table map[NodeID]*dhtInfo
peers chan *dhtInfo // other goroutines put incoming dht updates here peers chan *dhtInfo // other goroutines put incoming dht updates here
reqs map[boxPubKey]map[NodeID]time.Time reqs map[boxPubKey]map[NodeID]time.Time
search time.Time
} }
// Initializes the DHT // Initializes the DHT
@ -85,12 +84,11 @@ func (t *dht) reset() {
} }
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)
t.search = time.Now().Add(-time.Minute)
if successor != nil { if successor != nil {
t.ping(successor, &t.nodeID) t.ping(successor, nil)
} }
if predecessor != nil { if predecessor != nil {
t.ping(predecessor, &t.nodeID) t.ping(predecessor, nil)
} }
} }
@ -199,7 +197,24 @@ func (t *dht) handleReq(req *dhtReq) {
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
t.insert(&info) //t.insert(&info)
// FIXME? DEBUG testing what happens if we only add better predecessors/successors
var successor *dhtInfo
var predecessor *dhtInfo
for infoID, v := range t.table {
// Get current successor and predecessor
if successor == nil || dht_ordered(&t.nodeID, &infoID, successor.getNodeID()) {
successor = v
}
if predecessor == nil || dht_ordered(predecessor.getNodeID(), &infoID, &t.nodeID) {
predecessor = v
}
}
if successor != nil && dht_ordered(&t.nodeID, info.getNodeID(), successor.getNodeID()) {
t.insert(&info)
} else if predecessor != nil && dht_ordered(predecessor.getNodeID(), info.getNodeID(), &t.nodeID) {
t.insert(&info)
}
} }
// Sends a lookup response to the specified node. // Sends a lookup response to the specified node.
@ -263,10 +278,10 @@ func (t *dht) handleRes(res *dhtRes) {
var predecessor *dhtInfo var predecessor *dhtInfo
for infoID, info := range t.table { for infoID, info := range t.table {
// Get current successor and predecessor // Get current successor and predecessor
if successor == nil || dht_ordered(&t.nodeID, &infoID, successor.getNodeID()) { if successor != nil && dht_ordered(&t.nodeID, &infoID, successor.getNodeID()) {
successor = info successor = info
} }
if predecessor == nil || dht_ordered(predecessor.getNodeID(), &infoID, &t.nodeID) { if predecessor != nil && dht_ordered(predecessor.getNodeID(), &infoID, &t.nodeID) {
predecessor = info predecessor = info
} }
} }
@ -284,10 +299,9 @@ func (t *dht) handleRes(res *dhtRes) {
// 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()) {
t.ping(info, &t.nodeID) t.ping(info, nil)
} } else 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, nil)
t.ping(info, &t.nodeID)
} }
} }
// 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?)
@ -322,7 +336,7 @@ func (t *dht) sendReq(req *dhtReq, dest *dhtInfo) {
func (t *dht) ping(info *dhtInfo, target *NodeID) { func (t *dht) ping(info *dhtInfo, target *NodeID) {
// Creates a req for the node at dhtInfo, asking them about the target (if one is given) or themself (if no target is given) // Creates a req for the node at dhtInfo, asking them about the target (if one is given) or themself (if no target is given)
if target == nil { if target == nil {
target = info.getNodeID() target = &t.nodeID
} }
loc := t.core.switchTable.getLocator() loc := t.core.switchTable.getLocator()
coords := loc.getCoords() coords := loc.getCoords()
@ -337,42 +351,67 @@ func (t *dht) ping(info *dhtInfo, target *NodeID) {
func (t *dht) doMaintenance() { 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
var predecessor *dhtInfo
toPing := make(map[NodeID]*dhtInfo)
now := time.Now() now := time.Now()
for infoID, info := range t.table { for infoID, info := range t.table {
if now.Sub(info.recv) > time.Minute || info.pings > 3 { if now.Sub(info.recv) > time.Minute || info.pings > 3 {
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
} else if predecessor == nil || dht_ordered(predecessor.getNodeID(), &infoID, &t.nodeID) {
predecessor = info
} }
} }
//////////////////////////////////////////////////////////////////////////////
t.core.switchTable.mutex.RLock()
parentPort := t.core.switchTable.parent
parentInfo := t.core.switchTable.data.peers[parentPort]
t.core.switchTable.mutex.RUnlock()
ports := t.core.peers.getPorts()
if parent, isIn := ports[parentPort]; isIn {
loc := parentInfo.locator.clone()
end := len(loc.coords)
if end > 0 {
end -= 1
}
loc.coords = loc.coords[:end]
pinfo := dhtInfo{key: parent.box, coords: loc.getCoords()}
t.insert(&pinfo)
}
//////////////////////////////////////////////////////////////////////////////
if successor != nil {
toPing[*successor.getNodeID()] = successor
}
if predecessor != nil {
toPing[*predecessor.getNodeID()] = predecessor
}
for _, info := range toPing {
if now.Sub(info.recv) > info.throttle {
t.ping(info, nil)
info.pings++
info.throttle += time.Second
if info.throttle > 30*time.Second {
info.throttle = 30 * time.Second
}
//fmt.Println("DEBUG self:", t.nodeID[:8], "throttle:", info.throttle, "nodeID:", info.getNodeID()[:8], "coords:", info.coords)
}
}
return
//////////////////////////////////////////////////////////////////////////////
if successor != nil && if successor != nil &&
now.Sub(successor.recv) > successor.throttle { now.Sub(successor.recv) > successor.throttle {
t.ping(successor, nil) t.ping(successor, nil)
successor.pings++ successor.pings++
successor.throttle += time.Second successor.throttle += time.Second
///// //return
if now.Sub(t.search) > 30*time.Second {
t.search = now
target := successor.getNodeID().prev()
sinfo, isIn := t.core.searches.searches[target]
if !isIn {
var mask NodeID
for idx := range mask {
mask[idx] = 0xff
}
sinfo = t.core.searches.newIterSearch(&target, &mask)
}
t.core.searches.continueSearch(sinfo)
}
/////
return
fmt.Println("DEBUG self:", t.nodeID[:8], "throttle:", successor.throttle, "nodeID:", successor.getNodeID()[:8], "coords:", successor.coords) fmt.Println("DEBUG self:", t.nodeID[:8], "throttle:", successor.throttle, "nodeID:", successor.getNodeID()[:8], "coords:", successor.coords)
for infoID := range t.table { //for infoID := range t.table {
fmt.Println("DEBUG other info:", infoID[:8], "ordered", dht_ordered(&t.nodeID, &infoID, successor.getNodeID()), "swapped:", dht_ordered(&t.nodeID, successor.getNodeID(), &infoID)) // fmt.Println("DEBUG other info:", infoID[:8], "ordered", dht_ordered(&t.nodeID, &infoID, successor.getNodeID()), "swapped:", dht_ordered(&t.nodeID, successor.getNodeID(), &infoID))
} //}
if successor.throttle > 30*time.Second { if successor.throttle > 30*time.Second {
successor.throttle = 30 * time.Second successor.throttle = 30 * time.Second
} }
fmt.Println("Table size:", len(t.table)) //fmt.Println("Table size:", len(t.table))
} }
} }

View File

@ -183,6 +183,7 @@ func (p *peer) linkLoop() {
} }
p.sendSwitchMsg() p.sendSwitchMsg()
case _ = <-tick.C: case _ = <-tick.C:
break // FIXME disabled the below completely to test something
pdinfo := p.dinfo // FIXME this is a bad workarond NPE on the next line pdinfo := p.dinfo // FIXME this is a bad workarond NPE on the next line
if pdinfo != nil { if pdinfo != nil {
dinfo := *pdinfo dinfo := *pdinfo
@ -332,7 +333,7 @@ func (p *peer) handleSwitchMsg(packet []byte) {
key: p.box, key: p.box,
coords: loc.getCoords(), coords: loc.getCoords(),
} }
p.core.dht.peers <- &dinfo //p.core.dht.peers <- &dinfo
p.dinfo = &dinfo p.dinfo = &dinfo
} }