[PD1] Generic networking server and client implemented

This commit is contained in:
Afonso Franco 2024-04-17 14:09:42 +01:00
parent 8553e1674e
commit 278b8e1a73
Signed by: afonso
SSH key fingerprint: SHA256:aiLbdlPwXKJS5wMnghdtod0SPy8imZjlVvCyUX9DJNk
4 changed files with 114 additions and 38 deletions

View file

@ -1,8 +1,6 @@
package protocol
import (
"encoding/json"
"fmt"
"time"
)
@ -12,8 +10,9 @@ const (
ReqPK PacketType = iota
ReqAllMsg
ReqMsg
SubmitMsg
SendPK
UsrMsg
Msg
)
type PacketBody interface {}
@ -39,18 +38,19 @@ type RequestMsg struct {
Num uint16
}
// Server --> Client: Send the client the requested public key
type SendPubKey struct {
Key []byte
}
// Bidirectional: Send messages between server and clients
type SendMessage struct {
// Client --> Server: Send message from client to server
type SubmitMessage struct {
ToUID string
Subject []byte
Body []byte
}
// Server --> Client: Send the client the requested public key
type SendPubKey struct {
Key []byte
}
// Server --> Client: Send the client a message
type Message struct {
FromUID string
ToUID string
@ -58,11 +58,3 @@ type Message struct {
Body []byte
Timestamp time.Time
}
func (p Packet) Marshal() ([]byte, error) {
return json.Marshal(p)
}
func (p *Packet) Unmarshal(data []byte) error {
return json.Unmarshal(data, p)
}