mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 21:57:16 +00:00
24 lines
711 B
Go
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")
|
||
|
}
|
||
|
})
|
||
|
}
|