i2pd/TunnelGateway.h

64 lines
1.6 KiB
C
Raw Normal View History

2013-11-11 00:19:49 +01:00
#ifndef TUNNEL_GATEWAY_H__
#define TUNNEL_GATEWAY_H__
#include <inttypes.h>
#include <vector>
#include "I2NPProtocol.h"
#include "TunnelBase.h"
namespace i2p
{
namespace tunnel
{
class TunnelGatewayBuffer
{
struct TunnelMessageBlockExt: public TunnelMessageBlock
{
size_t deliveryInstructionsLen, totalLen;
bool isFragmented;
2013-11-11 00:19:49 +01:00
};
public:
2013-11-29 13:52:09 +01:00
TunnelGatewayBuffer (uint32_t tunnelID): m_TunnelID (tunnelID), m_Remaining (0) {};
2013-11-11 00:19:49 +01:00
void PutI2NPMsg (const uint8_t * gwHash, uint32_t gwTunnel, I2NPMessage * msg);
2013-11-29 13:52:09 +01:00
std::vector<I2NPMessage *> GetTunnelDataMsgs ();
2013-11-11 00:19:49 +01:00
private:
size_t CreateFirstFragment (TunnelMessageBlockExt * block, uint8_t * buf, size_t len);
size_t CreateFollowOnFragment (TunnelMessageBlockExt * block, uint8_t * buf, size_t len);
2013-11-29 13:52:09 +01:00
I2NPMessage * CreateNextTunnelMessage (int& ind);
2013-11-11 00:19:49 +01:00
private:
2013-11-29 13:52:09 +01:00
uint32_t m_TunnelID;
2013-11-11 00:19:49 +01:00
std::vector<TunnelMessageBlockExt *> m_I2NPMsgs;
// for fragmented messages
size_t m_NextOffset, m_NextSeqn, m_Remaining;
2013-11-11 00:19:49 +01:00
uint32_t m_NextMsgID;
};
class TunnelGateway
{
public:
2013-11-29 13:52:09 +01:00
TunnelGateway (TunnelBase * tunnel):
m_Tunnel (tunnel), m_Buffer (tunnel->GetNextTunnelID ()), m_NumSentBytes (0) {};
void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg);
void PutTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg);
void SendBuffer ();
2013-11-29 13:52:09 +01:00
size_t GetNumSentBytes () const { return m_NumSentBytes; };
private:
TunnelBase * m_Tunnel;
TunnelGatewayBuffer m_Buffer;
2013-11-29 13:52:09 +01:00
size_t m_NumSentBytes;
};
2013-11-11 00:19:49 +01:00
}
}
#endif