diff --git a/.gitignore b/.gitignore index 66fd13c..398baf2 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ # Dependency directories (remove the comment below to include it) # vendor/ + +.idea diff --git a/discover/v5_udp.go b/discover/v5_udp.go index dea1293..d9a0e23 100644 --- a/discover/v5_udp.go +++ b/discover/v5_udp.go @@ -123,8 +123,8 @@ type callTimeout struct { } // ListenV5 listens on the given connection. -func ListenV5(conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) { - t, err := newUDPv5(conn, ln, cfg) +func ListenV5(ctx context.Context, conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) { + t, err := newUDPv5(ctx, conn, ln, cfg) if err != nil { return nil, err } @@ -136,8 +136,8 @@ func ListenV5(conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) { } // newUDPv5 creates a UDPv5 transport, but doesn't start any goroutines. -func newUDPv5(conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) { - closeCtx, cancelCloseCtx := context.WithCancel(context.Background()) +func newUDPv5(ctx context.Context, conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) { + closeCtx, cancelCloseCtx := context.WithCancel(ctx) cfg = cfg.withDefaults() t := &UDPv5{ // static fields diff --git a/discover/v5_udp_test.go b/discover/v5_udp_test.go index 2261499..adf4724 100644 --- a/discover/v5_udp_test.go +++ b/discover/v5_udp_test.go @@ -18,6 +18,7 @@ package discover import ( "bytes" + "context" "crypto/ecdsa" "encoding/binary" "fmt" @@ -93,7 +94,7 @@ func startLocalhostV5(t *testing.T, cfg Config) *UDPv5 { realaddr := socket.LocalAddr().(*net.UDPAddr) ln.SetStaticIP(realaddr.IP) ln.Set(enr.UDP(realaddr.Port)) - udp, err := ListenV5(socket, ln, cfg) + udp, err := ListenV5(context.Background(), socket, ln, cfg) if err != nil { t.Fatal(err) } @@ -708,7 +709,7 @@ func newUDPV5Test(t *testing.T) *udpV5Test { ln := enode.NewLocalNode(test.db, test.localkey) ln.SetStaticIP(net.IP{10, 0, 0, 1}) ln.Set(enr.UDP(30303)) - test.udp, _ = ListenV5(test.pipe, ln, Config{ + test.udp, _ = ListenV5(context.Background(), test.pipe, ln, Config{ PrivateKey: test.localkey, Log: testlog.Logger(t, log.LvlTrace), ValidSchemes: enode.ValidSchemesForTesting,