Skip to content

Commit

Permalink
fix udp tunnels reload
Browse files Browse the repository at this point in the history
Signed-off-by: R4SAS <r4sas@i2pmail.org>
  • Loading branch information
r4sas committed May 15, 2022
1 parent 2cd3ebb commit 923eb9f
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 151 deletions.
24 changes: 16 additions & 8 deletions libi2pd_client/ClientContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,21 +608,29 @@ namespace client
if (type == I2P_TUNNELS_SECTION_TYPE_UDPCLIENT) {
// udp client
// TODO: hostnames
boost::asio::ip::udp::endpoint end(boost::asio::ip::address::from_string(address), port);
boost::asio::ip::udp::endpoint end (boost::asio::ip::address::from_string(address), port);
if (!localDestination)
localDestination = m_SharedLocalDestination;

bool gzip = section.second.get (I2P_CLIENT_TUNNEL_GZIP, true);
auto clientTunnel = std::make_shared<I2PUDPClientTunnel>(name, dest, end, localDestination, destinationPort, gzip);
auto clientTunnel = std::make_shared<I2PUDPClientTunnel> (name, dest, end, localDestination, destinationPort, gzip);

auto ins = m_ClientForwards.insert(std::make_pair(end, clientTunnel));
auto ins = m_ClientForwards.insert (std::make_pair (end, clientTunnel));
if (ins.second)
{
clientTunnel->Start();
clientTunnel->Start ();
numClientTunnels++;
}
else
{
// TODO: update
if (ins.first->second->GetLocalDestination () != clientTunnel->GetLocalDestination ())
{
LogPrint (eLogInfo, "Clients: I2P UDP client tunnel destination updated");
ins.first->second->Stop ();
ins.first->second->SetLocalDestination (clientTunnel->GetLocalDestination ());
ins.first->second->Start ();
}
ins.first->second->isUpdated = true;
LogPrint(eLogError, "Clients: I2P Client forward for endpoint ", end, " already exists");
}
Expand Down Expand Up @@ -976,11 +984,11 @@ namespace client
}
}

/* // TODO: Write correct UDP tunnels stop
// TODO: Write correct UDP tunnels stop
for (auto it = m_ClientForwards.begin (); it != m_ClientForwards.end ();)
{
if(clean && !it->second->isUpdated) {
it->second = nullptr;
it->second->Stop ();
it = m_ClientForwards.erase(it);
} else {
it->second->isUpdated = false;
Expand All @@ -991,13 +999,13 @@ namespace client
for (auto it = m_ServerForwards.begin (); it != m_ServerForwards.end ();)
{
if(clean && !it->second->isUpdated) {
it->second = nullptr;
it->second->Stop ();
it = m_ServerForwards.erase(it);
} else {
it->second->isUpdated = false;
it++;
}
} */
}
}
}
}
4 changes: 2 additions & 2 deletions libi2pd_client/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ namespace client

i2p::proxy::HTTPProxy * m_HttpProxy;
i2p::proxy::SOCKSProxy * m_SocksProxy;
std::map<boost::asio::ip::tcp::endpoint, std::shared_ptr<I2PService> > m_ClientTunnels; // local endpoint->tunnel
std::map<std::pair<i2p::data::IdentHash, int>, std::shared_ptr<I2PServerTunnel> > m_ServerTunnels; // <destination,port>->tunnel
std::map<boost::asio::ip::tcp::endpoint, std::shared_ptr<I2PService> > m_ClientTunnels; // local endpoint -> tunnel
std::map<std::pair<i2p::data::IdentHash, int>, std::shared_ptr<I2PServerTunnel> > m_ServerTunnels; // <destination,port> -> tunnel

std::mutex m_ForwardsMutex;
std::map<boost::asio::ip::udp::endpoint, std::shared_ptr<I2PUDPClientTunnel> > m_ClientForwards; // local endpoint -> udp tunnel
Expand Down
Loading

0 comments on commit 923eb9f

Please sign in to comment.