mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 01:12:24 +08:00
refactor(identify) extract proto encoding
This commit is contained in:
@ -34,17 +34,14 @@ var ErrUnsupportedKeyType = errors.New("unsupported key type")
|
|||||||
// Performs initial communication with this peer to share node ID's and
|
// Performs initial communication with this peer to share node ID's and
|
||||||
// initiate communication. (secureIn, secureOut, error)
|
// initiate communication. (secureIn, secureOut, error)
|
||||||
func Handshake(self, remote *peer.Peer, in <-chan []byte, out chan<- []byte) (<-chan []byte, chan<- []byte, 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 {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
encoded, err := proto.Marshal(h)
|
// TODO(brian): select on |ctx|
|
||||||
if err != nil {
|
out <- encodedHello
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
out <- encoded
|
|
||||||
|
|
||||||
// Parse their Hello packet and generate an Exchange packet.
|
// Parse their Hello packet and generate an Exchange packet.
|
||||||
// Exchange = (EphemeralPubKey, Signature)
|
// Exchange = (EphemeralPubKey, Signature)
|
||||||
@ -322,3 +319,12 @@ func genRandHello(self *peer.Peer) (*Hello, error) {
|
|||||||
hello.Hashes = &SupportedHashes
|
hello.Hashes = &SupportedHashes
|
||||||
return hello, nil
|
return hello, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func encodedProtoHello(self *peer.Peer) ([]byte, error) {
|
||||||
|
h, err := genRandHello(self)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return proto.Marshal(h)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user