[PD1] Added SQLlite queries and minor protocol changes
This commit is contained in:
parent
1e12bcde6c
commit
23584e2901
6 changed files with 213 additions and 46 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue