Define presentation layer types
This commit is contained in:
parent
a2b7f1bfab
commit
ffc23c362b
64
internal/protocol/types.go
Normal file
64
internal/protocol/types.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package protocol
|
||||
|
||||
import (
|
||||
"hash-of-wisdom/internal/pow/challenge"
|
||||
"hash-of-wisdom/internal/quotes"
|
||||
)
|
||||
|
||||
// MessageType represents the type of protocol message
|
||||
type MessageType byte
|
||||
|
||||
const (
|
||||
ChallengeRequest MessageType = 0x01
|
||||
ChallengeResponse MessageType = 0x02
|
||||
SolutionRequest MessageType = 0x03
|
||||
QuoteResponse MessageType = 0x04
|
||||
ErrorResponse MessageType = 0x05
|
||||
)
|
||||
|
||||
// Message represents a protocol message with type and payload
|
||||
type Message struct {
|
||||
Type MessageType
|
||||
Payload []byte
|
||||
}
|
||||
|
||||
// ChallengeRequestPayload is empty (no payload for challenge requests)
|
||||
type ChallengeRequestPayload struct{}
|
||||
|
||||
// ChallengeResponsePayload is the direct challenge object (not wrapped)
|
||||
type ChallengeResponsePayload challenge.Challenge
|
||||
|
||||
// SolutionRequestPayload contains the client's solution attempt
|
||||
type SolutionRequestPayload struct {
|
||||
Challenge challenge.Challenge `json:"challenge"`
|
||||
Nonce uint64 `json:"nonce"`
|
||||
}
|
||||
|
||||
// QuoteResponsePayload is the direct quote object (not wrapped)
|
||||
type QuoteResponsePayload quotes.Quote
|
||||
|
||||
// ErrorResponsePayload contains error information
|
||||
type ErrorResponsePayload struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
RetryAfter int `json:"retry_after,omitempty"`
|
||||
Details map[string]string `json:"details,omitempty"`
|
||||
}
|
||||
|
||||
// Error codes as defined in protocol specification
|
||||
const (
|
||||
ErrMalformedMessage = "MALFORMED_MESSAGE"
|
||||
ErrInvalidChallenge = "INVALID_CHALLENGE"
|
||||
ErrInvalidSolution = "INVALID_SOLUTION"
|
||||
ErrExpiredChallenge = "EXPIRED_CHALLENGE"
|
||||
ErrRateLimited = "RATE_LIMITED"
|
||||
ErrServerError = "SERVER_ERROR"
|
||||
ErrTooManyConnections = "TOO_MANY_CONNECTIONS"
|
||||
ErrDifficultyTooHigh = "DIFFICULTY_TOO_HIGH"
|
||||
)
|
||||
|
||||
// Protocol constants
|
||||
const (
|
||||
MaxPayloadSize = 8 * 1024 // 8KB maximum payload size
|
||||
HeaderSize = 5 // 1 byte type + 4 bytes length
|
||||
)
|
||||
Loading…
Reference in a new issue