From 6f6d79d6992a00895e11558f89f6f0966d65788d Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Sat, 13 Sep 2014 01:42:59 -0700 Subject: [PATCH] refactor(identify) extract proto encoding --- identify/identify.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/identify/identify.go b/identify/identify.go index 01e629baf..205e56733 100644 --- a/identify/identify.go +++ b/identify/identify.go @@ -34,17 +34,14 @@ var ErrUnsupportedKeyType = errors.New("unsupported key type") // Performs initial communication with this peer to share node ID's and // initiate communication. (secureIn, secureOut, error) func Handshake(self, remote *peer.Peer, in <-chan []byte, out chan<- []byte) (<-chan []byte, chan<- []byte, error) { - h, err := genRandHello(self) + + encodedHello, err := encodedProtoHello(self) if err != nil { return nil, nil, err } - encoded, err := proto.Marshal(h) - if err != nil { - return nil, nil, err - } - - out <- encoded + // TODO(brian): select on |ctx| + out <- encodedHello // Parse their Hello packet and generate an Exchange packet. // Exchange = (EphemeralPubKey, Signature) @@ -322,3 +319,12 @@ func genRandHello(self *peer.Peer) (*Hello, error) { hello.Hashes = &SupportedHashes return hello, nil } + +func encodedProtoHello(self *peer.Peer) ([]byte, error) { + h, err := genRandHello(self) + if err != nil { + return nil, err + } + + return proto.Marshal(h) +}