5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 17:40:26 +00:00

remove TTL from traffic packets

This commit is contained in:
Arceliar 2018-06-07 20:29:22 -05:00
parent 84c13fac90
commit bced15b138
7 changed files with 13 additions and 38 deletions

View File

@ -160,17 +160,11 @@ func testPaths(store map[[32]byte]*Node) bool {
ttl := ^uint64(0) ttl := ^uint64(0)
oldTTL := ttl oldTTL := ttl
for here := source; here != dest; { for here := source; here != dest; {
if ttl == 0 {
fmt.Println("Drop:", source.index, here.index, dest.index, oldTTL)
return false
}
temp++ temp++
if temp > 4096 { if temp > 4096 {
panic("Loop?") panic("Loop?")
} }
oldTTL = ttl nextPort := here.core.DEBUG_switchLookup(coords)
nextPort, newTTL := here.core.DEBUG_switchLookup(coords, ttl)
ttl = newTTL
// First check if "here" is accepting packets from the previous node // First check if "here" is accepting packets from the previous node
// TODO explain how this works // TODO explain how this works
ports := here.core.DEBUG_getPeers().DEBUG_getPorts() ports := here.core.DEBUG_getPeers().DEBUG_getPorts()
@ -208,7 +202,7 @@ func testPaths(store map[[32]byte]*Node) bool {
//break //break
} }
if here == next { 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 return false
} }
here = next here = next
@ -231,7 +225,7 @@ func stressTest(store map[[32]byte]*Node) {
start := time.Now() start := time.Now()
for _, source := range store { for _, source := range store {
for _, coords := range dests { for _, coords := range dests {
source.core.DEBUG_switchLookup(coords, ^uint64(0)) source.core.DEBUG_switchLookup(coords)
lookups++ lookups++
} }
} }

View File

@ -126,8 +126,8 @@ func (l *switchLocator) DEBUG_getCoords() []byte {
return l.getCoords() return l.getCoords()
} }
func (c *Core) DEBUG_switchLookup(dest []byte, ttl uint64) (switchPort, uint64) { func (c *Core) DEBUG_switchLookup(dest []byte) switchPort {
return c.switchTable.lookup(dest, ttl) return c.switchTable.lookup(dest)
} }
/* /*

View File

@ -326,7 +326,6 @@ func (t *dht) sendReq(req *dhtReq, dest *dhtInfo) {
shared := t.core.sessions.getSharedKey(&t.core.boxPriv, &dest.key) shared := t.core.sessions.getSharedKey(&t.core.boxPriv, &dest.key)
payload, nonce := boxSeal(shared, bs, nil) payload, nonce := boxSeal(shared, bs, nil)
p := wire_protoTrafficPacket{ p := wire_protoTrafficPacket{
TTL: ^uint64(0),
Coords: dest.coords, Coords: dest.coords,
ToKey: dest.key, ToKey: dest.key,
FromKey: t.core.boxPub, 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) shared := t.core.sessions.getSharedKey(&t.core.boxPriv, &req.Key)
payload, nonce := boxSeal(shared, bs, nil) payload, nonce := boxSeal(shared, bs, nil)
p := wire_protoTrafficPacket{ p := wire_protoTrafficPacket{
TTL: ^uint64(0),
Coords: req.Coords, Coords: req.Coords,
ToKey: req.Key, ToKey: req.Key,
FromKey: t.core.boxPub, FromKey: t.core.boxPub,

View File

@ -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 // Drop traffic until the peer manages to send us at least one good switchMsg
return return
} }
_, ttlLen := wire_decode_uint64(packet[pTypeLen:]) coords, coordLen := wire_decode_coords(packet[pTypeLen:])
ttlEnd := pTypeLen + ttlLen if coordLen >= len(packet) {
coords, coordLen := wire_decode_coords(packet[ttlEnd:])
coordEnd := ttlEnd + coordLen
if coordEnd == len(packet) {
return return
} // No payload } // No payload
toPort, _ := p.core.switchTable.lookup(coords, 0) toPort := p.core.switchTable.lookup(coords)
if toPort == p.port { if toPort == p.port {
return return
} }

View File

@ -255,7 +255,6 @@ func (ss *sessions) sendPingPong(sinfo *sessionInfo, isPong bool) {
shared := ss.getSharedKey(&ss.core.boxPriv, &sinfo.theirPermPub) shared := ss.getSharedKey(&ss.core.boxPriv, &sinfo.theirPermPub)
payload, nonce := boxSeal(shared, bs, nil) payload, nonce := boxSeal(shared, bs, nil)
p := wire_protoTrafficPacket{ p := wire_protoTrafficPacket{
TTL: ^uint64(0),
Coords: sinfo.coords, Coords: sinfo.coords,
ToKey: sinfo.theirPermPub, ToKey: sinfo.theirPermPub,
FromKey: ss.core.boxPub, FromKey: ss.core.boxPub,
@ -383,7 +382,6 @@ func (sinfo *sessionInfo) doSend(bs []byte) {
payload, nonce := boxSeal(&sinfo.sharedSesKey, bs, &sinfo.myNonce) payload, nonce := boxSeal(&sinfo.sharedSesKey, bs, &sinfo.myNonce)
defer util_putBytes(payload) defer util_putBytes(payload)
p := wire_trafficPacket{ p := wire_trafficPacket{
TTL: ^uint64(0),
Coords: sinfo.coords, Coords: sinfo.coords,
Handle: sinfo.theirHandle, Handle: sinfo.theirHandle,
Nonce: *nonce, Nonce: *nonce,

View File

@ -413,22 +413,19 @@ func (t *switchTable) updateTable() {
t.table.Store(newTable) 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) t.updater.Load().(*sync.Once).Do(t.updateTable)
table := t.table.Load().(lookupTable) table := t.table.Load().(lookupTable)
myDist := table.self.dist(dest) //getDist(table.self.coords) myDist := table.self.dist(dest)
if !(uint64(myDist) < ttl) {
//return 0, 0
}
if myDist == 0 { 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 // 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() ports := t.core.peers.getPorts()
var best switchPort var best switchPort
bestCost := int64(^uint64(0) >> 1) bestCost := int64(^uint64(0) >> 1)
for _, info := range table.elems { for _, info := range table.elems {
dist := info.locator.dist(dest) //getDist(info.locator.coords) dist := info.locator.dist(dest)
if !(dist < myDist) { if !(dist < myDist) {
continue continue
} }
@ -442,9 +439,8 @@ func (t *switchTable) lookup(dest []byte, ttl uint64) (switchPort, uint64) {
bestCost = cost bestCost = cost
} }
} }
//t.core.log.Println("DEBUG: sending to", best, "bandwidth", getBandwidth(best))
//t.core.log.Println("DEBUG: sending to", best, "cost", bestCost) //t.core.log.Println("DEBUG: sending to", best, "cost", bestCost)
return best, ttl //uint64(myDist) return best
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -192,7 +192,6 @@ func wire_chop_uint64(toUInt64 *uint64, fromSlice *[]byte) bool {
// Wire traffic packets // Wire traffic packets
type wire_trafficPacket struct { type wire_trafficPacket struct {
TTL uint64
Coords []byte Coords []byte
Handle handle Handle handle
Nonce boxNonce Nonce boxNonce
@ -203,7 +202,6 @@ type wire_trafficPacket struct {
func (p *wire_trafficPacket) encode() []byte { func (p *wire_trafficPacket) encode() []byte {
bs := util_getBytes() bs := util_getBytes()
bs = wire_put_uint64(wire_Traffic, bs) bs = wire_put_uint64(wire_Traffic, bs)
bs = wire_put_uint64(p.TTL, bs)
bs = wire_put_coords(p.Coords, bs) bs = wire_put_coords(p.Coords, bs)
bs = append(bs, p.Handle[:]...) bs = append(bs, p.Handle[:]...)
bs = append(bs, p.Nonce[:]...) bs = append(bs, p.Nonce[:]...)
@ -219,8 +217,6 @@ func (p *wire_trafficPacket) decode(bs []byte) bool {
return false return false
case pType != wire_Traffic: case pType != wire_Traffic:
return false return false
case !wire_chop_uint64(&p.TTL, &bs):
return false
case !wire_chop_coords(&p.Coords, &bs): case !wire_chop_coords(&p.Coords, &bs):
return false return false
case !wire_chop_slice(p.Handle[:], &bs): case !wire_chop_slice(p.Handle[:], &bs):
@ -233,7 +229,6 @@ func (p *wire_trafficPacket) decode(bs []byte) bool {
} }
type wire_protoTrafficPacket struct { type wire_protoTrafficPacket struct {
TTL uint64
Coords []byte Coords []byte
ToKey boxPubKey ToKey boxPubKey
FromKey boxPubKey FromKey boxPubKey
@ -244,7 +239,6 @@ type wire_protoTrafficPacket struct {
func (p *wire_protoTrafficPacket) encode() []byte { func (p *wire_protoTrafficPacket) encode() []byte {
coords := wire_encode_coords(p.Coords) coords := wire_encode_coords(p.Coords)
bs := wire_encode_uint64(wire_ProtocolTraffic) bs := wire_encode_uint64(wire_ProtocolTraffic)
bs = append(bs, wire_encode_uint64(p.TTL)...)
bs = append(bs, coords...) bs = append(bs, coords...)
bs = append(bs, p.ToKey[:]...) bs = append(bs, p.ToKey[:]...)
bs = append(bs, p.FromKey[:]...) bs = append(bs, p.FromKey[:]...)
@ -260,8 +254,6 @@ func (p *wire_protoTrafficPacket) decode(bs []byte) bool {
return false return false
case pType != wire_ProtocolTraffic: case pType != wire_ProtocolTraffic:
return false return false
case !wire_chop_uint64(&p.TTL, &bs):
return false
case !wire_chop_coords(&p.Coords, &bs): case !wire_chop_coords(&p.Coords, &bs):
return false return false
case !wire_chop_slice(p.ToKey[:], &bs): case !wire_chop_slice(p.ToKey[:], &bs):