2024-04-14 18:29:29 +10: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-04-14 18:29:29 +10:00
|
|
|
|
|
|
|
import (
|
2024-05-03 16:13:59 +10:00
|
|
|
"context"
|
2024-04-14 18:29:29 +10:00
|
|
|
"fmt"
|
|
|
|
|
2024-10-18 13:20:34 +11:00
|
|
|
"drjosh.dev/jrouter/atalk/aep"
|
2024-04-14 18:29:29 +10:00
|
|
|
"github.com/sfiera/multitalk/pkg/ddp"
|
|
|
|
)
|
|
|
|
|
2024-05-03 16:13:59 +10:00
|
|
|
func (rtr *Router) HandleAEP(ctx context.Context, ddpkt *ddp.ExtPacket) error {
|
2024-04-14 18:29:29 +10:00
|
|
|
if ddpkt.Proto != ddp.ProtoAEP {
|
|
|
|
return fmt.Errorf("invalid DDP type %d on socket 4", ddpkt.Proto)
|
|
|
|
}
|
|
|
|
ep, err := aep.Unmarshal(ddpkt.Data)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
switch ep.Function {
|
|
|
|
case aep.EchoReply:
|
|
|
|
// we didn't send a request? I don't think?
|
|
|
|
// we shouldn't be sending them from this socket
|
|
|
|
return fmt.Errorf("echo reply received at socket 4 why?")
|
|
|
|
|
|
|
|
case aep.EchoRequest:
|
|
|
|
// Uno Reverso the packet
|
|
|
|
// "The client can send the Echo Request datagram through any socket
|
|
|
|
// the client has open, and the Echo Reply will come back to this socket."
|
|
|
|
ddpkt.DstNet, ddpkt.SrcNet = ddpkt.SrcNet, ddpkt.DstNet
|
|
|
|
ddpkt.DstNode, ddpkt.SrcNode = ddpkt.SrcNode, ddpkt.DstNode
|
|
|
|
ddpkt.DstSocket, ddpkt.SrcSocket = ddpkt.SrcSocket, ddpkt.DstSocket
|
|
|
|
ddpkt.Data[0] = byte(aep.EchoReply)
|
|
|
|
|
2024-05-04 15:36:33 +10:00
|
|
|
return rtr.Output(ctx, ddpkt)
|
2024-04-14 18:29:29 +10:00
|
|
|
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("invalid AEP function %d", ep.Function)
|
|
|
|
}
|
|
|
|
}
|