func New(h host.Host, netid uint32, opts ...Opt) *Handshake {
	ctx, cancel := context.WithCancel(context.Background())
	hs := &Handshake{
		logger: log.NewNop(),
		netid:  netid,
		h:      h,
		cancel: cancel,
	}
	for _, opt := range opts {
		opt(hs)
	}
	h.SetStreamHandler(protocol.ID(hsprotocol), hs.handler)
	emitter, err := h.EventBus().Emitter(new(EventHandshakeComplete))
	if err != nil {
		hs.logger.With().Panic("failed to initialize emitter for handshake", log.Err(err))
	}
	sub, err := h.EventBus().Subscribe(new(event.EvtPeerIdentificationCompleted))
	if err != nil {
		hs.logger.With().Panic("failed to subsribe for events", log.Err(err))
	}
	hs.emitter = emitter
	hs.start(ctx, sub)
	return hs
}
New instantiates handshake protocol for the host.
package handshake
import (
	"context"
	"errors"
	"fmt"
	"time"
	"github.com/libp2p/go-libp2p-core/event"
	"github.com/libp2p/go-libp2p-core/host"
	"github.com/libp2p/go-libp2p-core/network"
	"github.com/libp2p/go-libp2p-core/peer"
	"github.com/libp2p/go-libp2p-core/protocol"
	"golang.org/x/sync/errgroup"
	"github.com/spacemeshos/go-spacemesh/codec"
	"github.com/spacemeshos/go-spacemesh/log"
)
type EventHandshakeComplete struct {
	PID       peer.ID
	Direction network.Direction
}
type Opt func(*Handshake)
func WithLog(logger log.Log) Opt {
	return func(hs *Handshake) {
		hs.logger = logger
	}
}
const (
	hsprotocol    = "/handshake/1.0.0"
	streamTimeout = 10 * time.Second
)
type handshakeMessage struct {
	Network uint32
}
type handshakeAck struct {
	Error string
}