TunnelEndpoint.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef TUNNEL_ENDPOINT_H__
  2. #define TUNNEL_ENDPOINT_H__
  3. #include <inttypes.h>
  4. #include <map>
  5. #include <string>
  6. #include "I2NPProtocol.h"
  7. #include "TunnelBase.h"
  8. namespace i2p
  9. {
  10. namespace tunnel
  11. {
  12. class TunnelEndpoint
  13. {
  14. struct TunnelMessageBlockEx: public TunnelMessageBlock
  15. {
  16. uint64_t receiveTime; // milliseconds since epoch
  17. uint8_t nextFragmentNum;
  18. };
  19. struct Fragment
  20. {
  21. bool isLastFragment;
  22. std::shared_ptr<I2NPMessage> data;
  23. uint64_t receiveTime; // milliseconds since epoch
  24. };
  25. public:
  26. TunnelEndpoint (bool isInbound): m_IsInbound (isInbound), m_NumReceivedBytes (0) {};
  27. ~TunnelEndpoint ();
  28. size_t GetNumReceivedBytes () const { return m_NumReceivedBytes; };
  29. void Cleanup ();
  30. void HandleDecryptedTunnelDataMsg (std::shared_ptr<I2NPMessage> msg);
  31. private:
  32. void HandleFollowOnFragment (uint32_t msgID, bool isLastFragment, const TunnelMessageBlockEx& m);
  33. void HandleNextMessage (const TunnelMessageBlock& msg);
  34. void AddOutOfSequenceFragment (uint32_t msgID, uint8_t fragmentNum, bool isLastFragment, std::shared_ptr<I2NPMessage> data);
  35. bool ConcatNextOutOfSequenceFragment (uint32_t msgID, TunnelMessageBlockEx& msg); // true if something added
  36. void HandleOutOfSequenceFragments (uint32_t msgID, TunnelMessageBlockEx& msg);
  37. private:
  38. std::map<uint32_t, TunnelMessageBlockEx> m_IncompleteMessages;
  39. std::map<std::pair<uint32_t, uint8_t>, Fragment> m_OutOfSequenceFragments; // (msgID, fragment#)->fragment
  40. bool m_IsInbound;
  41. size_t m_NumReceivedBytes;
  42. };
  43. }
  44. }
  45. #endif