aurp: Control extendedness of tuples

This commit is contained in:
Josh Deprez 2024-04-06 16:06:32 +11:00
parent acf8400f47
commit fc5b07b975
Signed by: josh
SSH key fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw
2 changed files with 9 additions and 4 deletions

View file

@ -114,6 +114,7 @@ func parseNetworkTuples(p []byte) (NetworkTuples, error) {
}
type NetworkTuple struct {
Extended bool
RangeStart uint16
Distance uint8
RangeEnd uint16
@ -123,7 +124,7 @@ type NetworkTuple struct {
func (nt *NetworkTuple) WriteTo(w io.Writer) (int64, error) {
a := acc(w)
a.write16(nt.RangeStart)
if nt.RangeStart == nt.RangeEnd {
if !nt.Extended {
// non-extended tuple
a.write8(nt.Distance)
return a.ret()
@ -144,8 +145,9 @@ func parseNetworkTuple(p []byte) (NetworkTuple, []byte, error) {
nt.RangeStart = binary.BigEndian.Uint16(p[:2])
nt.RangeEnd = nt.RangeStart
nt.Distance = p[2]
nt.Extended = nt.Distance&0x80 != 0
if nt.Distance&0x80 == 0 {
if !nt.Extended {
return nt, p[3:], nil
}
@ -185,6 +187,7 @@ func parseEventTuples(p []byte) (EventTuples, error) {
type EventTuple struct {
EventCode EventCode
Extended bool
RangeStart uint16
Distance uint8
RangeEnd uint16
@ -194,7 +197,7 @@ func (et *EventTuple) WriteTo(w io.Writer) (int64, error) {
a := acc(w)
a.write8(uint8(et.EventCode))
a.write16(et.RangeStart)
if et.RangeStart == et.RangeEnd {
if !et.Extended {
// non-extended tuple
a.write8(et.Distance)
return a.ret()
@ -215,8 +218,9 @@ func parseEventTuple(p []byte) (EventTuple, []byte, error) {
et.RangeStart = binary.BigEndian.Uint16(p[1:3])
et.RangeEnd = et.RangeStart
et.Distance = p[3]
et.Extended = et.Distance&0x80 != 0
if et.Distance&0x80 == 0 {
if !et.Extended {
return et, p[4:], nil
}

View file

@ -255,6 +255,7 @@ func (p *peer) handle(ctx context.Context) error {
nets := aurp.NetworkTuples{
{
Extended: true,
RangeStart: p.cfg.EtherTalk.NetStart,
RangeEnd: p.cfg.EtherTalk.NetEnd,
Distance: 0,