[PD1] restructure

This commit is contained in:
Afonso Franco 2024-04-16 12:23:00 +01:00
parent c0e19b5774
commit 8553e1674e
Signed by: afonso
SSH key fingerprint: SHA256:aiLbdlPwXKJS5wMnghdtod0SPy8imZjlVvCyUX9DJNk
17 changed files with 141 additions and 33 deletions

View file

@ -0,0 +1,7 @@
package client
import "fmt"
func Run() {
fmt.Println("Client is running...")
}

View file

@ -0,0 +1 @@
package client

View file

@ -0,0 +1,68 @@
package protocol
import (
"encoding/json"
"fmt"
"time"
)
type PacketType int
const (
ReqPK PacketType = iota
ReqAllMsg
ReqMsg
SendPK
UsrMsg
)
type PacketBody interface {}
type Packet struct {
Flag PacketType
Body PacketBody
}
// Client --> Server: Ask for a user's public key
type RequestPubKey struct {
FromUID string
KeyUID string
}
// Client --> Server: Ask for all the client's messages in the queue
type RequestAllMsg struct {
FromUID string
}
// Client --> Server: Ask for a specific message in the queue
type RequestMsg struct {
Num uint16
}
// Server --> Client: Send the client the requested public key
type SendPubKey struct {
Key []byte
}
// Bidirectional: Send messages between server and clients
type SendMessage struct {
ToUID string
Subject []byte
Body []byte
}
type Message struct {
FromUID string
ToUID string
Subject []byte
Body []byte
Timestamp time.Time
}
func (p Packet) Marshal() ([]byte, error) {
return json.Marshal(p)
}
func (p *Packet) Unmarshal(data []byte) error {
return json.Unmarshal(data, p)
}

View file

@ -0,0 +1 @@
package server

View file

@ -0,0 +1,30 @@
package server
import (
_ "PD1/internal/utils/cryptoUtils"
_ "PD1/internal/utils/networking"
"fmt"
"net"
)
func clientHandler(conn net.Conn) {
}
func Run(port int) {
ip, err := net.ResolveTCPAddr("tcp", ":8080")
if err != nil {
panic("Server could not bind to address")
}
listener, err := net.ListenTCP("tcp", ip)
if err != nil {
panic("Server could not listen on address")
}
for {
conn, err := listener.Accept()
if err!=nil{
panic("Server could not accept connection")
}
go clientHandler(conn)
}
}

View file

@ -0,0 +1,7 @@
package cryptoUtils
import "fmt"
func Print(){
fmt.Println("crypto package")
}

View file

@ -0,0 +1,5 @@
package networking
func sendPacket(){
}