mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 10:05:17 +00:00
simplify pathfinder
This commit is contained in:
parent
b5cd40b801
commit
994c26e5f7
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user