update for wire format changes

This commit is contained in:
Arceliar 2018-06-02 16:30:05 -05:00
commit 34939d4b18
7 changed files with 283 additions and 283 deletions

View file

@ -121,21 +121,21 @@ func wire_decode_coords(packet []byte) ([]byte, int) {
// Announces that we can send parts of a Message with a particular seq
type msgAnnounce struct {
root sigPubKey
tstamp int64
seq uint64
len uint64
Root sigPubKey
Tstamp int64
Seq uint64
Len uint64
//Deg uint64
rseq uint64
Rseq uint64
}
func (m *msgAnnounce) encode() []byte {
bs := wire_encode_uint64(wire_SwitchAnnounce)
bs = append(bs, m.root[:]...)
bs = append(bs, wire_encode_uint64(wire_intToUint(m.tstamp))...)
bs = append(bs, wire_encode_uint64(m.seq)...)
bs = append(bs, wire_encode_uint64(m.len)...)
bs = append(bs, wire_encode_uint64(m.rseq)...)
bs = append(bs, m.Root[:]...)
bs = append(bs, wire_encode_uint64(wire_intToUint(m.Tstamp))...)
bs = append(bs, wire_encode_uint64(m.Seq)...)
bs = append(bs, wire_encode_uint64(m.Len)...)
bs = append(bs, wire_encode_uint64(m.Rseq)...)
return bs
}
@ -147,34 +147,34 @@ func (m *msgAnnounce) decode(bs []byte) bool {
return false
case pType != wire_SwitchAnnounce:
return false
case !wire_chop_slice(m.root[:], &bs):
case !wire_chop_slice(m.Root[:], &bs):
return false
case !wire_chop_uint64(&tstamp, &bs):
return false
case !wire_chop_uint64(&m.seq, &bs):
case !wire_chop_uint64(&m.Seq, &bs):
return false
case !wire_chop_uint64(&m.len, &bs):
case !wire_chop_uint64(&m.Len, &bs):
return false
case !wire_chop_uint64(&m.rseq, &bs):
case !wire_chop_uint64(&m.Rseq, &bs):
return false
}
m.tstamp = wire_intFromUint(tstamp)
m.Tstamp = wire_intFromUint(tstamp)
return true
}
type msgHopReq struct {
root sigPubKey
tstamp int64
seq uint64
hop uint64
Root sigPubKey
Tstamp int64
Seq uint64
Hop uint64
}
func (m *msgHopReq) encode() []byte {
bs := wire_encode_uint64(wire_SwitchHopRequest)
bs = append(bs, m.root[:]...)
bs = append(bs, wire_encode_uint64(wire_intToUint(m.tstamp))...)
bs = append(bs, wire_encode_uint64(m.seq)...)
bs = append(bs, wire_encode_uint64(m.hop)...)
bs = append(bs, m.Root[:]...)
bs = append(bs, wire_encode_uint64(wire_intToUint(m.Tstamp))...)
bs = append(bs, wire_encode_uint64(m.Seq)...)
bs = append(bs, wire_encode_uint64(m.Hop)...)
return bs
}
@ -186,38 +186,38 @@ func (m *msgHopReq) decode(bs []byte) bool {
return false
case pType != wire_SwitchHopRequest:
return false
case !wire_chop_slice(m.root[:], &bs):
case !wire_chop_slice(m.Root[:], &bs):
return false
case !wire_chop_uint64(&tstamp, &bs):
return false
case !wire_chop_uint64(&m.seq, &bs):
case !wire_chop_uint64(&m.Seq, &bs):
return false
case !wire_chop_uint64(&m.hop, &bs):
case !wire_chop_uint64(&m.Hop, &bs):
return false
}
m.tstamp = wire_intFromUint(tstamp)
m.Tstamp = wire_intFromUint(tstamp)
return true
}
type msgHop struct {
root sigPubKey
tstamp int64
seq uint64
hop uint64
port switchPort
next sigPubKey
sig sigBytes
Root sigPubKey
Tstamp int64
Seq uint64
Hop uint64
Port switchPort
Next sigPubKey
Sig sigBytes
}
func (m *msgHop) encode() []byte {
bs := wire_encode_uint64(wire_SwitchHop)
bs = append(bs, m.root[:]...)
bs = append(bs, wire_encode_uint64(wire_intToUint(m.tstamp))...)
bs = append(bs, wire_encode_uint64(m.seq)...)
bs = append(bs, wire_encode_uint64(m.hop)...)
bs = append(bs, wire_encode_uint64(uint64(m.port))...)
bs = append(bs, m.next[:]...)
bs = append(bs, m.sig[:]...)
bs = append(bs, m.Root[:]...)
bs = append(bs, wire_encode_uint64(wire_intToUint(m.Tstamp))...)
bs = append(bs, wire_encode_uint64(m.Seq)...)
bs = append(bs, wire_encode_uint64(m.Hop)...)
bs = append(bs, wire_encode_uint64(uint64(m.Port))...)
bs = append(bs, m.Next[:]...)
bs = append(bs, m.Sig[:]...)
return bs
}
@ -229,22 +229,22 @@ func (m *msgHop) decode(bs []byte) bool {
return false
case pType != wire_SwitchHop:
return false
case !wire_chop_slice(m.root[:], &bs):
case !wire_chop_slice(m.Root[:], &bs):
return false
case !wire_chop_uint64(&tstamp, &bs):
return false
case !wire_chop_uint64(&m.seq, &bs):
case !wire_chop_uint64(&m.Seq, &bs):
return false
case !wire_chop_uint64(&m.hop, &bs):
case !wire_chop_uint64(&m.Hop, &bs):
return false
case !wire_chop_uint64((*uint64)(&m.port), &bs):
case !wire_chop_uint64((*uint64)(&m.Port), &bs):
return false
case !wire_chop_slice(m.next[:], &bs):
case !wire_chop_slice(m.Next[:], &bs):
return false
case !wire_chop_slice(m.sig[:], &bs):
case !wire_chop_slice(m.Sig[:], &bs):
return false
}
m.tstamp = wire_intFromUint(tstamp)
m.Tstamp = wire_intFromUint(tstamp)
return true
}
@ -292,22 +292,22 @@ func wire_chop_uint64(toUInt64 *uint64, fromSlice *[]byte) bool {
// Wire traffic packets
type wire_trafficPacket struct {
ttl uint64
coords []byte
handle handle
nonce boxNonce
payload []byte
TTL uint64
Coords []byte
Handle handle
Nonce boxNonce
Payload []byte
}
// This is basically MarshalBinary, but decode doesn't allow that...
func (p *wire_trafficPacket) encode() []byte {
bs := util_getBytes()
bs = wire_put_uint64(wire_Traffic, bs)
bs = wire_put_uint64(p.ttl, bs)
bs = wire_put_coords(p.coords, bs)
bs = append(bs, p.handle[:]...)
bs = append(bs, p.nonce[:]...)
bs = append(bs, p.payload...)
bs = wire_put_uint64(p.TTL, bs)
bs = wire_put_coords(p.Coords, bs)
bs = append(bs, p.Handle[:]...)
bs = append(bs, p.Nonce[:]...)
bs = append(bs, p.Payload...)
return bs
}
@ -319,37 +319,37 @@ func (p *wire_trafficPacket) decode(bs []byte) bool {
return false
case pType != wire_Traffic:
return false
case !wire_chop_uint64(&p.ttl, &bs):
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
case !wire_chop_slice(p.handle[:], &bs):
case !wire_chop_slice(p.Handle[:], &bs):
return false
case !wire_chop_slice(p.nonce[:], &bs):
case !wire_chop_slice(p.Nonce[:], &bs):
return false
}
p.payload = append(util_getBytes(), bs...)
p.Payload = append(util_getBytes(), bs...)
return true
}
type wire_protoTrafficPacket struct {
ttl uint64
coords []byte
toKey boxPubKey
fromKey boxPubKey
nonce boxNonce
payload []byte
TTL uint64
Coords []byte
ToKey boxPubKey
FromKey boxPubKey
Nonce boxNonce
Payload []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 = append(bs, wire_encode_uint64(p.ttl)...)
bs = append(bs, wire_encode_uint64(p.TTL)...)
bs = append(bs, coords...)
bs = append(bs, p.toKey[:]...)
bs = append(bs, p.fromKey[:]...)
bs = append(bs, p.nonce[:]...)
bs = append(bs, p.payload...)
bs = append(bs, p.ToKey[:]...)
bs = append(bs, p.FromKey[:]...)
bs = append(bs, p.Nonce[:]...)
bs = append(bs, p.Payload...)
return bs
}
@ -360,30 +360,30 @@ func (p *wire_protoTrafficPacket) decode(bs []byte) bool {
return false
case pType != wire_ProtocolTraffic:
return false
case !wire_chop_uint64(&p.ttl, &bs):
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
case !wire_chop_slice(p.toKey[:], &bs):
case !wire_chop_slice(p.ToKey[:], &bs):
return false
case !wire_chop_slice(p.fromKey[:], &bs):
case !wire_chop_slice(p.FromKey[:], &bs):
return false
case !wire_chop_slice(p.nonce[:], &bs):
case !wire_chop_slice(p.Nonce[:], &bs):
return false
}
p.payload = bs
p.Payload = bs
return true
}
type wire_linkProtoTrafficPacket struct {
nonce boxNonce
payload []byte
Nonce boxNonce
Payload []byte
}
func (p *wire_linkProtoTrafficPacket) encode() []byte {
bs := wire_encode_uint64(wire_LinkProtocolTraffic)
bs = append(bs, p.nonce[:]...)
bs = append(bs, p.payload...)
bs = append(bs, p.Nonce[:]...)
bs = append(bs, p.Payload...)
return bs
}
@ -394,10 +394,10 @@ func (p *wire_linkProtoTrafficPacket) decode(bs []byte) bool {
return false
case pType != wire_LinkProtocolTraffic:
return false
case !wire_chop_slice(p.nonce[:], &bs):
case !wire_chop_slice(p.Nonce[:], &bs):
return false
}
p.payload = bs
p.Payload = bs
return true
}
@ -405,19 +405,19 @@ func (p *wire_linkProtoTrafficPacket) decode(bs []byte) bool {
func (p *sessionPing) encode() []byte {
var pTypeVal uint64
if p.isPong {
if p.IsPong {
pTypeVal = wire_SessionPong
} else {
pTypeVal = wire_SessionPing
}
bs := wire_encode_uint64(pTypeVal)
//p.sendPermPub used in top level (crypto), so skipped here
bs = append(bs, p.handle[:]...)
bs = append(bs, p.sendSesPub[:]...)
bs = append(bs, wire_encode_uint64(wire_intToUint(p.tstamp))...)
coords := wire_encode_coords(p.coords)
bs = append(bs, p.Handle[:]...)
bs = append(bs, p.SendSesPub[:]...)
bs = append(bs, wire_encode_uint64(wire_intToUint(p.Tstamp))...)
coords := wire_encode_coords(p.Coords)
bs = append(bs, coords...)
bs = append(bs, wire_encode_uint64(uint64(p.mtu))...)
bs = append(bs, wire_encode_uint64(uint64(p.MTU))...)
return bs
}
@ -430,33 +430,33 @@ func (p *sessionPing) decode(bs []byte) bool {
return false
case pType != wire_SessionPing && pType != wire_SessionPong:
return false
//p.sendPermPub used in top level (crypto), so skipped here
case !wire_chop_slice(p.handle[:], &bs):
//p.sendPermPub used in top level (crypto), so skipped here
case !wire_chop_slice(p.Handle[:], &bs):
return false
case !wire_chop_slice(p.sendSesPub[:], &bs):
case !wire_chop_slice(p.SendSesPub[:], &bs):
return false
case !wire_chop_uint64(&tstamp, &bs):
return false
case !wire_chop_coords(&p.coords, &bs):
case !wire_chop_coords(&p.Coords, &bs):
return false
case !wire_chop_uint64(&mtu, &bs):
mtu = 1280
}
p.tstamp = wire_intFromUint(tstamp)
p.Tstamp = wire_intFromUint(tstamp)
if pType == wire_SessionPong {
p.isPong = true
p.IsPong = true
}
p.mtu = uint16(mtu)
p.MTU = uint16(mtu)
return true
}
////////////////////////////////////////////////////////////////////////////////
func (r *dhtReq) encode() []byte {
coords := wire_encode_coords(r.coords)
coords := wire_encode_coords(r.Coords)
bs := wire_encode_uint64(wire_DHTLookupRequest)
bs = append(bs, coords...)
bs = append(bs, r.dest[:]...)
bs = append(bs, r.Dest[:]...)
return bs
}
@ -467,9 +467,9 @@ func (r *dhtReq) decode(bs []byte) bool {
return false
case pType != wire_DHTLookupRequest:
return false
case !wire_chop_coords(&r.coords, &bs):
case !wire_chop_coords(&r.Coords, &bs):
return false
case !wire_chop_slice(r.dest[:], &bs):
case !wire_chop_slice(r.Dest[:], &bs):
return false
default:
return true
@ -477,11 +477,11 @@ func (r *dhtReq) decode(bs []byte) bool {
}
func (r *dhtRes) encode() []byte {
coords := wire_encode_coords(r.coords)
coords := wire_encode_coords(r.Coords)
bs := wire_encode_uint64(wire_DHTLookupResponse)
bs = append(bs, coords...)
bs = append(bs, r.dest[:]...)
for _, info := range r.infos {
bs = append(bs, r.Dest[:]...)
for _, info := range r.Infos {
coords = wire_encode_coords(info.coords)
bs = append(bs, info.key[:]...)
bs = append(bs, coords...)
@ -496,9 +496,9 @@ func (r *dhtRes) decode(bs []byte) bool {
return false
case pType != wire_DHTLookupResponse:
return false
case !wire_chop_coords(&r.coords, &bs):
case !wire_chop_coords(&r.Coords, &bs):
return false
case !wire_chop_slice(r.dest[:], &bs):
case !wire_chop_slice(r.Dest[:], &bs):
return false
}
for len(bs) > 0 {
@ -509,7 +509,7 @@ func (r *dhtRes) decode(bs []byte) bool {
case !wire_chop_coords(&info.coords, &bs):
return false
}
r.infos = append(r.infos, &info)
r.Infos = append(r.Infos, &info)
}
return true
}