Documentation
¶
Overview ¶
route.go
Index ¶
Constants ¶
const ( MACLength = 6 // Length of MAC address in bytes SignatureLength = 64 // Example length for Signature (e.g., 512-bit signature) IPLength = 16 // Supports both IPv4 and IPv6 )
Define constants for lengths (adjust as per your actual requirements)
const PeerStatePacketVersion byte = 1
Variables ¶
This section is empty.
Functions ¶
func SerializeRoutePacket ¶
func SerializeRoutePacket(pkt *RoutePacket) ([]byte, error)
SerializeRoutePacket serializes a RoutePacket into a byte slice
Types ¶
type ActorPacket ¶
type ActorPacket struct {
Address types.Address // Address of the actor itself
Status uint8 // 0 => proposed, 1 => approved, 2 => rejected
Message string // Optional message providing additional information
Roles types.Roles // Roles or permissions of the actor
SupportedTransports []types.TransportType // Transport types supported by this actor
SupportedProtocols []types.ProtocolType // Supported protocols by this actor
SupportedSigners []types.SignerType // Supported signers by this actor
ConsensusPublicKey []byte // Consensus Distributed Key Generation (DKG) public key (if actor should be part of consensus)
PublicKey []byte // Serialized public key (only in responses)
}
ActorPacket represents both request and response types with status codes.
func DeserializeActorPacket ¶
func DeserializeActorPacket(data []byte) (*ActorPacket, error)
DeserializeActorPacket deserializes a byte slice into an ActorPacket using binary encoding.
func (*ActorPacket) Serialize ¶
func (ap *ActorPacket) Serialize() ([]byte, error)
Serialize serializes the ActorPacket into a byte slice using binary encoding.
type ConsensusPacket ¶
type ConsensusPacket struct {
Type PacketType // Type of the packet (Proposal, PartialSignature, AggregatedSignature, Finalization)
Signer types.SignerType // Signer type used
ProposerID peer.ID // ID of the validator proposing the block (for ProposalPacket)
//ValidatorID peer.ID // ID of the validator approving the proposal (for PartialSignaturePacket)
BlockHash types.Hash // Hash of the block involved in the packet
BlockData []byte // Raw block data (optional, used in ProposalPacket)
Signature []byte // Aggregated signature (used in AggregatedSignaturePacket)
PartialSig []byte // Partial signature (used in PartialSignaturePacket)
//ParticipantIndex uint32 // Participant index (used in partial signatures)
SignatureSize int // Size of partial signatures received (optional)
}
ConsensusPacket represents a packet exchanged during the consensus protocol.
func DeserializeConsensusPacket ¶
func DeserializeConsensusPacket(data []byte) (*ConsensusPacket, error)
DeserializeConsensusPacket deserializes a byte slice into a ConsensusPacket.
func (*ConsensusPacket) Serialize ¶
func (cp *ConsensusPacket) Serialize() ([]byte, error)
Serialize serializes a ConsensusPacket into a byte slice.
type GeneralPacket ¶
type GeneralPacket struct {
Type PacketType
Payload []byte
}
GeneralPacket wraps any Packet with its PacketType.
func DeserializeGeneralPacket ¶
func DeserializeGeneralPacket(data []byte) (*GeneralPacket, error)
DeserializeGeneralPacket parses the byte slice into a GeneralPacket.
func (*GeneralPacket) Serialize ¶
func (gp *GeneralPacket) Serialize() ([]byte, error)
Serialize the GeneralPacket by prepending the PacketType.
type MessageResponse ¶
type MessageResponse struct {
Status types.HandlerStatus // 0x00 for error, 0x01 for success
ID uuid.UUID // Correlation ID for request/response matching
Length uint32 // Length of the data in bytes
Data []byte // The actual response data
}
MessageResponse represents a structured response from the database The wire format is: [status byte][16 bytes UUID][4 bytes length][data...]
func DecodeMessageResponse ¶
func DecodeMessageResponse(data []byte) (*MessageResponse, error)
DecodeMessageResponse parses a byte slice into a MessageResponse It expects the format: [status byte][16 bytes UUID][4 bytes length][data...]
func (*MessageResponse) Encode ¶
func (r *MessageResponse) Encode() []byte
Encode converts the MessageResponse to a byte slice for transmission Format: [status byte][16 bytes UUID][4 bytes length][data...]
func (*MessageResponse) GetErrorMessage ¶
func (r *MessageResponse) GetErrorMessage() string
GetErrorMessage returns the error message if Status is DBResponseStatusError If Status is not DBResponseStatusError, it returns an empty string
func (*MessageResponse) IsError ¶
func (r *MessageResponse) IsError() bool
IsError returns true if the response status indicates an error
func (*MessageResponse) IsSuccess ¶
func (r *MessageResponse) IsSuccess() bool
IsSuccess returns true if the response status indicates success
type NetworkPacket ¶
type NetworkPacket struct {
Type PacketType // Type of the packet (Ping, Request, Response)
SenderID peer.ID // ID of the sender
ReceiverID peer.ID // ID of the receiver (optional, can be zero value for broadcasts)
Payload []byte // Payload of the packet
Signature []byte // Signature for the packet
SignaturePubKey []byte // Public key corresponding to the signature
}
NetworkPacket represents the structure of packets exchanged in the network.
func DeserializeNetworkPacket ¶
func DeserializeNetworkPacket(data []byte) (*NetworkPacket, error)
DeserializeNetworkPacket deserializes a byte slice into a NetworkPacket. It handles optional fields like Signature and SignaturePubKey gracefully.
func (*NetworkPacket) Serialize ¶
func (np *NetworkPacket) Serialize() ([]byte, error)
Serialize serializes the NetworkPacket into a byte slice. It includes the Signature and SignaturePubKey fields if they are present.
func (*NetworkPacket) SerializeWithoutSignature ¶
func (np *NetworkPacket) SerializeWithoutSignature() ([]byte, error)
SerializeWithoutSignature serializes the NetworkPacket without including the Signature and SignaturePubKey fields.
type Packet ¶
type Packet interface {
Serialize() ([]byte, error)
Deserialize([]byte) error
GetType() PacketType
}
Packet is the interface that all packet types will implement.
type PacketType ¶
type PacketType uint8
PacketType represents the type of a packet, encompassing both consensus and network messages.
const ( PacketTypeUnknown PacketType = 0 // Represents an unknown message type // Network exchange packets ActorPacketType PacketType = 1 // Consensus Packet Types PacketTypeProposal PacketType = 4 // Indicates a new block proposal PacketTypeApproval PacketType = 5 // Indicates approval of a proposal PacketTypeFinalization PacketType = 6 // Indicates block finalization PacketTypePartialSignature PacketType = 7 PacketTypeAggregatedSignature PacketType = 8 // Network Packet Types PacketTypePing PacketType = 9 // Represents a simple ping message PacketTypeRequest PacketType = 10 // Represents a request message PacketTypeResponse PacketType = 11 // Represents a response message // State synchronization and snapshots PacketTypePeerState PacketType = 12 PacketTypeSnapshotMetadataRequest PacketType = 13 PacketTypeSnapshotMetadataResponse PacketType = 14 PacketTypeSnapshotRequest PacketType = 15 PacketTypeSnapshotChunk PacketType = 16 // Distributed Key Generation packets PacketDealBundle PacketType = 17 PacketResponseBundle PacketType = 18 PacketJustificationBundle PacketType = 19 // Block production PacketBlockProduction PacketType = 20 // Validator Packet Types PacketTypeValidatorJoin PacketType = 21 PacketTypeValidatorLeave PacketType = 22 PacketTypeCommitment PacketType = 23 // Block synchronization packets PacketTypeBlockRequest PacketType = 25 PacketTypeBlockResponse PacketType = 26 PacketTypePeerStateRequest PacketType = 27 PacketTypePeerStateResponse PacketType = 28 // Record distribution packets RecordBatchType PacketType = 30 // Batch of database records for P2P distribution )
func GetPacketType ¶
func GetPacketType(data []byte) (PacketType, error)
GetPacketType reads the first byte from the data to determine the PacketType.
func (PacketType) Bytes ¶
func (t PacketType) Bytes() []byte
func (*PacketType) FromBytes ¶
func (t *PacketType) FromBytes(data []byte) error
FromBytes converts a byte slice to PacketType.
func (PacketType) String ¶
func (t PacketType) String() string
type PeerStatePacket ¶
type PeerStatePacket struct {
Version byte // Protocol version
RequestID uint64 // Unique ID for request-response matching. 0 for broadcasts.
BlockHeight uint64 // Current block height of the peer
}
PeerStatePacket contains information about the peer's state.
func DeserializePeerStatePacket ¶
func DeserializePeerStatePacket(data []byte) (*PeerStatePacket, error)
DeserializePeerStatePacket deserializes a byte slice into a PeerStatePacket.
func (*PeerStatePacket) Serialize ¶
func (psp *PeerStatePacket) Serialize() ([]byte, error)
Serialize serializes the PeerStatePacket into a byte slice.
type Record ¶
type Record struct {
Key [32]byte // Fixed-size byte array for keys
Value []byte // Value as byte slice
}
Record represents a key-value pair in a record batch
type RecordBatch ¶
type RecordBatch struct {
Records []Record
}
RecordBatch represents a batch of records to be distributed
func DeserializeRecordBatch ¶
func DeserializeRecordBatch(data []byte) (*RecordBatch, error)
Deserialize parses a byte slice into a RecordBatch
func (*RecordBatch) Serialize ¶
func (rb *RecordBatch) Serialize() ([]byte, error)
Serialize converts a RecordBatch to a byte slice
type RoutePacket ¶
type RoutePacket struct {
NextHopIP [IPLength]byte // Fixed-size array for IP to simplify serialization
NextHopMAC []byte // Optional MAC address
Signature []byte // Optional Signature
}
RoutePacket represents a network route packet
func DeserializeRoutePacket ¶
func DeserializeRoutePacket(data []byte) (*RoutePacket, error)
DeserializeRoutePacket deserializes a byte slice into a RoutePacket
func NewRoutePacket ¶
func NewRoutePacket(nextHopIP [IPLength]byte) *RoutePacket
NewRoutePacket creates a new RoutePacket with mandatory fields