identify.go 733 Bytes
Newer Older
1 2 3 4 5 6
// The identify package handles how peers identify with eachother upon
// connection to the network
package identify

import (
	peer "github.com/jbenet/go-ipfs/peer"
7
	u "github.com/jbenet/go-ipfs/util"
8 9 10 11
)

// Perform initial communication with this peer to share node ID's and
// initiate communication
12
func Handshake(self, remote *peer.Peer, in, out chan []byte) error {
13 14 15 16 17 18 19

	// temporary:
	// put your own id in a 16byte buffer and send that over to
	// the peer as your ID, then wait for them to send their ID.
	// Once that trade is finished, the handshake is complete and
	// both sides should 'trust' each other

20 21 22 23
	out <- self.ID
	resp := <-in
	remote.ID = peer.ID(resp)
	u.DOut("Got node id: %s", string(remote.ID))
24 25 26

	return nil
}