Handle GDZL and GZN

This commit is contained in:
Josh Deprez 2024-04-01 15:33:57 +11:00
parent d45678b812
commit 0358eea5a4
Signed by: josh
SSH key fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw
3 changed files with 87 additions and 0 deletions

View file

@ -239,3 +239,14 @@ const (
EventCodeNDC EventCode = 4
EventCodeZC EventCode = 5
)
func (ec EventCode) String() string {
return map[EventCode]string{
EventCodeNull: "null",
EventCodeNA: "network added",
EventCodeND: "network deleted",
EventCodeNRC: "network route change",
EventCodeNDC: "network distance change",
EventCodeZC: "zone name change",
}[ec]
}

View file

@ -209,6 +209,63 @@ func (tr *Transport) NewZIRspPacket(zones ZoneTuples) *ZIRspPacket {
}
}
// NewGDZLReqPacket returns a new GDZL-Req packet structure.
func (tr *Transport) NewGDZLReqPacket(startIdx uint16) *GDZLReqPacket {
return &GDZLReqPacket{
Header: Header{
TrHeader: tr.transaction(tr.LocalConnID),
CommandCode: CmdCodeZoneReq,
Flags: 0,
},
Subcode: SubcodeGetDomainZoneList,
StartIndex: startIdx,
}
}
// NewGZNRspPacket returns a new GDZL-Rsp packet structure. If GDZL function is
// not supported, startIdx should be set to -1.
func (tr *Transport) NewGDZLRspPacket(startIdx int16, zoneNames []string) *GDZLRspPacket {
return &GDZLRspPacket{
Header: Header{
TrHeader: tr.transaction(tr.RemoteConnID),
CommandCode: CmdCodeZoneReq,
Flags: 0,
},
Subcode: SubcodeGetDomainZoneList,
StartIndex: startIdx,
ZoneNames: zoneNames,
}
}
// NewGZNReqPacket returns a new GZN-Req packet structure requesting nets for a
// given zone name.
func (tr *Transport) NewGZNReqPacket(zoneName string) *GZNReqPacket {
return &GZNReqPacket{
Header: Header{
TrHeader: tr.transaction(tr.LocalConnID),
CommandCode: CmdCodeZoneReq,
Flags: 0,
},
Subcode: SubcodeGetZonesNet,
ZoneName: zoneName,
}
}
// NewGZNRspPacket returns a new GZN-Rsp packet structure.
func (tr *Transport) NewGZNRspPacket(zoneName string, notSupported bool, nets NetworkTuples) *GZNRspPacket {
return &GZNRspPacket{
Header: Header{
TrHeader: tr.transaction(tr.RemoteConnID),
CommandCode: CmdCodeZoneReq,
Flags: 0,
},
Subcode: SubcodeGetZonesNet,
ZoneName: zoneName,
NotSupported: notSupported,
Networks: nets,
}
}
// NewRDPacket returns a new RD packet structure.
func (tr *Transport) NewRDPacket(errCode ErrorCode) *RDPacket {
return &RDPacket{

19
peer.go
View file

@ -345,12 +345,31 @@ func (p *peer) handle(ctx context.Context) error {
}
if _, err := p.send(p.tr.NewZIRspPacket(zones)); err != nil {
log.Printf("Couldn't send ZI-Rsp packet: %v", err)
return err
}
case *aurp.ZIRspPacket:
// TODO: Integrate info into zone table
log.Printf("Learned about these zones: %v", pkt.Zones)
case *aurp.GDZLReqPacket:
if _, err := p.send(p.tr.NewGDZLRspPacket(-1, nil)); err != nil {
log.Printf("Couldn't send GDZL-Rsp packet: %v", err)
return err
}
case *aurp.GDZLRspPacket:
log.Printf("Received a GDZL-Rsp, but I wouldn't have sent a GDZL-Req - that's weird")
case *aurp.GZNReqPacket:
if _, err := p.send(p.tr.NewGZNRspPacket(pkt.ZoneName, false, nil)); err != nil {
log.Printf("Couldn't send GZN-Rsp packet: %v", err)
return err
}
case *aurp.GZNRspPacket:
log.Printf("Received a GZN-Rsp, but I wouldn't have sent a GZN-Req - that's weird")
case *aurp.TicklePacket:
// Immediately respond with Tickle-Ack
if _, err := p.send(p.tr.NewTickleAckPacket()); err != nil {