From a7fa896b3ecc59b12f8b7f839e5934cb223350b0 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 24 Sep 2014 12:01:26 -0400 Subject: [PATCH] SAM added --- SAM.cpp | 78 +++++++++++++++++++++++++++++++++++++ SAM.h | 40 +++++++++++++++++++ Win32/i2pd.vcxproj | 2 + build/CMakeLists.txt | 1 + build/autotools/Makefile.in | 4 +- filelist.mk | 4 +- 6 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 SAM.cpp create mode 100644 SAM.h diff --git a/SAM.cpp b/SAM.cpp new file mode 100644 index 00000000..156df4cf --- /dev/null +++ b/SAM.cpp @@ -0,0 +1,78 @@ +#include +#include "Log.h" +#include "SAM.h" + +namespace i2p +{ +namespace stream +{ + SAMBridge::SAMBridge (int port): + m_IsRunning (false), m_Thread (nullptr), + m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)), + m_NewSocket (nullptr) + { + } + + SAMBridge::~SAMBridge () + { + Stop (); + delete m_NewSocket; + } + + void SAMBridge::Start () + { + Accept (); + m_Thread = new std::thread (std::bind (&SAMBridge::Run, this)); + } + + void SAMBridge::Stop () + { + m_IsRunning = false; + m_Service.stop (); + if (m_Thread) + { + m_Thread->join (); + delete m_Thread; + m_Thread = nullptr; + } + } + + void SAMBridge::Run () + { + while (m_IsRunning) + { + try + { + m_Service.run (); + } + catch (std::exception& ex) + { + LogPrint ("SAM: ", ex.what ()); + } + } + } + + void SAMBridge::Accept () + { + m_NewSocket = new boost::asio::ip::tcp::socket (m_Service); + m_Acceptor.async_accept (*m_NewSocket, boost::bind (&SAMBridge::HandleAccept, this, + boost::asio::placeholders::error)); + } + + void SAMBridge::HandleAccept(const boost::system::error_code& ecode) + { + if (!ecode) + { + //TODO: + } + else + { + delete m_NewSocket; + m_NewSocket = nullptr; + } + + if (ecode != boost::asio::error::operation_aborted) + Accept (); + } +} +} diff --git a/SAM.h b/SAM.h new file mode 100644 index 00000000..e547adfe --- /dev/null +++ b/SAM.h @@ -0,0 +1,40 @@ +#ifndef SAM_H__ +#define SAM_H__ + +#include +#include + +namespace i2p +{ +namespace stream +{ + class SAMBridge + { + public: + + SAMBridge (int port); + ~SAMBridge (); + + void Start (); + void Stop (); + + private: + + void Run (); + + void Accept (); + void HandleAccept(const boost::system::error_code& ecode); + + private: + + bool m_IsRunning; + std::thread * m_Thread; + boost::asio::io_service m_Service; + boost::asio::ip::tcp::acceptor m_Acceptor; + boost::asio::ip::tcp::socket * m_NewSocket; + }; +} +} + +#endif + diff --git a/Win32/i2pd.vcxproj b/Win32/i2pd.vcxproj index 99511ab4..9d5b8d8f 100644 --- a/Win32/i2pd.vcxproj +++ b/Win32/i2pd.vcxproj @@ -44,6 +44,7 @@ + @@ -85,6 +86,7 @@ + diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 0b959b59..db7db5d2 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -41,6 +41,7 @@ set (SOURCES "${CMAKE_SOURCE_DIR}/base64.cpp" "${CMAKE_SOURCE_DIR}/i2p.cpp" "${CMAKE_SOURCE_DIR}/util.cpp" + "${CMAKE_SOURCE_DIR}/SAM.cpp" ) file (GLOB HEADERS "${CMAKE_SOURCE_DIR}/*.h") diff --git a/build/autotools/Makefile.in b/build/autotools/Makefile.in index 45e72734..a408a39c 100644 --- a/build/autotools/Makefile.in +++ b/build/autotools/Makefile.in @@ -113,7 +113,8 @@ am_i2p_OBJECTS = AddressBook.$(OBJEXT) CryptoConst.$(OBJEXT) \ SSUData.$(OBJEXT) Streaming.$(OBJEXT) TransitTunnel.$(OBJEXT) \ Transports.$(OBJEXT) Tunnel.$(OBJEXT) TunnelEndpoint.$(OBJEXT) \ TunnelGateway.$(OBJEXT) TunnelPool.$(OBJEXT) UPnP.$(OBJEXT) \ - aes.$(OBJEXT) base64.$(OBJEXT) i2p.$(OBJEXT) util.$(OBJEXT) + aes.$(OBJEXT) base64.$(OBJEXT) i2p.$(OBJEXT) util.$(OBJEXT) \ + SAM.$(OBJEXT) i2p_OBJECTS = $(am_i2p_OBJECTS) i2p_LDADD = $(LDADD) AM_V_P = $(am__v_P_@AM_V@) @@ -480,6 +481,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/base64.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i2p.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SAM.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 9a7e9d9c..8a44be18 100644 --- a/filelist.mk +++ b/filelist.mk @@ -4,14 +4,14 @@ CPP_FILES := CryptoConst.cpp base64.cpp NTCPSession.cpp RouterInfo.cpp Transport RouterContext.cpp NetDb.cpp LeaseSet.cpp Tunnel.cpp TunnelEndpoint.cpp TunnelGateway.cpp \ TransitTunnel.cpp I2NPProtocol.cpp Log.cpp Garlic.cpp HTTPServer.cpp Streaming.cpp Identity.cpp \ SSU.cpp util.cpp Reseed.cpp DaemonLinux.cpp SSUData.cpp i2p.cpp aes.cpp SOCKS.cpp UPnP.cpp \ - TunnelPool.cpp HTTPProxy.cpp AddressBook.cpp Daemon.cpp I2PTunnel.cpp + TunnelPool.cpp HTTPProxy.cpp AddressBook.cpp Daemon.cpp I2PTunnel.cpp SAM.cpp H_FILES := CryptoConst.h base64.h NTCPSession.h RouterInfo.h Transports.h \ RouterContext.h NetDb.h LeaseSet.h Tunnel.h TunnelEndpoint.h TunnelGateway.h \ TransitTunnel.h I2NPProtocol.h Log.h Garlic.h HTTPServer.h Streaming.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 + HTTPProxy.h AddressBook.h Daemon.h I2PTunnel.h version.h Signature.h SAM.h OBJECTS = $(addprefix obj/, $(notdir $(CPP_FILES:.cpp=.o)))