Skip to content

Commit

Permalink
send ports with datagram
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Mar 27, 2015
1 parent 96ace89 commit cc91a6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions Datagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace datagram
{
}

void DatagramDestination::SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident)
void DatagramDestination::SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint16_t fromPort, uint16_t toPort)
{
uint8_t buf[MAX_DATAGRAM_SIZE];
auto identityLen = m_Owner.GetIdentity ().ToBuffer (buf, MAX_DATAGRAM_SIZE);
Expand All @@ -36,7 +36,7 @@ namespace datagram
else
m_Owner.Sign (buf1, len, signature);

auto msg = CreateDataMessage (buf, len + headerLen);
auto msg = CreateDataMessage (buf, len + headerLen, fromPort, toPort);
auto remote = m_Owner.FindLeaseSet (ident);
if (remote)
m_Owner.GetService ().post (std::bind (&DatagramDestination::SendMsg, this, msg, remote));
Expand Down Expand Up @@ -132,7 +132,7 @@ namespace datagram

}

I2NPMessage * DatagramDestination::CreateDataMessage (const uint8_t * payload, size_t len)
I2NPMessage * DatagramDestination::CreateDataMessage (const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort)
{
I2NPMessage * msg = NewI2NPMessage ();
CryptoPP::Gzip compressor; // default level
Expand All @@ -143,7 +143,8 @@ namespace datagram
htobe32buf (buf, size); // length
buf += 4;
compressor.Get (buf, size);
memset (buf + 4, 0, 4); // source and destination are zeroes
htobe16buf (buf + 4, fromPort); // source port
htobe16buf (buf + 6, toPort); // destination port
buf[9] = i2p::client::PROTOCOL_TYPE_DATAGRAM; // datagram protocol
msg->len += size + 4;
FillI2NPMessageHeader (msg, eI2NPData);
Expand Down
4 changes: 2 additions & 2 deletions Datagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace datagram
DatagramDestination (i2p::client::ClientDestination& owner);
~DatagramDestination () {};

void SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident);
void SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint16_t fromPort = 0, uint16_t toPort = 0);
void HandleDataMessagePayload (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);

void SetReceiver (const Receiver& receiver) { m_Receiver = receiver; };
Expand All @@ -36,7 +36,7 @@ namespace datagram

void HandleLeaseSetRequestComplete (bool success, I2NPMessage * msg, i2p::data::IdentHash ident);

I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len);
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort);
void SendMsg (I2NPMessage * msg, std::shared_ptr<const i2p::data::LeaseSet> remote);
void HandleDatagram (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);

Expand Down

0 comments on commit cc91a6d

Please sign in to comment.