diff --git a/client/identity.go b/client/identity.go index ac8fa09..32221b8 100644 --- a/client/identity.go +++ b/client/identity.go @@ -15,23 +15,23 @@ import ( const maxHiddenCount = 30 type Identity struct { - Nickname string `json:"nickname,omitempty"` - DefaultAvatarUuid string `json:"default_avatar_uuid,omitempty"` - RootKp meowlib.KeyPair `json:"id_kp,omitempty"` - Status string `json:"status,omitempty"` - Peers PeerList `json:"peers,omitempty"` - HiddenPeers [][]byte `json:"hiddend_peers,omitempty"` - Device meowlib.KeyPair `json:"device,omitempty"` - KnownServers InternalServerList `json:"known_servers,omitempty"` - MessageServers InternalServerList `json:"message_servers,omitempty"` - ArchiveServers InternalServerList `json:"archive_servers,omitempty"` - OwnedServers InternalServerList `json:"owned_servers,omitempty"` - DefaultDbPassword string `json:"default_db_password,omitempty"` - DbPasswordStore bool `json:"db_password_store,omitempty"` - OwnedDevices PeerList `json:"owned_devices,omitempty"` - StaticMtkServerPaths []InternalServerList `json:"static_mtk_server_paths,omitempty"` - DynamicMtkServeRules []string `json:"dynamic_mtk_serve_rules,omitempty"` - InvitationTimeout int `json:"invitation_timeout,omitempty"` + Nickname string `json:"nickname,omitempty"` + DefaultAvatarUuid string `json:"default_avatar_uuid,omitempty"` + RootKp meowlib.KeyPair `json:"id_kp,omitempty"` + Status string `json:"status,omitempty"` + Peers PeerList `json:"peers,omitempty"` + HiddenPeers [][]byte `json:"hiddend_peers,omitempty"` + Device meowlib.KeyPair `json:"device,omitempty"` + KnownServers ServerList `json:"known_servers,omitempty"` + MessageServers ServerList `json:"message_servers,omitempty"` + ArchiveServers ServerList `json:"archive_servers,omitempty"` + OwnedServers ServerList `json:"owned_servers,omitempty"` + DefaultDbPassword string `json:"default_db_password,omitempty"` + DbPasswordStore bool `json:"db_password_store,omitempty"` + OwnedDevices PeerList `json:"owned_devices,omitempty"` + StaticMtkServerPaths []ServerList `json:"static_mtk_server_paths,omitempty"` + DynamicMtkServeRules []string `json:"dynamic_mtk_serve_rules,omitempty"` + InvitationTimeout int `json:"invitation_timeout,omitempty"` unlockedHiddenPeers PeerList } diff --git a/client/matriochka.go b/client/matriochka.go index d8b5727..ecb503a 100644 --- a/client/matriochka.go +++ b/client/matriochka.go @@ -5,7 +5,7 @@ import ( "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 // LAST SERVER : Message delivery as usual srv := &servers.Servers[lastIdx] diff --git a/client/message.go b/client/message.go index 93fef28..2853eca 100644 --- a/client/message.go +++ b/client/message.go @@ -7,7 +7,7 @@ type InternalUserMessage struct { 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 usermessage, err := peer.BuildSimpleUserMessage([]byte(text)) if err != nil { diff --git a/client/server.go b/client/server.go index c7e000b..7797997 100644 --- a/client/server.go +++ b/client/server.go @@ -9,13 +9,13 @@ import ( "google.golang.org/protobuf/proto" ) -// InternalServer manages server related operations +// Server manages server related operations // - Sending messages for server usage // - Two first steps of an invitation // - User message sending // - Messages lookup requests // - Utility functions for packing/unpacking, encrypting/decrypting messages for server communication -type InternalServer struct { +type Server struct { ServerData meowlib.ServerCard `json:"server_data,omitempty"` Presence bool `json:"presence,omitempty"` LastCheck time.Time `json:"last_check,omitempty"` @@ -27,32 +27,32 @@ type InternalServer struct { AllowedDelay int `json:"allowed_delay,omitempty"` } -type InternalServerList struct { +type ServerList struct { Name string - Servers []InternalServer + Servers []Server } -func InternalServerFromUrl(url string) *InternalServer { - var is InternalServer +func ServerFromUrl(url string) *Server { + var is Server is.ServerData.Url = url return &is } -func InternalServerFromServer(server *meowlib.ServerCard) *InternalServer { - var is InternalServer +func CreateServerFromServerCard(server *meowlib.ServerCard) *Server { + var is Server is.ServerData = *server is.Me = meowlib.NewKeyPair() return &is } -func (sl *InternalServerList) AddUrls(urls []string) { +func (sl *ServerList) AddUrls(urls []string) { 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 -func (ints *InternalServer) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessage, error) { +func (ints *Server) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessage, error) { var enc *meowlib.EncryptedMessage enc, err := meowlib.AsymEncryptAndSign(ints.ServerData.PublicKey, ints.Me.Private, Message) if err != nil { @@ -63,7 +63,7 @@ func (ints *InternalServer) AsymEncryptMessage(Message []byte) (*meowlib.Encrypt } // 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) if err != nil { 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 -func (ints *InternalServer) BuildToServerMessageFromUserMessage(usermsg *meowlib.PackedUserMessage) *meowlib.ToServerMessage { +func (ints *Server) BuildToServerMessageFromUserMessage(usermsg *meowlib.PackedUserMessage) *meowlib.ToServerMessage { var msg meowlib.ToServerMessage msg.Uuid = uuid.New().String() 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 -func (ints *InternalServer) BuildMessageSendingMessage(usermsg *meowlib.PackedUserMessage) ([]byte, error) { +func (ints *Server) BuildMessageSendingMessage(usermsg *meowlib.PackedUserMessage) ([]byte, error) { msg := ints.BuildToServerMessageFromUserMessage(usermsg) out, err := proto.Marshal(msg) 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 -func (ints *InternalServer) BuildMessageRequestMessage(lookupKeys []string) ([]byte, error) { +func (ints *Server) BuildMessageRequestMessage(lookupKeys []string) ([]byte, error) { var msg meowlib.ToServerMessage msg.Uuid = uuid.New().String() 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 -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 inv meowlib.Invitation 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 -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 inv meowlib.Invitation msg.Type = "1" @@ -137,7 +137,7 @@ func (ints *InternalServer) BuildToServerMessageInvitationRequest(url string, pa 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 msg.From = ints.Me.Public msg.Payload = payload @@ -149,7 +149,7 @@ func (ints *InternalServer) PackServerMessage(payload []byte, signature []byte) 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{} if err := proto.Unmarshal(protoPackedMessage, msg); err != nil { return nil, nil, err @@ -157,7 +157,7 @@ func (ints *InternalServer) UnPackServerMessage(protoPackedMessage []byte) (payl 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) if err != nil { return nil, err @@ -175,7 +175,7 @@ func (srv *InternalServer) ProcessOutboundMessage(toServerMessage *meowlib.ToSer return protoPackedServerMsg, nil } -func (srv *InternalServer) ProcessInboundServerResponse(msg []byte) (*meowlib.FromServerMessage, error) { +func (srv *Server) ProcessInboundServerResponse(msg []byte) (*meowlib.FromServerMessage, error) { fsmsg := &meowlib.FromServerMessage{} payload, signature, err := srv.UnPackServerMessage(msg) if err != nil { diff --git a/endtoend_test.go b/endtoend_test.go index a67f5cb..78ab295 100644 --- a/endtoend_test.go +++ b/endtoend_test.go @@ -100,7 +100,7 @@ func TestEndToEnd(t *testing.T) { packedMsg := MyFirstFriend.PackUserMessage(enc.Data, enc.Signature) srv := MyFirstFriend.Contact.PullServers[0] - intS1 := client.InternalServerFromServer(srv) + intS1 := client.CreateServerFromServerCard(srv) // Creating Server message for transporting the user message toServerMessage, err := intS1.BuildMessageSendingMessage(packedMsg)