i2pd/libi2pd/TunnelEndpoint.h

67 lines
1.7 KiB
C
Raw Normal View History

/*
* Copyright (c) 2013-2021, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
* See full license text in LICENSE file at top of project tree
*/
2013-11-11 03:19:49 +04:00
#ifndef TUNNEL_ENDPOINT_H__
#define TUNNEL_ENDPOINT_H__
#include <inttypes.h>
#include <map>
#include <unordered_map>
2013-11-11 03:19:49 +04:00
#include <string>
#include "I2NPProtocol.h"
#include "TunnelBase.h"
namespace i2p
{
namespace tunnel
{
class TunnelEndpoint
2018-01-06 06:48:51 +03:00
{
2014-07-05 04:54:03 +04:00
struct TunnelMessageBlockEx: public TunnelMessageBlock
{
2016-12-07 00:23:52 +03:00
uint64_t receiveTime; // milliseconds since epoch
2014-07-05 04:54:03 +04:00
uint8_t nextFragmentNum;
2018-01-06 06:48:51 +03:00
};
struct Fragment
{
bool isLastFragment;
std::shared_ptr<I2NPMessage> data;
uint64_t receiveTime; // milliseconds since epoch
2018-01-06 06:48:51 +03:00
};
2013-11-11 03:19:49 +04:00
public:
TunnelEndpoint (bool isInbound): m_IsInbound (isInbound), m_NumReceivedBytes (0) {};
2014-07-05 16:33:08 +04:00
~TunnelEndpoint ();
2013-12-10 17:10:49 +04:00
size_t GetNumReceivedBytes () const { return m_NumReceivedBytes; };
2018-01-06 06:48:51 +03:00
void Cleanup ();
void HandleDecryptedTunnelDataMsg (std::shared_ptr<I2NPMessage> msg);
2013-11-11 03:19:49 +04:00
private:
2014-07-05 04:54:03 +04:00
void HandleFollowOnFragment (uint32_t msgID, bool isLastFragment, const TunnelMessageBlockEx& m);
2013-11-11 03:19:49 +04:00
void HandleNextMessage (const TunnelMessageBlock& msg);
void AddOutOfSequenceFragment (uint32_t msgID, uint8_t fragmentNum, bool isLastFragment, std::shared_ptr<I2NPMessage> data);
bool ConcatNextOutOfSequenceFragment (uint32_t msgID, TunnelMessageBlockEx& msg); // true if something added
2018-01-06 06:48:51 +03:00
void HandleOutOfSequenceFragments (uint32_t msgID, TunnelMessageBlockEx& msg);
2018-01-06 06:48:51 +03:00
private:
2014-06-11 18:56:20 +04:00
std::unordered_map<uint32_t, TunnelMessageBlockEx> m_IncompleteMessages;
std::map<std::pair<uint32_t, uint8_t>, Fragment> m_OutOfSequenceFragments; // (msgID, fragment#)->fragment
bool m_IsInbound;
2013-12-10 17:10:49 +04:00
size_t m_NumReceivedBytes;
2018-01-06 06:48:51 +03:00
};
}
2013-11-11 03:19:49 +04:00
}
#endif