2020-05-22 15:18:41 +02:00
|
|
|
/*
|
2021-06-22 21:35:44 +02:00
|
|
|
* Copyright (c) 2013-2021, The PurpleI2P Project
|
2020-05-22 15:18:41 +02:00
|
|
|
*
|
|
|
|
* 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 00:19:49 +01:00
|
|
|
#ifndef TUNNEL_ENDPOINT_H__
|
|
|
|
#define TUNNEL_ENDPOINT_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
2021-06-26 23:40:25 +02:00
|
|
|
#include <vector>
|
2013-11-11 00:19:49 +01:00
|
|
|
#include <string>
|
2021-09-25 01:12:12 +02:00
|
|
|
#include <boost/container/flat_map.hpp>
|
2013-11-11 00:19:49 +01:00
|
|
|
#include "I2NPProtocol.h"
|
|
|
|
#include "TunnelBase.h"
|
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace tunnel
|
|
|
|
{
|
|
|
|
class TunnelEndpoint
|
2018-01-06 04:48:51 +01:00
|
|
|
{
|
2014-07-05 02:54:03 +02:00
|
|
|
struct TunnelMessageBlockEx: public TunnelMessageBlock
|
|
|
|
{
|
2016-12-06 22:23:52 +01:00
|
|
|
uint64_t receiveTime; // milliseconds since epoch
|
2014-07-05 02:54:03 +02:00
|
|
|
uint8_t nextFragmentNum;
|
2018-01-06 04:48:51 +01:00
|
|
|
};
|
2014-09-11 03:31:32 +02:00
|
|
|
|
|
|
|
struct Fragment
|
|
|
|
{
|
2021-06-26 23:40:25 +02:00
|
|
|
Fragment (bool last, uint64_t t, size_t size): isLastFragment (last), receiveTime (t), data (size) {};
|
2014-09-11 03:31:32 +02:00
|
|
|
bool isLastFragment;
|
2016-11-09 20:51:55 +01:00
|
|
|
uint64_t receiveTime; // milliseconds since epoch
|
2021-06-26 23:40:25 +02:00
|
|
|
std::vector<uint8_t> data;
|
2018-01-06 04:48:51 +01:00
|
|
|
};
|
|
|
|
|
2013-11-11 00:19:49 +01:00
|
|
|
public:
|
|
|
|
|
2021-06-26 13:18:42 +02:00
|
|
|
TunnelEndpoint (bool isInbound): m_IsInbound (isInbound), m_NumReceivedBytes (0), m_CurrentMsgID (0) {};
|
2014-07-05 14:33:08 +02:00
|
|
|
~TunnelEndpoint ();
|
2013-12-10 14:10:49 +01:00
|
|
|
size_t GetNumReceivedBytes () const { return m_NumReceivedBytes; };
|
2018-01-06 04:48:51 +01:00
|
|
|
void Cleanup ();
|
2016-11-09 20:51:55 +01:00
|
|
|
|
2015-06-19 20:38:31 +02:00
|
|
|
void HandleDecryptedTunnelDataMsg (std::shared_ptr<I2NPMessage> msg);
|
2013-11-11 00:19:49 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2021-06-26 23:40:25 +02:00
|
|
|
void HandleFollowOnFragment (uint32_t msgID, bool isLastFragment, uint8_t fragmentNum, const uint8_t * fragment, size_t size);
|
2021-06-26 13:18:42 +02:00
|
|
|
bool ConcatFollowOnFragment (TunnelMessageBlockEx& msg, const uint8_t * fragment, size_t size) const; // true if success
|
|
|
|
void HandleCurrenMessageFollowOnFragment (const uint8_t * frgament, size_t size, bool isLastFragment);
|
2013-11-11 00:19:49 +01:00
|
|
|
void HandleNextMessage (const TunnelMessageBlock& msg);
|
2014-09-11 03:31:32 +02:00
|
|
|
|
2021-06-26 23:40:25 +02:00
|
|
|
void AddOutOfSequenceFragment (uint32_t msgID, uint8_t fragmentNum, bool isLastFragment, const uint8_t * fragment, size_t size);
|
2016-11-08 21:37:27 +01:00
|
|
|
bool ConcatNextOutOfSequenceFragment (uint32_t msgID, TunnelMessageBlockEx& msg); // true if something added
|
2018-01-06 04:48:51 +01:00
|
|
|
void HandleOutOfSequenceFragments (uint32_t msgID, TunnelMessageBlockEx& msg);
|
2021-06-26 13:18:42 +02:00
|
|
|
void AddIncompleteCurrentMessage ();
|
|
|
|
|
2018-01-06 04:48:51 +01:00
|
|
|
private:
|
2014-06-11 16:56:20 +02:00
|
|
|
|
2021-09-25 01:12:12 +02:00
|
|
|
boost::container::flat_map<uint32_t, TunnelMessageBlockEx> m_IncompleteMessages;
|
|
|
|
boost::container::flat_map<uint64_t, std::unique_ptr<Fragment> > m_OutOfSequenceFragments; // ((msgID << 8) + fragment#)->fragment
|
2014-07-10 18:44:49 +02:00
|
|
|
bool m_IsInbound;
|
2013-12-10 14:10:49 +01:00
|
|
|
size_t m_NumReceivedBytes;
|
2021-06-26 13:18:42 +02:00
|
|
|
TunnelMessageBlockEx m_CurrentMessage;
|
|
|
|
uint32_t m_CurrentMsgID;
|
2018-01-06 04:48:51 +01:00
|
|
|
};
|
|
|
|
}
|
2013-11-11 00:19:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|