[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,60 +1,122 @@
|
|||
package protocol
|
||||
|
||||
import (
|
||||
"time"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PacketType int
|
||||
|
||||
const (
|
||||
ReqPK PacketType = iota
|
||||
ReqAllMsg
|
||||
ReqMsg
|
||||
ReqPK PacketType = iota
|
||||
ReqAllMsg
|
||||
ReqMsg
|
||||
SubmitMsg
|
||||
SendPK
|
||||
SendPK
|
||||
Msg
|
||||
)
|
||||
|
||||
type PacketBody interface {}
|
||||
type PacketBody interface{}
|
||||
|
||||
type Packet struct {
|
||||
Flag PacketType
|
||||
Body PacketBody
|
||||
Flag PacketType
|
||||
Body PacketBody
|
||||
}
|
||||
|
||||
// Client --> Server: Ask for a user's public key
|
||||
type RequestPubKey struct {
|
||||
FromUID string
|
||||
KeyUID string
|
||||
FromUID string
|
||||
KeyUID string
|
||||
}
|
||||
|
||||
func NewRequestPubKey(fromUID, keyUID string) Packet {
|
||||
return Packet{
|
||||
Flag: ReqPK,
|
||||
Body: RequestPubKey{
|
||||
FromUID: fromUID,
|
||||
KeyUID: keyUID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Client --> Server: Ask for all the client's messages in the queue
|
||||
type RequestAllMsg struct {
|
||||
FromUID string
|
||||
FromUID string
|
||||
}
|
||||
|
||||
func NewRequestAllMsg(fromUID string) Packet {
|
||||
return Packet{
|
||||
Flag: ReqAllMsg,
|
||||
Body: RequestAllMsg{
|
||||
FromUID: fromUID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Client --> Server: Ask for a specific message in the queue
|
||||
type RequestMsg struct {
|
||||
Num uint16
|
||||
Num uint16
|
||||
}
|
||||
|
||||
// Client --> Server: Send message from client to server
|
||||
func NewRequestMsg(num uint16) Packet {
|
||||
return Packet{
|
||||
Flag: ReqMsg,
|
||||
Body: RequestMsg{
|
||||
Num: num,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Client --> Server: Send message from client to server
|
||||
type SubmitMessage struct {
|
||||
ToUID string
|
||||
Subject []byte
|
||||
Body []byte
|
||||
ToUID string
|
||||
Subject []byte
|
||||
Body []byte
|
||||
}
|
||||
|
||||
func NewSubmitMessage(toUID string, subject, body []byte) Packet {
|
||||
return Packet{
|
||||
Flag: SubmitMsg,
|
||||
Body: SubmitMessage{
|
||||
ToUID: toUID,
|
||||
Subject: subject,
|
||||
Body: body,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Server --> Client: Send the client the requested public key
|
||||
type SendPubKey struct {
|
||||
Key []byte
|
||||
Key []byte
|
||||
}
|
||||
|
||||
func NewSendPubKey(key []byte) Packet {
|
||||
return Packet{
|
||||
Flag: SendPK,
|
||||
Body: SendPubKey{
|
||||
Key: key,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Server --> Client: Send the client a message
|
||||
type Message struct {
|
||||
FromUID string
|
||||
ToUID string
|
||||
Subject []byte
|
||||
Body []byte
|
||||
FromUID string
|
||||
ToUID string
|
||||
Subject []byte
|
||||
Body []byte
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
func NewMessage(fromUID, toUID string, subject, body []byte, timestamp time.Time) Packet {
|
||||
return Packet{
|
||||
Flag: Msg,
|
||||
Body: Message{
|
||||
FromUID: fromUID,
|
||||
ToUID: toUID,
|
||||
Subject: subject,
|
||||
Body: body,
|
||||
Timestamp: timestamp,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue