mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 06:54:15 +00:00
handle local destination port
This commit is contained in:
parent
ac57e7ced2
commit
0f8ea92a53
@ -67,7 +67,7 @@ namespace datagram
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatagramDestination::HandleDatagram (const uint8_t * buf, size_t len)
|
void DatagramDestination::HandleDatagram (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
i2p::data::IdentityEx identity;
|
i2p::data::IdentityEx identity;
|
||||||
size_t identityLen = identity.FromBuffer (buf, len);
|
size_t identityLen = identity.FromBuffer (buf, len);
|
||||||
@ -91,7 +91,7 @@ namespace datagram
|
|||||||
LogPrint (eLogWarning, "Datagram signature verification failed");
|
LogPrint (eLogWarning, "Datagram signature verification failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatagramDestination::HandleDataMessagePayload (const uint8_t * buf, size_t len)
|
void DatagramDestination::HandleDataMessagePayload (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
// unzip it
|
// unzip it
|
||||||
CryptoPP::Gunzip decompressor;
|
CryptoPP::Gunzip decompressor;
|
||||||
@ -102,7 +102,7 @@ namespace datagram
|
|||||||
if (uncompressedLen <= MAX_DATAGRAM_SIZE)
|
if (uncompressedLen <= MAX_DATAGRAM_SIZE)
|
||||||
{
|
{
|
||||||
decompressor.Get (uncompressed, uncompressedLen);
|
decompressor.Get (uncompressed, uncompressedLen);
|
||||||
HandleDatagram (uncompressed, uncompressedLen);
|
HandleDatagram (fromPort, toPort, uncompressed, uncompressedLen);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint ("Received datagram size ", uncompressedLen, " exceeds max size");
|
LogPrint ("Received datagram size ", uncompressedLen, " exceeds max size");
|
||||||
|
@ -27,7 +27,7 @@ namespace datagram
|
|||||||
~DatagramDestination () {};
|
~DatagramDestination () {};
|
||||||
|
|
||||||
void SendDatagramTo (const uint8_t * payload, size_t len, std::shared_ptr<const i2p::data::LeaseSet> remote);
|
void SendDatagramTo (const uint8_t * payload, size_t len, std::shared_ptr<const i2p::data::LeaseSet> remote);
|
||||||
void HandleDataMessagePayload (const uint8_t * buf, size_t len);
|
void HandleDataMessagePayload (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
|
||||||
|
|
||||||
void SetReceiver (const Receiver& receiver) { m_Receiver = receiver; };
|
void SetReceiver (const Receiver& receiver) { m_Receiver = receiver; };
|
||||||
void ResetReceiver () { m_Receiver = nullptr; };
|
void ResetReceiver () { m_Receiver = nullptr; };
|
||||||
@ -36,7 +36,7 @@ namespace datagram
|
|||||||
|
|
||||||
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len);
|
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len);
|
||||||
void SendMsg (I2NPMessage * msg, std::shared_ptr<const i2p::data::LeaseSet> remote);
|
void SendMsg (I2NPMessage * msg, std::shared_ptr<const i2p::data::LeaseSet> remote);
|
||||||
void HandleDatagram (const uint8_t * buf, size_t len);
|
void HandleDatagram (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "ElGamal.h"
|
#include "ElGamal.h"
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
|
#include "AddressBook.h"
|
||||||
#include "Destination.h"
|
#include "Destination.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
@ -46,7 +47,7 @@ namespace client
|
|||||||
}
|
}
|
||||||
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (this, inboundTunnelLen, outboundTunnelLen);
|
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (this, inboundTunnelLen, outboundTunnelLen);
|
||||||
if (m_IsPublic)
|
if (m_IsPublic)
|
||||||
LogPrint (eLogInfo, "Local address ", GetIdentHash().ToBase32 (), ".b32.i2p created");
|
LogPrint (eLogInfo, "Local address ", i2p::client::GetB32Address(GetIdentHash()), " created");
|
||||||
m_StreamingDestination = new i2p::stream::StreamingDestination (*this); // TODO:
|
m_StreamingDestination = new i2p::stream::StreamingDestination (*this); // TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,6 +368,8 @@ namespace client
|
|||||||
uint32_t length = bufbe32toh (buf);
|
uint32_t length = bufbe32toh (buf);
|
||||||
buf += 4;
|
buf += 4;
|
||||||
// we assume I2CP payload
|
// we assume I2CP payload
|
||||||
|
uint16_t fromPort = bufbe16toh (buf + 4), // source
|
||||||
|
toPort = bufbe16toh (buf + 6); // destination
|
||||||
switch (buf[9])
|
switch (buf[9])
|
||||||
{
|
{
|
||||||
case PROTOCOL_TYPE_STREAMING:
|
case PROTOCOL_TYPE_STREAMING:
|
||||||
@ -379,7 +382,7 @@ namespace client
|
|||||||
case PROTOCOL_TYPE_DATAGRAM:
|
case PROTOCOL_TYPE_DATAGRAM:
|
||||||
// datagram protocol
|
// datagram protocol
|
||||||
if (m_DatagramDestination)
|
if (m_DatagramDestination)
|
||||||
m_DatagramDestination->HandleDataMessagePayload (buf, length);
|
m_DatagramDestination->HandleDataMessagePayload (fromPort, toPort, buf, length);
|
||||||
else
|
else
|
||||||
LogPrint ("Missing streaming destination");
|
LogPrint ("Missing streaming destination");
|
||||||
break;
|
break;
|
||||||
|
@ -661,7 +661,7 @@ namespace stream
|
|||||||
htobe32buf (buf, size); // length
|
htobe32buf (buf, size); // length
|
||||||
buf += 4;
|
buf += 4;
|
||||||
compressor.Get (buf, size);
|
compressor.Get (buf, size);
|
||||||
htobuf16(buf + 4, 0); // source port
|
htobe16buf (buf + 4, m_LocalDestination.GetLocalPort ()); // source port
|
||||||
htobe16buf (buf + 6, m_Port); // destination port
|
htobe16buf (buf + 6, m_Port); // destination port
|
||||||
buf[9] = i2p::client::PROTOCOL_TYPE_STREAMING; // streaming protocol
|
buf[9] = i2p::client::PROTOCOL_TYPE_STREAMING; // streaming protocol
|
||||||
msg->len += size + 4;
|
msg->len += size + 4;
|
||||||
|
@ -174,7 +174,8 @@ namespace stream
|
|||||||
|
|
||||||
typedef std::function<void (std::shared_ptr<Stream>)> Acceptor;
|
typedef std::function<void (std::shared_ptr<Stream>)> Acceptor;
|
||||||
|
|
||||||
StreamingDestination (i2p::client::ClientDestination& owner): m_Owner (owner) {};
|
StreamingDestination (i2p::client::ClientDestination& owner, uint16_t localPort = 0):
|
||||||
|
m_Owner (owner), m_LocalPort (localPort) {};
|
||||||
~StreamingDestination () {};
|
~StreamingDestination () {};
|
||||||
|
|
||||||
void Start ();
|
void Start ();
|
||||||
@ -186,6 +187,7 @@ namespace stream
|
|||||||
void ResetAcceptor () { if (m_Acceptor) m_Acceptor (nullptr); m_Acceptor = nullptr; };
|
void ResetAcceptor () { if (m_Acceptor) m_Acceptor (nullptr); m_Acceptor = nullptr; };
|
||||||
bool IsAcceptorSet () const { return m_Acceptor != nullptr; };
|
bool IsAcceptorSet () const { return m_Acceptor != nullptr; };
|
||||||
i2p::client::ClientDestination& GetOwner () { return m_Owner; };
|
i2p::client::ClientDestination& GetOwner () { return m_Owner; };
|
||||||
|
uint16_t GetLocalPort () const { return m_LocalPort; };
|
||||||
|
|
||||||
void HandleDataMessagePayload (const uint8_t * buf, size_t len);
|
void HandleDataMessagePayload (const uint8_t * buf, size_t len);
|
||||||
|
|
||||||
@ -197,6 +199,7 @@ namespace stream
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
i2p::client::ClientDestination& m_Owner;
|
i2p::client::ClientDestination& m_Owner;
|
||||||
|
uint16_t m_LocalPort;
|
||||||
std::mutex m_StreamsMutex;
|
std::mutex m_StreamsMutex;
|
||||||
std::map<uint32_t, std::shared_ptr<Stream> > m_Streams;
|
std::map<uint32_t, std::shared_ptr<Stream> > m_Streams;
|
||||||
Acceptor m_Acceptor;
|
Acceptor m_Acceptor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user