Add AARP statuses

This commit is contained in:
Josh Deprez 2024-04-23 14:15:41 +10:00
parent 56a1919942
commit e8e5ca31b5
Signed by: josh
SSH Key Fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw
1 changed files with 11 additions and 0 deletions

View File

@ -18,11 +18,13 @@ package router
import (
"context"
"fmt"
"log"
"math/rand/v2"
"sync"
"time"
"gitea.drjosh.dev/josh/jrouter/status"
"github.com/google/gopacket/pcap"
"github.com/sfiera/multitalk/pkg/aarp"
"github.com/sfiera/multitalk/pkg/ddp"
@ -85,6 +87,11 @@ func (a *AARPMachine) Assigned() <-chan struct{} {
// Run executes the machine.
func (a *AARPMachine) Run(ctx context.Context, incomingCh <-chan *ethertalk.Packet) error {
ctx, setStatus, done := status.AddSimpleItem(ctx, "AARP")
defer done()
setStatus("Initialising")
// Initialise our DDP address with a preferred address (first network.1)
a.mu.Lock()
a.probes = 0
@ -109,6 +116,8 @@ func (a *AARPMachine) Run(ctx context.Context, incomingCh <-chan *ethertalk.Pack
a.mu.Unlock()
close(a.assignedCh)
ticker.Stop()
setStatus(fmt.Sprintf("Assigned address %d.%d", a.myAddr.Proto.Network, a.myAddr.Proto.Node))
continue
}
@ -120,6 +129,8 @@ func (a *AARPMachine) Run(ctx context.Context, incomingCh <-chan *ethertalk.Pack
log.Printf("Couldn't broadcast a Probe: %v", err)
}
setStatus(fmt.Sprintf("Probed %d times", a.probes))
case ethFrame, ok := <-incomingCh:
if !ok {
incomingCh = nil