Tweak ZI-Rsp subcode logic

This commit is contained in:
Josh Deprez 2024-04-01 15:14:31 +11:00
parent 26e9f67dc5
commit d45678b812
Signed by: josh
SSH key fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw

View file

@ -182,15 +182,20 @@ func (tr *Transport) NewRIAckPacket(connID, seq uint16, szi RoutingFlag) *RIAckP
// zone information. It automatically chooses between subcodes 1 or 2 depending // zone information. It automatically chooses between subcodes 1 or 2 depending
// on whether there is one network ID or more than one network ID. // on whether there is one network ID or more than one network ID.
func (tr *Transport) NewZIRspPacket(zones ZoneTuples) *ZIRspPacket { func (tr *Transport) NewZIRspPacket(zones ZoneTuples) *ZIRspPacket {
nns := make(map[uint16]struct{}) // Only one zone: use non-extended
for _, z := range zones { subcode := SubcodeZoneInfoNonExt
nns[z.Network] = struct{}{} if len(zones) > 1 {
} // Count distinct networks
// Only one network: use extended nns := make(map[uint16]struct{})
// More than one network: use non-extended for _, z := range zones {
subcode := SubcodeZoneInfoExt nns[z.Network] = struct{}{}
if len(nns) != 1 { }
subcode = SubcodeZoneInfoNonExt
// Only one network: use extended format
// More than one network: use non-extended
if len(nns) == 1 {
subcode = SubcodeZoneInfoExt
}
} }
return &ZIRspPacket{ return &ZIRspPacket{