From c7b930c9357bb89a62751738072c2d82e433dc47 Mon Sep 17 00:00:00 2001 From: Savely Krendelhoff Date: Sat, 23 Aug 2025 12:08:09 +0700 Subject: [PATCH] [PHASE-5] Move constants into separate file --- internal/protocol/constants.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 internal/protocol/constants.go diff --git a/internal/protocol/constants.go b/internal/protocol/constants.go new file mode 100644 index 0000000..015853c --- /dev/null +++ b/internal/protocol/constants.go @@ -0,0 +1,31 @@ +package protocol + +// MessageType represents the type of protocol message +type MessageType byte + +const ( + ChallengeRequestType MessageType = 0x01 + SolutionRequestType MessageType = 0x03 + // Response types (for responses.go) + ChallengeResponseType MessageType = 0x02 + QuoteResponseType MessageType = 0x04 + ErrorResponseType MessageType = 0x05 +) + +// 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 +)