Browse Source

move FillI2NPMessageHeader into I2NPMessage

pull/225/head
orignal 10 years ago
parent
commit
bf14b7da9a
  1. 2
      Datagram.cpp
  2. 2
      Garlic.cpp
  3. 49
      I2NPProtocol.cpp
  4. 5
      I2NPProtocol.h
  5. 2
      NetDb.cpp
  6. 2
      Streaming.cpp
  7. 2
      TransitTunnel.cpp
  8. 2
      Tunnel.cpp
  9. 2
      TunnelGateway.cpp

2
Datagram.cpp

@ -143,7 +143,7 @@ namespace datagram
htobe16buf (buf + 6, toPort); // destination port htobe16buf (buf + 6, toPort); // destination port
buf[9] = i2p::client::PROTOCOL_TYPE_DATAGRAM; // datagram protocol buf[9] = i2p::client::PROTOCOL_TYPE_DATAGRAM; // datagram protocol
msg->len += size + 4; msg->len += size + 4;
FillI2NPMessageHeader (msg, eI2NPData); msg->FillI2NPMessageHeader (eI2NPData);
return msg; return msg;
} }
} }

2
Garlic.cpp

@ -167,7 +167,7 @@ namespace garlic
len += CreateAESBlock (buf, msg.get ()); // TODO len += CreateAESBlock (buf, msg.get ()); // TODO
htobe32buf (m->GetPayload (), len); htobe32buf (m->GetPayload (), len);
m->len += len + 4; m->len += len + 4;
FillI2NPMessageHeader (m.get (), eI2NPGarlic); // TODO m->FillI2NPMessageHeader (eI2NPGarlic);
return m; return m;
} }

49
I2NPProtocol.cpp

@ -41,25 +41,22 @@ namespace i2p
return std::shared_ptr<I2NPMessage>(msg, DeleteI2NPMessage); return std::shared_ptr<I2NPMessage>(msg, DeleteI2NPMessage);
} }
void FillI2NPMessageHeader (I2NPMessage * msg, I2NPMessageType msgType, uint32_t replyMsgID) void I2NPMessage::FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID)
{ {
msg->SetTypeID (msgType); SetTypeID (msgType);
if (replyMsgID) // for tunnel creation if (replyMsgID) // for tunnel creation
msg->SetMsgID (replyMsgID); SetMsgID (replyMsgID);
else else
msg->SetMsgID (i2p::context.GetRandomNumberGenerator ().GenerateWord32 ()); SetMsgID (i2p::context.GetRandomNumberGenerator ().GenerateWord32 ());
msg->SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 5000); // TODO: 5 secs is a magic number SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 5000); // TODO: 5 secs is a magic number
msg->UpdateSize (); UpdateSize ();
msg->UpdateChks (); UpdateChks ();
} }
void RenewI2NPMessageHeader (I2NPMessage * msg) void I2NPMessage::RenewI2NPMessageHeader ()
{ {
if (msg) SetMsgID (i2p::context.GetRandomNumberGenerator ().GenerateWord32 ());
{ SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 5000);
msg->SetMsgID (i2p::context.GetRandomNumberGenerator ().GenerateWord32 ());
msg->SetExpiration (i2p::util::GetMillisecondsSinceEpoch () + 5000);
}
} }
I2NPMessage * CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, int len, uint32_t replyMsgID) I2NPMessage * CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, int len, uint32_t replyMsgID)
@ -72,7 +69,7 @@ namespace i2p
} }
else else
LogPrint (eLogError, "I2NP message length ", len, " exceeds max length"); LogPrint (eLogError, "I2NP message length ", len, " exceeds max length");
FillI2NPMessageHeader (msg, msgType, replyMsgID); msg->FillI2NPMessageHeader (msgType, replyMsgID);
return msg; return msg;
} }
@ -105,7 +102,7 @@ namespace i2p
htobe64buf (buf + DELIVERY_STATUS_TIMESTAMP_OFFSET, 2); // netID = 2 htobe64buf (buf + DELIVERY_STATUS_TIMESTAMP_OFFSET, 2); // netID = 2
} }
m->len += DELIVERY_STATUS_SIZE; m->len += DELIVERY_STATUS_SIZE;
FillI2NPMessageHeader (m, eI2NPDeliveryStatus); m->FillI2NPMessageHeader (eI2NPDeliveryStatus);
return ToSharedI2NPMessage (m); return ToSharedI2NPMessage (m);
} }
@ -150,7 +147,7 @@ namespace i2p
} }
m->len += (buf - m->GetPayload ()); m->len += (buf - m->GetPayload ());
FillI2NPMessageHeader (m, eI2NPDatabaseLookup); m->FillI2NPMessageHeader (eI2NPDatabaseLookup);
return m; return m;
} }
@ -187,7 +184,7 @@ namespace i2p
buf += 65; buf += 65;
m->len += (buf - m->GetPayload ()); m->len += (buf - m->GetPayload ());
FillI2NPMessageHeader (m, eI2NPDatabaseLookup); m->FillI2NPMessageHeader (eI2NPDatabaseLookup);
return m; return m;
} }
@ -211,7 +208,7 @@ namespace i2p
memcpy (buf + len, i2p::context.GetRouterInfo ().GetIdentHash (), 32); memcpy (buf + len, i2p::context.GetRouterInfo ().GetIdentHash (), 32);
len += 32; len += 32;
m->len += len; m->len += len;
FillI2NPMessageHeader (m, eI2NPDatabaseSearchReply); m->FillI2NPMessageHeader (eI2NPDatabaseSearchReply);
return m; return m;
} }
@ -245,7 +242,7 @@ namespace i2p
compressor.Get (buf, size); compressor.Get (buf, size);
buf += size; buf += size;
m->len += (buf - payload); // payload size m->len += (buf - payload); // payload size
FillI2NPMessageHeader (m, eI2NPDatabaseStore); m->FillI2NPMessageHeader (eI2NPDatabaseStore);
return m; return m;
} }
@ -275,7 +272,7 @@ namespace i2p
memcpy (payload + size, leaseSet->GetBuffer (), leaseSet->GetBufferLen ()); memcpy (payload + size, leaseSet->GetBuffer (), leaseSet->GetBufferLen ());
size += leaseSet->GetBufferLen (); size += leaseSet->GetBufferLen ();
m->len += size; m->len += size;
FillI2NPMessageHeader (m, eI2NPDatabaseStore); m->FillI2NPMessageHeader (eI2NPDatabaseStore);
return m; return m;
} }
@ -419,7 +416,7 @@ namespace i2p
I2NPMessage * msg = NewI2NPShortMessage (); I2NPMessage * msg = NewI2NPShortMessage ();
memcpy (msg->GetPayload (), buf, i2p::tunnel::TUNNEL_DATA_MSG_SIZE); memcpy (msg->GetPayload (), buf, i2p::tunnel::TUNNEL_DATA_MSG_SIZE);
msg->len += i2p::tunnel::TUNNEL_DATA_MSG_SIZE; msg->len += i2p::tunnel::TUNNEL_DATA_MSG_SIZE;
FillI2NPMessageHeader (msg, eI2NPTunnelData); msg->FillI2NPMessageHeader (eI2NPTunnelData);
return msg; return msg;
} }
@ -429,7 +426,7 @@ namespace i2p
memcpy (msg->GetPayload () + 4, payload, i2p::tunnel::TUNNEL_DATA_MSG_SIZE - 4); memcpy (msg->GetPayload () + 4, payload, i2p::tunnel::TUNNEL_DATA_MSG_SIZE - 4);
htobe32buf (msg->GetPayload (), tunnelID); htobe32buf (msg->GetPayload (), tunnelID);
msg->len += i2p::tunnel::TUNNEL_DATA_MSG_SIZE; msg->len += i2p::tunnel::TUNNEL_DATA_MSG_SIZE;
FillI2NPMessageHeader (msg, eI2NPTunnelData); msg->FillI2NPMessageHeader (eI2NPTunnelData);
return msg; return msg;
} }
@ -448,7 +445,7 @@ namespace i2p
htobe16buf (payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len); htobe16buf (payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len);
memcpy (payload + TUNNEL_GATEWAY_HEADER_SIZE, buf, len); memcpy (payload + TUNNEL_GATEWAY_HEADER_SIZE, buf, len);
msg->len += TUNNEL_GATEWAY_HEADER_SIZE + len; msg->len += TUNNEL_GATEWAY_HEADER_SIZE + len;
FillI2NPMessageHeader (msg, eI2NPTunnelGateway); msg->FillI2NPMessageHeader (eI2NPTunnelGateway);
return msg; return msg;
} }
@ -463,7 +460,7 @@ namespace i2p
htobe16buf (payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len); htobe16buf (payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len);
msg->offset -= (I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE); msg->offset -= (I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE);
msg->len = msg->offset + I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE +len; msg->len = msg->offset + I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE +len;
FillI2NPMessageHeader (msg.get(), eI2NPTunnelGateway); // TODO msg->FillI2NPMessageHeader (eI2NPTunnelGateway);
return msg; return msg;
} }
else else
@ -482,13 +479,13 @@ namespace i2p
msg->len += gatewayMsgOffset; msg->len += gatewayMsgOffset;
memcpy (msg->GetPayload (), buf, len); memcpy (msg->GetPayload (), buf, len);
msg->len += len; msg->len += len;
FillI2NPMessageHeader (msg, msgType, replyMsgID); // create content message msg->FillI2NPMessageHeader (msgType, replyMsgID); // create content message
len = msg->GetLength (); len = msg->GetLength ();
msg->offset -= gatewayMsgOffset; msg->offset -= gatewayMsgOffset;
uint8_t * payload = msg->GetPayload (); uint8_t * payload = msg->GetPayload ();
htobe32buf (payload + TUNNEL_GATEWAY_HEADER_TUNNELID_OFFSET, tunnelID); htobe32buf (payload + TUNNEL_GATEWAY_HEADER_TUNNELID_OFFSET, tunnelID);
htobe16buf (payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len); htobe16buf (payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len);
FillI2NPMessageHeader (msg, eI2NPTunnelGateway); // gateway message msg->FillI2NPMessageHeader (eI2NPTunnelGateway); // gateway message
return msg; return msg;
} }

5
I2NPProtocol.h

@ -184,6 +184,9 @@ namespace tunnel
len = offset + I2NP_SHORT_HEADER_SIZE + bufbe16toh (header + I2NP_HEADER_SIZE_OFFSET); len = offset + I2NP_SHORT_HEADER_SIZE + bufbe16toh (header + I2NP_HEADER_SIZE_OFFSET);
return bufbe32toh (header + I2NP_HEADER_MSGID_OFFSET); return bufbe32toh (header + I2NP_HEADER_MSGID_OFFSET);
} }
void FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID = 0);
void RenewI2NPMessageHeader ();
}; };
template<int sz> template<int sz>
@ -199,8 +202,6 @@ namespace tunnel
void DeleteI2NPMessage (I2NPMessage * msg); void DeleteI2NPMessage (I2NPMessage * msg);
std::shared_ptr<I2NPMessage> ToSharedI2NPMessage (I2NPMessage * msg); std::shared_ptr<I2NPMessage> ToSharedI2NPMessage (I2NPMessage * msg);
void FillI2NPMessageHeader (I2NPMessage * msg, I2NPMessageType msgType, uint32_t replyMsgID = 0);
void RenewI2NPMessageHeader (I2NPMessage * msg);
I2NPMessage * CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, int len, uint32_t replyMsgID = 0); I2NPMessage * CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, int len, uint32_t replyMsgID = 0);
std::shared_ptr<I2NPMessage> CreateI2NPMessage (const uint8_t * buf, int len, std::shared_ptr<i2p::tunnel::InboundTunnel> from = nullptr); std::shared_ptr<I2NPMessage> CreateI2NPMessage (const uint8_t * buf, int len, std::shared_ptr<i2p::tunnel::InboundTunnel> from = nullptr);

2
NetDb.cpp

@ -492,7 +492,7 @@ namespace data
htobe32buf (payload + DATABASE_STORE_REPLY_TOKEN_OFFSET, 0); // zero reply token htobe32buf (payload + DATABASE_STORE_REPLY_TOKEN_OFFSET, 0); // zero reply token
memcpy (payload + DATABASE_STORE_HEADER_SIZE, buf + offset, len - offset); memcpy (payload + DATABASE_STORE_HEADER_SIZE, buf + offset, len - offset);
floodMsg->len += DATABASE_STORE_HEADER_SIZE + len -offset; floodMsg->len += DATABASE_STORE_HEADER_SIZE + len -offset;
FillI2NPMessageHeader (floodMsg.get (), eI2NPDatabaseStore); // TODO floodMsg->FillI2NPMessageHeader (eI2NPDatabaseStore);
std::set<IdentHash> excluded; std::set<IdentHash> excluded;
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {

2
Streaming.cpp

@ -780,7 +780,7 @@ namespace stream
htobe16buf (buf + 6, m_Port); // destination port htobe16buf (buf + 6, m_Port); // destination port
buf[9] = i2p::client::PROTOCOL_TYPE_STREAMING; // streaming protocol buf[9] = i2p::client::PROTOCOL_TYPE_STREAMING; // streaming protocol
msg->len += size + 4; msg->len += size + 4;
FillI2NPMessageHeader (msg.get (), eI2NPData); // TODO: msg->FillI2NPMessageHeader (eI2NPData);
return msg; return msg;
} }

2
TransitTunnel.cpp

@ -36,7 +36,7 @@ namespace tunnel
m_NumTransmittedBytes += tunnelMsg->GetLength (); m_NumTransmittedBytes += tunnelMsg->GetLength ();
htobe32buf (newMsg->GetPayload (), GetNextTunnelID ()); htobe32buf (newMsg->GetPayload (), GetNextTunnelID ());
FillI2NPMessageHeader (newMsg.get (), eI2NPTunnelData); // TODO newMsg->FillI2NPMessageHeader (eI2NPTunnelData);
m_TunnelDataMsgs.push_back (newMsg); m_TunnelDataMsgs.push_back (newMsg);
} }

2
Tunnel.cpp

@ -77,7 +77,7 @@ namespace tunnel
} }
hop = hop->prev; hop = hop->prev;
} }
FillI2NPMessageHeader (msg, eI2NPVariableTunnelBuild); msg->FillI2NPMessageHeader (eI2NPVariableTunnelBuild);
// send message // send message
if (outboundTunnel) if (outboundTunnel)

2
TunnelGateway.cpp

@ -201,7 +201,7 @@ namespace tunnel
for (auto tunnelMsg : tunnelMsgs) for (auto tunnelMsg : tunnelMsgs)
{ {
m_Tunnel->EncryptTunnelMsg (tunnelMsg, tunnelMsg); m_Tunnel->EncryptTunnelMsg (tunnelMsg, tunnelMsg);
FillI2NPMessageHeader (tunnelMsg.get (), eI2NPTunnelData); // TODO: tunnelMsg->FillI2NPMessageHeader (eI2NPTunnelData);
m_NumSentBytes += TUNNEL_DATA_MSG_SIZE; m_NumSentBytes += TUNNEL_DATA_MSG_SIZE;
} }
i2p::transport::transports.SendMessages (m_Tunnel->GetNextIdentHash (), tunnelMsgs); i2p::transport::transports.SendMessages (m_Tunnel->GetNextIdentHash (), tunnelMsgs);

Loading…
Cancel
Save