Add AARP statuses
This commit is contained in:
parent
56a1919942
commit
e8e5ca31b5
1 changed files with 11 additions and 0 deletions
|
@ -18,11 +18,13 @@ package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitea.drjosh.dev/josh/jrouter/status"
|
||||||
"github.com/google/gopacket/pcap"
|
"github.com/google/gopacket/pcap"
|
||||||
"github.com/sfiera/multitalk/pkg/aarp"
|
"github.com/sfiera/multitalk/pkg/aarp"
|
||||||
"github.com/sfiera/multitalk/pkg/ddp"
|
"github.com/sfiera/multitalk/pkg/ddp"
|
||||||
|
@ -85,6 +87,11 @@ func (a *AARPMachine) Assigned() <-chan struct{} {
|
||||||
|
|
||||||
// Run executes the machine.
|
// Run executes the machine.
|
||||||
func (a *AARPMachine) Run(ctx context.Context, incomingCh <-chan *ethertalk.Packet) error {
|
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)
|
// Initialise our DDP address with a preferred address (first network.1)
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
a.probes = 0
|
a.probes = 0
|
||||||
|
@ -109,6 +116,8 @@ func (a *AARPMachine) Run(ctx context.Context, incomingCh <-chan *ethertalk.Pack
|
||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
close(a.assignedCh)
|
close(a.assignedCh)
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
|
|
||||||
|
setStatus(fmt.Sprintf("Assigned address %d.%d", a.myAddr.Proto.Network, a.myAddr.Proto.Node))
|
||||||
continue
|
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)
|
log.Printf("Couldn't broadcast a Probe: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setStatus(fmt.Sprintf("Probed %d times", a.probes))
|
||||||
|
|
||||||
case ethFrame, ok := <-incomingCh:
|
case ethFrame, ok := <-incomingCh:
|
||||||
if !ok {
|
if !ok {
|
||||||
incomingCh = nil
|
incomingCh = nil
|
||||||
|
|
Loading…
Reference in a new issue