func AuthenticateMessage(message types.Message, stream network.Stream) bool {
	var sign, bin []byte
	switch t := message.(type) {
	case *types.P2PRequest:
		sign = t.Headers.Sign
		t.Headers.Sign = nil
		bin = types.Encode(t)
		t.Headers.Sign = sign
	case *types.P2PResponse:
		sign = t.Headers.Sign
		t.Headers.Sign = nil
		bin = types.Encode(t)
		t.Headers.Sign = sign
	default:
		return false
	}
	return verifyData(bin, sign, stream.Conn().RemotePublicKey())
}
AuthenticateMessage authenticates p2p message.
package protocol
import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"math/rand"
	"runtime"
	"time"
	"github.com/33cn/chain33/common/log/log15"
	"github.com/33cn/chain33/queue"
	types2 "github.com/33cn/chain33/system/p2p/dht/types"
	"github.com/33cn/chain33/types"
	"github.com/libp2p/go-libp2p-core/crypto"
	"github.com/libp2p/go-libp2p-core/network"
	"github.com/libp2p/go-msgio"
)
var log = log15.New("module", "p2p.protocol")
func init() {
	rand.Seed(time.Now().UnixNano())
}
const messageHeaderLen = 17
var (
	messageHeader = headerSafe([]byte("/protobuf/msgio"))
)
func ReadStream(data types.Message, stream network.Stream) error {
	var header [messageHeaderLen]byte
	_, err := io.ReadFull(stream, header[:])
	if err != nil || !bytes.Equal(header[:], messageHeader) {
		log.Error("ReadStream", "pid", stream.Conn().RemotePeer().Pretty(), "protocolID", stream.Protocol(), "read header err", err)
		return err
	}
	reader := msgio.NewReaderSize(stream, types.MaxBlockSize)
	msg, err := reader.ReadMsg()
	defer reader.ReleaseMsg(msg)
	if err != nil {
		log.Error("ReadStream", "pid", stream.Conn().RemotePeer().Pretty(), "protocolID", stream.Protocol(), "read msg err", err)
		return err
	}
	err = types.Decode(msg, data)
	if err != nil {
		log.Error("ReadStream", "pid", stream.Conn().RemotePeer().Pretty(), "protocolID", stream.Protocol(), "decode err", err)
		return err
	}
	return nil
}
func WriteStream(data types.Message, stream network.Stream) error {
	_, err := stream.Write(messageHeader)
	if err != nil {
		log.Error("WriteStream", "pid", stream.Conn().RemotePeer().Pretty(), "protocolID", stream.Protocol(), "write header err", err)
		return err
	}
	msg := types.Encode(data)
	writer := msgio.NewWriter(stream)
	err = writer.WriteMsg(msg)
	if err != nil {
		log.Error("WriteStream", "pid", stream.Conn().RemotePeer().Pretty(), "protocolID", stream.Protocol(), "write msg err", err)
		return err
	}
	return nil
}
func CloseStream(stream network.Stream) {
	if stream == nil {
		return
	}
	_ = stream.CloseWrite()
	_ = stream.CloseRead()
	go func() {
		err := AwaitEOF(stream)
		if err != nil {
			log.Debug("CloseStream", "err", err, "protocol ID", stream.Protocol())
		}
	}()
}