mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-27 04:54:14 +00:00
address parameter for server tunnels
This commit is contained in:
parent
94659ba890
commit
616f0b2a21
@ -750,12 +750,13 @@ namespace client
|
|||||||
else // regular server tunnel by default
|
else // regular server tunnel by default
|
||||||
serverTunnel = std::make_shared<I2PServerTunnel> (name, host, port, localDestination, inPort, gzip);
|
serverTunnel = std::make_shared<I2PServerTunnel> (name, host, port, localDestination, inPort, gzip);
|
||||||
|
|
||||||
|
if (!address.empty ())
|
||||||
|
serverTunnel->SetLocalAddress (address);
|
||||||
if(!isUniqueLocal)
|
if(!isUniqueLocal)
|
||||||
{
|
{
|
||||||
LogPrint(eLogInfo, "Clients: disabling loopback address mapping");
|
LogPrint(eLogInfo, "Clients: disabling loopback address mapping");
|
||||||
serverTunnel->SetUniqueLocal(isUniqueLocal);
|
serverTunnel->SetUniqueLocal(isUniqueLocal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accessList.length () > 0)
|
if (accessList.length () > 0)
|
||||||
{
|
{
|
||||||
std::set<i2p::data::IdentHash> idents;
|
std::set<i2p::data::IdentHash> idents;
|
||||||
|
@ -107,6 +107,18 @@ namespace client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void I2PTunnelConnection::Connect (const boost::asio::ip::address& localAddress)
|
||||||
|
{
|
||||||
|
if (m_Socket)
|
||||||
|
{
|
||||||
|
boost::system::error_code ec;
|
||||||
|
m_Socket->bind (boost::asio::ip::tcp::endpoint (localAddress, 0), ec);
|
||||||
|
if (ec)
|
||||||
|
LogPrint (eLogError, "I2PTunnel: can't bind to ", localAddress.to_string (), ": ", ec.message ());
|
||||||
|
}
|
||||||
|
Connect (false);
|
||||||
|
}
|
||||||
|
|
||||||
void I2PTunnelConnection::Terminate ()
|
void I2PTunnelConnection::Terminate ()
|
||||||
{
|
{
|
||||||
if (Kill()) return;
|
if (Kill()) return;
|
||||||
@ -600,6 +612,16 @@ namespace client
|
|||||||
m_IsAccessList = true;
|
m_IsAccessList = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void I2PServerTunnel::SetLocalAddress (const std::string& localAddress)
|
||||||
|
{
|
||||||
|
boost::system::error_code ec;
|
||||||
|
auto addr = boost::asio::ip::address::from_string(localAddress, ec);
|
||||||
|
if (!ec)
|
||||||
|
m_LocalAddress.reset (new boost::asio::ip::address (addr));
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "I2PTunnel: can't set local address ", localAddress);
|
||||||
|
}
|
||||||
|
|
||||||
void I2PServerTunnel::Accept ()
|
void I2PServerTunnel::Accept ()
|
||||||
{
|
{
|
||||||
if (m_PortDestination)
|
if (m_PortDestination)
|
||||||
@ -631,7 +653,10 @@ namespace client
|
|||||||
// new connection
|
// new connection
|
||||||
auto conn = CreateI2PConnection (stream);
|
auto conn = CreateI2PConnection (stream);
|
||||||
AddHandler (conn);
|
AddHandler (conn);
|
||||||
conn->Connect (m_IsUniqueLocal);
|
if (m_LocalAddress)
|
||||||
|
conn->Connect (*m_LocalAddress);
|
||||||
|
else
|
||||||
|
conn->Connect (m_IsUniqueLocal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,8 @@ namespace client
|
|||||||
~I2PTunnelConnection ();
|
~I2PTunnelConnection ();
|
||||||
void I2PConnect (const uint8_t * msg = nullptr, size_t len = 0);
|
void I2PConnect (const uint8_t * msg = nullptr, size_t len = 0);
|
||||||
void Connect (bool isUniqueLocal = true);
|
void Connect (bool isUniqueLocal = true);
|
||||||
|
void Connect (const boost::asio::ip::address& localAddress);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void Terminate ();
|
void Terminate ();
|
||||||
@ -314,6 +315,8 @@ namespace client
|
|||||||
void SetUniqueLocal (bool isUniqueLocal) { m_IsUniqueLocal = isUniqueLocal; }
|
void SetUniqueLocal (bool isUniqueLocal) { m_IsUniqueLocal = isUniqueLocal; }
|
||||||
bool IsUniqueLocal () const { return m_IsUniqueLocal; }
|
bool IsUniqueLocal () const { return m_IsUniqueLocal; }
|
||||||
|
|
||||||
|
void SetLocalAddress (const std::string& localAddress);
|
||||||
|
|
||||||
const std::string& GetAddress() const { return m_Address; }
|
const std::string& GetAddress() const { return m_Address; }
|
||||||
int GetPort () const { return m_Port; };
|
int GetPort () const { return m_Port; };
|
||||||
uint16_t GetLocalPort () const { return m_PortDestination->GetLocalPort (); };
|
uint16_t GetLocalPort () const { return m_PortDestination->GetLocalPort (); };
|
||||||
@ -339,6 +342,7 @@ namespace client
|
|||||||
std::shared_ptr<i2p::stream::StreamingDestination> m_PortDestination;
|
std::shared_ptr<i2p::stream::StreamingDestination> m_PortDestination;
|
||||||
std::set<i2p::data::IdentHash> m_AccessList;
|
std::set<i2p::data::IdentHash> m_AccessList;
|
||||||
bool m_IsAccessList;
|
bool m_IsAccessList;
|
||||||
|
std::unique_ptr<boost::asio::ip::address> m_LocalAddress;
|
||||||
};
|
};
|
||||||
|
|
||||||
class I2PServerTunnelHTTP: public I2PServerTunnel
|
class I2PServerTunnelHTTP: public I2PServerTunnel
|
||||||
|
Loading…
x
Reference in New Issue
Block a user