send streaming protocol data

This commit is contained in:
orignal 2014-01-01 18:19:03 -05:00
parent 24ad255053
commit 1130287d28
4 changed files with 107 additions and 31 deletions

View file

@ -3,7 +3,9 @@
#include <inttypes.h>
#include <map>
#include <cryptopp/dsa.h>
#include "Identity.h"
#include "LeaseSet.h"
#include "I2NPProtocol.h"
namespace i2p
@ -22,21 +24,27 @@ namespace stream
const uint16_t PACKET_FLAG_ECHO = 0x0200;
const uint16_t PACKET_FLAG_NO_ACK = 0x0400;
const size_t STREAMING_MTU = 1730;
class StreamingDestination;
class Stream
{
public:
Stream (StreamingDestination * local, const i2p::data::IdentHash& remote);
Stream (StreamingDestination * local, const i2p::data::LeaseSet * remote);
uint32_t GetSendStreamID () const { return m_SendStreamID; };
uint32_t GetRecvStreamID () const { return m_RecvStreamID; };
const i2p::data::LeaseSet * GetRemoteLeaseSet () const { return m_RemoteLeaseSet; };
bool IsEstablished () const { return !m_SendStreamID; };
void HandleNextPacket (const uint8_t * buf, size_t len);
size_t Send (uint8_t * buf, size_t len, int timeout); // timeout in seconds
private:
uint32_t m_SendStreamID, m_RecvStreamID;
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber;
StreamingDestination * m_LocalDestination;
const i2p::data::LeaseSet * m_RemoteLeaseSet;
};
class StreamingDestination
@ -45,10 +53,13 @@ namespace stream
StreamingDestination ();
const i2p::data::Keys GetKeys () const { return m_Keys; };
const i2p::data::Keys& GetKeys () const { return m_Keys; };
const i2p::data::Identity& GetIdentity () const { return m_Identity; };
I2NPMessage * CreateLeaseSet () const;
void Sign (uint8_t * buf, int len, uint8_t * signature) const;
Stream * CreateNewStream (const i2p::data::IdentHash& destination);
Stream * CreateNewStream (const i2p::data::LeaseSet * remote);
void DeleteStream (Stream * stream);
void HandleNextPacket (const uint8_t * buf, size_t len);
private:
@ -57,7 +68,12 @@ namespace stream
i2p::data::Keys m_Keys;
i2p::data::Identity m_Identity;
i2p::data::IdentHash m_IdentHash;
CryptoPP::DSA::PrivateKey m_SigningPrivateKey;
};
Stream * CreateStream (const i2p::data::LeaseSet * remote);
void CloseStream (Stream * stream);
// assuming data is I2CP message
void HandleDataMessage (i2p::data::IdentHash * destination, const uint8_t * buf, size_t len);