Redefined protocol
This commit is contained in:
parent
af491e27a0
commit
4e9b0f24bb
|
@ -8,48 +8,51 @@ import (
|
|||
"git.qowevisa.me/Qowevisa/gotell/gmyerr"
|
||||
)
|
||||
|
||||
// VERSION field
|
||||
// VERSION is 1 byte
|
||||
const (
|
||||
V1 = 1 + iota
|
||||
)
|
||||
|
||||
// FROM field
|
||||
// ID is 1 byte
|
||||
const (
|
||||
FROM_SERVER = 1 + iota
|
||||
FROM_CLIENT
|
||||
FROM_MY_ID
|
||||
// Client Handles
|
||||
ID_SERVER_ASK_CLIENT_NICKNAME = 1
|
||||
// Server Handles
|
||||
ID_CLIENT_SEND_SERVER_NICKNAME = 2
|
||||
// Client Handles
|
||||
ID_SERVER_APPROVE_CLIENT_NICKNAME = 3
|
||||
ID_SERVER_DECLINE_CLIENT_NICKNAME = 4
|
||||
// Server Handles
|
||||
ID_CLIENT_SEND_SERVER_LINK = 5
|
||||
// Client Handles
|
||||
ID_SERVER_APPROVE_CLIENT_LINK = 6
|
||||
ID_SERVER_DECLINE_CLIENT_LINK = 7
|
||||
// Server Handles
|
||||
ID_CLIENT_ASK_SERVER_LINK = 8
|
||||
// Client Handles
|
||||
ID_SERVER_SEND_CLIENT_ANOTHER_ID = 9
|
||||
// Client Handles . Server redirects
|
||||
ID_CLIENT_ASK_CLIENT_HANDSHAKE = 10
|
||||
ID_CLIENT_APPROVE_CLIENT_HANDSHAKE = 11
|
||||
ID_CLIENT_DECLINE_CLIENT_HANDSHAKE = 12
|
||||
ID_CLIENT_SEND_CLIENT_ECDH_PUBKEY = 13
|
||||
ID_CLIENT_SEND_CLIENT_CBES_SPECS = 14
|
||||
ID_CLIENT_SEND_CLIENT_MKLG_FINGERPRINT = 15
|
||||
ID_CLIENT_DECLINE_CLIENT_MKLG_FINGERPRINT = 16
|
||||
ID_CLIENT_SEND_CLIENT_MESSAGE = 17
|
||||
)
|
||||
|
||||
// FROM_ID is 2 bytes
|
||||
|
||||
// TO_ID is 2 bytes
|
||||
|
||||
// ACTION field
|
||||
const (
|
||||
ACTION_ASK = 1 + iota
|
||||
ACTION_SEND
|
||||
)
|
||||
|
||||
// ABOUT field
|
||||
const (
|
||||
ABOUT_NICKNAME = 1 + iota
|
||||
ABOUT_ID
|
||||
ABOUT_LINK
|
||||
ABOUT_ECDH_PUB_KEY
|
||||
ABOUT_CBES_SPECS
|
||||
ABOUT_MKLG_FGPRINT
|
||||
ABOUT_MESSAGE
|
||||
)
|
||||
|
||||
// DATA_LEN is 2 bytes
|
||||
|
||||
type Message struct {
|
||||
Version uint8
|
||||
From uint8
|
||||
ID uint8
|
||||
FromID uint16
|
||||
ToID uint16
|
||||
Action uint8
|
||||
About uint8
|
||||
DataLen uint16
|
||||
Data []byte
|
||||
}
|
||||
|
@ -78,11 +81,9 @@ func Decode(serverBytes []byte) (*Message, error) {
|
|||
func ServerAskClientAboutNickname() ([]byte, error) {
|
||||
c := Message{
|
||||
Version: V1,
|
||||
From: FROM_SERVER,
|
||||
ID: ID_SERVER_ASK_CLIENT_NICKNAME,
|
||||
FromID: 0,
|
||||
ToID: 0,
|
||||
Action: ACTION_ASK,
|
||||
About: ABOUT_NICKNAME,
|
||||
DataLen: 0,
|
||||
Data: []byte{},
|
||||
}
|
||||
|
@ -92,11 +93,9 @@ func ServerAskClientAboutNickname() ([]byte, error) {
|
|||
func ClientSendServerNickname(nickname []byte) ([]byte, error) {
|
||||
c := Message{
|
||||
Version: V1,
|
||||
From: FROM_CLIENT,
|
||||
ID: ID_CLIENT_SEND_SERVER_NICKNAME,
|
||||
FromID: 0,
|
||||
ToID: 0,
|
||||
Action: ACTION_SEND,
|
||||
About: ABOUT_NICKNAME,
|
||||
DataLen: uint16(len(nickname)),
|
||||
Data: nickname,
|
||||
}
|
||||
|
@ -106,17 +105,27 @@ func ClientSendServerNickname(nickname []byte) ([]byte, error) {
|
|||
func ServerSendClientHisID(id []byte) ([]byte, error) {
|
||||
c := Message{
|
||||
Version: V1,
|
||||
From: FROM_SERVER,
|
||||
ID: ID_SERVER_APPROVE_CLIENT_NICKNAME,
|
||||
FromID: 0,
|
||||
ToID: 0,
|
||||
Action: ACTION_SEND,
|
||||
About: ABOUT_ID,
|
||||
DataLen: uint16(len(id)),
|
||||
Data: id,
|
||||
}
|
||||
return c.Bytes()
|
||||
}
|
||||
|
||||
func ServerSendClientDecline() ([]byte, error) {
|
||||
c := Message{
|
||||
Version: V1,
|
||||
ID: ID_SERVER_DECLINE_CLIENT_NICKNAME,
|
||||
FromID: 0,
|
||||
ToID: 0,
|
||||
DataLen: 0,
|
||||
Data: []byte{},
|
||||
}
|
||||
return c.Bytes()
|
||||
}
|
||||
|
||||
func (r *RegisteredUser) GenerateLink(count uint32) (Link, error) {
|
||||
var l Link
|
||||
buf := make([]byte, LINK_LEN_V1)
|
||||
|
@ -152,11 +161,9 @@ func (r *RegisteredUser) GetIDFromLink(l Link) ([]byte, error) {
|
|||
}
|
||||
c := Message{
|
||||
Version: V1,
|
||||
From: FROM_CLIENT,
|
||||
ID: ID_CLIENT_ASK_SERVER_LINK,
|
||||
FromID: r.ID,
|
||||
ToID: 0,
|
||||
Action: ACTION_ASK,
|
||||
About: ABOUT_LINK,
|
||||
DataLen: uint16(len(bb)),
|
||||
Data: bb,
|
||||
}
|
||||
|
@ -166,39 +173,57 @@ func (r *RegisteredUser) GetIDFromLink(l Link) ([]byte, error) {
|
|||
func ServerSendClientIDFromLink(toID uint16, toName []byte) ([]byte, error) {
|
||||
c := Message{
|
||||
Version: V1,
|
||||
From: FROM_SERVER,
|
||||
FromID: 0,
|
||||
ID: ID_SERVER_SEND_CLIENT_ANOTHER_ID,
|
||||
ToID: toID,
|
||||
Action: ACTION_SEND,
|
||||
About: ABOUT_LINK,
|
||||
DataLen: uint16(len(toName)),
|
||||
Data: toName,
|
||||
}
|
||||
return c.Bytes()
|
||||
}
|
||||
|
||||
func (r *RegisteredUser) ClientSendThroughServerECDHPubKey(to uint16, pubkey []byte) ([]byte, error) {
|
||||
c := Message{
|
||||
Version: V1,
|
||||
ID: ID_CLIENT_SEND_CLIENT_ECDH_PUBKEY,
|
||||
FromID: r.ID,
|
||||
ToID: to,
|
||||
DataLen: uint16(len(pubkey)),
|
||||
Data: pubkey,
|
||||
}
|
||||
return c.Bytes()
|
||||
}
|
||||
|
||||
func (r *RegisteredUser) ClientSendThroughServerCBESSpecs(to uint16, data []byte) ([]byte, error) {
|
||||
c := Message{
|
||||
Version: V1,
|
||||
From: FROM_CLIENT,
|
||||
ID: ID_CLIENT_SEND_CLIENT_CBES_SPECS,
|
||||
FromID: r.ID,
|
||||
ToID: to,
|
||||
Action: ACTION_SEND,
|
||||
About: ABOUT_CBES_SPECS,
|
||||
DataLen: uint16(len(data)),
|
||||
Data: data,
|
||||
}
|
||||
return c.Bytes()
|
||||
}
|
||||
|
||||
func (r *RegisteredUser) ClientSendThroughServerMKLGPrint(to uint16, mklg []byte) ([]byte, error) {
|
||||
c := Message{
|
||||
Version: V1,
|
||||
ID: ID_CLIENT_SEND_CLIENT_MKLG_FINGERPRINT,
|
||||
FromID: r.ID,
|
||||
ToID: to,
|
||||
DataLen: uint16(len(mklg)),
|
||||
Data: mklg,
|
||||
}
|
||||
return c.Bytes()
|
||||
}
|
||||
|
||||
func (r *RegisteredUser) SendMessageToID(to uint16, msg []byte) ([]byte, error) {
|
||||
c := Message{
|
||||
Version: V1,
|
||||
From: FROM_CLIENT,
|
||||
ID: ID_CLIENT_SEND_CLIENT_MESSAGE,
|
||||
FromID: r.ID,
|
||||
ToID: to,
|
||||
Action: ACTION_SEND,
|
||||
About: ABOUT_MESSAGE,
|
||||
DataLen: uint16(len(msg)),
|
||||
Data: msg,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user