2020-05-22 13:18:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2020, 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-10 23:19:49 +00:00
|
|
|
#ifndef TUNNEL_ENDPOINT_H__
|
|
|
|
#define TUNNEL_ENDPOINT_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include "I2NPProtocol.h"
|
|
|
|
#include "TunnelBase.h"
|
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace tunnel
|
|
|
|
{
|
|
|
|
class TunnelEndpoint
|
2018-01-06 03:48:51 +00:00
|
|
|
{
|
2014-07-05 00:54:03 +00:00
|
|
|
struct TunnelMessageBlockEx: public TunnelMessageBlock
|
|
|
|
{
|
2016-12-06 21:23:52 +00:00
|
|
|
uint64_t receiveTime; // milliseconds since epoch
|
2014-07-05 00:54:03 +00:00
|
|
|
uint8_t nextFragmentNum;
|
2018-01-06 03:48:51 +00:00
|
|
|
};
|
2014-09-11 01:31:32 +00:00
|
|
|
|
|
|
|
struct Fragment
|
|
|
|
{
|
|
|
|
bool isLastFragment;
|
2015-06-19 18:38:31 +00:00
|
|
|
std::shared_ptr<I2NPMessage> data;
|
2016-11-09 19:51:55 +00:00
|
|
|
uint64_t receiveTime; // milliseconds since epoch
|
2018-01-06 03:48:51 +00:00
|
|
|
};
|
|
|
|
|
2013-11-10 23:19:49 +00:00
|
|
|
public:
|
|
|
|
|
2014-07-10 16:44:49 +00:00
|
|
|
TunnelEndpoint (bool isInbound): m_IsInbound (isInbound), m_NumReceivedBytes (0) {};
|
2014-07-05 12:33:08 +00:00
|
|
|
~TunnelEndpoint ();
|
2013-12-10 13:10:49 +00:00
|
|
|
size_t GetNumReceivedBytes () const { return m_NumReceivedBytes; };
|
2018-01-06 03:48:51 +00:00
|
|
|
void Cleanup ();
|
2016-11-09 19:51:55 +00:00
|
|
|
|
2015-06-19 18:38:31 +00:00
|
|
|
void HandleDecryptedTunnelDataMsg (std::shared_ptr<I2NPMessage> msg);
|
2013-11-10 23:19:49 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2014-07-05 00:54:03 +00:00
|
|
|
void HandleFollowOnFragment (uint32_t msgID, bool isLastFragment, const TunnelMessageBlockEx& m);
|
2013-11-10 23:19:49 +00:00
|
|
|
void HandleNextMessage (const TunnelMessageBlock& msg);
|
2014-09-11 01:31:32 +00:00
|
|
|
|
2015-06-19 18:38:31 +00:00
|
|
|
void AddOutOfSequenceFragment (uint32_t msgID, uint8_t fragmentNum, bool isLastFragment, std::shared_ptr<I2NPMessage> data);
|
2016-11-08 20:37:27 +00:00
|
|
|
bool ConcatNextOutOfSequenceFragment (uint32_t msgID, TunnelMessageBlockEx& msg); // true if something added
|
2018-01-06 03:48:51 +00:00
|
|
|
void HandleOutOfSequenceFragments (uint32_t msgID, TunnelMessageBlockEx& msg);
|
2016-11-08 20:37:27 +00:00
|
|
|
|
2018-01-06 03:48:51 +00:00
|
|
|
private:
|
2014-06-11 14:56:20 +00:00
|
|
|
|
|
|
|
std::map<uint32_t, TunnelMessageBlockEx> m_IncompleteMessages;
|
2016-11-08 20:37:27 +00:00
|
|
|
std::map<std::pair<uint32_t, uint8_t>, Fragment> m_OutOfSequenceFragments; // (msgID, fragment#)->fragment
|
2014-07-10 16:44:49 +00:00
|
|
|
bool m_IsInbound;
|
2013-12-10 13:10:49 +00:00
|
|
|
size_t m_NumReceivedBytes;
|
2018-01-06 03:48:51 +00:00
|
|
|
};
|
|
|
|
}
|
2013-11-10 23:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|