Browse Source

handle local destination port

pull/163/head
orignal 10 years ago
parent
commit
0f8ea92a53
  1. 6
      Datagram.cpp
  2. 4
      Datagram.h
  3. 7
      Destination.cpp
  4. 2
      Streaming.cpp
  5. 5
      Streaming.h

6
Datagram.cpp

@ -67,7 +67,7 @@ namespace datagram @@ -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;
size_t identityLen = identity.FromBuffer (buf, len);
@ -91,7 +91,7 @@ namespace datagram @@ -91,7 +91,7 @@ namespace datagram
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
CryptoPP::Gunzip decompressor;
@ -102,7 +102,7 @@ namespace datagram @@ -102,7 +102,7 @@ namespace datagram
if (uncompressedLen <= MAX_DATAGRAM_SIZE)
{
decompressor.Get (uncompressed, uncompressedLen);
HandleDatagram (uncompressed, uncompressedLen);
HandleDatagram (fromPort, toPort, uncompressed, uncompressedLen);
}
else
LogPrint ("Received datagram size ", uncompressedLen, " exceeds max size");

4
Datagram.h

@ -27,7 +27,7 @@ namespace datagram @@ -27,7 +27,7 @@ namespace datagram
~DatagramDestination () {};
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 ResetReceiver () { m_Receiver = nullptr; };
@ -36,7 +36,7 @@ namespace datagram @@ -36,7 +36,7 @@ namespace datagram
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len);
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:

7
Destination.cpp

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
#include "ElGamal.h"
#include "Timestamp.h"
#include "NetDb.h"
#include "AddressBook.h"
#include "Destination.h"
namespace i2p
@ -46,7 +47,7 @@ namespace client @@ -46,7 +47,7 @@ namespace client
}
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (this, inboundTunnelLen, outboundTunnelLen);
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:
}
@ -367,6 +368,8 @@ namespace client @@ -367,6 +368,8 @@ namespace client
uint32_t length = bufbe32toh (buf);
buf += 4;
// we assume I2CP payload
uint16_t fromPort = bufbe16toh (buf + 4), // source
toPort = bufbe16toh (buf + 6); // destination
switch (buf[9])
{
case PROTOCOL_TYPE_STREAMING:
@ -379,7 +382,7 @@ namespace client @@ -379,7 +382,7 @@ namespace client
case PROTOCOL_TYPE_DATAGRAM:
// datagram protocol
if (m_DatagramDestination)
m_DatagramDestination->HandleDataMessagePayload (buf, length);
m_DatagramDestination->HandleDataMessagePayload (fromPort, toPort, buf, length);
else
LogPrint ("Missing streaming destination");
break;

2
Streaming.cpp

@ -661,7 +661,7 @@ namespace stream @@ -661,7 +661,7 @@ namespace stream
htobe32buf (buf, size); // length
buf += 4;
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
buf[9] = i2p::client::PROTOCOL_TYPE_STREAMING; // streaming protocol
msg->len += size + 4;

5
Streaming.h

@ -174,7 +174,8 @@ namespace stream @@ -174,7 +174,8 @@ namespace stream
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 () {};
void Start ();
@ -186,6 +187,7 @@ namespace stream @@ -186,6 +187,7 @@ namespace stream
void ResetAcceptor () { if (m_Acceptor) m_Acceptor (nullptr); m_Acceptor = nullptr; };
bool IsAcceptorSet () const { return m_Acceptor != nullptr; };
i2p::client::ClientDestination& GetOwner () { return m_Owner; };
uint16_t GetLocalPort () const { return m_LocalPort; };
void HandleDataMessagePayload (const uint8_t * buf, size_t len);
@ -197,6 +199,7 @@ namespace stream @@ -197,6 +199,7 @@ namespace stream
private:
i2p::client::ClientDestination& m_Owner;
uint16_t m_LocalPort;
std::mutex m_StreamsMutex;
std::map<uint32_t, std::shared_ptr<Stream> > m_Streams;
Acceptor m_Acceptor;

Loading…
Cancel
Save