mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-14 02:10:29 +00:00
add (but don't use) offset field for (protocol) traffic packets
This commit is contained in:
parent
f1e9837a98
commit
92dbb48eda
@ -54,7 +54,8 @@ func (q *packetQueue) drop() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *packetQueue) push(packet []byte) {
|
func (q *packetQueue) push(packet []byte) {
|
||||||
id := pqStreamID(peer_getPacketCoords(packet)) // just coords for now
|
_, coords := wire_getTrafficOffsetAndCoords(packet)
|
||||||
|
id := pqStreamID(coords) // just coords for now
|
||||||
info := pqPacketInfo{packet: packet, time: time.Now()}
|
info := pqPacketInfo{packet: packet, time: time.Now()}
|
||||||
for idx := range q.streams {
|
for idx := range q.streams {
|
||||||
if q.streams[idx].id == id {
|
if q.streams[idx].id == id {
|
||||||
|
@ -236,13 +236,6 @@ func (p *peer) _handlePacket(packet []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the coords of a packet without decoding
|
|
||||||
func peer_getPacketCoords(packet []byte) []byte {
|
|
||||||
_, pTypeLen := wire_decode_uint64(packet)
|
|
||||||
coords, _ := wire_decode_coords(packet[pTypeLen:])
|
|
||||||
return coords
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called to handle traffic or protocolTraffic packets.
|
// Called to handle traffic or protocolTraffic packets.
|
||||||
// In either case, this reads from the coords of the packet header, does a switch lookup, and forwards to the next node.
|
// In either case, this reads from the coords of the packet header, does a switch lookup, and forwards to the next node.
|
||||||
func (p *peer) _handleTraffic(packet []byte) {
|
func (p *peer) _handleTraffic(packet []byte) {
|
||||||
@ -250,7 +243,7 @@ func (p *peer) _handleTraffic(packet []byte) {
|
|||||||
// Drop traffic if the peer isn't in the switch
|
// Drop traffic if the peer isn't in the switch
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
coords := peer_getPacketCoords(packet)
|
_, coords := wire_getTrafficOffsetAndCoords(packet)
|
||||||
next := p.table.lookup(coords)
|
next := p.table.lookup(coords)
|
||||||
if nPeer, isIn := p.ports[next]; isIn {
|
if nPeer, isIn := p.ports[next]; isIn {
|
||||||
nPeer.sendPacketFrom(p, packet)
|
nPeer.sendPacketFrom(p, packet)
|
||||||
|
@ -24,7 +24,7 @@ func version_getBaseMetadata() version_metadata {
|
|||||||
return version_metadata{
|
return version_metadata{
|
||||||
meta: [4]byte{'m', 'e', 't', 'a'},
|
meta: [4]byte{'m', 'e', 't', 'a'},
|
||||||
ver: 0,
|
ver: 0,
|
||||||
minorVer: 2,
|
minorVer: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,6 +222,7 @@ func wire_chop_uint64(toUInt64 *uint64, fromSlice *[]byte) bool {
|
|||||||
|
|
||||||
// The wire format for ordinary IPv6 traffic encapsulated by the network.
|
// The wire format for ordinary IPv6 traffic encapsulated by the network.
|
||||||
type wire_trafficPacket struct {
|
type wire_trafficPacket struct {
|
||||||
|
Offset uint64
|
||||||
Coords []byte
|
Coords []byte
|
||||||
Handle crypto.Handle
|
Handle crypto.Handle
|
||||||
Nonce crypto.BoxNonce
|
Nonce crypto.BoxNonce
|
||||||
@ -233,6 +234,7 @@ type wire_trafficPacket struct {
|
|||||||
func (p *wire_trafficPacket) encode() []byte {
|
func (p *wire_trafficPacket) encode() []byte {
|
||||||
bs := pool_getBytes(0)
|
bs := pool_getBytes(0)
|
||||||
bs = wire_put_uint64(wire_Traffic, bs)
|
bs = wire_put_uint64(wire_Traffic, bs)
|
||||||
|
bs = wire_put_uint64(p.Offset, 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[:]...)
|
||||||
@ -250,6 +252,8 @@ 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.Offset, &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):
|
||||||
@ -263,6 +267,7 @@ func (p *wire_trafficPacket) decode(bs []byte) bool {
|
|||||||
|
|
||||||
// The wire format for protocol traffic, such as dht req/res or session ping/pong packets.
|
// The wire format for protocol traffic, such as dht req/res or session ping/pong packets.
|
||||||
type wire_protoTrafficPacket struct {
|
type wire_protoTrafficPacket struct {
|
||||||
|
Offset uint64
|
||||||
Coords []byte
|
Coords []byte
|
||||||
ToKey crypto.BoxPubKey
|
ToKey crypto.BoxPubKey
|
||||||
FromKey crypto.BoxPubKey
|
FromKey crypto.BoxPubKey
|
||||||
@ -274,6 +279,7 @@ 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 = wire_put_uint64(p.Offset, bs)
|
||||||
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[:]...)
|
||||||
@ -290,6 +296,8 @@ 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.Offset, &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):
|
||||||
@ -303,6 +311,16 @@ func (p *wire_protoTrafficPacket) decode(bs []byte) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the offset and coord slices of a (protocol) traffic packet without decoding
|
||||||
|
func wire_getTrafficOffsetAndCoords(packet []byte) ([]byte, []byte) {
|
||||||
|
_, offsetBegin := wire_decode_uint64(packet)
|
||||||
|
_, offsetLen := wire_decode_uint64(packet[offsetBegin:])
|
||||||
|
offsetEnd := offsetBegin + offsetLen
|
||||||
|
offset := packet[offsetBegin:offsetEnd]
|
||||||
|
coords, _ := wire_decode_coords(packet[offsetEnd:])
|
||||||
|
return offset, coords
|
||||||
|
}
|
||||||
|
|
||||||
// The wire format for link protocol traffic, namely switchMsg.
|
// The wire format for link protocol traffic, namely switchMsg.
|
||||||
// There's really two layers of this, with the outer layer using permanent keys, and the inner layer using ephemeral keys.
|
// There's really two layers of this, with the outer layer using permanent keys, and the inner layer using ephemeral keys.
|
||||||
// The keys themselves are exchanged as part of the connection setup, and then omitted from the packets.
|
// The keys themselves are exchanged as part of the connection setup, and then omitted from the packets.
|
||||||
|
Loading…
Reference in New Issue
Block a user