[PD1] Structured client.
Still need to create crypto object and use it to encrypt messages Need to create TLS still
This commit is contained in:
parent
278b8e1a73
commit
cdaae8fb7e
9 changed files with 252 additions and 110 deletions
|
@ -1,7 +1,60 @@
|
|||
package client
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"PD1/internal/protocol"
|
||||
"PD1/internal/utils/networking"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func Run() {
|
||||
fmt.Println("Client is running...")
|
||||
var userFile string
|
||||
flag.StringVar(&userFile, "user", "userdata.p12", "Specify user data file")
|
||||
flag.Parse()
|
||||
|
||||
if flag.NArg() == 0 {
|
||||
panic("No command provided. Use 'help' for instructions.")
|
||||
}
|
||||
|
||||
command := flag.Arg(0)
|
||||
switch command {
|
||||
case "send":
|
||||
if flag.NArg() < 3 {
|
||||
panic("Insufficient arguments for 'send' command. Usage: send <UID> <SUBJECT>")
|
||||
}
|
||||
uid := flag.Arg(1)
|
||||
subject := flag.Arg(2)
|
||||
// Read message content from stdin
|
||||
messageContent := readMessageContent()
|
||||
cl := networking.NewClient[protocol.Packet]()
|
||||
defer cl.Connection.Conn.Close()
|
||||
|
||||
// TODO: cipherSubject := CHAMAR CRYPTO
|
||||
// TODO: cipherBody := CHAMAR CRYPTO
|
||||
submitMessage(cl,uid,cipherSubject,cipherBody)
|
||||
|
||||
case "askqueue":
|
||||
cl = networking.NewClient[protocol.Packet]()
|
||||
defer cl.Connection.Conn.Close()
|
||||
|
||||
case "getmsg":
|
||||
if flag.NArg() < 2 {
|
||||
panic("Insufficient arguments for 'getmsg' command. Usage: getmsg <NUM>")
|
||||
}
|
||||
num := flag.Arg(1)
|
||||
cl = networking.NewClient[protocol.Packet]()
|
||||
defer cl.Connection.Conn.Close()
|
||||
|
||||
case "help":
|
||||
showHelp()
|
||||
|
||||
default:
|
||||
fmt.Println("Invalid command. Use 'help' for instructions.")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func submitMessage(cl networking.Client[protocol.Packet],uid string,subject []byte,body []byte) {
|
||||
pack := protocol.NewSubmitMessage(uid, subject, body)
|
||||
cl.Connection.Send(pack)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue