mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 08:14:15 +00:00
more changes
This commit is contained in:
parent
979575c311
commit
1d7d7cf9a0
@ -406,9 +406,6 @@ namespace client
|
|||||||
// udp client
|
// udp client
|
||||||
// TODO: ip6 and hostnames
|
// TODO: ip6 and 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(destinationPort == 0) {
|
|
||||||
destinationPort = port;
|
|
||||||
}
|
|
||||||
if (!localDestination) {
|
if (!localDestination) {
|
||||||
localDestination = m_SharedLocalDestination;
|
localDestination = m_SharedLocalDestination;
|
||||||
}
|
}
|
||||||
|
@ -534,6 +534,7 @@ namespace client
|
|||||||
for ( UDPSession * s : m_Sessions ) {
|
for ( UDPSession * s : m_Sessions ) {
|
||||||
if ( s->Identity == ih) {
|
if ( s->Identity == ih) {
|
||||||
/** found existing */
|
/** found existing */
|
||||||
|
LogPrint(eLogDebug, "UDPServer: found session ", s->IPSocket.local_endpoint());
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -558,20 +559,19 @@ namespace client
|
|||||||
|
|
||||||
|
|
||||||
void UDPSession::Receive() {
|
void UDPSession::Receive() {
|
||||||
LogPrint(eLogDebug, "UDPSesssion: Recveive");
|
LogPrint(eLogDebug, "UDPSession: Receive");
|
||||||
IPSocket.async_receive_from(boost::asio::buffer(m_Buffer, I2P_UDP_MAX_MTU), FromEndpoint, std::bind(&UDPSession::HandleReceived, this, std::placeholders::_1, std::placeholders::_2));
|
IPSocket.async_receive_from(boost::asio::buffer(m_Buffer, I2P_UDP_MAX_MTU), FromEndpoint, std::bind(&UDPSession::HandleReceived, this, std::placeholders::_1, std::placeholders::_2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPSession::HandleReceived(const boost::system::error_code & ecode, std::size_t len)
|
void UDPSession::HandleReceived(const boost::system::error_code & ecode, std::size_t len)
|
||||||
{
|
{
|
||||||
LogPrint(eLogDebug, "UDPSesssion: HandleRecveived");
|
|
||||||
if(!ecode) {
|
if(!ecode) {
|
||||||
LogPrint(eLogDebug, "UDPSession: forward ", len, "B from ", FromEndpoint);
|
LogPrint(eLogDebug, "UDPSession: forward ", len, "B from ", FromEndpoint);
|
||||||
LastActivity = i2p::util::GetMillisecondsSinceEpoch();
|
LastActivity = i2p::util::GetMillisecondsSinceEpoch();
|
||||||
uint8_t * data = new uint8_t[len];
|
uint8_t * data = new uint8_t[len];
|
||||||
memcpy(data, m_Buffer, len);
|
memcpy(data, m_Buffer, len);
|
||||||
m_Service.post([&,len, data] () {
|
m_Service.post([&,len, data] () {
|
||||||
m_Destination->SendDatagramTo(data, len, Identity, 0, 0);
|
m_Destination->SendDatagramTo(data, len, Identity, LocalPort, RemotePort);
|
||||||
delete [] data;
|
delete [] data;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -590,14 +590,14 @@ namespace client
|
|||||||
m_LocalDest = localDestination;
|
m_LocalDest = localDestination;
|
||||||
m_LocalDest->Start();
|
m_LocalDest->Start();
|
||||||
auto dgram = m_LocalDest->CreateDatagramDestination();
|
auto dgram = m_LocalDest->CreateDatagramDestination();
|
||||||
dgram->SetReceiver(std::bind(&I2PUDPServerTunnel::HandleRecvFromI2P, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5), 0);
|
dgram->SetReceiver(std::bind(&I2PUDPServerTunnel::HandleRecvFromI2P, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5), LocalPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
I2PUDPServerTunnel::~I2PUDPServerTunnel()
|
I2PUDPServerTunnel::~I2PUDPServerTunnel()
|
||||||
{
|
{
|
||||||
auto dgram = m_LocalDest->GetDatagramDestination();
|
auto dgram = m_LocalDest->GetDatagramDestination();
|
||||||
if (dgram) {
|
if (dgram) {
|
||||||
dgram->ResetReceiver(0);
|
dgram->ResetReceiver(LocalPort);
|
||||||
}
|
}
|
||||||
LogPrint(eLogInfo, "UDPServer: done");
|
LogPrint(eLogInfo, "UDPServer: done");
|
||||||
}
|
}
|
||||||
@ -658,7 +658,7 @@ namespace client
|
|||||||
// address match
|
// address match
|
||||||
if(m_Session) {
|
if(m_Session) {
|
||||||
// tell session
|
// tell session
|
||||||
LogPrint(eLogDebug, "UDP Client: got ", len, "B from ", from.GetIdentHash().ToBase32(), " via ", m_Session->SendEndpoint);
|
LogPrint(eLogDebug, "UDP Client: got ", len, "B from ", from.GetIdentHash().ToBase32());
|
||||||
m_Session->IPSocket.send_to(boost::asio::buffer(buf, len), m_Session->FromEndpoint);
|
m_Session->IPSocket.send_to(boost::asio::buffer(buf, len), m_Session->FromEndpoint);
|
||||||
} else {
|
} else {
|
||||||
LogPrint(eLogWarning, "UDP Client: no session");
|
LogPrint(eLogWarning, "UDP Client: no session");
|
||||||
|
@ -136,7 +136,7 @@ namespace client
|
|||||||
const uint64_t I2P_UDP_SESSION_TIMEOUT = 1000 * 60 * 2;
|
const uint64_t I2P_UDP_SESSION_TIMEOUT = 1000 * 60 * 2;
|
||||||
|
|
||||||
/** max size for i2p udp */
|
/** max size for i2p udp */
|
||||||
const size_t I2P_UDP_MAX_MTU = 4000;
|
const size_t I2P_UDP_MAX_MTU = i2p::datagram::MAX_DATAGRAM_SIZE;
|
||||||
|
|
||||||
struct UDPSession
|
struct UDPSession
|
||||||
{
|
{
|
||||||
@ -152,7 +152,6 @@ namespace client
|
|||||||
uint16_t RemotePort;
|
uint16_t RemotePort;
|
||||||
|
|
||||||
uint8_t m_Buffer[I2P_UDP_MAX_MTU];
|
uint8_t m_Buffer[I2P_UDP_MAX_MTU];
|
||||||
uint8_t * m_Forward;
|
|
||||||
|
|
||||||
UDPSession(boost::asio::ip::udp::endpoint localEndpoint, const std::shared_ptr<i2p::client::ClientDestination> & localDestination, boost::asio::ip::udp::endpoint remote, const i2p::data::IdentHash ident, uint16_t ourPort, uint16_t theirPort);
|
UDPSession(boost::asio::ip::udp::endpoint localEndpoint, const std::shared_ptr<i2p::client::ClientDestination> & localDestination, boost::asio::ip::udp::endpoint remote, const i2p::data::IdentHash ident, uint16_t ourPort, uint16_t theirPort);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user