[PD1] restructure
This commit is contained in:
parent
c0e19b5774
commit
8553e1674e
17 changed files with 141 additions and 33 deletions
|
@ -1 +0,0 @@
|
||||||
package client
|
|
9
Projs/PD1/cmd/client/client.go
Normal file
9
Projs/PD1/cmd/client/client.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"PD1/internal/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main(){
|
||||||
|
client.Run()
|
||||||
|
}
|
9
Projs/PD1/cmd/server/server.go
Normal file
9
Projs/PD1/cmd/server/server.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"PD1/internal/server"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main(){
|
||||||
|
server.Run()
|
||||||
|
}
|
|
@ -1,3 +1,8 @@
|
||||||
module PD1
|
module PD1
|
||||||
|
|
||||||
go 1.22.2
|
go 1.22.2
|
||||||
|
|
||||||
|
require (
|
||||||
|
golang.org/x/crypto v0.11.0 // indirect
|
||||||
|
software.sslmate.com/src/go-pkcs12 v0.4.0 // indirect
|
||||||
|
)
|
||||||
|
|
4
Projs/PD1/go.sum
Normal file
4
Projs/PD1/go.sum
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
||||||
|
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||||
|
software.sslmate.com/src/go-pkcs12 v0.4.0 h1:H2g08FrTvSFKUj+D309j1DPfk5APnIdAQAB8aEykJ5k=
|
||||||
|
software.sslmate.com/src/go-pkcs12 v0.4.0/go.mod h1:Qiz0EyvDRJjjxGyUQa2cCNZn/wMyzrRJ/qcDXOQazLI=
|
7
Projs/PD1/internal/client/client.go
Normal file
7
Projs/PD1/internal/client/client.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package client
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func Run() {
|
||||||
|
fmt.Println("Client is running...")
|
||||||
|
}
|
68
Projs/PD1/internal/protocol/protocol.go
Normal file
68
Projs/PD1/internal/protocol/protocol.go
Normal 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)
|
||||||
|
}
|
30
Projs/PD1/internal/server/server.go
Normal file
30
Projs/PD1/internal/server/server.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package crypto
|
package cryptoUtils
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
5
Projs/PD1/internal/utils/networking/networking.go
Normal file
5
Projs/PD1/internal/utils/networking/networking.go
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
package networking
|
||||||
|
|
||||||
|
func sendPacket(){
|
||||||
|
|
||||||
|
}
|
1
Projs/PD1/ltex.dictionary.en-US.txt
Normal file
1
Projs/PD1/ltex.dictionary.en-US.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Libs
|
|
@ -1,17 +0,0 @@
|
||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "PD1/utils/networking"
|
|
||||||
_ "PD1/utils/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
a = iota
|
|
||||||
b
|
|
||||||
c
|
|
||||||
d
|
|
||||||
e
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
}
|
|
|
@ -11,8 +11,8 @@ cmd="go build"
|
||||||
|
|
||||||
[targets.server]
|
[targets.server]
|
||||||
deps=["check"]
|
deps=["check"]
|
||||||
cmd="go run ./src/server/server.go"
|
cmd="go run ./cmd/server/server.go"
|
||||||
|
|
||||||
[targets.client]
|
[targets.client]
|
||||||
deps=["check"]
|
deps=["check"]
|
||||||
cmd="go run ./src/server/client.go"
|
cmd="go run ./cmd/client/client.go"
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package networking
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func Print(){
|
|
||||||
fmt.Println("networking package")
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
package protocol
|
|
||||||
|
|
||||||
type message struct{
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue