Reorganise

This commit is contained in:
Josh Deprez 2024-04-23 14:47:22 +10:00
parent 339459d37a
commit 35262a9e03
Signed by: josh
SSH key fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw

11
main.go
View file

@ -96,6 +96,7 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("Couldn't listen on udp4:387: %v", err) log.Fatalf("Couldn't listen on udp4:387: %v", err)
} }
defer ln.Close()
log.Printf("Listening on %v", ln.LocalAddr()) log.Printf("Listening on %v", ln.LocalAddr())
log.Println("Press ^C or send SIGINT to stop the router gracefully") log.Println("Press ^C or send SIGINT to stop the router gracefully")
@ -144,11 +145,6 @@ func main() {
// -------------------------------- Peers --------------------------------- // -------------------------------- Peers ---------------------------------
// Wait until all peer handlers have finished before closing the port // Wait until all peer handlers have finished before closing the port
var handlersWG sync.WaitGroup var handlersWG sync.WaitGroup
defer func() {
log.Print("Waiting for handlers to return...")
handlersWG.Wait()
ln.Close()
}()
goPeerHandler := func(p *router.Peer) { goPeerHandler := func(p *router.Peer) {
handlersWG.Add(1) handlersWG.Add(1)
go func() { go func() {
@ -370,6 +366,7 @@ func main() {
}() }()
// ----------------------------- AURP inbound ----------------------------- // ----------------------------- AURP inbound -----------------------------
go func() {
ctx, setStatus, done := status.AddSimpleItem(ctx, "AURP inbound") ctx, setStatus, done := status.AddSimpleItem(ctx, "AURP inbound")
defer done() defer done()
setStatus("Running") setStatus("Running")
@ -500,6 +497,10 @@ func main() {
log.Printf("AURP: Got unknown packet type %v", dh.PacketType) log.Printf("AURP: Got unknown packet type %v", dh.PacketType)
} }
} }
}()
// -------------------------------- Close ---------------------------------
handlersWG.Wait()
} }
// Hashable net.UDPAddr // Hashable net.UDPAddr