[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

@ -6,19 +6,23 @@ import (
"fmt"
)
func clientHandler(connection networking.Connection[protocol.Packet]) {
defer connection.Conn.Close()
func clientHandler(connection networking.Connection[protocol.Packet], dataStore DataStore) {
defer connection.Conn.Close()
// FIX: GET THE UID FROM THE USER CERTIFICATE FROM THE TLS SESSION
uid := "0"
for {
pac := connection.Receive()
pac := connection.Receive()
switch pac.Flag {
case protocol.ReqPK:
fmt.Println("ReqPK")
case protocol.ReqAllMsg:
case protocol.ReqUserCertPkt:
userCertPacket := dataStore.GetUserCertificate(uid)
connection.Send(userCertPacket)
case protocol.ReqAllMsgPkt:
fmt.Println("ReqAllMsg")
case protocol.ReqMsg:
case protocol.ReqMsgPkt:
fmt.Println("ReqMsg")
case protocol.SubmitMsg:
case protocol.SubmitMsgPkt:
fmt.Println("SubmitMsg")
}
}
@ -26,13 +30,18 @@ func clientHandler(connection networking.Connection[protocol.Packet]) {
}
func Run(port int) {
server := networking.NewServer[protocol.Packet](port)
go server.ListenLoop()
//Open connection to DB
dataStore := OpenDB()
defer dataStore.db.Close()
//Create server listener
server := networking.NewServer[protocol.Packet](port)
go server.ListenLoop()
for {
//Receive Connection via channel
conn := <-server.C
//Launch client handler via clientHandler
go clientHandler(conn)
go clientHandler(conn, dataStore)
}
}