mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-27 11:17:49 +02:00
implement i2cp session reconfigure
This commit is contained in:
parent
7b00d828b2
commit
938d5d901a
5 changed files with 114 additions and 2 deletions
|
@ -416,8 +416,59 @@ namespace client
|
|||
|
||||
void I2CPSession::ReconfigureSessionMessageHandler (const uint8_t * buf, size_t len)
|
||||
{
|
||||
// TODO: implement actual reconfiguration
|
||||
SendSessionStatusMessage (2); // updated
|
||||
uint8_t status = 3; // rejected
|
||||
if(len > sizeof(uint16_t))
|
||||
{
|
||||
uint16_t sessionID = bufbe16toh(buf);
|
||||
if(sessionID == m_SessionID)
|
||||
{
|
||||
buf += sizeof(uint16_t);
|
||||
const uint8_t * body = buf;
|
||||
i2p::data::IdentityEx ident;
|
||||
if(ident.FromBuffer(buf, len - sizeof(uint16_t)))
|
||||
{
|
||||
if (ident == *m_Destination->GetIdentity())
|
||||
{
|
||||
size_t identsz = ident.GetFullLen();
|
||||
buf += identsz;
|
||||
uint16_t optssize = bufbe16toh(buf);
|
||||
if (optssize <= len - sizeof(uint16_t) - sizeof(uint64_t) - identsz - ident.GetSignatureLen() - sizeof(uint16_t))
|
||||
{
|
||||
buf += sizeof(uint16_t);
|
||||
std::map<std::string, std::string> opts;
|
||||
ExtractMapping(buf, optssize, opts);
|
||||
buf += optssize;
|
||||
//uint64_t date = bufbe64toh(buf);
|
||||
buf += sizeof(uint64_t);
|
||||
const uint8_t * sig = buf;
|
||||
if(ident.Verify(body, len - sizeof(uint16_t), sig))
|
||||
{
|
||||
if(m_Destination->Reconfigure(opts))
|
||||
{
|
||||
LogPrint(eLogInfo, "I2CP: reconfigured destination");
|
||||
status = 2; // updated
|
||||
}
|
||||
else
|
||||
LogPrint(eLogWarning, "I2CP: failed to reconfigure destination");
|
||||
}
|
||||
else
|
||||
LogPrint(eLogError, "I2CP: invalid reconfigure message signature");
|
||||
}
|
||||
else
|
||||
LogPrint(eLogError, "I2CP: mapping size missmatch");
|
||||
}
|
||||
else
|
||||
LogPrint(eLogError, "I2CP: destination missmatch");
|
||||
}
|
||||
else
|
||||
LogPrint(eLogError, "I2CP: malfromed destination");
|
||||
}
|
||||
else
|
||||
LogPrint(eLogError, "I2CP: session missmatch");
|
||||
}
|
||||
else
|
||||
LogPrint(eLogError, "I2CP: short message");
|
||||
SendSessionStatusMessage (status);
|
||||
}
|
||||
|
||||
void I2CPSession::SendSessionStatusMessage (uint8_t status)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue