Skip to content

Commit

Permalink
handle local destination port
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Mar 2, 2015
1 parent ac57e7c commit 0f8ea92
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Datagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions Datagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand All @@ -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:

Expand Down
7 changes: 5 additions & 2 deletions Destination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ElGamal.h"
#include "Timestamp.h"
#include "NetDb.h"
#include "AddressBook.h"
#include "Destination.h"

namespace i2p
Expand Down Expand Up @@ -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:
}

Expand Down Expand Up @@ -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:
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Streaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion Streaming.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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);

Expand All @@ -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;
Expand Down

0 comments on commit 0f8ea92

Please sign in to comment.