-
Notifications
You must be signed in to change notification settings - Fork 27
Mail and Instant Message(IM) Message Format
All messages derive from message_header:
struct message_header
{
uint32_t size; //number of bytes in message
uint32_t type; //Type of message, used to properly unpack different message types.
//Also basis for message versioning.
};
struct message : public message_header
{
std::vector<char> data;
template<typename T> T as()const; //unpack message as type specified in message_header
...
};
Mail connections receive two types of messages in on_connection_message:
- encrypted_message::type: KH tries to decode these using message keys it knows. If it succeeds, it forward the decrypted message on further processing in bitchat_message_received. Profile's last_sync_time is updated with the message's timestamp (when message was sent, but for mail it is sender's local time plus server_time_offset).
- server_info_message::type: currently this is only used to update the server_time_offset from server reported time. This message also contains information such as server version, mirrors, and current_difficulty (all currently ignored).
bitchat_channel_impl::handle_message receives many types of messages, including encrypted messages. Encrypted messages are passed to channel_impl::handle_priv_msg which:
- validates the message's proof-of-work
- validates message was requested
- puts it on list of new_msgs to broadcast if it's less than 30 minutes old
- caches it in its _message_cache
- forwards to client_impl::handle_message which tries to decrypt it.
If the message can be decrypted in handle_message using message keys it knows, the decrypted message is forwarded to bitchat_message_received. Profile's last_sync_time is not updated in this case.
Decrypted messages contain their own embedded msg_type (distinct from the type in the originating encrypted message):
struct decrypted_message
{
/** type of the decrypted, uncompressed message */
fc::enum_type<fc::unsigned_int,private_message_type> msg_type;
std::vector<char> data;
fc::time_point_sec sig_time;
fc::optional<fc::ecc::compact_signature> from_sig;
fc::optional<fc::ecc::public_key> from_key;
fc::optional<fc::ecc::private_key> decrypt_key;
...
};
bitchat_message_received caches the decrypted message in Profile's cache, unpacks the message based on it's type, and forwards unpacked messaged to an appropriate handler in the client.
Current decrypted message types:
- private_message_type::text_msg: instant message is passed to client's received_text(msg)
- private_message_type::email_msg: email message is passed to client's received_email(msg)
- private_message_type::contact_request_msg: request to authorize a user passed to client's received_request(msg). This involves exchange of extended_private_keys for enhanced transaction privacy and will also be used to establish "direct-connect" IM links.