Add NBP machine (WIP)

This commit is contained in:
Josh Deprez 2024-04-12 13:09:04 +10:00
parent 7f9a15bff1
commit ce3aa5faf5
No known key found for this signature in database
3 changed files with 53 additions and 0 deletions

View file

@ -35,6 +35,15 @@ const (
FunctionFwdReq Function = 4
)
func (f Function) String() string {
return map[Function]string{
FunctionBrRq: "BrRq",
FunctionLkUp: "LkUp",
FunctionLkUpReply: "LkUp-Reply",
FunctionFwdReq: "FwdReq",
}[f]
}
// Packet represents an NBP packet.
type Packet struct {
Function Function // top 4 bits of first byte

11
main.go
View file

@ -169,6 +169,14 @@ func main() {
rtmpCh := make(chan *ddp.ExtPacket, 1024)
go rtmpMachine.Run(ctx, rtmpCh)
// --------------------- NBP --------------------
nbpMachine := &NBPMachine{
aarp: aarpMachine,
pcapHandle: pcapHandle,
}
nbpCh := make(chan *ddp.ExtPacket, 1024)
go nbpMachine.Run(ctx, nbpCh)
// ---------- Raw AppleTalk/AARP inbound ----------
go func() {
for {
@ -247,6 +255,9 @@ func main() {
case 1: // The RTMP socket
rtmpCh <- &ddpkt
case 2: // The NIS (NBP socket)
nbpCh <- &ddpkt
case 4: // The AEP socket
if err := handleAEP(pcapHandle, myHWAddr, ethFrame.Src, &ddpkt); err != nil {
log.Printf("AEP: Couldn't handle: %v", err)

33
nbp.go Normal file
View file

@ -0,0 +1,33 @@
package main
import (
"context"
"log"
"gitea.drjosh.dev/josh/jrouter/atalk/nbp"
"github.com/google/gopacket/pcap"
"github.com/sfiera/multitalk/pkg/ddp"
)
type NBPMachine struct {
aarp *AARPMachine
pcapHandle *pcap.Handle
}
func (NBPMachine) Run(ctx context.Context, incoming <-chan *ddp.ExtPacket) error {
for {
select {
case <-ctx.Done():
return ctx.Err()
case ddpkt := <-incoming:
pkt, err := nbp.Unmarshal(ddpkt.Data)
if err != nil {
log.Printf("NBP: invalid packet: %v", err)
continue
}
// TODO:
log.Printf("NBP: Got %v", pkt.Function)
}
}
}