mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
ADNL Tunnel library integration
This commit is contained in:
parent
2a68c8610b
commit
4737d5f83d
13 changed files with 348 additions and 10 deletions
|
@ -76,6 +76,35 @@ size_t AdnlNetworkManagerImpl::add_listening_udp_port(td::uint16 port) {
|
|||
return idx;
|
||||
}
|
||||
|
||||
size_t AdnlNetworkManagerImpl::add_tunnel_udp_port(td::uint16 port, td::Promise<td::IPAddress> on_ready) {
|
||||
auto it = port_2_socket_.find(port);
|
||||
if (it != port_2_socket_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
class Callback : public td::UdpServer::Callback {
|
||||
public:
|
||||
Callback(td::actor::ActorShared<AdnlNetworkManagerImpl> manager, size_t idx)
|
||||
: manager_(std::move(manager)), idx_(idx) {
|
||||
}
|
||||
|
||||
private:
|
||||
td::actor::ActorShared<AdnlNetworkManagerImpl> manager_;
|
||||
size_t idx_;
|
||||
void on_udp_message(td::UdpMessage udp_message) override {
|
||||
td::actor::send_closure_later(manager_, &AdnlNetworkManagerImpl::receive_udp_message, std::move(udp_message),
|
||||
idx_);
|
||||
}
|
||||
};
|
||||
|
||||
auto idx = udp_sockets_.size();
|
||||
auto X = td::UdpServer::create_via_tunnel("udp tunnel server", port,
|
||||
std::make_unique<Callback>(actor_shared(this), idx), std::move(on_ready));
|
||||
X.ensure();
|
||||
port_2_socket_[port] = idx;
|
||||
udp_sockets_.push_back(UdpSocketDesc{port, X.move_as_ok()});
|
||||
return idx;
|
||||
}
|
||||
|
||||
void AdnlNetworkManagerImpl::add_self_addr(td::IPAddress addr, AdnlCategoryMask cat_mask, td::uint32 priority) {
|
||||
auto port = td::narrow_cast<td::uint16>(addr.get_port());
|
||||
size_t idx = add_listening_udp_port(port);
|
||||
|
@ -92,6 +121,23 @@ void AdnlNetworkManagerImpl::add_self_addr(td::IPAddress addr, AdnlCategoryMask
|
|||
out_desc_[priority].push_back(std::move(d));
|
||||
}
|
||||
|
||||
void AdnlNetworkManagerImpl::add_tunnel(td::uint16 port, AdnlCategoryMask cat_mask, td::uint32 priority,
|
||||
td::Promise<td::IPAddress> on_ready) {
|
||||
size_t idx = add_tunnel_udp_port(port, std::move(on_ready));
|
||||
|
||||
add_in_addr(InDesc{port, nullptr, cat_mask}, idx);
|
||||
auto d = OutDesc{port, td::IPAddress{}, nullptr, idx};
|
||||
for (auto &it : out_desc_[priority]) {
|
||||
if (it == d) {
|
||||
it.cat_mask |= cat_mask;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
d.cat_mask = cat_mask;
|
||||
out_desc_[priority].push_back(std::move(d));
|
||||
}
|
||||
|
||||
void AdnlNetworkManagerImpl::add_proxy_addr(td::IPAddress addr, td::uint16 local_port, std::shared_ptr<AdnlProxy> proxy,
|
||||
AdnlCategoryMask cat_mask, td::uint32 priority) {
|
||||
size_t idx = add_listening_udp_port(local_port);
|
||||
|
|
|
@ -70,6 +70,8 @@ class AdnlNetworkManager : public td::actor::Actor {
|
|||
|
||||
virtual void install_callback(std::unique_ptr<Callback> callback) = 0;
|
||||
|
||||
virtual void add_tunnel(td::uint16 port, AdnlCategoryMask cat_mask, td::uint32 priority,
|
||||
td::Promise<td::IPAddress> on_ready) = 0;
|
||||
virtual void add_self_addr(td::IPAddress addr, AdnlCategoryMask cat_mask, td::uint32 priority) = 0;
|
||||
virtual void add_proxy_addr(td::IPAddress addr, td::uint16 local_port, std::shared_ptr<AdnlProxy> proxy,
|
||||
AdnlCategoryMask cat_mask, td::uint32 priority) = 0;
|
||||
|
|
|
@ -95,6 +95,10 @@ class AdnlNetworkManagerImpl : public AdnlNetworkManager {
|
|||
size_t in_desc{std::numeric_limits<size_t>::max()};
|
||||
bool allow_proxy{false};
|
||||
};
|
||||
struct TunnelDesc {
|
||||
size_t index{};
|
||||
td::IPAddress address;
|
||||
};
|
||||
|
||||
OutDesc *choose_out_iface(td::uint8 cat, td::uint32 priority);
|
||||
|
||||
|
@ -127,6 +131,8 @@ class AdnlNetworkManagerImpl : public AdnlNetworkManager {
|
|||
in_desc_.push_back(std::move(desc));
|
||||
}
|
||||
|
||||
void add_tunnel(td::uint16 port, AdnlCategoryMask cat_mask, td::uint32 priority,
|
||||
td::Promise<td::IPAddress> on_ready) override;
|
||||
void add_self_addr(td::IPAddress addr, AdnlCategoryMask cat_mask, td::uint32 priority) override;
|
||||
void add_proxy_addr(td::IPAddress addr, td::uint16 local_port, std::shared_ptr<AdnlProxy> proxy,
|
||||
AdnlCategoryMask cat_mask, td::uint32 priority) override;
|
||||
|
@ -141,6 +147,7 @@ class AdnlNetworkManagerImpl : public AdnlNetworkManager {
|
|||
}
|
||||
}
|
||||
|
||||
size_t add_tunnel_udp_port(td::uint16 port, td::Promise<td::IPAddress> on_ready);
|
||||
size_t add_listening_udp_port(td::uint16 port);
|
||||
void receive_udp_message(td::UdpMessage message, size_t idx);
|
||||
void proxy_register(OutDesc &desc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue