67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package bsc
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/ethereum/go-ethereum/rlp"
|
|
)
|
|
|
|
// Constants to match up protocol versions and messages
|
|
const (
|
|
Bsc1 = 1
|
|
)
|
|
|
|
// ProtocolName is the official short name of the `bsc` protocol used during
|
|
// devp2p capability negotiation.
|
|
const ProtocolName = "bsc"
|
|
|
|
// ProtocolVersions are the supported versions of the `bsc` protocol (first
|
|
// is primary).
|
|
var ProtocolVersions = []uint{Bsc1}
|
|
|
|
// protocolLengths are the number of implemented message corresponding to
|
|
// different protocol versions.
|
|
var protocolLengths = map[uint]uint64{Bsc1: 2}
|
|
|
|
// maxMessageSize is the maximum cap on the size of a protocol message.
|
|
const maxMessageSize = 10 * 1024 * 1024
|
|
|
|
const (
|
|
BscCapMsg = 0x00 // bsc capability msg used upon handshake
|
|
VotesMsg = 0x01
|
|
)
|
|
|
|
var defaultExtra = []byte{0x00}
|
|
|
|
var (
|
|
errNoBscCapMsg = errors.New("no bsc capability message")
|
|
errMsgTooLarge = errors.New("message too long")
|
|
errDecode = errors.New("invalid message")
|
|
errInvalidMsgCode = errors.New("invalid message code")
|
|
errProtocolVersionMismatch = errors.New("protocol version mismatch")
|
|
)
|
|
|
|
// Packet represents a p2p message in the `bsc` protocol.
|
|
type Packet interface {
|
|
Name() string // Name returns a string corresponding to the message type.
|
|
Kind() byte // Kind returns the message type.
|
|
}
|
|
|
|
// BscCapPacket is the network packet for bsc capability message.
|
|
type BscCapPacket struct {
|
|
ProtocolVersion uint
|
|
Extra rlp.RawValue // for extension
|
|
}
|
|
|
|
// VotesPacket is the network packet for votes record.
|
|
type VotesPacket struct {
|
|
Votes []*types.VoteEnvelope
|
|
}
|
|
|
|
func (*BscCapPacket) Name() string { return "BscCap" }
|
|
func (*BscCapPacket) Kind() byte { return BscCapMsg }
|
|
|
|
func (*VotesPacket) Name() string { return "Votes" }
|
|
func (*VotesPacket) Kind() byte { return VotesMsg }
|