From f8a1cb6f68ea7c02b0a988ff0ae6d8974d715901 Mon Sep 17 00:00:00 2001 From: ycc Date: Thu, 18 Jan 2024 22:43:41 +0100 Subject: [PATCH] begin adding device to device communication --- client/identity.go | 26 ++++++++++++++++++-------- pb/messages.proto | 12 ++++++++---- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/client/identity.go b/client/identity.go index d70e15a..b2cbc05 100644 --- a/client/identity.go +++ b/client/identity.go @@ -21,6 +21,7 @@ type Identity struct { RootKp meowlib.KeyPair `json:"id_kp,omitempty"` Status string `json:"status,omitempty"` Peers PeerList `json:"peers,omitempty"` + Devices PeerList `json:"devices,omitempty"` HiddenPeers [][]byte `json:"hiddend_peers,omitempty"` Device meowlib.KeyPair `json:"device,omitempty"` KnownServers ServerList `json:"known_servers,omitempty"` @@ -207,9 +208,15 @@ func (id *Identity) generateRandomHiddenStuff() { } } +type BackgroundJob struct { + RootPublic string `json:"root_public,omitempty"` + Device meowlib.KeyPair `json:"device,omitempty"` + Jobs []*RequestsJob `json:"jobs,omitempty"` +} + type RequestsJob struct { - server Server `json:"server,omitempty"` - lookupKeys []meowlib.KeyPair `json:"lookup_keys,omitempty"` + Server Server `json:"server,omitempty"` + LookupKeys []meowlib.KeyPair `json:"lookup_keys,omitempty"` } func (id *Identity) GetRequestJobs() []*RequestsJob { @@ -218,19 +225,19 @@ func (id *Identity) GetRequestJobs() []*RequestsJob { // build a server map for _, server := range id.MessageServers.Servers { var rj RequestsJob - rj.server = server + rj.Server = server srvs[server.ServerData.GetUid()] = &rj } // add ids to the map for _, peer := range id.Peers { for _, server := range peer.MyPullServers { - srvs[server.GetUid()].lookupKeys = append(srvs[server.GetUid()].lookupKeys, peer.MyLookupKp) + srvs[server.GetUid()].LookupKeys = append(srvs[server.GetUid()].LookupKeys, peer.MyLookupKp) } } // add hidden peers for _, peer := range id.unlockedHiddenPeers { for _, server := range peer.MyPullServers { - srvs[server.GetUid()].lookupKeys = append(srvs[server.GetUid()].lookupKeys, peer.MyLookupKp) + srvs[server.GetUid()].LookupKeys = append(srvs[server.GetUid()].LookupKeys, peer.MyLookupKp) } } // todo add garbage @@ -244,9 +251,12 @@ func (id *Identity) GetRequestJobs() []*RequestsJob { return list } -func (id *Identity) SaveRequestJobs() error { - jobs := id.GetRequestJobs() - jsonjobs, err := json.Marshal(jobs) +func (id *Identity) SaveBackgroundJob() error { + var bj BackgroundJob + bj.Jobs = id.GetRequestJobs() + bj.RootPublic = id.RootKp.Public + bj.Device = id.Device + jsonjobs, err := json.Marshal(bj) if err != nil { return err } diff --git a/pb/messages.proto b/pb/messages.proto index 1aeafad..ac60935 100644 --- a/pb/messages.proto +++ b/pb/messages.proto @@ -65,6 +65,7 @@ message ToServerMessage { Invitation invitation = 9; // invitation for the 2 first steps of a "through server" invitation process + repeated PackedUserMessage device_messages = 10; // messages to another device belonging to the same user } message ConversationResponse { @@ -74,17 +75,20 @@ message ToServerMessage { // structure defining a from server receiver message decrypted from a "packedmessage" payload message FromServerMessage { string type = 1; // Type - string serverPublicKey = 2 ; // Pub key from the server + string server_public_key = 2 ; // Pub key from the server bytes payload = 3 ; // - string uuidAck = 4 ; // Ack for the last received ToServerMessage Uuid - string serverUuid = 5 ; // Provides the server uuid that replaced the client uuid + string uuid_ack = 4 ; // Ack for the last received ToServerMessage Uuid + string server_uuid = 5 ; // Provides the server uuid that replaced the client uuid repeated PackedUserMessage chat = 6; - repeated ServerCard knownServers = 7; + repeated ServerCard known_servers = 7; Invitation invitation = 8; // invitation answer, for the third steps of any invitation + repeated PackedUserMessage device_messages = 9; // messages from other devices belonging to the same user + + } message MatriochkaServer {