Monero
message_transporter.h
Go to the documentation of this file.
1 // Copyright (c) 2018, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 #include "serialization/keyvalue_serialization.h"
34 #include "net/http_server_impl_base.h"
35 #include "net/http_client.h"
36 #include "net/abstract_http_client.h"
37 #include "common/util.h"
38 #include "wipeable_string.h"
39 #include <vector>
40 
41 namespace mms
42 {
43 
45 {
50  crypto::chacha_iv iv;
52  uint64_t timestamp;
53  uint32_t type;
54  std::string subject;
55  std::string content;
58  uint32_t round;
59  uint32_t signature_count;
60  std::string transport_id;
61 
62  BEGIN_KV_SERIALIZE_MAP()
63  KV_SERIALIZE(source_monero_address)
64  KV_SERIALIZE(source_transport_address)
65  KV_SERIALIZE(destination_monero_address)
66  KV_SERIALIZE(destination_transport_address)
67  KV_SERIALIZE_VAL_POD_AS_BLOB(iv)
68  KV_SERIALIZE_VAL_POD_AS_BLOB(encryption_public_key)
69  KV_SERIALIZE(timestamp)
70  KV_SERIALIZE(type)
71  KV_SERIALIZE(subject)
72  KV_SERIALIZE(content)
73  KV_SERIALIZE_VAL_POD_AS_BLOB(hash)
74  KV_SERIALIZE_VAL_POD_AS_BLOB(signature)
75  KV_SERIALIZE(round)
76  KV_SERIALIZE(signature_count)
77  KV_SERIALIZE(transport_id)
78  END_KV_SERIALIZE_MAP()
79 };
80 typedef epee::misc_utils::struct_init<transport_message_t> transport_message;
81 
83 {
84 public:
85  message_transporter(std::unique_ptr<epee::net_utils::http::abstract_http_client> http_client);
86  void set_options(const std::string &bitmessage_address, const epee::wipeable_string &bitmessage_login);
87  bool send_message(const transport_message &message);
88  bool receive_messages(const std::vector<std::string> &destination_transport_addresses,
89  std::vector<transport_message> &messages);
90  bool delete_message(const std::string &transport_id);
91  void stop() { m_run.store(false, std::memory_order_relaxed); }
92  std::string derive_transport_address(const std::string &seed);
93  bool delete_transport_address(const std::string &transport_address);
94 
95 private:
96  const std::unique_ptr<epee::net_utils::http::abstract_http_client> m_http_client;
97  std::string m_bitmessage_url;
98  epee::wipeable_string m_bitmessage_login;
99  std::atomic<bool> m_run;
100 
101  bool post_request(const std::string &request, std::string &answer);
102  static std::string get_str_between_tags(const std::string &s, const std::string &start_delim, const std::string &stop_delim);
103 
104  static void start_xml_rpc_cmd(std::string &xml, const std::string &method_name);
105  static void add_xml_rpc_string_param(std::string &xml, const std::string &param);
106  static void add_xml_rpc_base64_param(std::string &xml, const std::string &param);
107  static void add_xml_rpc_integer_param(std::string &xml, const int32_t &param);
108  static void end_xml_rpc_cmd(std::string &xml);
109 
110 };
111 
112 }
#define s(x, c)
Definition: aesb.c:47
Definition: message_transporter.h:83
std::atomic< bool > m_run
Definition: message_transporter.h:99
const std::unique_ptr< epee::net_utils::http::abstract_http_client > m_http_client
Definition: message_transporter.h:96
epee::wipeable_string m_bitmessage_login
Definition: message_transporter.h:98
std::string m_bitmessage_url
Definition: message_transporter.h:97
void stop()
Definition: message_transporter.h:91
POD_CLASS signature
Definition: crypto.h:93
POD_CLASS public_key
Definition: crypto.h:61
POD_CLASS hash
Definition: hash.h:48
Definition: cryptonote_format_utils.h:44
Definition: message_store.cpp:49
epee::misc_utils::struct_init< transport_message_t > transport_message
Definition: message_transporter.h:80
Definition: cryptonote_basic.h:501
Definition: message_store.h:103
Definition: message_transporter.h:45
cryptonote::account_public_address source_monero_address
Definition: message_transporter.h:46
std::string transport_id
Definition: message_transporter.h:60
crypto::hash hash
Definition: message_transporter.h:56
std::string content
Definition: message_transporter.h:55
crypto::signature signature
Definition: message_transporter.h:57
uint64_t timestamp
Definition: message_transporter.h:52
std::string destination_transport_address
Definition: message_transporter.h:49
uint32_t round
Definition: message_transporter.h:58
cryptonote::account_public_address destination_monero_address
Definition: message_transporter.h:48
uint32_t signature_count
Definition: message_transporter.h:59
std::string subject
Definition: message_transporter.h:54
crypto::chacha_iv iv
Definition: message_transporter.h:50
std::string source_transport_address
Definition: message_transporter.h:47
crypto::public_key encryption_public_key
Definition: message_transporter.h:51
uint32_t type
Definition: message_transporter.h:53