aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/rlpx_test.go
diff options
context:
space:
mode:
authorAnton Evangelatov <anton.evangelatov@gmail.com>2018-02-22 18:41:06 +0800
committerFelix Lange <fjl@users.noreply.github.com>2018-02-22 18:41:06 +0800
commit1e457b659989478004329c2f3a82b5ac67b32cbf (patch)
tree5c29f77423957484852f6efd790834f916ae643b /p2p/rlpx_test.go
parentbb5349b15463255d269870fec9839a942eeecc1a (diff)
downloadgo-tangerine-1e457b659989478004329c2f3a82b5ac67b32cbf.tar
go-tangerine-1e457b659989478004329c2f3a82b5ac67b32cbf.tar.gz
go-tangerine-1e457b659989478004329c2f3a82b5ac67b32cbf.tar.bz2
go-tangerine-1e457b659989478004329c2f3a82b5ac67b32cbf.tar.lz
go-tangerine-1e457b659989478004329c2f3a82b5ac67b32cbf.tar.xz
go-tangerine-1e457b659989478004329c2f3a82b5ac67b32cbf.tar.zst
go-tangerine-1e457b659989478004329c2f3a82b5ac67b32cbf.zip
p2p: don't send DiscReason when using net.Pipe (#16004)
Diffstat (limited to 'p2p/rlpx_test.go')
-rw-r--r--p2p/rlpx_test.go38
1 files changed, 35 insertions, 3 deletions
diff --git a/p2p/rlpx_test.go b/p2p/rlpx_test.go
index f4cefa650..bca460402 100644
--- a/p2p/rlpx_test.go
+++ b/p2p/rlpx_test.go
@@ -156,14 +156,18 @@ func TestProtocolHandshake(t *testing.T) {
node1 = &discover.Node{ID: discover.PubkeyID(&prv1.PublicKey), IP: net.IP{5, 6, 7, 8}, TCP: 44}
hs1 = &protoHandshake{Version: 3, ID: node1.ID, Caps: []Cap{{"c", 1}, {"d", 3}}}
- fd0, fd1 = net.Pipe()
- wg sync.WaitGroup
+ wg sync.WaitGroup
)
+ fd0, fd1, err := tcpPipe()
+ if err != nil {
+ t.Fatal(err)
+ }
+
wg.Add(2)
go func() {
defer wg.Done()
- defer fd1.Close()
+ defer fd0.Close()
rlpx := newRLPX(fd0)
remid, err := rlpx.doEncHandshake(prv0, node1)
if err != nil {
@@ -597,3 +601,31 @@ func TestHandshakeForwardCompatibility(t *testing.T) {
t.Errorf("ingress-mac('foo') mismatch:\ngot %x\nwant %x", fooIngressHash, wantFooIngressHash)
}
}
+
+// tcpPipe creates an in process full duplex pipe based on a localhost TCP socket
+func tcpPipe() (net.Conn, net.Conn, error) {
+ l, err := net.Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ return nil, nil, err
+ }
+ defer l.Close()
+
+ var aconn net.Conn
+ aerr := make(chan error, 1)
+ go func() {
+ var err error
+ aconn, err = l.Accept()
+ aerr <- err
+ }()
+
+ dconn, err := net.Dial("tcp", l.Addr().String())
+ if err != nil {
+ <-aerr
+ return nil, nil, err
+ }
+ if err := <-aerr; err != nil {
+ dconn.Close()
+ return nil, nil, err
+ }
+ return aconn, dconn, nil
+}