From e9aebac1a2a4732763c2f7e4428a23983d4eb6a3 Mon Sep 17 00:00:00 2001 From: bt Date: Fri, 10 Apr 2026 19:31:31 +0200 Subject: [common] Exchange messages between servers --- core/data.go | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'core/data.go') diff --git a/core/data.go b/core/data.go index a96b56f..dd2777f 100644 --- a/core/data.go +++ b/core/data.go @@ -16,13 +16,14 @@ type Wrapper interface { type PayloadType uint8 const ( - PayloadUnknown PayloadType = 0x00 - PayloadSuccess = 0x01 - PayloadError = 0x02 - PayloadHandshake = 0x03 - PayloadAuth = 0x04 - PayloadMessage = 0x05 - PayloadTest = 0xFF + PayloadUnknown PayloadType = 0x00 + PayloadSuccess = 0x01 + PayloadError = 0x02 + PayloadHandshake = 0x03 + PayloadUserAuth = 0x04 + PayloadMessage = 0x05 + PayloadServerAuth = 0x06 + PayloadTest = 0xFF ) type ErrorType uint8 @@ -33,6 +34,14 @@ const ( ErrorNotFound = 0x02 ) +type ConnType uint8 + +const ( + ConnTypeUnknown ConnType = 0x00 + ConnTypeUser = 0x01 + ConnTypeServer = 0x02 +) + type Frame struct { Length uint16 Type PayloadType @@ -99,7 +108,7 @@ func Decode(buf io.Reader) (any, error) { err := binary.Read(buf, binary.BigEndian, &pTypeByte) if err != nil { - return nil, fmt.Errorf("cannot read payload type: %v", err) + return nil, fmt.Errorf("cannot read payload type: %w", err) } pType := PayloadType(pTypeByte) @@ -107,7 +116,7 @@ func Decode(buf io.Reader) (any, error) { var pLen uint16 err = binary.Read(buf, binary.BigEndian, &pLen) if err != nil { - return nil, fmt.Errorf("cannot read payload length: %v", err) + return nil, fmt.Errorf("cannot read payload length: %w", err) } switch pType { @@ -117,8 +126,10 @@ func Decode(buf io.Reader) (any, error) { return DecodeError(buf) case PayloadHandshake: return DecodeHandshake(buf) - case PayloadAuth: - return DecodeAuth(buf) + case PayloadUserAuth: + return DecodeUserAuth(buf) + case PayloadServerAuth: + return DecodeServerAuth(buf) case PayloadMessage: return DecodeMessage(buf) case PayloadTest: -- cgit v1.2.3