InternalServer to Server refactor
All checks were successful
continuous-integration/drone Build is passing
All checks were successful
continuous-integration/drone Build is passing
This commit is contained in:
parent
04a390d558
commit
c203431ede
@ -22,14 +22,14 @@ type Identity struct {
|
|||||||
Peers PeerList `json:"peers,omitempty"`
|
Peers PeerList `json:"peers,omitempty"`
|
||||||
HiddenPeers [][]byte `json:"hiddend_peers,omitempty"`
|
HiddenPeers [][]byte `json:"hiddend_peers,omitempty"`
|
||||||
Device meowlib.KeyPair `json:"device,omitempty"`
|
Device meowlib.KeyPair `json:"device,omitempty"`
|
||||||
KnownServers InternalServerList `json:"known_servers,omitempty"`
|
KnownServers ServerList `json:"known_servers,omitempty"`
|
||||||
MessageServers InternalServerList `json:"message_servers,omitempty"`
|
MessageServers ServerList `json:"message_servers,omitempty"`
|
||||||
ArchiveServers InternalServerList `json:"archive_servers,omitempty"`
|
ArchiveServers ServerList `json:"archive_servers,omitempty"`
|
||||||
OwnedServers InternalServerList `json:"owned_servers,omitempty"`
|
OwnedServers ServerList `json:"owned_servers,omitempty"`
|
||||||
DefaultDbPassword string `json:"default_db_password,omitempty"`
|
DefaultDbPassword string `json:"default_db_password,omitempty"`
|
||||||
DbPasswordStore bool `json:"db_password_store,omitempty"`
|
DbPasswordStore bool `json:"db_password_store,omitempty"`
|
||||||
OwnedDevices PeerList `json:"owned_devices,omitempty"`
|
OwnedDevices PeerList `json:"owned_devices,omitempty"`
|
||||||
StaticMtkServerPaths []InternalServerList `json:"static_mtk_server_paths,omitempty"`
|
StaticMtkServerPaths []ServerList `json:"static_mtk_server_paths,omitempty"`
|
||||||
DynamicMtkServeRules []string `json:"dynamic_mtk_serve_rules,omitempty"`
|
DynamicMtkServeRules []string `json:"dynamic_mtk_serve_rules,omitempty"`
|
||||||
InvitationTimeout int `json:"invitation_timeout,omitempty"`
|
InvitationTimeout int `json:"invitation_timeout,omitempty"`
|
||||||
unlockedHiddenPeers PeerList
|
unlockedHiddenPeers PeerList
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProcessForOutput(usermessage *meowlib.UserMessage, peer *Peer, servers *InternalServerList, trackingLookupKey string) ([]byte, error) {
|
func ProcessForOutput(usermessage *meowlib.UserMessage, peer *Peer, servers *ServerList, trackingLookupKey string) ([]byte, error) {
|
||||||
lastIdx := len(servers.Servers) - 1
|
lastIdx := len(servers.Servers) - 1
|
||||||
// LAST SERVER : Message delivery as usual
|
// LAST SERVER : Message delivery as usual
|
||||||
srv := &servers.Servers[lastIdx]
|
srv := &servers.Servers[lastIdx]
|
||||||
|
@ -7,7 +7,7 @@ type InternalUserMessage struct {
|
|||||||
dbid int64
|
dbid int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProcessOutboundTextMessage(peer *Peer, text string, srv *InternalServer) ([]byte, error) {
|
func ProcessOutboundTextMessage(peer *Peer, text string, srv *Server) ([]byte, error) {
|
||||||
// Creating User message
|
// Creating User message
|
||||||
usermessage, err := peer.BuildSimpleUserMessage([]byte(text))
|
usermessage, err := peer.BuildSimpleUserMessage([]byte(text))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -9,13 +9,13 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InternalServer manages server related operations
|
// Server manages server related operations
|
||||||
// - Sending messages for server usage
|
// - Sending messages for server usage
|
||||||
// - Two first steps of an invitation
|
// - Two first steps of an invitation
|
||||||
// - User message sending
|
// - User message sending
|
||||||
// - Messages lookup requests
|
// - Messages lookup requests
|
||||||
// - Utility functions for packing/unpacking, encrypting/decrypting messages for server communication
|
// - Utility functions for packing/unpacking, encrypting/decrypting messages for server communication
|
||||||
type InternalServer struct {
|
type Server struct {
|
||||||
ServerData meowlib.ServerCard `json:"server_data,omitempty"`
|
ServerData meowlib.ServerCard `json:"server_data,omitempty"`
|
||||||
Presence bool `json:"presence,omitempty"`
|
Presence bool `json:"presence,omitempty"`
|
||||||
LastCheck time.Time `json:"last_check,omitempty"`
|
LastCheck time.Time `json:"last_check,omitempty"`
|
||||||
@ -27,32 +27,32 @@ type InternalServer struct {
|
|||||||
AllowedDelay int `json:"allowed_delay,omitempty"`
|
AllowedDelay int `json:"allowed_delay,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InternalServerList struct {
|
type ServerList struct {
|
||||||
Name string
|
Name string
|
||||||
Servers []InternalServer
|
Servers []Server
|
||||||
}
|
}
|
||||||
|
|
||||||
func InternalServerFromUrl(url string) *InternalServer {
|
func ServerFromUrl(url string) *Server {
|
||||||
var is InternalServer
|
var is Server
|
||||||
is.ServerData.Url = url
|
is.ServerData.Url = url
|
||||||
return &is
|
return &is
|
||||||
}
|
}
|
||||||
|
|
||||||
func InternalServerFromServer(server *meowlib.ServerCard) *InternalServer {
|
func CreateServerFromServerCard(server *meowlib.ServerCard) *Server {
|
||||||
var is InternalServer
|
var is Server
|
||||||
is.ServerData = *server
|
is.ServerData = *server
|
||||||
is.Me = meowlib.NewKeyPair()
|
is.Me = meowlib.NewKeyPair()
|
||||||
return &is
|
return &is
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sl *InternalServerList) AddUrls(urls []string) {
|
func (sl *ServerList) AddUrls(urls []string) {
|
||||||
for _, url := range urls {
|
for _, url := range urls {
|
||||||
sl.Servers = append(sl.Servers, *InternalServerFromUrl(url))
|
sl.Servers = append(sl.Servers, *ServerFromUrl(url))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsymEncryptMessage prepares a message to send to a specific internal server
|
// AsymEncryptMessage prepares a message to send to a specific internal server
|
||||||
func (ints *InternalServer) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessage, error) {
|
func (ints *Server) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessage, error) {
|
||||||
var enc *meowlib.EncryptedMessage
|
var enc *meowlib.EncryptedMessage
|
||||||
enc, err := meowlib.AsymEncryptAndSign(ints.ServerData.PublicKey, ints.Me.Private, Message)
|
enc, err := meowlib.AsymEncryptAndSign(ints.ServerData.PublicKey, ints.Me.Private, Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -63,7 +63,7 @@ func (ints *InternalServer) AsymEncryptMessage(Message []byte) (*meowlib.Encrypt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AsymDecryptMessage reads a message from a specific internal server
|
// AsymDecryptMessage reads a message from a specific internal server
|
||||||
func (ints *InternalServer) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMessage []byte, err error) {
|
func (ints *Server) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMessage []byte, err error) {
|
||||||
DecryptedMessage, err = meowlib.AsymDecryptAndCheck(ints.Me.Private, ints.ServerData.PublicKey, Message, Signature)
|
DecryptedMessage, err = meowlib.AsymDecryptAndCheck(ints.Me.Private, ints.ServerData.PublicKey, Message, Signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
@ -73,7 +73,7 @@ func (ints *InternalServer) AsymDecryptMessage(Message []byte, Signature []byte)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BuildToServerMessageFromUserMessage creates a basic message to server from a single packed user message and returns a meowlib.ToServerMessage
|
// BuildToServerMessageFromUserMessage creates a basic message to server from a single packed user message and returns a meowlib.ToServerMessage
|
||||||
func (ints *InternalServer) BuildToServerMessageFromUserMessage(usermsg *meowlib.PackedUserMessage) *meowlib.ToServerMessage {
|
func (ints *Server) BuildToServerMessageFromUserMessage(usermsg *meowlib.PackedUserMessage) *meowlib.ToServerMessage {
|
||||||
var msg meowlib.ToServerMessage
|
var msg meowlib.ToServerMessage
|
||||||
msg.Uuid = uuid.New().String()
|
msg.Uuid = uuid.New().String()
|
||||||
msg.Type = "1"
|
msg.Type = "1"
|
||||||
@ -83,7 +83,7 @@ func (ints *InternalServer) BuildToServerMessageFromUserMessage(usermsg *meowlib
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BuildMessageSendingMessage creates a basic message to server from a single packed user message and returns it as protobuf serialized byte array
|
// BuildMessageSendingMessage creates a basic message to server from a single packed user message and returns it as protobuf serialized byte array
|
||||||
func (ints *InternalServer) BuildMessageSendingMessage(usermsg *meowlib.PackedUserMessage) ([]byte, error) {
|
func (ints *Server) BuildMessageSendingMessage(usermsg *meowlib.PackedUserMessage) ([]byte, error) {
|
||||||
msg := ints.BuildToServerMessageFromUserMessage(usermsg)
|
msg := ints.BuildToServerMessageFromUserMessage(usermsg)
|
||||||
out, err := proto.Marshal(msg)
|
out, err := proto.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -93,7 +93,7 @@ func (ints *InternalServer) BuildMessageSendingMessage(usermsg *meowlib.PackedUs
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BuildMessageRequestMessage creates a message lookup message to server and returns it as protobuf serialized byte array
|
// BuildMessageRequestMessage creates a message lookup message to server and returns it as protobuf serialized byte array
|
||||||
func (ints *InternalServer) BuildMessageRequestMessage(lookupKeys []string) ([]byte, error) {
|
func (ints *Server) BuildMessageRequestMessage(lookupKeys []string) ([]byte, error) {
|
||||||
var msg meowlib.ToServerMessage
|
var msg meowlib.ToServerMessage
|
||||||
msg.Uuid = uuid.New().String()
|
msg.Uuid = uuid.New().String()
|
||||||
msg.Type = "1"
|
msg.Type = "1"
|
||||||
@ -106,7 +106,7 @@ func (ints *InternalServer) BuildMessageRequestMessage(lookupKeys []string) ([]b
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BuildToServerMessageInvitation creates an invitation message to server and returns it as a meowlib.ToServerMessage
|
// BuildToServerMessageInvitation creates an invitation message to server and returns it as a meowlib.ToServerMessage
|
||||||
func (ints *InternalServer) BuildToServerMessageInvitationCreation(invitation *meowlib.ContactCard, password string, timeout int, urllen int) (*meowlib.ToServerMessage, error) {
|
func (ints *Server) BuildToServerMessageInvitationCreation(invitation *meowlib.ContactCard, password string, timeout int, urllen int) (*meowlib.ToServerMessage, error) {
|
||||||
var msg meowlib.ToServerMessage
|
var msg meowlib.ToServerMessage
|
||||||
var inv meowlib.Invitation
|
var inv meowlib.Invitation
|
||||||
payload, err := invitation.Compress()
|
payload, err := invitation.Compress()
|
||||||
@ -125,7 +125,7 @@ func (ints *InternalServer) BuildToServerMessageInvitationCreation(invitation *m
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BuildToServerMessageInvitationRequest requests invitation with provided id from server and returns it as a meowlib.ToServerMessage
|
// BuildToServerMessageInvitationRequest requests invitation with provided id from server and returns it as a meowlib.ToServerMessage
|
||||||
func (ints *InternalServer) BuildToServerMessageInvitationRequest(url string, password string) (*meowlib.ToServerMessage, error) {
|
func (ints *Server) BuildToServerMessageInvitationRequest(url string, password string) (*meowlib.ToServerMessage, error) {
|
||||||
var msg meowlib.ToServerMessage
|
var msg meowlib.ToServerMessage
|
||||||
var inv meowlib.Invitation
|
var inv meowlib.Invitation
|
||||||
msg.Type = "1"
|
msg.Type = "1"
|
||||||
@ -137,7 +137,7 @@ func (ints *InternalServer) BuildToServerMessageInvitationRequest(url string, pa
|
|||||||
return &msg, nil
|
return &msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ints *InternalServer) PackServerMessage(payload []byte, signature []byte) (protoPackedMessage []byte, err error) {
|
func (ints *Server) PackServerMessage(payload []byte, signature []byte) (protoPackedMessage []byte, err error) {
|
||||||
var msg meowlib.PackedServerMessage
|
var msg meowlib.PackedServerMessage
|
||||||
msg.From = ints.Me.Public
|
msg.From = ints.Me.Public
|
||||||
msg.Payload = payload
|
msg.Payload = payload
|
||||||
@ -149,7 +149,7 @@ func (ints *InternalServer) PackServerMessage(payload []byte, signature []byte)
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ints *InternalServer) UnPackServerMessage(protoPackedMessage []byte) (payload []byte, signature []byte, err error) {
|
func (ints *Server) UnPackServerMessage(protoPackedMessage []byte) (payload []byte, signature []byte, err error) {
|
||||||
msg := &meowlib.PackedServerMessage{}
|
msg := &meowlib.PackedServerMessage{}
|
||||||
if err := proto.Unmarshal(protoPackedMessage, msg); err != nil {
|
if err := proto.Unmarshal(protoPackedMessage, msg); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -157,7 +157,7 @@ func (ints *InternalServer) UnPackServerMessage(protoPackedMessage []byte) (payl
|
|||||||
return msg.Payload, msg.Signature, nil
|
return msg.Payload, msg.Signature, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *InternalServer) ProcessOutboundMessage(toServerMessage *meowlib.ToServerMessage) ([]byte, error) {
|
func (srv *Server) ProcessOutboundMessage(toServerMessage *meowlib.ToServerMessage) ([]byte, error) {
|
||||||
byteToServerMessage, err := proto.Marshal(toServerMessage)
|
byteToServerMessage, err := proto.Marshal(toServerMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -175,7 +175,7 @@ func (srv *InternalServer) ProcessOutboundMessage(toServerMessage *meowlib.ToSer
|
|||||||
return protoPackedServerMsg, nil
|
return protoPackedServerMsg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *InternalServer) ProcessInboundServerResponse(msg []byte) (*meowlib.FromServerMessage, error) {
|
func (srv *Server) ProcessInboundServerResponse(msg []byte) (*meowlib.FromServerMessage, error) {
|
||||||
fsmsg := &meowlib.FromServerMessage{}
|
fsmsg := &meowlib.FromServerMessage{}
|
||||||
payload, signature, err := srv.UnPackServerMessage(msg)
|
payload, signature, err := srv.UnPackServerMessage(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -100,7 +100,7 @@ func TestEndToEnd(t *testing.T) {
|
|||||||
packedMsg := MyFirstFriend.PackUserMessage(enc.Data, enc.Signature)
|
packedMsg := MyFirstFriend.PackUserMessage(enc.Data, enc.Signature)
|
||||||
|
|
||||||
srv := MyFirstFriend.Contact.PullServers[0]
|
srv := MyFirstFriend.Contact.PullServers[0]
|
||||||
intS1 := client.InternalServerFromServer(srv)
|
intS1 := client.CreateServerFromServerCard(srv)
|
||||||
|
|
||||||
// Creating Server message for transporting the user message
|
// Creating Server message for transporting the user message
|
||||||
toServerMessage, err := intS1.BuildMessageSendingMessage(packedMsg)
|
toServerMessage, err := intS1.BuildMessageSendingMessage(packedMsg)
|
||||||
|
Loading…
Reference in New Issue
Block a user