@cryptotaxi247 / kubo / commits / 6f6d79d69

refactor(identify) extract proto encoding

Brian Tiger Chow committed Sep 13, 2014 at 01:42 UTC 6f6d79d6992a00895e11558f89f6f0966d65788d
1 file changed +12 -6
identify/identify.go
+12 -6
@@ -34,17 +34,14 @@ var ErrUnsupportedKeyType = errors.New("unsupported key type")
34 // Performs initial communication with this peer to share node ID's and
35 // initiate communication. (secureIn, secureOut, error)
36 func Handshake(self, remote *peer.Peer, in <-chan []byte, out chan<- []byte) (<-chan []byte, chan<- []byte, error) {
37 - h, err := genRandHello(self)
38 - if err != nil {
39 - return nil, nil, err
40 - }
37
42 - encoded, err := proto.Marshal(h)
38 + encodedHello, err := encodedProtoHello(self)
39 if err != nil {
40 return nil, nil, err
41 }
42
47 - out <- encoded
43 + // TODO(brian): select on |ctx|
44 + out <- encodedHello
45
46 // Parse their Hello packet and generate an Exchange packet.
47 // Exchange = (EphemeralPubKey, Signature)
@@ -322,3 +319,12 @@ func genRandHello(self *peer.Peer) (*Hello, error) {
319 hello.Hashes = &SupportedHashes
320 return hello, nil
321 }
322 +
323 +func encodedProtoHello(self *peer.Peer) ([]byte, error) {
324 + h, err := genRandHello(self)
325 + if err != nil {
326 + return nil, err
327 + }
328 +
329 + return proto.Marshal(h)
330 +}