jrouter/router/peer.go

513 lines
14 KiB
Go
Raw Normal View History

2024-03-31 09:31:50 +11:00
/*
Copyright 2024 Josh Deprez
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2024-04-19 14:57:25 +10:00
package router
2024-03-25 19:30:06 +11:00
import (
"bytes"
2024-03-30 14:13:34 +11:00
"context"
2024-03-25 19:30:06 +11:00
"log"
"net"
2024-03-30 14:13:34 +11:00
"time"
2024-03-25 19:30:06 +11:00
"gitea.drjosh.dev/josh/jrouter/aurp"
2024-04-12 16:14:27 +10:00
"github.com/sfiera/multitalk/pkg/ddp"
2024-03-25 19:30:06 +11:00
)
2024-03-30 16:43:14 +11:00
const (
// TODO: check these parameters
2024-04-01 15:42:35 +11:00
lastHeardFromTimer = 90 * time.Second
2024-03-30 16:48:47 +11:00
tickleRetryLimit = 10
sendRetryTimer = 10 * time.Second
sendRetryLimit = 5
2024-04-21 15:26:07 +10:00
reconnectTimer = 10 * time.Minute
2024-04-20 12:01:03 +10:00
updateTimer = 10 * time.Second
2024-03-30 16:43:14 +11:00
)
2024-03-30 16:14:18 +11:00
type receiverState int
const (
2024-03-30 16:48:47 +11:00
rsUnconnected receiverState = iota
rsConnected
rsWaitForOpenRsp
rsWaitForRIRsp
rsWaitForTickleAck
2024-03-30 16:14:18 +11:00
)
2024-03-30 18:01:28 +11:00
func (rs receiverState) String() string {
return map[receiverState]string{
rsUnconnected: "unconnected",
rsConnected: "connected",
rsWaitForOpenRsp: "waiting for Open-Rsp",
rsWaitForRIRsp: "waiting for RI-Rsp",
rsWaitForTickleAck: "waiting for Tickle-Ack",
}[rs]
}
2024-03-30 16:14:18 +11:00
type senderState int
const (
2024-03-30 16:48:47 +11:00
ssUnconnected senderState = iota
ssConnected
2024-04-21 14:18:58 +10:00
ssWaitForRIRspAck
ssWaitForRIUpdAck
ssWaitForRDAck
2024-03-30 16:14:18 +11:00
)
2024-03-30 18:01:28 +11:00
func (ss senderState) String() string {
return map[senderState]string{
2024-04-21 14:18:58 +10:00
ssUnconnected: "unconnected",
ssConnected: "connected",
ssWaitForRIRspAck: "waiting for RI-Ack for RI-Rsp",
ssWaitForRIUpdAck: "waiting for RI-Ack for RI-Upd",
ssWaitForRDAck: "waiting for RI-Ack for RD",
2024-03-30 18:01:28 +11:00
}[ss]
}
2024-04-19 14:57:25 +10:00
type Peer struct {
Config *Config
Transport *aurp.Transport
UDPConn *net.UDPConn
RemoteAddr *net.UDPAddr
RecieveCh chan aurp.Packet
RoutingTable *RoutingTable
ZoneTable *ZoneTable
2024-04-19 17:10:00 +10:00
Reconnect bool
2024-03-25 19:30:06 +11:00
}
2024-04-19 14:57:25 +10:00
// Send encodes and sends pkt to the remote host.
func (p *Peer) Send(pkt aurp.Packet) (int, error) {
2024-03-25 19:30:06 +11:00
var b bytes.Buffer
if _, err := pkt.WriteTo(&b); err != nil {
return 0, err
}
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Sending %T (len %d) to %v", pkt, b.Len(), p.RemoteAddr)
2024-04-19 14:57:25 +10:00
return p.UDPConn.WriteToUDP(b.Bytes(), p.RemoteAddr)
2024-03-25 19:30:06 +11:00
}
2024-04-19 14:57:25 +10:00
func (p *Peer) Handle(ctx context.Context) error {
2024-04-20 12:01:03 +10:00
rticker := time.NewTicker(1 * time.Second)
defer rticker.Stop()
sticker := time.NewTicker(1 * time.Second)
defer sticker.Stop()
2024-03-30 14:13:34 +11:00
2024-04-20 12:01:03 +10:00
lastReconnect := time.Now()
2024-03-30 15:26:23 +11:00
lastHeardFrom := time.Now()
2024-03-30 16:43:14 +11:00
lastSend := time.Now()
2024-04-20 12:01:03 +10:00
lastUpdate := time.Now()
2024-03-30 16:43:14 +11:00
sendRetries := 0
2024-03-30 14:24:16 +11:00
2024-04-21 14:18:58 +10:00
var lastRISent aurp.Packet
2024-03-30 16:48:47 +11:00
rstate := rsUnconnected
sstate := ssUnconnected
2024-03-30 16:14:18 +11:00
2024-03-25 19:30:06 +11:00
// Write an Open-Req packet
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewOpenReqPacket(nil)); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send Open-Req packet: %v", err)
2024-03-30 14:13:34 +11:00
return err
2024-03-25 19:30:06 +11:00
}
2024-03-30 16:48:47 +11:00
rstate = rsWaitForOpenRsp
2024-03-30 16:14:18 +11:00
2024-03-30 14:13:34 +11:00
for {
select {
case <-ctx.Done():
2024-03-30 16:48:47 +11:00
if sstate == ssUnconnected {
// Return immediately
2024-03-30 16:14:18 +11:00
return ctx.Err()
}
2024-03-30 14:24:16 +11:00
// Send a best-effort Router Down before returning
2024-04-21 14:18:58 +10:00
lastRISent = p.Transport.NewRDPacket(aurp.ErrCodeNormalClose)
if _, err := p.Send(lastRISent); err != nil {
2024-03-30 14:24:16 +11:00
log.Printf("Couldn't send RD packet: %v", err)
}
2024-03-30 14:13:34 +11:00
return ctx.Err()
2024-04-20 12:01:03 +10:00
case <-rticker.C:
2024-03-30 16:43:14 +11:00
switch rstate {
2024-03-30 16:48:47 +11:00
case rsWaitForOpenRsp:
2024-03-30 16:43:14 +11:00
if time.Since(lastSend) <= sendRetryTimer {
break
}
if sendRetries >= sendRetryLimit {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Send retry limit reached while waiting for Open-Rsp, closing connection")
2024-03-30 16:48:47 +11:00
rstate = rsUnconnected
2024-03-30 16:43:14 +11:00
break
}
// Send another Open-Req
sendRetries++
2024-03-30 16:48:47 +11:00
lastSend = time.Now()
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewOpenReqPacket(nil)); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send Open-Req packet: %v", err)
2024-03-30 16:43:14 +11:00
return err
}
2024-03-30 16:48:47 +11:00
case rsConnected:
2024-03-30 16:14:18 +11:00
// Check LHFT, send tickle?
2024-03-30 16:48:47 +11:00
if time.Since(lastHeardFrom) <= lastHeardFromTimer {
break
}
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewTicklePacket()); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send Tickle: %v", err)
2024-03-30 16:48:47 +11:00
return err
}
rstate = rsWaitForTickleAck
sendRetries = 0
lastSend = time.Now()
case rsWaitForTickleAck:
if time.Since(lastSend) <= sendRetryTimer {
break
}
if sendRetries >= tickleRetryLimit {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Send retry limit reached while waiting for Tickle-Ack, closing connection")
2024-03-30 16:48:47 +11:00
rstate = rsUnconnected
2024-04-19 16:32:27 +10:00
p.RoutingTable.DeletePeer(p)
2024-03-30 16:48:47 +11:00
break
}
sendRetries++
lastSend = time.Now()
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewTicklePacket()); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send Tickle: %v", err)
2024-03-30 16:48:47 +11:00
return err
2024-03-30 14:13:34 +11:00
}
2024-04-19 16:32:27 +10:00
// still in Wait For Tickle-Ack
2024-04-01 15:43:53 +11:00
case rsWaitForRIRsp:
2024-04-19 16:32:27 +10:00
if time.Since(lastSend) <= sendRetryTimer {
break
}
if sendRetries >= sendRetryLimit {
log.Printf("AURP Peer: Send retry limit reached while waiting for RI-Rsp, closing connection")
rstate = rsUnconnected
p.RoutingTable.DeletePeer(p)
break
}
// RI-Req is stateless, so we don't need to cache the one we
// sent earlier just to send it again
sendRetries++
if _, err := p.Send(p.Transport.NewRIReqPacket()); err != nil {
log.Printf("AURP Peer: Couldn't send RI-Req packet: %v", err)
return err
}
// still in Wait For RI-Rsp
2024-04-01 15:43:53 +11:00
case rsUnconnected:
2024-04-21 14:18:58 +10:00
// Data receiver is unconnected. If data sender is connected,
// send a null RI-Upd to check if the sender is also unconnected
if sstate == ssConnected && time.Since(lastSend) > sendRetryTimer {
2024-04-20 12:01:03 +10:00
if sendRetries >= sendRetryLimit {
log.Printf("AURP Peer: Send retry limit reached while probing sender connect, closing connection")
}
sendRetries++
lastSend = time.Now()
aurp.Inc(&p.Transport.LocalSeq)
events := aurp.EventTuples{{
EventCode: aurp.EventCodeNull,
}}
2024-04-21 14:18:58 +10:00
lastRISent = p.Transport.NewRIUpdPacket(events)
if _, err := p.Send(lastRISent); err != nil {
2024-04-20 12:01:03 +10:00
log.Printf("AURP Peer: Couldn't send RI-Upd packet: %v", err)
return err
}
2024-04-21 14:18:58 +10:00
sstate = ssWaitForRIUpdAck
2024-04-20 12:01:03 +10:00
}
if p.Reconnect {
// Periodically try to reconnect, if this peer is in the config file
if time.Since(lastReconnect) <= reconnectTimer {
break
}
2024-04-21 13:46:27 +10:00
lastReconnect = time.Now()
2024-04-20 12:01:03 +10:00
sendRetries = 0
lastSend = time.Now()
if _, err := p.Send(p.Transport.NewOpenReqPacket(nil)); err != nil {
log.Printf("AURP Peer: Couldn't send Open-Req packet: %v", err)
return err
}
rstate = rsWaitForOpenRsp
}
}
case <-sticker.C:
switch sstate {
case ssUnconnected:
// Do nothing
case ssConnected:
if time.Since(lastUpdate) <= updateTimer {
break
}
// TODO: is there a routing update to send?
2024-04-21 14:18:58 +10:00
case ssWaitForRIRspAck, ssWaitForRIUpdAck:
2024-04-20 12:01:03 +10:00
if time.Since(lastSend) <= sendRetryTimer {
break
}
2024-04-21 14:18:58 +10:00
if lastRISent == nil {
log.Print("AURP Peer: sender retry: lastRISent = nil?")
continue
}
if sendRetries >= sendRetryLimit {
log.Printf("AURP Peer: Send retry limit reached, closing connection")
sstate = ssUnconnected
continue
}
sendRetries++
lastSend = time.Now()
if _, err := p.Send(lastRISent); err != nil {
log.Printf("AURP Peer: Couldn't re-send %T: %v", lastRISent, err)
return err
2024-04-20 12:01:03 +10:00
}
2024-04-21 14:18:58 +10:00
case ssWaitForRDAck:
2024-04-20 12:01:03 +10:00
if time.Since(lastSend) <= sendRetryTimer {
break
}
sstate = ssUnconnected
2024-03-25 19:30:06 +11:00
}
2024-04-19 14:57:25 +10:00
case pkt := <-p.RecieveCh:
2024-03-30 15:26:23 +11:00
lastHeardFrom = time.Now()
2024-03-30 14:13:34 +11:00
switch pkt := pkt.(type) {
case *aurp.OpenReqPacket:
2024-03-30 16:48:47 +11:00
if sstate != ssUnconnected {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Open-Req received but sender state is not unconnected (was %v)", sstate)
2024-03-30 16:14:18 +11:00
}
2024-03-30 14:13:34 +11:00
// The peer tells us their connection ID in Open-Req.
2024-04-19 14:57:25 +10:00
p.Transport.RemoteConnID = pkt.ConnectionID
2024-03-30 14:13:34 +11:00
// Formulate a response.
var orsp *aurp.OpenRspPacket
switch {
case pkt.Version != 1:
// Respond with Open-Rsp with unknown version error.
2024-04-19 14:57:25 +10:00
orsp = p.Transport.NewOpenRspPacket(0, int16(aurp.ErrCodeInvalidVersion), nil)
2024-03-30 14:13:34 +11:00
case len(pkt.Options) > 0:
// Options? OPTIONS? We don't accept no stinkin' _options_
2024-04-19 14:57:25 +10:00
orsp = p.Transport.NewOpenRspPacket(0, int16(aurp.ErrCodeOptionNegotiation), nil)
2024-03-30 14:13:34 +11:00
default:
// Accept it I guess.
2024-04-19 14:57:25 +10:00
orsp = p.Transport.NewOpenRspPacket(0, 1, nil)
2024-03-30 14:13:34 +11:00
}
2024-04-19 14:57:25 +10:00
if _, err := p.Send(orsp); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send Open-Rsp: %v", err)
2024-03-30 16:48:47 +11:00
return err
2024-03-30 14:13:34 +11:00
}
2024-03-30 16:14:18 +11:00
if orsp.RateOrErrCode >= 0 {
2024-03-30 16:48:47 +11:00
sstate = ssConnected
2024-03-30 16:14:18 +11:00
}
2024-03-30 14:13:34 +11:00
2024-03-30 18:53:31 +11:00
// If receiver is unconnected, commence connecting
if rstate == rsUnconnected {
lastSend = time.Now()
sendRetries = 0
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewOpenReqPacket(nil)); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send Open-Req packet: %v", err)
2024-03-30 18:53:31 +11:00
return err
}
rstate = rsWaitForOpenRsp
}
2024-03-30 14:13:34 +11:00
case *aurp.OpenRspPacket:
2024-03-30 16:48:47 +11:00
if rstate != rsWaitForOpenRsp {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Received Open-Rsp but was not waiting for one (receiver state was %v)", rstate)
2024-03-30 16:14:18 +11:00
}
2024-03-30 14:13:34 +11:00
if pkt.RateOrErrCode < 0 {
// It's an error code.
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Open-Rsp error code from peer %v: %d", p.RemoteAddr.IP, pkt.RateOrErrCode)
2024-03-30 16:48:47 +11:00
rstate = rsUnconnected
2024-03-30 18:01:28 +11:00
break
2024-03-30 14:13:34 +11:00
}
2024-04-19 16:25:39 +10:00
//log.Printf("AURP Peer: Data receiver is connected!")
2024-03-30 18:01:28 +11:00
rstate = rsConnected
2024-03-30 14:13:34 +11:00
2024-04-01 14:44:51 +11:00
// Send an RI-Req
2024-04-19 16:32:27 +10:00
sendRetries = 0
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewRIReqPacket()); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send RI-Req packet: %v", err)
2024-04-01 14:44:51 +11:00
return err
}
2024-04-01 14:56:49 +11:00
rstate = rsWaitForRIRsp
2024-03-30 14:13:34 +11:00
case *aurp.RIReqPacket:
2024-03-30 18:01:28 +11:00
if sstate != ssConnected {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Received RI-Req but was not expecting one (sender state was %v)", sstate)
2024-03-30 18:01:28 +11:00
}
2024-03-30 18:53:31 +11:00
2024-03-30 20:27:24 +11:00
nets := aurp.NetworkTuples{
{
2024-04-06 16:06:32 +11:00
Extended: true,
2024-04-19 14:57:25 +10:00
RangeStart: uint16(p.Config.EtherTalk.NetStart),
RangeEnd: uint16(p.Config.EtherTalk.NetEnd),
2024-03-30 20:53:58 +11:00
Distance: 0,
2024-03-30 20:27:24 +11:00
},
}
2024-04-19 14:57:25 +10:00
p.Transport.LocalSeq = 1
2024-04-21 14:18:58 +10:00
lastRISent = p.Transport.NewRIRspPacket(aurp.RoutingFlagLast, nets)
if _, err := p.Send(lastRISent); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send RI-Rsp packet: %v", err)
2024-04-01 14:56:49 +11:00
return err
2024-03-30 20:27:24 +11:00
}
2024-04-21 14:18:58 +10:00
sstate = ssWaitForRIRspAck
2024-03-30 14:13:34 +11:00
case *aurp.RIRspPacket:
2024-03-30 18:01:28 +11:00
if rstate != rsWaitForRIRsp {
log.Printf("Received RI-Rsp but was not waiting for one (receiver state was %v)", rstate)
}
2024-04-01 14:56:49 +11:00
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Learned about these networks: %v", pkt.Networks)
2024-04-01 14:56:49 +11:00
2024-04-12 16:14:27 +10:00
for _, nt := range pkt.Networks {
2024-04-19 14:57:25 +10:00
p.RoutingTable.UpsertRoute(
2024-04-13 15:47:58 +10:00
nt.Extended,
ddp.Network(nt.RangeStart),
ddp.Network(nt.RangeEnd),
p,
nt.Distance,
)
2024-04-12 16:14:27 +10:00
}
2024-03-30 14:13:34 +11:00
2024-04-01 14:56:49 +11:00
// TODO: track which networks we don't have zone info for, and
// only set SZI for those ?
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewRIAckPacket(pkt.ConnectionID, pkt.Sequence, aurp.RoutingFlagSendZoneInfo)); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send RI-Ack packet: %v", err)
2024-04-01 14:56:49 +11:00
return err
}
2024-04-01 15:09:26 +11:00
if pkt.Flags&aurp.RoutingFlagLast != 0 {
// No longer waiting for an RI-Rsp
rstate = rsConnected
}
2024-04-01 14:56:49 +11:00
2024-03-30 14:13:34 +11:00
case *aurp.RIAckPacket:
2024-03-30 20:27:24 +11:00
switch sstate {
2024-04-21 14:18:58 +10:00
case ssWaitForRIRspAck:
2024-03-30 20:27:24 +11:00
// We sent an RI-Rsp, this is the RI-Ack we expected.
2024-04-21 14:18:58 +10:00
case ssWaitForRIUpdAck:
2024-03-30 20:27:24 +11:00
// We sent an RI-Upd, this is the RI-Ack we expected.
2024-04-21 14:18:58 +10:00
case ssWaitForRDAck:
2024-03-30 20:27:24 +11:00
// We sent an RD... Why are we here?
continue
default:
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Received RI-Ack but was not waiting for one (sender state was %v)", sstate)
2024-03-30 20:27:24 +11:00
}
sstate = ssConnected
2024-04-22 09:47:08 +10:00
sendRetries = 0
2024-03-30 20:27:24 +11:00
// If SZI flag is set, send ZI-Rsp (transaction)
2024-04-19 16:48:59 +10:00
// TODO: split ZI-Rsp packets similarly to ZIP Replies
2024-03-30 20:27:24 +11:00
if pkt.Flags&aurp.RoutingFlagSendZoneInfo != 0 {
2024-04-19 16:48:59 +10:00
zones := map[ddp.Network][]string{
p.Config.EtherTalk.NetStart: {p.Config.EtherTalk.ZoneName},
2024-03-30 20:27:24 +11:00
}
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewZIRspPacket(zones)); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send ZI-Rsp packet: %v", err)
2024-03-30 20:27:24 +11:00
}
}
// TODO: Continue sending next RI-Rsp (streamed)?
2024-03-30 14:13:34 +11:00
case *aurp.RIUpdPacket:
// TODO: Integrate info into route table
2024-04-19 16:48:59 +10:00
for _, et := range pkt.Events {
log.Printf("AURP Peer: RI-Upd event %v", et)
}
2024-03-30 14:13:34 +11:00
2024-04-19 17:10:00 +10:00
if _, err := p.Send(p.Transport.NewRIAckPacket(pkt.ConnectionID, pkt.Sequence, 0)); err != nil {
log.Printf("AURP Peer: Couldn't send RI-Ack: %v", err)
return err
}
2024-03-30 14:13:34 +11:00
case *aurp.RDPacket:
2024-03-30 18:01:28 +11:00
if rstate == rsUnconnected || rstate == rsWaitForOpenRsp {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Received RD but was not expecting one (receiver state was %v)", rstate)
2024-03-30 18:01:28 +11:00
}
2024-03-30 16:16:46 +11:00
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Router Down: error code %d %s", pkt.ErrorCode, pkt.ErrorCode)
p.RoutingTable.DeletePeer(p)
2024-03-30 16:14:18 +11:00
// Respond with RI-Ack
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewRIAckPacket(pkt.ConnectionID, pkt.Sequence, 0)); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send RI-Ack: %v", err)
2024-03-30 16:48:47 +11:00
return err
2024-03-30 16:14:18 +11:00
}
2024-04-20 12:01:03 +10:00
// Connections closed
2024-03-30 16:48:47 +11:00
rstate = rsUnconnected
2024-04-20 12:01:03 +10:00
sstate = ssUnconnected
2024-03-30 14:13:34 +11:00
case *aurp.ZIReqPacket:
2024-04-19 16:48:59 +10:00
// TODO: split ZI-Rsp packets similarly to ZIP Replies
zones := p.ZoneTable.Query(pkt.Networks)
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewZIRspPacket(zones)); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send ZI-Rsp packet: %v", err)
2024-04-01 15:33:57 +11:00
return err
2024-04-01 14:56:49 +11:00
}
2024-03-30 14:13:34 +11:00
case *aurp.ZIRspPacket:
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Learned about these zones: %v", pkt.Zones)
2024-04-14 18:29:29 +10:00
for _, zt := range pkt.Zones {
2024-04-19 14:57:25 +10:00
p.ZoneTable.Upsert(ddp.Network(zt.Network), zt.Name, false)
2024-04-14 18:29:29 +10:00
}
2024-03-30 14:13:34 +11:00
2024-04-01 15:33:57 +11:00
case *aurp.GDZLReqPacket:
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewGDZLRspPacket(-1, nil)); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send GDZL-Rsp packet: %v", err)
2024-04-01 15:33:57 +11:00
return err
}
case *aurp.GDZLRspPacket:
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Received a GDZL-Rsp, but I wouldn't have sent a GDZL-Req - that's weird")
2024-04-01 15:33:57 +11:00
case *aurp.GZNReqPacket:
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewGZNRspPacket(pkt.ZoneName, false, nil)); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send GZN-Rsp packet: %v", err)
2024-04-01 15:33:57 +11:00
return err
}
case *aurp.GZNRspPacket:
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Received a GZN-Rsp, but I wouldn't have sent a GZN-Req - that's weird")
2024-04-01 15:33:57 +11:00
2024-03-30 14:13:34 +11:00
case *aurp.TicklePacket:
2024-03-30 15:26:23 +11:00
// Immediately respond with Tickle-Ack
2024-04-19 14:57:25 +10:00
if _, err := p.Send(p.Transport.NewTickleAckPacket()); err != nil {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Couldn't send Tickle-Ack: %v", err)
2024-03-30 16:48:47 +11:00
return err
2024-03-30 14:13:34 +11:00
}
case *aurp.TickleAckPacket:
2024-03-30 16:48:47 +11:00
if rstate != rsWaitForTickleAck {
2024-04-19 16:25:39 +10:00
log.Printf("AURP Peer: Received Tickle-Ack but was not waiting for one (receiver state was %v)", rstate)
2024-03-30 16:14:18 +11:00
}
2024-03-30 16:48:47 +11:00
rstate = rsConnected
2024-03-25 19:30:06 +11:00
}
}
}
}