Version: 0.0.1

home

communication模块主要负责朋友或者区块链群组之间消息的沟通, 同时作为time server,通过统计网络中位数时间,为其它模块提供时间基准

[report issue]

new_msg_signal

Declared in "libtorrent/communication/new_msg_signal.hpp"

The new_msg_signal class represents one type of mutable wrapper, is used to publish new message info in XY channel

class new_msg_signal
{
   new_msg_signal (aux::bytesConstRef _rlp);
   aux::bytes device_id () const;
   aux::bytes hash_prefix_bytes () const;
   uint32_t timestamp () const;
   void streamRLP (aux::RLPStream& _s) const;
   aux::bytes rlp () const;
};
[report issue]

new_msg_signal()

new_msg_signal (aux::bytesConstRef _rlp);

@param _rlp rlp encode

[report issue]

device_id()

aux::bytes device_id () const;

@returns device id

[report issue]

hash_prefix_bytes()

aux::bytes hash_prefix_bytes () const;

@returns hash prefix bytes

[report issue]

timestamp()

uint32_t timestamp () const;

@returns timestamp

[report issue]

streamRLP()

void streamRLP (aux::RLPStream& _s) const;

Serialises this new message signal to an RLPStream

[report issue]

rlp()

aux::bytes rlp () const;

@returns the RLP serialisation of this new message signal

[report issue]

message

Declared in "libtorrent/communication/message.hpp"

The message class shows message struct

class message
{
   message () = default;
   message (aux::bytesConstRef _rlp);
   message_version version () const;
   uint32_t timestamp () const;
   const aux::bytes &sender () const;
   const aux::bytes &receiver () const;
   const aux::bytes &logic_msg_hash () const;
   const aux::bigint &nonce () const;
   message_type type () const;
   const aux::bytes &encrypted_content () const;
   void streamRLP (aux::RLPStream& _s) const;
   aux::bytes rlp () const;
   sha256_hash sha256 () const;
   std::string to_string () const;
};
[report issue]

message()

message (aux::bytesConstRef _rlp);

@param _rlp rlp encode

[report issue]

version()

message_version version () const;

@returns message version

[report issue]

timestamp()

uint32_t timestamp () const;

@returns message timestamp

[report issue]

&sender()

const aux::bytes &sender () const;

@returns message sender

[report issue]

&receiver()

const aux::bytes &receiver () const;

@returns message receiver

[report issue]

&logic_msg_hash()

const aux::bytes &logic_msg_hash () const;

@returns message logic msg hash

[report issue]

&nonce()

const aux::bigint &nonce () const;

@returns message nonce

[report issue]

type()

message_type type () const;

@returns message type

[report issue]

&encrypted_content()

const aux::bytes &encrypted_content () const;

@returns encrypted content

[report issue]

streamRLP()

void streamRLP (aux::RLPStream& _s) const;

Serialises this message to an RLPStream

[report issue]

rlp()

aux::bytes rlp () const;

@returns the RLP serialisation of this message

[report issue]

sha256()

sha256_hash sha256 () const;

@returns the SHA256 hash of the RLP serialisation of this message

[report issue]

to_string()

std::string to_string () const;

@returns a pretty-printed string representation of message structure

[report issue]

communication

Declared in "libtorrent/communication/communication.hpp"

class communication final: public std::enable_shared_from_this<communication>
{
   bool start ();
   bool stop ();
   void set_loop_time_interval (int milliseconds);
   bool add_new_friend (const aux::bytes& pubkey);
   bool delete_friend (const aux::bytes& pubkey);
   aux::bytes get_friend_info (aux::bytes pubkey);
   bool update_friend_info (aux::bytes pubkey, aux::bytes friend_info);
   void set_chatting_friend (aux::bytes chatting_friend);
   void unset_chatting_friend ();
   void set_active_friends (std::vector<aux::bytes> &&active_friends);
   bool add_new_message (const message& msg);
   void account_changed ();
};
[report issue]

start()

bool start ();

start communication

[report issue]

stop()

bool stop ();

stop

[report issue]

set_loop_time_interval()

void set_loop_time_interval (int milliseconds);

set main loop time interval (ms)

[report issue]

add_new_friend()

bool add_new_friend (const aux::bytes& pubkey);

add new friend in memory & db

[report issue]

delete_friend()

bool delete_friend (const aux::bytes& pubkey);

delete friend and all related data in memory & db

[report issue]

get_friend_info()

aux::bytes get_friend_info (aux::bytes pubkey);

get friend info by public key

[report issue]

update_friend_info()

bool update_friend_info (aux::bytes pubkey, aux::bytes friend_info);

save friend info

[report issue]

set_chatting_friend()

void set_chatting_friend (aux::bytes chatting_friend);

set chatting friends

[report issue]

unset_chatting_friend()

void unset_chatting_friend ();

unset chatting friends

[report issue]

set_active_friends()

void set_active_friends (std::vector<aux::bytes> &&active_friends);

set active friends

[report issue]

add_new_message()

bool add_new_message (const message& msg);

add a new message

[report issue]

account_changed()

void account_changed ();

reset when account changed

[report issue]

message_container

Declared in "libtorrent/communication/message_container.hpp"

The message_container class represents one type of mutable wrapper, is used to put multiple messages together

class message_container
{
   explicit message_container (aux::bytesConstRef _rlp);
   explicit message_container (std::vector<message> messages);
   std::vector<message> messages () const;
   void streamRLP (aux::RLPStream& _s) const;
   aux::bytes rlp () const;
};
[report issue]

messages()

std::vector<message> messages () const;

@returns all messages in this container

[report issue]

streamRLP()

void streamRLP (aux::RLPStream& _s) const;

Serialises this message container to an RLPStream

[report issue]

rlp()

aux::bytes rlp () const;

@returns the RLP serialisation of this message container

[report issue]

message_db_interface

Declared in "libtorrent/communication/message_db_interface.hpp"

The message_db_interface 提供message相关的存储接口, 包括朋友公钥的存取删除,消息的存取删除,以及最新消息哈希列表编码的存取删除, 每一个朋友都会对应一个最新消息哈希集合,该集合是该通信对最新200个消息完整哈希的时间排列的顺序列表, 每当有更新的消息加入该列表,列表满载时会删除其最老的消息哈希,并根据该哈希删除相应的消息; 并且,该哈希列表也用来生成对应的莱温斯坦数组,只需取哈希的第一个字节,并按对应顺序排列即可

struct message_db_interface
{
   virtual bool init () = 0;
   virtual std::vector<aux::bytes> get_all_friends () = 0;
   virtual bool save_friend (aux::bytes public_key) = 0;
   virtual bool delete_friend (aux::bytes public_key) = 0;
   virtual aux::bytes get_friend_info (aux::bytes public_key) = 0;
   virtual bool save_friend_info (aux::bytes public_key, aux::bytes friend_info) = 0;
   virtual bool delete_friend_info (aux::bytes public_key) = 0;
   virtual communication::message get_message (aux::bytes hash) = 0;
   virtual bool save_message (communication::message msg) = 0;
   virtual bool delete_message (aux::bytes hash) = 0;
   virtual aux::bytes get_latest_message_hash_list_encode (aux::bytes public_key) = 0;
   virtual bool save_latest_message_hash_list_encode (aux::bytes public_key, aux::bytes encode) = 0;
   virtual bool delete_latest_message_hash_list_encode (aux::bytes public_key) = 0;
   virtual ~message_db_interface ();
};
[report issue]

init()

virtual bool init () = 0;

init db

[report issue]

get_all_friends()

virtual std::vector<aux::bytes> get_all_friends () = 0;

get all friends

[report issue]

save_friend()

virtual bool save_friend (aux::bytes public_key) = 0;

save a friend in db

[report issue]

delete_friend()

virtual bool delete_friend (aux::bytes public_key) = 0;

delete a friend

[report issue]

get_friend_info()

virtual aux::bytes get_friend_info (aux::bytes public_key) = 0;

get friend info by public key

[report issue]

save_friend_info()

virtual bool save_friend_info (aux::bytes public_key, aux::bytes friend_info) = 0;

save friend info

[report issue]

delete_friend_info()

virtual bool delete_friend_info (aux::bytes public_key) = 0;

delete friend info

[report issue]

get_message()

virtual communication::message get_message (aux::bytes hash) = 0;

get message by hash

[report issue]

save_message()

virtual bool save_message (communication::message msg) = 0;

save message

[report issue]

delete_message()

virtual bool delete_message (aux::bytes hash) = 0;

delete message

[report issue]

get_latest_message_hash_list_encode()

virtual aux::bytes get_latest_message_hash_list_encode (aux::bytes public_key) = 0;

get encode of the latest message hash list

[report issue]

save_latest_message_hash_list_encode()

virtual bool save_latest_message_hash_list_encode (aux::bytes public_key, aux::bytes encode) = 0;

save encode of the latest message hash list

[report issue]

delete_latest_message_hash_list_encode()

virtual bool delete_latest_message_hash_list_encode (aux::bytes public_key) = 0;

delete encode of the latest message hash list

[report issue]

message_hash_list

Declared in "libtorrent/communication/message_hash_list.hpp"

The message_hash_list class is a list, encode/decode message hash list

class message_hash_list
{
   explicit message_hash_list (aux::bytesConstRef _rlp);
   explicit message_hash_list (std::vector<aux::bytes> message_hash_list);
   std::vector<aux::bytes> hash_list () const;
   void streamRLP (aux::RLPStream& _s) const;
   aux::bytes rlp () const;
};
[report issue]

hash_list()

std::vector<aux::bytes> hash_list () const;

@returns all message hash in this container

[report issue]

streamRLP()

void streamRLP (aux::RLPStream& _s) const;

Serialises this message hash list to an RLPStream

[report issue]

rlp()

aux::bytes rlp () const;

@returns the RLP serialisation of this message hash list

[report issue]

mutable_data_wrapper

Declared in "libtorrent/communication/mutable_data_wrapper.hpp"

The mutable_data_wrapper class represents wrap all mutable data including message container, online signal, new message signal.

class mutable_data_wrapper
{
   explicit mutable_data_wrapper (aux::bytesConstRef _rlp);
   mutable_data_wrapper (uint32_t mTimestamp, mutable_data_type mType, aux::bytes mPayload);
   uint32_t timestamp () const;
   mutable_data_type type () const;
   aux::bytes payload () const;
   void streamRLP (aux::RLPStream& _s) const;
   aux::bytes rlp () const;
};
[report issue]

mutable_data_wrapper()

explicit mutable_data_wrapper (aux::bytesConstRef _rlp);

@param _rlp rlp encode

[report issue]

timestamp()

uint32_t timestamp () const;

@returns timestamp

[report issue]

type()

mutable_data_type type () const;

@returns type

[report issue]

payload()

aux::bytes payload () const;

@returns payload

[report issue]

streamRLP()

void streamRLP (aux::RLPStream& _s) const;

Serialises this mutable data wrapper to an RLPStream

[report issue]

rlp()

aux::bytes rlp () const;

@returns the RLP serialisation of this mutable data wrapper

[report issue]

online_signal

Declared in "libtorrent/communication/online_signal.hpp"

The online_signal class represents one type of mutable wrapper, is used to publish online info in XX channel

struct online_signal
{
   online_signal (aux::bytesConstRef _rlp);
   inline aux::bytes device_id () const;
   inline aux::bytes hash_prefix_bytes () const;
   inline uint32_t timestamp () const;
   inline aux::bytes friend_info () const;
   void streamRLP (aux::RLPStream& _s) const;
   aux::bytes rlp () const;
};
[report issue]

online_signal()

online_signal (aux::bytesConstRef _rlp);

@param _rlp rlp encode

[report issue]

device_id()

inline aux::bytes device_id () const;

@returns device id

[report issue]

hash_prefix_bytes()

inline aux::bytes hash_prefix_bytes () const;

@returns hash prefix bytes

[report issue]

timestamp()

inline uint32_t timestamp () const;

@returns timestamp

[report issue]

friend_info()

inline aux::bytes friend_info () const;

@returns friend info bytes

[report issue]

streamRLP()

void streamRLP (aux::RLPStream& _s) const;

Serialises this online signal to an RLPStream

[report issue]

rlp()

aux::bytes rlp () const;

@returns the RLP serialisation of this message

[report issue]

enum message_version

Declared in "libtorrent/communication/message.hpp"

name value description
VERSION_1 0 current version
UNSUPPORTED_VERSION 1 unsupported version
[report issue]

enum message_type

Declared in "libtorrent/communication/message.hpp"

name value description
TEXT 0 message type is text
PICTURE 1 message type is picture
UNSUPPORTED_TYPE 2 unsupported message type
[report issue]

enum mutable_data_type

Declared in "libtorrent/communication/mutable_data_wrapper.hpp"

name value description
MESSAGE 0  
MESSAGE_CONTAINER 1  
ONLINE_SIGNAL 2  
NEW_MSG_SIGNAL 3  
UNKNOWN 4  
[report issue]

int

Declared in "libtorrent/communication/communication.hpp"

communication_default_refresh_time
default refresh time of main task
communication_max_message_list_size
max message list size(used in Levenshtein Distance)
communication_short_address_length
short address(public key) length