aboutsummaryrefslogtreecommitdiffstats
path: root/p2p
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-01-21 22:42:12 +0800
committerFelix Lange <fjl@twurst.com>2015-02-06 07:00:35 +0800
commit1f2adb05b57b0b657bfa62b47d46e3a9bf1d8496 (patch)
tree5169ea7ef64560e94b03914ca1e12b370e1976b1 /p2p
parent4afde4e738e3981e086d6e8710c3d711d0e8531d (diff)
downloadgo-tangerine-1f2adb05b57b0b657bfa62b47d46e3a9bf1d8496.tar
go-tangerine-1f2adb05b57b0b657bfa62b47d46e3a9bf1d8496.tar.gz
go-tangerine-1f2adb05b57b0b657bfa62b47d46e3a9bf1d8496.tar.bz2
go-tangerine-1f2adb05b57b0b657bfa62b47d46e3a9bf1d8496.tar.lz
go-tangerine-1f2adb05b57b0b657bfa62b47d46e3a9bf1d8496.tar.xz
go-tangerine-1f2adb05b57b0b657bfa62b47d46e3a9bf1d8496.tar.zst
go-tangerine-1f2adb05b57b0b657bfa62b47d46e3a9bf1d8496.zip
add initial peer level test (failing)
Diffstat (limited to 'p2p')
-rw-r--r--p2p/crypto_test.go53
1 files changed, 52 insertions, 1 deletions
diff --git a/p2p/crypto_test.go b/p2p/crypto_test.go
index 8000efaf1..5fbdc61e3 100644
--- a/p2p/crypto_test.go
+++ b/p2p/crypto_test.go
@@ -6,6 +6,7 @@ import (
// "crypto/elliptic"
// "crypto/rand"
"fmt"
+ "net"
"testing"
"github.com/ethereum/go-ethereum/crypto"
@@ -114,7 +115,9 @@ func TestCryptoHandshake(t *testing.T) {
t.Errorf("%v", err)
}
- fmt.Printf("\nauth %x\ninitNonce %x\nresponse%x\nremoteRecNonce %x\nremoteInitNonce %x\nremoteRandomPubKey %x\nrecNonce %x\nremoteInitRandomPubKey %x\ninitSessionToken %x\n\n", auth, initNonce, response, remoteRecNonce, remoteInitNonce, remoteRandomPubKey, recNonce, remoteInitRandomPubKey, initSessionToken)
+ fmt.Printf("\nauth (%v) %x\n\nresp (%v) %x\n\n", len(auth), auth, len(response), response)
+
+ // fmt.Printf("\nauth %x\ninitNonce %x\nresponse%x\nremoteRecNonce %x\nremoteInitNonce %x\nremoteRandomPubKey %x\nrecNonce %x\nremoteInitRandomPubKey %x\ninitSessionToken %x\n\n", auth, initNonce, response, remoteRecNonce, remoteInitNonce, remoteRandomPubKey, recNonce, remoteInitRandomPubKey, initSessionToken)
if !bytes.Equal(initNonce, remoteInitNonce) {
t.Errorf("nonces do not match")
@@ -140,3 +143,51 @@ func TestCryptoHandshake(t *testing.T) {
}
}
+
+func TestPeersHandshake(t *testing.T) {
+ defer testlog(t).detach()
+ var err error
+ // var sessionToken []byte
+ prv0, _ := crypto.GenerateKey() // = ecdsa.GenerateKey(crypto.S256(), rand.Reader)
+ pub0 := &prv0.PublicKey
+ prv1, _ := crypto.GenerateKey()
+ pub1 := &prv1.PublicKey
+
+ prv0s := crypto.FromECDSA(prv0)
+ pub0s := crypto.FromECDSAPub(pub0)
+ prv1s := crypto.FromECDSA(prv1)
+ pub1s := crypto.FromECDSAPub(pub1)
+
+ conn1, conn2 := net.Pipe()
+ initiator := newPeer(conn1, []Protocol{}, nil)
+ receiver := newPeer(conn2, []Protocol{}, nil)
+ initiator.dialAddr = &peerAddr{IP: net.ParseIP("1.2.3.4"), Port: 2222, Pubkey: pub1s[1:]}
+ initiator.ourID = &peerId{prv0s, pub0s}
+
+ // this is cheating. identity of initiator/dialler not available to listener/receiver
+ // its public key should be looked up based on IP address
+ receiver.identity = initiator.ourID
+ receiver.ourID = &peerId{prv1s, pub1s}
+
+ initiator.pubkeyHook = func(*peerAddr) error { return nil }
+ receiver.pubkeyHook = func(*peerAddr) error { return nil }
+
+ initiator.cryptoHandshake = true
+ receiver.cryptoHandshake = true
+ errc0 := make(chan error, 1)
+ errc1 := make(chan error, 1)
+ go func() {
+ _, err := initiator.loop()
+ errc0 <- err
+ }()
+ go func() {
+ _, err := receiver.loop()
+ errc1 <- err
+ }()
+ select {
+ case err = <-errc0:
+ t.Errorf("peer 0 quit with error: %v", err)
+ case err = <-errc1:
+ t.Errorf("peer 1 quit with error: %v", err)
+ }
+}