[PD1] Fixed almost everything
This commit is contained in:
parent
39a0e5c01f
commit
7b3172a850
13 changed files with 534 additions and 192 deletions
|
@ -16,28 +16,44 @@ func clientHandler(connection networking.Connection[protocol.Packet], dataStore
|
|||
oidMap := cryptoUtils.ExtractAllOIDValues(clientCert)
|
||||
//Get the UID of this user
|
||||
UID := oidMap["2.5.4.65"]
|
||||
if UID=="" {
|
||||
if UID == "" {
|
||||
panic("User certificate does not specify it's PSEUDONYM")
|
||||
}
|
||||
|
||||
dataStore.storeUserCertIfNotExists(UID, *clientCert)
|
||||
F:
|
||||
for {
|
||||
var pac protocol.Packet
|
||||
connection.Receive(&pac)
|
||||
pac, active := connection.Receive()
|
||||
if !active {
|
||||
break F
|
||||
}
|
||||
switch pac.Flag {
|
||||
case protocol.ReqUserCertPkt:
|
||||
fmt.Printf("Type of pac.Body: %T\n", pac.Body)
|
||||
UserCertPacket, ok := (pac.Body).(protocol.RequestUserCertPacket)
|
||||
if !ok {
|
||||
panic("Could not cast packet to it's type")
|
||||
reqUserCert := protocol.UnmarshalRequestUserCertPacket(pac.Body)
|
||||
userCertPacket := dataStore.GetUserCertificate(reqUserCert.UID)
|
||||
if active := connection.Send(userCertPacket); !active {
|
||||
break F
|
||||
}
|
||||
case protocol.ReqMsgsQueue:
|
||||
_ = protocol.UnmarshalRequestMsgsQueuePacket(pac.Body)
|
||||
messages := dataStore.GetUnreadMessagesInfoQueue(UID)
|
||||
fmt.Printf("Number of unread messages by user %v is %v\n",UID,len(messages))
|
||||
for _, message := range messages {
|
||||
if !connection.Send(message) {
|
||||
break
|
||||
}
|
||||
}
|
||||
userCertPacket := dataStore.GetUserCertificate(UserCertPacket.UID)
|
||||
connection.Send(userCertPacket)
|
||||
case protocol.ReqAllMsgPkt:
|
||||
fmt.Println("ReqAllMsg")
|
||||
case protocol.ReqMsgPkt:
|
||||
fmt.Println("ReqMsg")
|
||||
reqMsg := protocol.UnmarshalRequestMsgPacket(pac.Body)
|
||||
message := dataStore.GetMessage(UID, reqMsg.Num)
|
||||
if active := connection.Send(message); !active {
|
||||
break F
|
||||
}
|
||||
case protocol.SubmitMsgPkt:
|
||||
fmt.Println("SubmitMsg")
|
||||
submitMsg := protocol.UnmarshalSubmitMessagePacket(pac.Body)
|
||||
if submitMsg.ToUID != UID && dataStore.userExists(submitMsg.ToUID) {
|
||||
dataStore.AddMessageToQueue(UID, submitMsg)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue