Skip to content

Commit cc91a6d

Browse files
committed
send ports with datagram
1 parent 96ace89 commit cc91a6d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Datagram.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace datagram
1717
{
1818
}
1919

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

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

133133
}
134134

135-
I2NPMessage * DatagramDestination::CreateDataMessage (const uint8_t * payload, size_t len)
135+
I2NPMessage * DatagramDestination::CreateDataMessage (const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort)
136136
{
137137
I2NPMessage * msg = NewI2NPMessage ();
138138
CryptoPP::Gzip compressor; // default level
@@ -143,7 +143,8 @@ namespace datagram
143143
htobe32buf (buf, size); // length
144144
buf += 4;
145145
compressor.Get (buf, size);
146-
memset (buf + 4, 0, 4); // source and destination are zeroes
146+
htobe16buf (buf + 4, fromPort); // source port
147+
htobe16buf (buf + 6, toPort); // destination port
147148
buf[9] = i2p::client::PROTOCOL_TYPE_DATAGRAM; // datagram protocol
148149
msg->len += size + 4;
149150
FillI2NPMessageHeader (msg, eI2NPData);

Datagram.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace datagram
2626
DatagramDestination (i2p::client::ClientDestination& owner);
2727
~DatagramDestination () {};
2828

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

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

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

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

0 commit comments

Comments
 (0)