Browse Source

eliminated cast to DeliveryStatus struct

pull/130/head
orignal 10 years ago
parent
commit
b30de01b12
  1. 3
      Destination.cpp
  2. 15
      I2NPProtocol.cpp
  3. 44
      I2NPProtocol.h
  4. 2
      TunnelGateway.cpp

3
Destination.cpp

@ -288,8 +288,7 @@ namespace client
void ClientDestination::HandleDeliveryStatusMessage (I2NPMessage * msg) void ClientDestination::HandleDeliveryStatusMessage (I2NPMessage * msg)
{ {
I2NPDeliveryStatusMsg * deliveryStatus = (I2NPDeliveryStatusMsg *)msg->GetPayload (); uint32_t msgID = bufbe32toh (msg->GetPayload () + DELIVERY_STATUS_MSGID_OFFSET);
uint32_t msgID = bufbe32toh (&(deliveryStatus->msgID));
if (msgID == m_PublishReplyToken) if (msgID == m_PublishReplyToken)
{ {
LogPrint (eLogDebug, "Publishing confirmed"); LogPrint (eLogDebug, "Publishing confirmed");

15
I2NPProtocol.cpp

@ -82,18 +82,21 @@ namespace i2p
I2NPMessage * CreateDeliveryStatusMsg (uint32_t msgID) I2NPMessage * CreateDeliveryStatusMsg (uint32_t msgID)
{ {
I2NPDeliveryStatusMsg msg; I2NPMessage * m = NewI2NPMessage ();
uint8_t * buf = m->GetPayload ();
if (msgID) if (msgID)
{ {
msg.msgID = htobe32 (msgID); htobe32buf (buf + DELIVERY_STATUS_MSGID_OFFSET, msgID);
msg.timestamp = htobe64 (i2p::util::GetMillisecondsSinceEpoch ()); htobe64buf (buf + DELIVERY_STATUS_TIMESTAMP_OFFSET, i2p::util::GetMillisecondsSinceEpoch ());
} }
else // for SSU establishment else // for SSU establishment
{ {
msg.msgID = htobe32 (i2p::context.GetRandomNumberGenerator ().GenerateWord32 ()); htobe32buf (buf + DELIVERY_STATUS_MSGID_OFFSET, i2p::context.GetRandomNumberGenerator ().GenerateWord32 ());
msg.timestamp = htobe64 (2); // netID = 2 htobe64buf (buf + DELIVERY_STATUS_TIMESTAMP_OFFSET, 2); // netID = 2
} }
return CreateI2NPMessage (eI2NPDeliveryStatus, (uint8_t *)&msg, sizeof (msg)); m->len += DELIVERY_STATUS_SIZE;
FillI2NPMessageHeader (m, eI2NPDeliveryStatus);
return m;
} }
I2NPMessage * CreateDatabaseLookupMsg (const uint8_t * key, const uint8_t * from, I2NPMessage * CreateDatabaseLookupMsg (const uint8_t * key, const uint8_t * from,

44
I2NPProtocol.h

@ -30,6 +30,11 @@ namespace i2p
const size_t TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET = TUNNEL_GATEWAY_HEADER_TUNNELID_OFFSET + 4; const size_t TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET = TUNNEL_GATEWAY_HEADER_TUNNELID_OFFSET + 4;
const size_t TUNNEL_GATEWAY_HEADER_SIZE = TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET + 2; const size_t TUNNEL_GATEWAY_HEADER_SIZE = TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET + 2;
// DeliveryStatus
const size_t DELIVERY_STATUS_MSGID_OFFSET = 0;
const size_t DELIVERY_STATUS_TIMESTAMP_OFFSET = DELIVERY_STATUS_MSGID_OFFSET + 4;
const size_t DELIVERY_STATUS_SIZE = DELIVERY_STATUS_TIMESTAMP_OFFSET + 8;
#pragma pack (1) #pragma pack (1)
struct I2NPDatabaseStoreMsg struct I2NPDatabaseStoreMsg
@ -39,12 +44,6 @@ namespace i2p
uint32_t replyToken; uint32_t replyToken;
}; };
struct I2NPDeliveryStatusMsg
{
uint32_t msgID;
uint64_t timestamp;
};
struct I2NPBuildRequestRecordClearText struct I2NPBuildRequestRecordClearText
{ {
uint32_t receiveTunnel; uint32_t receiveTunnel;
@ -109,27 +108,26 @@ namespace tunnel
i2p::tunnel::InboundTunnel * from; i2p::tunnel::InboundTunnel * from;
I2NPMessage (): buf (nullptr),len (I2NP_HEADER_SIZE + 2), I2NPMessage (): buf (nullptr),len (I2NP_HEADER_SIZE + 2),
offset(2), maxLen (0), from (nullptr) {}; offset(2), maxLen (0), from (nullptr) {}; // reserve 2 bytes for NTCP header
// reserve 2 bytes for NTCP header
// I2NPHeader * GetHeader () { return (I2NPHeader *)GetBuffer (); }; // depricated
// header accessors // header accessors
uint8_t * GetHeaderBuffer () { return GetBuffer (); }; uint8_t * GetHeader () { return GetBuffer (); };
const uint8_t * GetHeaderBuffer () const { return GetBuffer (); }; const uint8_t * GetHeader () const { return GetBuffer (); };
void SetTypeID (uint8_t typeID) { GetHeaderBuffer ()[I2NP_HEADER_TYPEID_OFFSET] = typeID; }; void SetTypeID (uint8_t typeID) { GetHeader ()[I2NP_HEADER_TYPEID_OFFSET] = typeID; };
uint8_t GetTypeID () const { return GetHeaderBuffer ()[I2NP_HEADER_TYPEID_OFFSET]; }; uint8_t GetTypeID () const { return GetHeader ()[I2NP_HEADER_TYPEID_OFFSET]; };
void SetMsgID (uint32_t msgID) { htobe32buf (GetHeaderBuffer () + I2NP_HEADER_MSGID_OFFSET, msgID); }; void SetMsgID (uint32_t msgID) { htobe32buf (GetHeader () + I2NP_HEADER_MSGID_OFFSET, msgID); };
uint32_t GetMsgID () const { return bufbe32toh (GetHeaderBuffer () + I2NP_HEADER_MSGID_OFFSET); }; uint32_t GetMsgID () const { return bufbe32toh (GetHeader () + I2NP_HEADER_MSGID_OFFSET); };
void SetExpiration (uint64_t expiration) { htobe64buf (GetHeaderBuffer () + I2NP_HEADER_EXPIRATION_OFFSET, expiration); }; void SetExpiration (uint64_t expiration) { htobe64buf (GetHeader () + I2NP_HEADER_EXPIRATION_OFFSET, expiration); };
uint64_t GetExpiration () const { return bufbe64toh (GetHeaderBuffer () + I2NP_HEADER_EXPIRATION_OFFSET); }; uint64_t GetExpiration () const { return bufbe64toh (GetHeader () + I2NP_HEADER_EXPIRATION_OFFSET); };
void SetSize (uint16_t size) { htobe16buf (GetHeaderBuffer () + I2NP_HEADER_SIZE_OFFSET, size); }; void SetSize (uint16_t size) { htobe16buf (GetHeader () + I2NP_HEADER_SIZE_OFFSET, size); };
uint16_t GetSize () const { return bufbe16toh (GetHeaderBuffer () + I2NP_HEADER_SIZE_OFFSET); }; uint16_t GetSize () const { return bufbe16toh (GetHeader () + I2NP_HEADER_SIZE_OFFSET); };
void UpdateSize () { SetSize (GetPayloadLength ()); }; void UpdateSize () { SetSize (GetPayloadLength ()); };
void SetChks (uint8_t chks) { GetHeaderBuffer ()[I2NP_HEADER_CHKS_OFFSET] = chks; }; void SetChks (uint8_t chks) { GetHeader ()[I2NP_HEADER_CHKS_OFFSET] = chks; };
void UpdateChks () void UpdateChks ()
{ {
uint8_t hash[32]; uint8_t hash[32];
CryptoPP::SHA256().CalculateDigest(hash, GetPayload (), GetPayloadLength ()); CryptoPP::SHA256().CalculateDigest(hash, GetPayload (), GetPayloadLength ());
GetHeaderBuffer ()[I2NP_HEADER_CHKS_OFFSET] = hash[0]; GetHeader ()[I2NP_HEADER_CHKS_OFFSET] = hash[0];
} }
// payload // payload
@ -162,7 +160,7 @@ namespace tunnel
void FromSSU (uint32_t msgID) // we have received SSU message and convert it to regular void FromSSU (uint32_t msgID) // we have received SSU message and convert it to regular
{ {
const uint8_t * ssu = GetSSUHeader (); const uint8_t * ssu = GetSSUHeader ();
GetHeaderBuffer ()[I2NP_HEADER_TYPEID_OFFSET] = ssu[I2NP_SHORT_HEADER_TYPEID_OFFSET]; // typeid GetHeader ()[I2NP_HEADER_TYPEID_OFFSET] = ssu[I2NP_SHORT_HEADER_TYPEID_OFFSET]; // typeid
SetMsgID (msgID); SetMsgID (msgID);
SetExpiration (bufbe32toh (ssu + I2NP_SHORT_HEADER_EXPIRATION_OFFSET)*1000LL); SetExpiration (bufbe32toh (ssu + I2NP_SHORT_HEADER_EXPIRATION_OFFSET)*1000LL);
SetSize (len - offset - I2NP_HEADER_SIZE); SetSize (len - offset - I2NP_HEADER_SIZE);
@ -171,7 +169,7 @@ namespace tunnel
uint32_t ToSSU () // return msgID uint32_t ToSSU () // return msgID
{ {
uint8_t header[I2NP_HEADER_SIZE]; uint8_t header[I2NP_HEADER_SIZE];
memcpy (header, GetHeaderBuffer (), I2NP_HEADER_SIZE); memcpy (header, GetHeader (), I2NP_HEADER_SIZE);
uint8_t * ssu = GetSSUHeader (); uint8_t * ssu = GetSSUHeader ();
ssu[I2NP_SHORT_HEADER_TYPEID_OFFSET] = header[I2NP_HEADER_TYPEID_OFFSET]; // typeid ssu[I2NP_SHORT_HEADER_TYPEID_OFFSET] = header[I2NP_HEADER_TYPEID_OFFSET]; // typeid
htobe32buf (ssu + I2NP_SHORT_HEADER_EXPIRATION_OFFSET, bufbe64toh (header + I2NP_HEADER_EXPIRATION_OFFSET)/1000LL); htobe32buf (ssu + I2NP_SHORT_HEADER_EXPIRATION_OFFSET, bufbe64toh (header + I2NP_HEADER_EXPIRATION_OFFSET)/1000LL);

2
TunnelGateway.cpp

@ -69,7 +69,7 @@ namespace tunnel
{ {
// delivery instructions fit // delivery instructions fit
uint32_t msgID; uint32_t msgID;
memcpy (&msgID, msg->GetHeaderBuffer () + I2NP_HEADER_MSGID_OFFSET, 4); // in network bytes order memcpy (&msgID, msg->GetHeader () + I2NP_HEADER_MSGID_OFFSET, 4); // in network bytes order
size_t size = m_RemainingSize - diLen - 6; // 6 = 4 (msgID) + 2 (size) size_t size = m_RemainingSize - diLen - 6; // 6 = 4 (msgID) + 2 (size)
// first fragment // first fragment

Loading…
Cancel
Save