| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#pragma once |
| 31 |
#include "serialization/keyvalue_serialization.h" |
| 32 |
#include "cryptonote_basic/cryptonote_basic.h" |
| 33 |
#include "cryptonote_basic/cryptonote_boost_serialization.h" |
| 34 |
#include "cryptonote_basic/account_boost_serialization.h" |
| 35 |
#include "net/http_server_impl_base.h" |
| 36 |
#include "net/http_client.h" |
| 37 |
#include "net/abstract_http_client.h" |
| 38 |
#include "common/util.h" |
| 39 |
#include "wipeable_string.h" |
| 40 |
#include <vector> |
| 41 |
|
| 42 |
namespace mms |
| 43 |
{ |
| 44 |
|
| 45 |
struct transport_message_t |
| 46 |
{ |
| 47 |
cryptonote::account_public_address source_monero_address; |
| 48 |
std::string source_transport_address; |
| 49 |
cryptonote::account_public_address destination_monero_address; |
| 50 |
std::string destination_transport_address; |
| 51 |
crypto::chacha_iv iv; |
| 52 |
crypto::public_key encryption_public_key; |
| 53 |
uint64_t timestamp; |
| 54 |
uint32_t type; |
| 55 |
std::string subject; |
| 56 |
std::string content; |
| 57 |
crypto::hash hash; |
| 58 |
crypto::signature signature; |
| 59 |
uint32_t round; |
| 60 |
uint32_t signature_count; |
| 61 |
std::string transport_id; |
| 62 |
|
| 63 |
BEGIN_KV_SERIALIZE_MAP() |
| 64 |
KV_SERIALIZE(source_monero_address) |
| 65 |
KV_SERIALIZE(source_transport_address) |
| 66 |
KV_SERIALIZE(destination_monero_address) |
| 67 |
KV_SERIALIZE(destination_transport_address) |
| 68 |
KV_SERIALIZE_VAL_POD_AS_BLOB(iv) |
| 69 |
KV_SERIALIZE_VAL_POD_AS_BLOB(encryption_public_key) |
| 70 |
KV_SERIALIZE(timestamp) |
| 71 |
KV_SERIALIZE(type) |
| 72 |
KV_SERIALIZE(subject) |
| 73 |
KV_SERIALIZE(content) |
| 74 |
KV_SERIALIZE_VAL_POD_AS_BLOB(hash) |
| 75 |
KV_SERIALIZE_VAL_POD_AS_BLOB(signature) |
| 76 |
KV_SERIALIZE(round) |
| 77 |
KV_SERIALIZE(signature_count) |
| 78 |
KV_SERIALIZE(transport_id) |
| 79 |
END_KV_SERIALIZE_MAP() |
| 80 |
}; |
| 81 |
typedef epee::misc_utils::struct_init<transport_message_t> transport_message; |
| 82 |
|
| 83 |
class message_transporter |
| 84 |
{ |
| 85 |
public: |
| 86 |
message_transporter(std::unique_ptr<epee::net_utils::http::abstract_http_client> http_client); |
| 87 |
void set_options(const std::string &bitmessage_address, const epee::wipeable_string &bitmessage_login); |
| 88 |
bool send_message(const transport_message &message); |
| 89 |
bool receive_messages(const std::vector<std::string> &destination_transport_addresses, |
| 90 |
std::vector<transport_message> &messages); |
| 91 |
bool delete_message(const std::string &transport_id); |
| 92 |
void stop() { m_run.store(false, std::memory_order_relaxed); } |
| 93 |
std::string derive_transport_address(const std::string &seed); |
| 94 |
bool delete_transport_address(const std::string &transport_address); |
| 95 |
|
| 96 |
private: |
| 97 |
const std::unique_ptr<epee::net_utils::http::abstract_http_client> m_http_client; |
| 98 |
std::string m_bitmessage_url; |
| 99 |
epee::wipeable_string m_bitmessage_login; |
| 100 |
std::atomic<bool> m_run; |
| 101 |
|
| 102 |
bool post_request(const std::string &request, std::string &answer); |
| 103 |
static std::string get_str_between_tags(const std::string &s, const std::string &start_delim, const std::string &stop_delim); |
| 104 |
|
| 105 |
static void start_xml_rpc_cmd(std::string &xml, const std::string &method_name); |
| 106 |
static void add_xml_rpc_string_param(std::string &xml, const std::string ¶m); |
| 107 |
static void add_xml_rpc_base64_param(std::string &xml, const std::string ¶m); |
| 108 |
static void add_xml_rpc_integer_param(std::string &xml, const int32_t ¶m); |
| 109 |
static void end_xml_rpc_cmd(std::string &xml); |
| 110 |
|
| 111 |
}; |
| 112 |
|
| 113 |
} |