prysm-pulse/shared/p2p/handshake_handler.go
Preston Van Loon 210edfc940 P2P handshake handling (#2306)
* proto: illegal wireType 7 :(

* set addr to todo for now so somethign gets sent

* push latest progress

* Add feedback from @raulk. Stream never connects

* working handshake handler

* add exclusions for relay/bootstrap node

* fix tests, still need to add new ones

* remove race, fails coverage

* Add test for negotiation

* gazelle

* regen pb

* Update shared/p2p/handshake_handler.go

Co-Authored-By: prestonvanloon <preston@prysmaticlabs.com>
2019-04-27 14:08:27 -05:00

24 lines
711 B
Go

package p2p
import (
ggio "github.com/gogo/protobuf/io"
host "github.com/libp2p/go-libp2p-host"
inet "github.com/libp2p/go-libp2p-net"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)
// setHandshakeHandler to respond to requests for p2p handshake messages.
func setHandshakeHandler(host host.Host, contractAddress string) {
host.SetStreamHandler(handshakeProtocol, func(stream inet.Stream) {
defer stream.Close()
log.Debug("Handling handshake stream")
w := ggio.NewDelimitedWriter(stream)
defer w.Close()
hs := &pb.Handshake{DepositContractAddress: contractAddress}
if err := w.WriteMsg(hs); err != nil {
log.WithError(err).Error("Failed to write handshake response")
}
})
}