forked from ton-blockchain/ton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adnl-local-id.h
124 lines (92 loc) · 3.8 KB
/
adnl-local-id.h
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2020 Telegram Systems LLP
*/
#pragma once
#include <map>
#include "td/actor/actor.h"
#include "td/utils/BufferedUdp.h"
#include "auto/tl/ton_api.h"
#include "keys/encryptor.h"
#include "adnl-peer-table.h"
#include "dht/dht.h"
#include "adnl-peer-table.h"
#include "utils.hpp"
namespace ton {
namespace adnl {
class AdnlLocalId : public td::actor::Actor {
public:
AdnlNodeIdFull get_id() const;
AdnlNodeIdShort get_short_id() const;
AdnlAddressList get_addr_list() const;
void get_addr_list_async(td::Promise<AdnlAddressList> P) {
P.set_value(get_addr_list());
}
void update_dht_node(td::actor::ActorId<dht::Dht> dht_node) {
dht_node_ = dht_node;
publish_address_list();
}
void decrypt(td::BufferSlice data, td::Promise<AdnlPacket> promise);
void decrypt_continue(td::BufferSlice data, td::Promise<AdnlPacket> promise);
void decrypt_message(td::BufferSlice data, td::Promise<td::BufferSlice> promise);
void deliver(AdnlNodeIdShort src, td::BufferSlice data);
void deliver_query(AdnlNodeIdShort src, td::BufferSlice data, td::Promise<td::BufferSlice> promise);
void receive(td::IPAddress addr, td::BufferSlice data);
void subscribe(std::string prefix, std::unique_ptr<AdnlPeerTable::Callback> callback);
void unsubscribe(std::string prefix);
void update_address_list(AdnlAddressList addr_list);
void get_self_node(td::Promise<AdnlNode> promise);
void sign_async(td::BufferSlice data, td::Promise<td::BufferSlice> promise);
void sign_batch_async(std::vector<td::BufferSlice> data,
td::Promise<std::vector<td::Result<td::BufferSlice>>> promise);
AdnlLocalId(AdnlNodeIdFull id, AdnlAddressList addr_list, td::uint32 mode,
td::actor::ActorId<AdnlPeerTable> peer_table, td::actor::ActorId<keyring::Keyring> keyring,
td::actor::ActorId<dht::Dht> dht_node);
void start_up() override;
void alarm() override;
void update_packet(AdnlPacket packet, bool update_id, bool sign, td::int32 update_addr_list_if,
td::int32 update_priority_addr_list_if, td::Promise<AdnlPacket> promise);
td::uint32 get_mode() {
return mode_;
}
struct PrintId {
AdnlNodeIdShort id;
};
PrintId print_id() const {
return PrintId{short_id_};
}
private:
td::actor::ActorId<AdnlPeerTable> peer_table_;
td::actor::ActorId<keyring::Keyring> keyring_;
td::actor::ActorId<dht::Dht> dht_node_;
std::vector<std::pair<std::string, std::unique_ptr<AdnlPeerTable::Callback>>> cb_;
AdnlAddressList addr_list_;
AdnlNodeIdFull id_;
AdnlNodeIdShort short_id_;
td::uint32 mode_;
void publish_address_list();
};
inline td::StringBuilder &operator<<(td::StringBuilder &sb, const AdnlLocalId::PrintId &id) {
sb << "[localid " << id.id << "]";
return sb;
}
inline td::StringBuilder &operator<<(td::StringBuilder &sb, const AdnlLocalId &localid) {
sb << localid.print_id();
return sb;
}
inline td::StringBuilder &operator<<(td::StringBuilder &sb, const AdnlLocalId *localid) {
sb << localid->print_id();
return sb;
}
} // namespace adnl
} // namespace ton