Debian Codegraph @

src/wallet/message_transporter.h

raw symbols SCIP
1 // Copyright (c) 2018-2022, The Monero Project
2
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 &param);
107 static void add_xml_rpc_base64_param(std::string &xml, const std::string &param);
108 static void add_xml_rpc_integer_param(std::string &xml, const int32_t &param);
109 static void end_xml_rpc_cmd(std::string &xml);
110
111 };
112
113 }