Take 3
This commit is contained in:
parent
36e5ebc9bd
commit
6a55dfa581
1 changed files with 9 additions and 8 deletions
21
main.go
21
main.go
|
@ -62,7 +62,9 @@ func main() {
|
||||||
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")
|
||||||
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt)
|
cctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
ctx, _ := signal.NotifyContext(cctx, os.Interrupt)
|
||||||
go func() {
|
go func() {
|
||||||
// net.UDPConn is not context-aware? Hmmm.
|
// net.UDPConn is not context-aware? Hmmm.
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
@ -104,24 +106,23 @@ func main() {
|
||||||
pktlen, raddr, readErr := ln.ReadFromUDP(pktbuf)
|
pktlen, raddr, readErr := ln.ReadFromUDP(pktbuf)
|
||||||
// net.PacketConn.ReadFrom: "Callers should always process
|
// net.PacketConn.ReadFrom: "Callers should always process
|
||||||
// the n > 0 bytes returned before considering the error err."
|
// the n > 0 bytes returned before considering the error err."
|
||||||
if ctx.Err() != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("Received packet of length %d from %v", pktlen, raddr)
|
log.Printf("Received packet of length %d from %v", pktlen, raddr)
|
||||||
|
|
||||||
dh, pkt, parseErr := aurp.ParsePacket(pktbuf[:pktlen])
|
dh, pkt, parseErr := aurp.ParsePacket(pktbuf[:pktlen])
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
log.Printf("Failed to parse packet: %v", parseErr)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("The packet parsed succesfully as a %T", pkt)
|
|
||||||
|
|
||||||
if readErr != nil {
|
if readErr != nil {
|
||||||
log.Printf("Failed to read packet: %v", readErr)
|
log.Printf("Failed to read packet: %v", readErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Printf("Failed to parse packet: %v", parseErr)
|
||||||
|
}
|
||||||
|
if readErr != nil {
|
||||||
|
log.Printf("Failed to read packet: %v", readErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("The packet parsed succesfully as a %T", pkt)
|
||||||
|
|
||||||
// Existing peer?
|
// Existing peer?
|
||||||
ra := udpAddrFromNet(raddr)
|
ra := udpAddrFromNet(raddr)
|
||||||
|
|
Loading…
Reference in a new issue