mirror of
https://github.com/logos-messaging/go-discover.git
synced 2026-01-04 14:03:13 +00:00
Merge pull request #5 from waku-org/fix/discovery_dead_lock
feat: add context support to resolve discv5 deadlock issue
This commit is contained in:
commit
a3ca781403
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,3 +13,5 @@
|
|||||||
|
|
||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/
|
# vendor/
|
||||||
|
|
||||||
|
.idea
|
||||||
|
|||||||
@ -130,8 +130,8 @@ type callTimeout struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListenV5 listens on the given connection.
|
// ListenV5 listens on the given connection.
|
||||||
func ListenV5(conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) {
|
func ListenV5(ctx context.Context, conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) {
|
||||||
t, err := newUDPv5(conn, ln, cfg)
|
t, err := newUDPv5(ctx, conn, ln, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -143,8 +143,8 @@ func ListenV5(conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newUDPv5 creates a UDPv5 transport, but doesn't start any goroutines.
|
// newUDPv5 creates a UDPv5 transport, but doesn't start any goroutines.
|
||||||
func newUDPv5(conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) {
|
func newUDPv5(ctx context.Context, conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) {
|
||||||
closeCtx, cancelCloseCtx := context.WithCancel(context.Background())
|
closeCtx, cancelCloseCtx := context.WithCancel(ctx)
|
||||||
cfg = cfg.withDefaults()
|
cfg = cfg.withDefaults()
|
||||||
t := &UDPv5{
|
t := &UDPv5{
|
||||||
// static fields
|
// static fields
|
||||||
|
|||||||
@ -18,6 +18,7 @@ package discover
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -94,7 +95,7 @@ func startLocalhostV5(t *testing.T, cfg Config) *UDPv5 {
|
|||||||
realaddr := socket.LocalAddr().(*net.UDPAddr)
|
realaddr := socket.LocalAddr().(*net.UDPAddr)
|
||||||
ln.SetStaticIP(realaddr.IP)
|
ln.SetStaticIP(realaddr.IP)
|
||||||
ln.Set(enr.UDP(realaddr.Port))
|
ln.Set(enr.UDP(realaddr.Port))
|
||||||
udp, err := ListenV5(socket, ln, cfg)
|
udp, err := ListenV5(context.Background(), socket, ln, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -763,7 +764,7 @@ func newUDPV5Test(t *testing.T) *udpV5Test {
|
|||||||
ln := enode.NewLocalNode(test.db, test.localkey)
|
ln := enode.NewLocalNode(test.db, test.localkey)
|
||||||
ln.SetStaticIP(net.IP{10, 0, 0, 1})
|
ln.SetStaticIP(net.IP{10, 0, 0, 1})
|
||||||
ln.Set(enr.UDP(30303))
|
ln.Set(enr.UDP(30303))
|
||||||
test.udp, _ = ListenV5(test.pipe, ln, Config{
|
test.udp, _ = ListenV5(context.Background(), test.pipe, ln, Config{
|
||||||
PrivateKey: test.localkey,
|
PrivateKey: test.localkey,
|
||||||
Log: testlog.Logger(t, log.LvlTrace),
|
Log: testlog.Logger(t, log.LvlTrace),
|
||||||
ValidSchemes: enode.ValidSchemesForTesting,
|
ValidSchemes: enode.ValidSchemesForTesting,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user