This commit is contained in:
Josh Deprez 2024-04-23 11:56:15 +10:00
parent 1b33388e2a
commit 74936edbdd
Signed by: josh
SSH key fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw

31
main.go
View file

@ -127,15 +127,16 @@ func main() {
pcapHandle.Close()
log.Fatalf("Couldn't set BPF filter on packet capture: %v", err)
}
defer pcapHandle.Close()
// defer pcapHandle.Close()
// Wait until all peer handlers have finished before closing the port
var handlersWG sync.WaitGroup
defer func() {
log.Print("Waiting for handlers to return...")
handlersWG.Wait()
ln.Close()
}()
defer handlersWG.Wait()
// defer func() {
// // log.Print("Waiting for handlers to return...")
// // handlersWG.Wait()
// // ln.Close()
// }()
goPeerHandler := func(p *router.Peer) {
handlersWG.Add(1)
go func() {
@ -244,9 +245,9 @@ func main() {
}
rawPkt, _, err := pcapHandle.ReadPacketData()
if errors.Is(err, pcap.NextErrorTimeoutExpired) {
continue
}
// if errors.Is(err, pcap.NextErrorTimeoutExpired) {
// continue
// }
if errors.Is(err, io.EOF) || errors.Is(err, pcap.NextErrorNoMorePackets) {
return
}
@ -357,18 +358,19 @@ func main() {
}()
// ----------------------------- AURP inbound -----------------------------
go func() {
for {
if ctx.Err() != nil {
return
}
ln.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
// ln.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
pktbuf := make([]byte, 4096)
pktlen, raddr, readErr := ln.ReadFromUDP(pktbuf)
var operr *net.OpError
if errors.As(readErr, &operr) && operr.Timeout() {
continue
}
// var operr *net.OpError
// if errors.As(readErr, &operr) && operr.Timeout() {
// continue
// }
// log.Printf("AURP: Received packet of length %d from %v", pktlen, raddr)
@ -483,6 +485,7 @@ func main() {
log.Printf("AURP: Got unknown packet type %v", dh.PacketType)
}
}
}()
}
// Hashable net.UDPAddr