diff --git a/Datagram.cpp b/Datagram.cpp new file mode 100644 index 00000000..5c3cd259 --- /dev/null +++ b/Datagram.cpp @@ -0,0 +1,29 @@ +#include +#include "Log.h" +#include "Datagram.h" + +namespace i2p +{ +namespace datagram +{ + void DatagramDestination::HandleDataMessagePayload (const uint8_t * buf, size_t len) + { + // unzip it + CryptoPP::Gunzip decompressor; + decompressor.Put (buf, len); + decompressor.MessageEnd(); + uint8_t uncompressed[MAX_DATAGRAM_SIZE]; + auto uncompressedLen = decompressor.MaxRetrievable (); + if (uncompressedLen <= MAX_DATAGRAM_SIZE) + { + decompressor.Get (uncompressed, uncompressedLen); + //HandleNextPacket (uncompressed); + } + else + LogPrint ("Received datagram size ", uncompressedLen, " exceeds max size"); + + } + +} +} + diff --git a/Datagram.h b/Datagram.h new file mode 100644 index 00000000..d5c21f6b --- /dev/null +++ b/Datagram.h @@ -0,0 +1,32 @@ +#ifndef DATAGRAM_H__ +#define DATAGRAM_H__ + +#include + +namespace i2p +{ +namespace client +{ + class ClientDestination; +} +namespace datagram +{ + const size_t MAX_DATAGRAM_SIZE = 32768; + class DatagramDestination + { + public: + + DatagramDestination (i2p::client::ClientDestination& owner): m_Owner (owner) {}; + ~DatagramDestination () {}; + + void HandleDataMessagePayload (const uint8_t * buf, size_t len); + + private: + + i2p::client::ClientDestination& m_Owner; + }; +} +} + +#endif + diff --git a/Destination.cpp b/Destination.cpp index dc544ba6..af425694 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -12,7 +12,8 @@ namespace client { ClientDestination::ClientDestination (bool isPublic, i2p::data::SigningKeyType sigType): m_IsRunning (false), m_Thread (nullptr), m_Service (nullptr), m_Work (nullptr), - m_CurrentOutboundTunnel (nullptr), m_LeaseSet (nullptr), m_IsPublic (isPublic) + m_CurrentOutboundTunnel (nullptr), m_LeaseSet (nullptr), m_IsPublic (isPublic), + m_DatagramDestination (nullptr) { m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType); CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); @@ -25,7 +26,8 @@ namespace client ClientDestination::ClientDestination (const std::string& fullPath, bool isPublic): m_IsRunning (false), m_Thread (nullptr), m_Service (nullptr), m_Work (nullptr), - m_CurrentOutboundTunnel (nullptr), m_LeaseSet (nullptr), m_IsPublic (isPublic) + m_CurrentOutboundTunnel (nullptr), m_LeaseSet (nullptr), m_IsPublic (isPublic), + m_DatagramDestination (nullptr) { std::ifstream s(fullPath.c_str (), std::ifstream::binary); if (s.is_open ()) @@ -61,7 +63,8 @@ namespace client ClientDestination::ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic): m_IsRunning (false), m_Thread (nullptr), m_Service (nullptr), m_Work (nullptr), - m_Keys (keys), m_CurrentOutboundTunnel (nullptr), m_LeaseSet (nullptr), m_IsPublic (isPublic) + m_Keys (keys), m_CurrentOutboundTunnel (nullptr), m_LeaseSet (nullptr), m_IsPublic (isPublic), + m_DatagramDestination (nullptr) { CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg); dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey); @@ -249,6 +252,15 @@ namespace client // streaming protocol if (m_StreamingDestination) m_StreamingDestination->HandleDataMessagePayload (buf, length); + else + LogPrint ("Missing streaming destination"); + break; + case PROTOCOL_TYPE_DATAGRAM: + // datagram protocol + if (m_DatagramDestination) + m_DatagramDestination->HandleDataMessagePayload (buf, length); + else + LogPrint ("Missing streaming destination"); break; default: LogPrint ("Data: unexpected protocol ", buf[9]); diff --git a/Destination.h b/Destination.h index d7547ecf..fcb8329d 100644 --- a/Destination.h +++ b/Destination.h @@ -9,6 +9,7 @@ #include "LeaseSet.h" #include "Garlic.h" #include "Streaming.h" +#include "Datagram.h" namespace i2p { @@ -84,6 +85,7 @@ namespace client bool m_IsPublic; i2p::stream::StreamingDestination * m_StreamingDestination; + i2p::datagram::DatagramDestination * m_DatagramDestination; public: diff --git a/Win32/i2pd.vcxproj b/Win32/i2pd.vcxproj index c071c131..2bbba99b 100644 --- a/Win32/i2pd.vcxproj +++ b/Win32/i2pd.vcxproj @@ -47,6 +47,7 @@ + @@ -91,6 +92,8 @@ + + diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 55b5e6e5..02475c0d 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -43,7 +43,8 @@ set (SOURCES "${CMAKE_SOURCE_DIR}/i2p.cpp" "${CMAKE_SOURCE_DIR}/util.cpp" "${CMAKE_SOURCE_DIR}/SAM.cpp" - "${CMAKE_SOURCE_DIR}/ClientContext.cpp" + "${CMAKE_SOURCE_DIR}/ClientContext.cpp" + "${CMAKE_SOURCE_DIR}/Datagram.cpp" ) file (GLOB HEADERS "${CMAKE_SOURCE_DIR}/*.h") diff --git a/build/autotools/Makefile.in b/build/autotools/Makefile.in index 16b2cc2b..d80dfd62 100644 --- a/build/autotools/Makefile.in +++ b/build/autotools/Makefile.in @@ -325,7 +325,7 @@ i2p_SOURCES = AddressBook.cpp CryptoConst.cpp Daemon.cpp \ Transports.cpp Tunnel.cpp TunnelEndpoint.cpp \ TunnelGateway.cpp TunnelPool.cpp UPnP.cpp aes.cpp \ base64.cpp i2p.cpp util.cpp SAM.cpp Destination.cpp \ - ClientContext.cpp \ + ClientContext.cpp DataFram.cpp \ \ AddressBook.h CryptoConst.h Daemon.h ElGamal.h \ Garlic.h HTTPProxy.h HTTPServer.h I2NPProtocol.h \ @@ -336,7 +336,8 @@ i2p_SOURCES = AddressBook.cpp CryptoConst.cpp Daemon.cpp \ TransitTunnel.h Transports.h Tunnel.h TunnelBase.h \ TunnelConfig.h TunnelEndpoint.h TunnelGateway.h \ TunnelPool.h UPnP.h aes.h base64.h config.h hmac.h \ - util.h version.h Destination.h ClientContext.h + util.h version.h Destination.h ClientContext.h \ + TransportSession.h Datagram.h AM_LDFLAGS = @BOOST_DATE_TIME_LIB@ @BOOST_FILESYSTEM_LIB@ \ @BOOST_PROGRAM_OPTIONS_LIB@ @BOOST_REGEX_LIB@ \ @@ -485,6 +486,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SAM.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ClientContext.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Datagram.Po@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/filelist.mk b/filelist.mk index 1c413f7d..3ca5e9a5 100644 --- a/filelist.mk +++ b/filelist.mk @@ -5,7 +5,7 @@ CPP_FILES := CryptoConst.cpp base64.cpp NTCPSession.cpp RouterInfo.cpp Transport TransitTunnel.cpp I2NPProtocol.cpp Log.cpp Garlic.cpp HTTPServer.cpp Streaming.cpp \ Destination.cpp Identity.cpp SSU.cpp util.cpp Reseed.cpp DaemonLinux.cpp SSUData.cpp \ aes.cpp SOCKS.cpp UPnP.cpp TunnelPool.cpp HTTPProxy.cpp AddressBook.cpp Daemon.cpp \ - I2PTunnel.cpp SAM.cpp ClientContext.cpp i2p.cpp + I2PTunnel.cpp SAM.cpp ClientContext.cpp Datagram.cpp i2p.cpp H_FILES := CryptoConst.h base64.h NTCPSession.h RouterInfo.h Transports.h \ @@ -13,7 +13,7 @@ H_FILES := CryptoConst.h base64.h NTCPSession.h RouterInfo.h Transports.h \ TransitTunnel.h I2NPProtocol.h Log.h Garlic.h HTTPServer.h Streaming.h Destination.h \ Identity.h SSU.h util.h Reseed.h DaemonLinux.h SSUData.h i2p.h aes.h SOCKS.h \ UPnP.h TunnelPool.h HTTPProxy.h AddressBook.h Daemon.h I2PTunnel.h version.h \ - Signature.h SAM.h ClientContext.h + Signature.h SAM.h ClientContext.h TransportSession.h Datagram.h OBJECTS = $(addprefix obj/, $(notdir $(CPP_FILES:.cpp=.o)))