[PD1] Added SQLlite queries and minor protocol changes

This commit is contained in:
Afonso Franco 2024-04-18 01:18:51 +01:00
parent 1e12bcde6c
commit 23584e2901
Signed by: afonso
SSH key fingerprint: SHA256:aiLbdlPwXKJS5wMnghdtod0SPy8imZjlVvCyUX9DJNk
6 changed files with 213 additions and 46 deletions

View file

@ -7,12 +7,12 @@ import (
type PacketType int
const (
ReqPK PacketType = iota
ReqAllMsg
ReqMsg
SubmitMsg
SendPK
Msg
ReqUserCertPkt PacketType = iota
ReqAllMsgPkt
ReqMsgPkt
SubmitMsgPkt
SendUserCertPkt
ServerMsgPkt
)
type PacketBody interface{}
@ -22,91 +22,91 @@ type Packet struct {
Body PacketBody
}
// Client --> Server: Ask for a user's public key
type RequestPubKey struct {
FromUID string
KeyUID string
// Client --> Server: Ask for a user's certificate
type RequestUserCertPacket struct {
UID string
}
func NewRequestPubKey(fromUID, keyUID string) Packet {
func NewRequestUserCertPacket(UID string) Packet {
return Packet{
Flag: ReqPK,
Body: RequestPubKey{
FromUID: fromUID,
KeyUID: keyUID,
Flag: ReqUserCertPkt,
Body: RequestUserCertPacket{
UID: UID,
},
}
}
// Client --> Server: Ask for all the client's messages in the queue
type RequestAllMsg struct {
type RequestAllMsgPacket struct {
FromUID string
}
func NewRequestAllMsg(fromUID string) Packet {
func NewRequestAllMsgPacket(fromUID string) Packet {
return Packet{
Flag: ReqAllMsg,
Body: RequestAllMsg{
Flag: ReqAllMsgPkt,
Body: RequestAllMsgPacket{
FromUID: fromUID,
},
}
}
// Client --> Server: Ask for a specific message in the queue
type RequestMsg struct {
type RequestMsgPacket struct {
Num uint16
}
func NewRequestMsg(num uint16) Packet {
func NewRequestMsgPacket(num uint16) Packet {
return Packet{
Flag: ReqMsg,
Body: RequestMsg{
Flag: ReqMsgPkt,
Body: RequestMsgPacket{
Num: num,
},
}
}
// Client --> Server: Send message from client to server
type SubmitMessage struct {
type SubmitMessagePacket struct {
ToUID string
Content []byte
}
func NewSubmitMessage(toUID string, content []byte) Packet {
func NewSubmitMessagePacket(toUID string, content []byte) Packet {
return Packet{
Flag: SubmitMsg,
Body: SubmitMessage{
Flag: SubmitMsgPkt,
Body: SubmitMessagePacket{
ToUID: toUID,
Content: content},
}
}
// Server --> Client: Send the client the requested public key
type SendPubKey struct {
type SendUserCertPacket struct {
UID string
Key []byte
}
func NewSendPubKey(key []byte) Packet {
func NewSendUserCertPacket(uid string, key []byte) Packet {
return Packet{
Flag: SendPK,
Body: SendPubKey{
Flag: SendUserCertPkt,
Body: SendUserCertPacket{
UID: uid,
Key: key,
},
}
}
// Server --> Client: Send the client a message
type ServerMessage struct {
type ServerMessagePacket struct {
FromUID string
ToUID string
Content []byte
Timestamp time.Time
}
func NewMessage(fromUID, toUID string, content []byte, timestamp time.Time) Packet {
func NewMessagePacket(fromUID, toUID string, content []byte, timestamp time.Time) Packet {
return Packet{
Flag: Msg,
Body: ServerMessage{
Body: ServerMessagePacket{
FromUID: fromUID,
ToUID: toUID,
Content: content,