diff --git a/src/yggdrasil/peer.go b/src/yggdrasil/peer.go index 9f367695..74e1023f 100644 --- a/src/yggdrasil/peer.go +++ b/src/yggdrasil/peer.go @@ -245,7 +245,7 @@ func (p *peer) _handleTraffic(packet []byte) { } obs, coords := wire_getTrafficOffsetAndCoords(packet) offset, _ := wire_decode_uint64(obs) - ports := p.table.getPorts(coords) + ports := switch_getPorts(coords) if offset == 0 { offset = p.table.getOffset(ports) } @@ -262,7 +262,7 @@ func (p *peer) _handleTraffic(packet []byte) { wire_put_uint64(offset, obs[:0]) } } - packet = wire_put_uint64(uint64(next), packet) + packet = wire_put_uint64(uint64(p.port), packet) if nPeer, isIn := p.ports[next]; isIn { nPeer.sendPacketFrom(p, packet) } diff --git a/src/yggdrasil/session.go b/src/yggdrasil/session.go index 6a9589fa..4a06beed 100644 --- a/src/yggdrasil/session.go +++ b/src/yggdrasil/session.go @@ -474,8 +474,16 @@ func (sinfo *sessionInfo) _recvPacket(p *wire_trafficPacket) { sinfo._updateNonce(&p.Nonce) sinfo.bytesRecvd += uint64(len(bs)) sinfo.conn.recvMsg(sinfo, bs) - sinfo.path = append(sinfo.path[:0], p.RPath...) - sinfo.rpath = append(sinfo.rpath[:0], p.Path...) + a := switch_getPorts(p.RPath) + for i := len(a)/2 - 1; i >= 0; i-- { + opp := len(a) - 1 - i + a[i], a[opp] = a[opp], a[i] + } + sinfo.path = sinfo.path[:0] + for _, sPort := range a { + sinfo.path = wire_put_uint64(uint64(sPort), sinfo.path) + } + //sinfo.rpath = append(sinfo.rpath[:0], p.Path...) } ch <- callback sinfo.checkCallbacks() @@ -493,7 +501,7 @@ func (sinfo *sessionInfo) _send(msg FlowKeyMessage) { sinfo.bytesSent += uint64(len(msg.Message)) var coords []byte var offset uint64 - if len(sinfo.path) > 0 && len(sinfo.path) <= len(sinfo.rpath) { + if len(sinfo.path) > 0 { coords = append([]byte{0}, sinfo.path...) offset += 1 } else { diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index 4873d8b4..c291d82d 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -644,7 +644,7 @@ func (t *lookupTable) lookup(ports []switchPort) switchPort { return here.port } -func (t *lookupTable) getPorts(coords []byte) []switchPort { +func switch_getPorts(coords []byte) []switchPort { var ports []switchPort var offset int for offset < len(coords) { diff --git a/src/yggdrasil/wire.go b/src/yggdrasil/wire.go index e0c2614a..e8e9bf09 100644 --- a/src/yggdrasil/wire.go +++ b/src/yggdrasil/wire.go @@ -228,7 +228,6 @@ type wire_trafficPacket struct { Nonce crypto.BoxNonce Payload []byte RPath []byte - Path []byte } // Encodes a wire_trafficPacket into its wire format. @@ -241,8 +240,7 @@ func (p *wire_trafficPacket) encode() []byte { bs = append(bs, p.Handle[:]...) bs = append(bs, p.Nonce[:]...) bs = wire_put_vslice(p.Payload, bs) - bs = wire_put_vslice(p.RPath, bs) - bs = append(bs, p.Path...) + bs = append(bs, p.RPath...) return bs } @@ -266,10 +264,8 @@ func (p *wire_trafficPacket) decode(bs []byte) bool { return false case !wire_chop_vslice(&p.Payload, &bs): return false - case !wire_chop_vslice(&p.RPath, &bs): - return false } - p.Path = append(p.Path[:0], bs...) + p.RPath = append(p.RPath[:0], bs...) return true } @@ -282,7 +278,6 @@ type wire_protoTrafficPacket struct { Nonce crypto.BoxNonce Payload []byte RPath []byte - Path []byte } // Encodes a wire_protoTrafficPacket into its wire format. @@ -294,8 +289,7 @@ func (p *wire_protoTrafficPacket) encode() []byte { bs = append(bs, p.FromKey[:]...) bs = append(bs, p.Nonce[:]...) bs = wire_put_vslice(p.Payload, bs) - bs = wire_put_vslice(p.RPath, bs) - bs = append(bs, p.Path...) + bs = append(bs, p.RPath...) return bs } @@ -319,10 +313,8 @@ func (p *wire_protoTrafficPacket) decode(bs []byte) bool { return false case !wire_chop_vslice(&p.Payload, &bs): return false - case !wire_chop_vslice(&p.RPath, &bs): - return false } - p.Path = append(p.Path[:0], bs...) + p.RPath = append(p.RPath[:0], bs...) return true }