5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-25 23:01:38 +00:00

simplify pathfinder

This commit is contained in:
Arceliar 2020-11-07 12:08:01 -06:00
parent b5cd40b801
commit 994c26e5f7
4 changed files with 18 additions and 18 deletions

View File

@ -245,7 +245,7 @@ func (p *peer) _handleTraffic(packet []byte) {
} }
obs, coords := wire_getTrafficOffsetAndCoords(packet) obs, coords := wire_getTrafficOffsetAndCoords(packet)
offset, _ := wire_decode_uint64(obs) offset, _ := wire_decode_uint64(obs)
ports := p.table.getPorts(coords) ports := switch_getPorts(coords)
if offset == 0 { if offset == 0 {
offset = p.table.getOffset(ports) offset = p.table.getOffset(ports)
} }
@ -262,7 +262,7 @@ func (p *peer) _handleTraffic(packet []byte) {
wire_put_uint64(offset, obs[:0]) 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 { if nPeer, isIn := p.ports[next]; isIn {
nPeer.sendPacketFrom(p, packet) nPeer.sendPacketFrom(p, packet)
} }

View File

@ -474,8 +474,16 @@ func (sinfo *sessionInfo) _recvPacket(p *wire_trafficPacket) {
sinfo._updateNonce(&p.Nonce) sinfo._updateNonce(&p.Nonce)
sinfo.bytesRecvd += uint64(len(bs)) sinfo.bytesRecvd += uint64(len(bs))
sinfo.conn.recvMsg(sinfo, bs) sinfo.conn.recvMsg(sinfo, bs)
sinfo.path = append(sinfo.path[:0], p.RPath...) a := switch_getPorts(p.RPath)
sinfo.rpath = append(sinfo.rpath[:0], p.Path...) 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 ch <- callback
sinfo.checkCallbacks() sinfo.checkCallbacks()
@ -493,7 +501,7 @@ func (sinfo *sessionInfo) _send(msg FlowKeyMessage) {
sinfo.bytesSent += uint64(len(msg.Message)) sinfo.bytesSent += uint64(len(msg.Message))
var coords []byte var coords []byte
var offset uint64 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...) coords = append([]byte{0}, sinfo.path...)
offset += 1 offset += 1
} else { } else {

View File

@ -644,7 +644,7 @@ func (t *lookupTable) lookup(ports []switchPort) switchPort {
return here.port return here.port
} }
func (t *lookupTable) getPorts(coords []byte) []switchPort { func switch_getPorts(coords []byte) []switchPort {
var ports []switchPort var ports []switchPort
var offset int var offset int
for offset < len(coords) { for offset < len(coords) {

View File

@ -228,7 +228,6 @@ type wire_trafficPacket struct {
Nonce crypto.BoxNonce Nonce crypto.BoxNonce
Payload []byte Payload []byte
RPath []byte RPath []byte
Path []byte
} }
// Encodes a wire_trafficPacket into its wire format. // 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.Handle[:]...)
bs = append(bs, p.Nonce[:]...) bs = append(bs, p.Nonce[:]...)
bs = wire_put_vslice(p.Payload, bs) bs = wire_put_vslice(p.Payload, bs)
bs = wire_put_vslice(p.RPath, bs) bs = append(bs, p.RPath...)
bs = append(bs, p.Path...)
return bs return bs
} }
@ -266,10 +264,8 @@ func (p *wire_trafficPacket) decode(bs []byte) bool {
return false return false
case !wire_chop_vslice(&p.Payload, &bs): case !wire_chop_vslice(&p.Payload, &bs):
return false 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 return true
} }
@ -282,7 +278,6 @@ type wire_protoTrafficPacket struct {
Nonce crypto.BoxNonce Nonce crypto.BoxNonce
Payload []byte Payload []byte
RPath []byte RPath []byte
Path []byte
} }
// Encodes a wire_protoTrafficPacket into its wire format. // 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.FromKey[:]...)
bs = append(bs, p.Nonce[:]...) bs = append(bs, p.Nonce[:]...)
bs = wire_put_vslice(p.Payload, bs) bs = wire_put_vslice(p.Payload, bs)
bs = wire_put_vslice(p.RPath, bs) bs = append(bs, p.RPath...)
bs = append(bs, p.Path...)
return bs return bs
} }
@ -319,10 +313,8 @@ func (p *wire_protoTrafficPacket) decode(bs []byte) bool {
return false return false
case !wire_chop_vslice(&p.Payload, &bs): case !wire_chop_vslice(&p.Payload, &bs):
return false 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 return true
} }