aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/handshake.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-02-27 11:06:55 +0800
committerFelix Lange <fjl@twurst.com>2015-03-04 19:27:23 +0800
commit736e632215d49dd7bc61126f78dda4bad12768ea (patch)
tree063327c533fd57620e0448f331832e79f9ba0dda /p2p/handshake.go
parent51e01cceca81bc5e82896815754b7c33bb6e6005 (diff)
downloadgo-tangerine-736e632215d49dd7bc61126f78dda4bad12768ea.tar.gz
go-tangerine-736e632215d49dd7bc61126f78dda4bad12768ea.tar.zst
go-tangerine-736e632215d49dd7bc61126f78dda4bad12768ea.zip
p2p: use RLPx frames for messaging
Diffstat (limited to 'p2p/handshake.go')
-rw-r--r--p2p/handshake.go27
1 files changed, 10 insertions, 17 deletions
diff --git a/p2p/handshake.go b/p2p/handshake.go
index 17f572dea..10ef970dc 100644
--- a/p2p/handshake.go
+++ b/p2p/handshake.go
@@ -32,14 +32,10 @@ const (
)
type conn struct {
- *frameRW
+ MsgReadWriter
*protoHandshake
}
-func newConn(fd net.Conn, hs *protoHandshake) *conn {
- return &conn{newFrameRW(fd, msgWriteTimeout), hs}
-}
-
// encHandshake contains the state of the encryption handshake.
type encHandshake struct {
remoteID discover.NodeID
@@ -115,17 +111,16 @@ func setupInboundConn(fd net.Conn, prv *ecdsa.PrivateKey, our *protoHandshake) (
// Run the protocol handshake using authenticated messages.
// TODO: move buffering setup here (out of newFrameRW)
- phsrw := newRlpxFrameRW(fd, secrets)
- rhs, err := readProtocolHandshake(phsrw, our)
+ rw := newRlpxFrameRW(fd, secrets)
+ rhs, err := readProtocolHandshake(rw, our)
if err != nil {
return nil, err
}
- if err := writeProtocolHandshake(phsrw, our); err != nil {
+ // TODO: validate that handshake node ID matches
+ if err := writeProtocolHandshake(rw, our); err != nil {
return nil, fmt.Errorf("protocol write error: %v", err)
}
-
- rw := newFrameRW(fd, msgWriteTimeout)
- return &conn{rw, rhs}, nil
+ return &conn{&lockedRW{wrapped: rw}, rhs}, nil
}
func setupOutboundConn(fd net.Conn, prv *ecdsa.PrivateKey, our *protoHandshake, dial *discover.Node) (*conn, error) {
@@ -136,20 +131,18 @@ func setupOutboundConn(fd net.Conn, prv *ecdsa.PrivateKey, our *protoHandshake,
// Run the protocol handshake using authenticated messages.
// TODO: move buffering setup here (out of newFrameRW)
- phsrw := newRlpxFrameRW(fd, secrets)
- if err := writeProtocolHandshake(phsrw, our); err != nil {
+ rw := newRlpxFrameRW(fd, secrets)
+ if err := writeProtocolHandshake(rw, our); err != nil {
return nil, fmt.Errorf("protocol write error: %v", err)
}
- rhs, err := readProtocolHandshake(phsrw, our)
+ rhs, err := readProtocolHandshake(rw, our)
if err != nil {
return nil, fmt.Errorf("protocol handshake read error: %v", err)
}
if rhs.ID != dial.ID {
return nil, errors.New("dialed node id mismatch")
}
-
- rw := newFrameRW(fd, msgWriteTimeout)
- return &conn{rw, rhs}, nil
+ return &conn{&lockedRW{wrapped: rw}, rhs}, nil
}
// outboundEncHandshake negotiates a session token on conn.