Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
1f2adb05
Commit
1f2adb05
authored
Jan 21, 2015
by
zelig
Committed by
Felix Lange
Feb 05, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add initial peer level test (failing)
parent
4afde4e7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
1 deletion
+52
-1
crypto_test.go
p2p/crypto_test.go
+52
-1
No files found.
p2p/crypto_test.go
View file @
1f2adb05
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
// "crypto/elliptic"
// "crypto/elliptic"
// "crypto/rand"
// "crypto/rand"
"fmt"
"fmt"
"net"
"testing"
"testing"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
...
@@ -114,7 +115,9 @@ func TestCryptoHandshake(t *testing.T) {
...
@@ -114,7 +115,9 @@ func TestCryptoHandshake(t *testing.T) {
t
.
Errorf
(
"%v"
,
err
)
t
.
Errorf
(
"%v"
,
err
)
}
}
fmt
.
Printf
(
"
\n
auth %x
\n
initNonce %x
\n
response%x
\n
remoteRecNonce %x
\n
remoteInitNonce %x
\n
remoteRandomPubKey %x
\n
recNonce %x
\n
remoteInitRandomPubKey %x
\n
initSessionToken %x
\n\n
"
,
auth
,
initNonce
,
response
,
remoteRecNonce
,
remoteInitNonce
,
remoteRandomPubKey
,
recNonce
,
remoteInitRandomPubKey
,
initSessionToken
)
fmt
.
Printf
(
"
\n
auth (%v) %x
\n\n
resp (%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
)
{
if
!
bytes
.
Equal
(
initNonce
,
remoteInitNonce
)
{
t
.
Errorf
(
"nonces do not match"
)
t
.
Errorf
(
"nonces do not match"
)
...
@@ -140,3 +143,51 @@ func TestCryptoHandshake(t *testing.T) {
...
@@ -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
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment