Browse Source

SAM added

pull/102/head
orignal 10 years ago
parent
commit
a7fa896b3e
  1. 78
      SAM.cpp
  2. 40
      SAM.h
  3. 2
      Win32/i2pd.vcxproj
  4. 1
      build/CMakeLists.txt
  5. 4
      build/autotools/Makefile.in
  6. 4
      filelist.mk

78
SAM.cpp

@ -0,0 +1,78 @@
#include <boost/bind.hpp>
#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 ();
}
}
}

40
SAM.h

@ -0,0 +1,40 @@
#ifndef SAM_H__
#define SAM_H__
#include <thread>
#include <boost/asio.hpp>
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

2
Win32/i2pd.vcxproj

@ -44,6 +44,7 @@
<ClCompile Include="..\util.cpp" /> <ClCompile Include="..\util.cpp" />
<ClCompile Include="..\SOCKS.cpp" /> <ClCompile Include="..\SOCKS.cpp" />
<ClCompile Include="..\I2PTunnel.cpp" /> <ClCompile Include="..\I2PTunnel.cpp" />
<ClCompile Include="..\SAM.cpp" />
<ClCompile Include="Win32Service.cpp" /> <ClCompile Include="Win32Service.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -85,6 +86,7 @@
<ClInclude Include="..\I2PTunnel.h" /> <ClInclude Include="..\I2PTunnel.h" />
<ClInclude Include="..\version.h" /> <ClInclude Include="..\version.h" />
<ClInclude Include="..\Signature.h" /> <ClInclude Include="..\Signature.h" />
<ClInclude Include="..\SAM.h" />
<ClInclude Include="Win32Service.h" /> <ClInclude Include="Win32Service.h" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">

1
build/CMakeLists.txt

@ -41,6 +41,7 @@ set (SOURCES
"${CMAKE_SOURCE_DIR}/base64.cpp" "${CMAKE_SOURCE_DIR}/base64.cpp"
"${CMAKE_SOURCE_DIR}/i2p.cpp" "${CMAKE_SOURCE_DIR}/i2p.cpp"
"${CMAKE_SOURCE_DIR}/util.cpp" "${CMAKE_SOURCE_DIR}/util.cpp"
"${CMAKE_SOURCE_DIR}/SAM.cpp"
) )
file (GLOB HEADERS "${CMAKE_SOURCE_DIR}/*.h") file (GLOB HEADERS "${CMAKE_SOURCE_DIR}/*.h")

4
build/autotools/Makefile.in

@ -113,7 +113,8 @@ am_i2p_OBJECTS = AddressBook.$(OBJEXT) CryptoConst.$(OBJEXT) \
SSUData.$(OBJEXT) Streaming.$(OBJEXT) TransitTunnel.$(OBJEXT) \ SSUData.$(OBJEXT) Streaming.$(OBJEXT) TransitTunnel.$(OBJEXT) \
Transports.$(OBJEXT) Tunnel.$(OBJEXT) TunnelEndpoint.$(OBJEXT) \ Transports.$(OBJEXT) Tunnel.$(OBJEXT) TunnelEndpoint.$(OBJEXT) \
TunnelGateway.$(OBJEXT) TunnelPool.$(OBJEXT) UPnP.$(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_OBJECTS = $(am_i2p_OBJECTS)
i2p_LDADD = $(LDADD) i2p_LDADD = $(LDADD)
AM_V_P = $(am__v_P_@AM_V@) 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)/base64.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i2p.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)/util.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SAM.Po@am__quote@
.cpp.o: .cpp.o:
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<

4
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 \ 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 \ 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 \ 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 \ H_FILES := CryptoConst.h base64.h NTCPSession.h RouterInfo.h Transports.h \
RouterContext.h NetDb.h LeaseSet.h Tunnel.h TunnelEndpoint.h TunnelGateway.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 \ 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 \ 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))) OBJECTS = $(addprefix obj/, $(notdir $(CPP_FILES:.cpp=.o)))

Loading…
Cancel
Save