mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-14 08:50:12 +00:00
use unique_ptr for sent fragments
This commit is contained in:
parent
79087f6942
commit
618abd6320
@ -115,10 +115,7 @@ namespace transport
|
|||||||
if (bitfield & mask)
|
if (bitfield & mask)
|
||||||
{
|
{
|
||||||
if (fragment < numSentFragments)
|
if (fragment < numSentFragments)
|
||||||
{
|
it->second->fragments[fragment].reset (nullptr);
|
||||||
delete it->second->fragments[fragment];
|
|
||||||
it->second->fragments[fragment] = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fragment++;
|
fragment++;
|
||||||
mask <<= 1;
|
mask <<= 1;
|
||||||
@ -312,7 +309,6 @@ namespace transport
|
|||||||
Fragment * fragment = new Fragment;
|
Fragment * fragment = new Fragment;
|
||||||
fragment->fragmentNum = fragmentNum;
|
fragment->fragmentNum = fragmentNum;
|
||||||
uint8_t * buf = fragment->buf;
|
uint8_t * buf = fragment->buf;
|
||||||
fragments.push_back (fragment);
|
|
||||||
uint8_t * payload = buf + sizeof (SSUHeader);
|
uint8_t * payload = buf + sizeof (SSUHeader);
|
||||||
*payload = DATA_FLAG_WANT_REPLY; // for compatibility
|
*payload = DATA_FLAG_WANT_REPLY; // for compatibility
|
||||||
payload++;
|
payload++;
|
||||||
@ -336,6 +332,7 @@ namespace transport
|
|||||||
if (size & 0x0F) // make sure 16 bytes boundary
|
if (size & 0x0F) // make sure 16 bytes boundary
|
||||||
size = ((size >> 4) + 1) << 4; // (/16 + 1)*16
|
size = ((size >> 4) + 1) << 4; // (/16 + 1)*16
|
||||||
fragment->len = size;
|
fragment->len = size;
|
||||||
|
fragments.push_back (std::unique_ptr<Fragment> (fragment));
|
||||||
|
|
||||||
// encrypt message with session key
|
// encrypt message with session key
|
||||||
m_Session.FillHeaderAndEncrypt (PAYLOAD_TYPE_DATA, buf, size);
|
m_Session.FillHeaderAndEncrypt (PAYLOAD_TYPE_DATA, buf, size);
|
||||||
@ -417,7 +414,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
if (ts >= it.second->nextResendTime && it.second->numResends < MAX_NUM_RESENDS)
|
if (ts >= it.second->nextResendTime && it.second->numResends < MAX_NUM_RESENDS)
|
||||||
{
|
{
|
||||||
for (auto f: it.second->fragments)
|
for (auto& f: it.second->fragments)
|
||||||
if (f) m_Session.Send (f->buf, f->len); // resend
|
if (f) m_Session.Send (f->buf, f->len); // resend
|
||||||
|
|
||||||
it.second->numResends++;
|
it.second->numResends++;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <memory>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
@ -65,11 +66,9 @@ namespace transport
|
|||||||
|
|
||||||
struct SentMessage
|
struct SentMessage
|
||||||
{
|
{
|
||||||
std::vector<Fragment *> fragments;
|
std::vector<std::unique_ptr<Fragment> > fragments;
|
||||||
uint32_t nextResendTime; // in seconds
|
uint32_t nextResendTime; // in seconds
|
||||||
int numResends;
|
int numResends;
|
||||||
|
|
||||||
~SentMessage () { for (auto it: fragments) { delete it; }; };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SSUSession;
|
class SSUSession;
|
||||||
|
Loading…
Reference in New Issue
Block a user