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

2
Garlic.cpp

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

49
I2NPProtocol.cpp

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

5
I2NPProtocol.h

@ -184,6 +184,9 @@ namespace tunnel @@ -184,6 +184,9 @@ namespace tunnel
len = offset + I2NP_SHORT_HEADER_SIZE + bufbe16toh (header + I2NP_HEADER_SIZE_OFFSET);
return bufbe32toh (header + I2NP_HEADER_MSGID_OFFSET);
}
void FillI2NPMessageHeader (I2NPMessageType msgType, uint32_t replyMsgID = 0);
void RenewI2NPMessageHeader ();
};
template<int sz>
@ -199,8 +202,6 @@ namespace tunnel @@ -199,8 +202,6 @@ namespace tunnel
void DeleteI2NPMessage (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);
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 @@ -492,7 +492,7 @@ namespace data
htobe32buf (payload + DATABASE_STORE_REPLY_TOKEN_OFFSET, 0); // zero reply token
memcpy (payload + DATABASE_STORE_HEADER_SIZE, buf + offset, len - offset);
floodMsg->len += DATABASE_STORE_HEADER_SIZE + len -offset;
FillI2NPMessageHeader (floodMsg.get (), eI2NPDatabaseStore); // TODO
floodMsg->FillI2NPMessageHeader (eI2NPDatabaseStore);
std::set<IdentHash> excluded;
for (int i = 0; i < 3; i++)
{

2
Streaming.cpp

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

2
TransitTunnel.cpp

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

2
Tunnel.cpp

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

2
TunnelGateway.cpp

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

Loading…
Cancel
Save