mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
try adding garlic and session tags to datagram destination
This commit is contained in:
parent
abaf36a2de
commit
0b21fce94e
7 changed files with 300 additions and 51 deletions
65
Datagram.h
65
Datagram.h
|
@ -9,6 +9,7 @@
|
|||
#include "Identity.h"
|
||||
#include "LeaseSet.h"
|
||||
#include "I2NPProtocol.h"
|
||||
#include "Garlic.h"
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
|
@ -18,7 +19,52 @@ namespace client
|
|||
}
|
||||
namespace datagram
|
||||
{
|
||||
const size_t MAX_DATAGRAM_SIZE = 32768;
|
||||
|
||||
// seconds interval for cleanup timer
|
||||
const int DATAGRAM_SESSION_CLEANUP_INTERVAL = 30;
|
||||
// milliseconds for max session idle time (10 minutes)
|
||||
const uint64_t DATAGRAM_SESSION_MAX_IDLE = 3600 * 1000;
|
||||
|
||||
|
||||
class DatagramSession
|
||||
{
|
||||
public:
|
||||
DatagramSession(i2p::client::ClientDestination * localDestination,
|
||||
const i2p::data::IdentHash & remoteIdent);
|
||||
|
||||
/** send an i2np message to remote endpoint for this session */
|
||||
void SendMsg(std::shared_ptr<I2NPMessage> msg);
|
||||
/** get the last time in milliseconds for when we used this datagram session */
|
||||
uint64_t LastActivity() const { return m_LastUse; }
|
||||
private:
|
||||
|
||||
/** get next usable routing path, try reusing outbound tunnels */
|
||||
std::shared_ptr<i2p::garlic::GarlicRoutingPath> GetNextRoutingPath();
|
||||
/**
|
||||
* mark current routing path as invalid and clear it
|
||||
* if the outbound tunnel we were using was okay don't use the IBGW in the routing path's lease next time
|
||||
*/
|
||||
void ResetRoutingPath();
|
||||
|
||||
/** get next usable lease, does not fetch or update if expired or have no lease set */
|
||||
std::shared_ptr<const i2p::data::Lease> GetNextLease();
|
||||
|
||||
void HandleSend(std::shared_ptr<I2NPMessage> msg);
|
||||
void HandleGotLeaseSet(std::shared_ptr<const i2p::data::LeaseSet> remoteIdent,
|
||||
std::shared_ptr<I2NPMessage> msg);
|
||||
void UpdateLeaseSet(std::shared_ptr<I2NPMessage> msg=nullptr);
|
||||
|
||||
private:
|
||||
i2p::client::ClientDestination * m_LocalDestination;
|
||||
i2p::data::IdentHash m_RemoteIdentity;
|
||||
std::shared_ptr<i2p::garlic::GarlicRoutingSession> m_RoutingSession;
|
||||
// Ident hash of IBGW that are invalid
|
||||
std::vector<i2p::data::IdentHash> m_InvalidIBGW;
|
||||
std::shared_ptr<const i2p::data::LeaseSet> m_RemoteLeaseSet;
|
||||
uint64_t m_LastUse;
|
||||
};
|
||||
|
||||
const size_t MAX_DATAGRAM_SIZE = 32768;
|
||||
class DatagramDestination
|
||||
{
|
||||
typedef std::function<void (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len)> Receiver;
|
||||
|
@ -36,19 +82,26 @@ namespace datagram
|
|||
|
||||
void SetReceiver (const Receiver& receiver, uint16_t port) { m_ReceiversByPorts[port] = receiver; };
|
||||
void ResetReceiver (uint16_t port) { m_ReceiversByPorts.erase (port); };
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void HandleLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet, std::shared_ptr<I2NPMessage> msg);
|
||||
// clean up after next tick
|
||||
void ScheduleCleanup();
|
||||
|
||||
// clean up stale sessions and expire tags
|
||||
void HandleCleanUp(const boost::system::error_code & ecode);
|
||||
|
||||
std::shared_ptr<DatagramSession> ObtainSession(const i2p::data::IdentHash & ident);
|
||||
|
||||
std::shared_ptr<I2NPMessage> CreateDataMessage (const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort);
|
||||
void SendMsg (std::shared_ptr<I2NPMessage> msg, std::shared_ptr<const i2p::data::LeaseSet> remote);
|
||||
|
||||
void HandleDatagram (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
|
||||
|
||||
private:
|
||||
|
||||
i2p::client::ClientDestination * m_Owner;
|
||||
boost::asio::deadline_timer m_CleanupTimer;
|
||||
Receiver m_Receiver; // default
|
||||
std::mutex m_SessionsMutex;
|
||||
std::map<i2p::data::IdentHash, std::shared_ptr<DatagramSession> > m_Sessions;
|
||||
std::map<uint16_t, Receiver> m_ReceiversByPorts;
|
||||
|
||||
i2p::data::GzipInflator m_Inflator;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue