aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/network/protocol_test.go
diff options
context:
space:
mode:
authorlash <nolash@users.noreply.github.com>2019-02-20 21:46:00 +0800
committerViktor TrĂ³n <viktor.tron@gmail.com>2019-02-20 21:46:00 +0800
commit460d206f309fc0884c666bd191a1b6a4b63462fc (patch)
tree5a7a5edb620ba69731ab3544992472e094b3779b /swarm/network/protocol_test.go
parentba2dfa5ce43d72733c864bc43f7b80b39c674733 (diff)
downloadgo-tangerine-460d206f309fc0884c666bd191a1b6a4b63462fc.tar
go-tangerine-460d206f309fc0884c666bd191a1b6a4b63462fc.tar.gz
go-tangerine-460d206f309fc0884c666bd191a1b6a4b63462fc.tar.bz2
go-tangerine-460d206f309fc0884c666bd191a1b6a4b63462fc.tar.lz
go-tangerine-460d206f309fc0884c666bd191a1b6a4b63462fc.tar.xz
go-tangerine-460d206f309fc0884c666bd191a1b6a4b63462fc.tar.zst
go-tangerine-460d206f309fc0884c666bd191a1b6a4b63462fc.zip
swarm/network: Use actual remote peer ip in underlay (#19137)
* swarm/network: Logline to see handshake addr * swarm/network: Replace remote ip in handshake uaddr * swarm/network: Add test for enode uaddr rewrite method * swarm/network: Remove redundance pointer return from sanitize * swarm/network: Obeying the linting machine * swarm/network: Add panic comment (travis trigger take 1)
Diffstat (limited to 'swarm/network/protocol_test.go')
-rw-r--r--swarm/network/protocol_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/swarm/network/protocol_test.go b/swarm/network/protocol_test.go
index 64ce7ba4a..97cb4b97b 100644
--- a/swarm/network/protocol_test.go
+++ b/swarm/network/protocol_test.go
@@ -17,12 +17,15 @@
package network
import (
+ "bytes"
"flag"
"fmt"
+ "net"
"os"
"testing"
"time"
+ "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enode"
@@ -251,3 +254,26 @@ func TestBzzHandshakeLightNode(t *testing.T) {
})
}
}
+
+// Tests the overwriting of localhost enode in handshake if actual remote ip is known
+// (swarm.network/protocol.go:sanitizeEnodeRemote)
+func TestSanitizeEnodeRemote(t *testing.T) {
+ pk, err := crypto.GenerateKey()
+ if err != nil {
+ t.Fatal(err)
+ }
+ remoteIP := net.IPv4(0x80, 0x40, 0x20, 0x10)
+ remoteAddr := net.TCPAddr{
+ IP: remoteIP,
+ Port: 30399,
+ }
+ nodLocal := enode.NewV4(&pk.PublicKey, net.IPv4(0x7f, 0x00, 0x00, 0x01), 30341, 30341)
+ nodRemote := enode.NewV4(&pk.PublicKey, remoteIP, 30341, 30341)
+ baddr := RandomAddr()
+ oldUAddr := []byte(nodLocal.String())
+ baddr.UAddr = oldUAddr
+ sanitizeEnodeRemote(&remoteAddr, baddr)
+ if !bytes.Equal(baddr.UAddr, []byte(nodRemote.String())) {
+ t.Fatalf("insane address. expected %v, got %v", nodRemote.String(), string(baddr.UAddr))
+ }
+}