From bced15b1389a648dc4694f953304103bf5dc8ad9 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 7 Jun 2018 20:29:22 -0500 Subject: [PATCH] remove TTL from traffic packets --- misc/sim/treesim.go | 12 +++--------- src/yggdrasil/debug.go | 4 ++-- src/yggdrasil/dht.go | 2 -- src/yggdrasil/peer.go | 9 +++------ src/yggdrasil/session.go | 2 -- src/yggdrasil/switch.go | 14 +++++--------- src/yggdrasil/wire.go | 8 -------- 7 files changed, 13 insertions(+), 38 deletions(-) diff --git a/misc/sim/treesim.go b/misc/sim/treesim.go index 91b8e0e..83548e8 100644 --- a/misc/sim/treesim.go +++ b/misc/sim/treesim.go @@ -160,17 +160,11 @@ func testPaths(store map[[32]byte]*Node) bool { ttl := ^uint64(0) oldTTL := ttl for here := source; here != dest; { - if ttl == 0 { - fmt.Println("Drop:", source.index, here.index, dest.index, oldTTL) - return false - } temp++ if temp > 4096 { panic("Loop?") } - oldTTL = ttl - nextPort, newTTL := here.core.DEBUG_switchLookup(coords, ttl) - ttl = newTTL + nextPort := here.core.DEBUG_switchLookup(coords) // First check if "here" is accepting packets from the previous node // TODO explain how this works ports := here.core.DEBUG_getPeers().DEBUG_getPorts() @@ -208,7 +202,7 @@ func testPaths(store map[[32]byte]*Node) bool { //break } if here == next { - fmt.Println("Drop2:", source.index, here.index, dest.index, oldTTL) + fmt.Println("Drop:", source.index, here.index, dest.index, oldTTL) return false } here = next @@ -231,7 +225,7 @@ func stressTest(store map[[32]byte]*Node) { start := time.Now() for _, source := range store { for _, coords := range dests { - source.core.DEBUG_switchLookup(coords, ^uint64(0)) + source.core.DEBUG_switchLookup(coords) lookups++ } } diff --git a/src/yggdrasil/debug.go b/src/yggdrasil/debug.go index f080882..6b8211c 100644 --- a/src/yggdrasil/debug.go +++ b/src/yggdrasil/debug.go @@ -126,8 +126,8 @@ func (l *switchLocator) DEBUG_getCoords() []byte { return l.getCoords() } -func (c *Core) DEBUG_switchLookup(dest []byte, ttl uint64) (switchPort, uint64) { - return c.switchTable.lookup(dest, ttl) +func (c *Core) DEBUG_switchLookup(dest []byte) switchPort { + return c.switchTable.lookup(dest) } /* diff --git a/src/yggdrasil/dht.go b/src/yggdrasil/dht.go index 95f6bb1..3393391 100644 --- a/src/yggdrasil/dht.go +++ b/src/yggdrasil/dht.go @@ -326,7 +326,6 @@ func (t *dht) sendReq(req *dhtReq, dest *dhtInfo) { shared := t.core.sessions.getSharedKey(&t.core.boxPriv, &dest.key) payload, nonce := boxSeal(shared, bs, nil) p := wire_protoTrafficPacket{ - TTL: ^uint64(0), Coords: dest.coords, ToKey: dest.key, FromKey: t.core.boxPub, @@ -352,7 +351,6 @@ func (t *dht) sendRes(res *dhtRes, req *dhtReq) { shared := t.core.sessions.getSharedKey(&t.core.boxPriv, &req.Key) payload, nonce := boxSeal(shared, bs, nil) p := wire_protoTrafficPacket{ - TTL: ^uint64(0), Coords: req.Coords, ToKey: req.Key, FromKey: t.core.boxPub, diff --git a/src/yggdrasil/peer.go b/src/yggdrasil/peer.go index ee25b07..497024c 100644 --- a/src/yggdrasil/peer.go +++ b/src/yggdrasil/peer.go @@ -204,14 +204,11 @@ func (p *peer) handleTraffic(packet []byte, pTypeLen int) { // Drop traffic until the peer manages to send us at least one good switchMsg return } - _, ttlLen := wire_decode_uint64(packet[pTypeLen:]) - ttlEnd := pTypeLen + ttlLen - coords, coordLen := wire_decode_coords(packet[ttlEnd:]) - coordEnd := ttlEnd + coordLen - if coordEnd == len(packet) { + coords, coordLen := wire_decode_coords(packet[pTypeLen:]) + if coordLen >= len(packet) { return } // No payload - toPort, _ := p.core.switchTable.lookup(coords, 0) + toPort := p.core.switchTable.lookup(coords) if toPort == p.port { return } diff --git a/src/yggdrasil/session.go b/src/yggdrasil/session.go index 8bbbc33..3311142 100644 --- a/src/yggdrasil/session.go +++ b/src/yggdrasil/session.go @@ -255,7 +255,6 @@ func (ss *sessions) sendPingPong(sinfo *sessionInfo, isPong bool) { shared := ss.getSharedKey(&ss.core.boxPriv, &sinfo.theirPermPub) payload, nonce := boxSeal(shared, bs, nil) p := wire_protoTrafficPacket{ - TTL: ^uint64(0), Coords: sinfo.coords, ToKey: sinfo.theirPermPub, FromKey: ss.core.boxPub, @@ -383,7 +382,6 @@ func (sinfo *sessionInfo) doSend(bs []byte) { payload, nonce := boxSeal(&sinfo.sharedSesKey, bs, &sinfo.myNonce) defer util_putBytes(payload) p := wire_trafficPacket{ - TTL: ^uint64(0), Coords: sinfo.coords, Handle: sinfo.theirHandle, Nonce: *nonce, diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index be3027a..4db4c67 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -413,22 +413,19 @@ func (t *switchTable) updateTable() { t.table.Store(newTable) } -func (t *switchTable) lookup(dest []byte, ttl uint64) (switchPort, uint64) { +func (t *switchTable) lookup(dest []byte) switchPort { t.updater.Load().(*sync.Once).Do(t.updateTable) table := t.table.Load().(lookupTable) - myDist := table.self.dist(dest) //getDist(table.self.coords) - if !(uint64(myDist) < ttl) { - //return 0, 0 - } + myDist := table.self.dist(dest) if myDist == 0 { - return 0, 0 + return 0 } // cost is in units of (expected distance) + (expected queue size), where expected distance is used as an approximation of the minimum backpressure gradient needed for packets to flow ports := t.core.peers.getPorts() var best switchPort bestCost := int64(^uint64(0) >> 1) for _, info := range table.elems { - dist := info.locator.dist(dest) //getDist(info.locator.coords) + dist := info.locator.dist(dest) if !(dist < myDist) { continue } @@ -442,9 +439,8 @@ func (t *switchTable) lookup(dest []byte, ttl uint64) (switchPort, uint64) { bestCost = cost } } - //t.core.log.Println("DEBUG: sending to", best, "bandwidth", getBandwidth(best)) //t.core.log.Println("DEBUG: sending to", best, "cost", bestCost) - return best, ttl //uint64(myDist) + return best } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/yggdrasil/wire.go b/src/yggdrasil/wire.go index 305e5fc..3b43143 100644 --- a/src/yggdrasil/wire.go +++ b/src/yggdrasil/wire.go @@ -192,7 +192,6 @@ func wire_chop_uint64(toUInt64 *uint64, fromSlice *[]byte) bool { // Wire traffic packets type wire_trafficPacket struct { - TTL uint64 Coords []byte Handle handle Nonce boxNonce @@ -203,7 +202,6 @@ type wire_trafficPacket struct { func (p *wire_trafficPacket) encode() []byte { bs := util_getBytes() bs = wire_put_uint64(wire_Traffic, bs) - bs = wire_put_uint64(p.TTL, bs) bs = wire_put_coords(p.Coords, bs) bs = append(bs, p.Handle[:]...) bs = append(bs, p.Nonce[:]...) @@ -219,8 +217,6 @@ func (p *wire_trafficPacket) decode(bs []byte) bool { return false case pType != wire_Traffic: return false - case !wire_chop_uint64(&p.TTL, &bs): - return false case !wire_chop_coords(&p.Coords, &bs): return false case !wire_chop_slice(p.Handle[:], &bs): @@ -233,7 +229,6 @@ func (p *wire_trafficPacket) decode(bs []byte) bool { } type wire_protoTrafficPacket struct { - TTL uint64 Coords []byte ToKey boxPubKey FromKey boxPubKey @@ -244,7 +239,6 @@ type wire_protoTrafficPacket struct { func (p *wire_protoTrafficPacket) encode() []byte { coords := wire_encode_coords(p.Coords) bs := wire_encode_uint64(wire_ProtocolTraffic) - bs = append(bs, wire_encode_uint64(p.TTL)...) bs = append(bs, coords...) bs = append(bs, p.ToKey[:]...) bs = append(bs, p.FromKey[:]...) @@ -260,8 +254,6 @@ func (p *wire_protoTrafficPacket) decode(bs []byte) bool { return false case pType != wire_ProtocolTraffic: return false - case !wire_chop_uint64(&p.TTL, &bs): - return false case !wire_chop_coords(&p.Coords, &bs): return false case !wire_chop_slice(p.ToKey[:], &bs):