File: SSU2OutOfSession.h

package info (click to toggle)
i2pd 2.58.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,612 kB
  • sloc: cpp: 59,663; makefile: 224; sh: 138
file content (86 lines) | stat: -rw-r--r-- 2,839 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright (c) 2024, 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
*/

#ifndef SSU2_OUT_OF_SESSION_H__
#define SSU2_OUT_OF_SESSION_H__

#include <vector>
#include "SSU2Session.h"

namespace i2p
{
namespace transport
{
	const int SSU2_PEER_TEST_RESEND_INTERVAL = 3000; // in milliseconds
	const int SSU2_PEER_TEST_RESEND_INTERVAL_VARIANCE = 2000; // in milliseconds
	const int SSU2_PEER_TEST_MAX_NUM_RESENDS = 3;
	
	class SSU2PeerTestSession: public SSU2Session // for PeerTest msgs 5,6,7
	{
		public:

			SSU2PeerTestSession (SSU2Server& server, uint64_t sourceConnID, uint64_t destConnID);

			uint8_t GetMsgNumReceived () const { return m_MsgNumReceived; }	
			bool IsConnectedRecently () const { return m_IsConnectedRecently; }
			void SetStatusChanged () { m_IsStatusChanged = true; }
			
			void SendPeerTest (uint8_t msg, const uint8_t * signedData, size_t signedDataLen, 
				std::shared_ptr<const i2p::data::RouterInfo::Address> addr, bool delayed = false);
			bool ProcessPeerTest (uint8_t * buf, size_t len) override;
			void Connect () override; // outgoing
			bool ProcessFirstIncomingMessage (uint64_t connID, uint8_t * buf, size_t len) override; // incoming
			
		private:

			void SendPeerTest (uint8_t msg, const uint8_t * signedData, size_t signedDataLen, bool delayed = false); // PeerTest message
			void SendPeerTest (uint8_t msg); // send or resend m_SignedData
			void HandlePeerTest (const uint8_t * buf, size_t len) override;
			void HandleAddress (const uint8_t * buf, size_t len) override;

			void ScheduleResend (uint8_t msg);
			
		private:

			uint8_t m_MsgNumReceived, m_NumResends;
			bool m_IsConnectedRecently, m_IsStatusChanged;
			std::vector<uint8_t> m_SignedData; // for resends
			boost::asio::deadline_timer m_PeerTestResendTimer;
			boost::asio::ip::udp::endpoint m_OurEndpoint; // as seen by peer
	};	

	const int SSU2_HOLE_PUNCH_RESEND_INTERVAL = 1000; // in milliseconds
	const int SSU2_HOLE_PUNCH_RESEND_INTERVAL_VARIANCE = 500; // in milliseconds
	const int SSU2_HOLE_PUNCH_MAX_NUM_RESENDS = 3;
	
	class SSU2HolePunchSession: public SSU2Session // Charlie
	{
		public:

			SSU2HolePunchSession (SSU2Server& server, uint32_t nonce, const boost::asio::ip::udp::endpoint& remoteEndpoint,
				std::shared_ptr<const i2p::data::RouterInfo::Address> addr);

			void SendHolePunch (const uint8_t * relayResponseBlock, size_t relayResponseBlockLen);

			bool ProcessFirstIncomingMessage (uint64_t connID, uint8_t * buf, size_t len) override; // SessionRequest
			
		private:
			
			void SendHolePunch ();
			void ScheduleResend ();
			
		private:

			int m_NumResends;
			std::vector<uint8_t> m_RelayResponseBlock;
			boost::asio::deadline_timer m_HolePunchResendTimer;
	};	
}
}
	
#endif