From b02a19c52ebb3dca43f73de1e002d4cf67804a2c Mon Sep 17 00:00:00 2001 From: Arvid Lunnemark Date: Wed, 13 Jul 2022 22:38:39 -0400 Subject: [PATCH] Broadcasting messages (#26) * broadcasting schema * schema updates. next to fix tests * now, we have all the tests translated. \n Now, to write the C++ protobuf translation thing. * fix a lot of things (but more things left to do) * tests pass! * trunk fmt * remove comment Co-authored-by: Sualeh Asif --- .bazelrc | 10 ++++----- asphr/asphr.hpp | 3 ++- schema/daemon.proto | 50 ++++++++++++++++++++++++++------------------ schema/message.proto | 19 +++++++++++------ 4 files changed, 50 insertions(+), 32 deletions(-) diff --git a/.bazelrc b/.bazelrc index 8fe86d1..a92b96f 100644 --- a/.bazelrc +++ b/.bazelrc @@ -16,11 +16,11 @@ build --incompatible_enable_cc_toolchain_resolution try-import %workspace%/.user.bazelrc # setting up remote caching -#build --bes_results_url=https://app.buildbuddy.io/invocation/ -#build --bes_backend=grpcs://remote.buildbuddy.io -#build --remote_cache=grpcs://remote.buildbuddy.io -#build --remote_upload_local_results -#build --remote_timeout=3600 +build --bes_results_url=https://app.buildbuddy.io/invocation/ +build --bes_backend=grpcs://remote.buildbuddy.io +build --remote_cache=grpcs://remote.buildbuddy.io +# build --remote_upload_local_results +build --remote_timeout=3600 # build --experimental_remote_cache_compression # build --experimental_remote_cache_async # build --remote_download_toplevel diff --git a/asphr/asphr.hpp b/asphr/asphr.hpp index 082d2bc..913b537 100644 --- a/asphr/asphr.hpp +++ b/asphr/asphr.hpp @@ -69,11 +69,12 @@ using absl::Time; using std::unordered_map; using std::unordered_set; -} // namespace asphr +} // namespace asphr #define CEIL_DIV(a, b) (((a) + (b)-1) / (b)) // MESSAGE_SIZE is the size of the message in bytes +// this refers to the size of a CHUNK, not a complete message constexpr size_t MESSAGE_SIZE = 1024; constexpr size_t MESSAGE_SIZE_BITS = MESSAGE_SIZE * 8; diff --git a/schema/daemon.proto b/schema/daemon.proto index 1d9bf99..f90cf48 100644 --- a/schema/daemon.proto +++ b/schema/daemon.proto @@ -89,8 +89,8 @@ message GetMyPublicIDRequest {} message GetMyPublicIDResponse { string public_id = 1; - string story = - 2; // en encoding of the public identifier in a nice story format + string story = 2; + // en encoding of the public identifier in a nice story format } message AddSyncFriendRequest { @@ -168,38 +168,48 @@ message RemoveFriendRequest { string unique_name = 1; } message RemoveFriendResponse {} message SendMessageRequest { - string unique_name = 1; + repeated string unique_name = 1; string message = 2; } message SendMessageResponse {} -message BaseMessage { - // this ID is NOT the same as the ID in message.proto - // in particular, this ID is guaranteed to be unique among ALL messages (on a - // given device), whereas the ID in message.proto is only unique for each - // pair. the format of this ID is something like - // (to|from):sender:sequence_number - int32 id = 1; - string message = 2; - string unique_name = 3; - string display_name = 4; +message IncomingMaybeFriend { + string public_id = 1; + + optional string unique_name = 2; + optional string display_name = 3; } message IncomingMessage { - BaseMessage m = 1; - google.protobuf.Timestamp delivered_at = 2; - bool seen = 3; - bool delivered = 4; + int32 uid = 1; + string message = 2; + + string from_unique_name = 3; + string from_display_name = 4; + + repeated IncomingMaybeFriend other_recipients = 5; + + google.protobuf.Timestamp delivered_at = 6; + bool seen = 7; + bool delivered = 8; } -message OutgoingMessage { - BaseMessage m = 1; - google.protobuf.Timestamp sent_at = 2; +message OutgoingFriend { + string unique_name = 1; + string display_name = 2; bool delivered = 3; google.protobuf.Timestamp delivered_at = 4; } +message OutgoingMessage { + int32 uid = 1; + string message = 2; + + repeated OutgoingFriend to_friends = 3; + google.protobuf.Timestamp sent_at = 4; +} + message GetMessagesRequest { enum Filter { ALL = 0; diff --git a/schema/message.proto b/schema/message.proto index b79abd3..befd159 100644 --- a/schema/message.proto +++ b/schema/message.proto @@ -16,6 +16,15 @@ package asphrclient; // keep this in sync with db.rs, SystemMessage enum SystemMessage { OUTGOING_INVITATION = 0; } +// this message protobuf contains everything needed in +// a message. currently, messages only support a utf-8 message content +// as well as a list of cc-ed recipients. in the future, we may +// want to add pictures here, and more. +message Message { + repeated string other_recipients = 1; + string msg = 2; +} + // Given that we have a very very limited bandwidth, our goal is to define a // Message type that is as small as possible. // @@ -25,7 +34,7 @@ enum SystemMessage { OUTGOING_INVITATION = 0; } // // IMPORTANT: update GUARANTEED_MESSAGE_SIZE in client_lib.hpp whenever this is // updated. -message Message { +message Chunk { // sequence_number is a unique id for the message. it is unique for a ordered pair. if the id is 0, then the message is a dummy // message, with no actual msg to display to the user. @@ -33,11 +42,9 @@ message Message { // used for encryption. this requires some careful thought with dummy // messages. uint32 sequence_number = 1; - // msg contains the actual UTF-8 message, if such a message exists - // In the future, we probably want this to be `bytes`, encoding a protobuf. - // The protobuf will contain a string message and possibly other information, - // like pictures or reply metadata. - string msg = 2; + // msg is a chunk of a byte sequence that alltogether form the serialization + // of a Message, defined above. this msg has a maximum length. + bytes msg = 2; // if the message is a long message, this field contains the number of parts // it has this field is not set if the message isn't long. uint32 num_chunks = 3;