From 439b8798c9d1326102f3a25736cf4e12137be012 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 17 Nov 2014 14:42:45 -0500 Subject: [PATCH] start/stop/init through api --- api/api.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ api/api.h | 3 +++ api/filelist.mk | 16 ++++++---------- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/api/api.cpp b/api/api.cpp index 2a838f5a..33ae2d47 100644 --- a/api/api.cpp +++ b/api/api.cpp @@ -1,9 +1,58 @@ +#include +#include +#include "Log.h" +#include "NetDb.h" +#include "Transports.h" +#include "Tunnel.h" +#include "RouterContext.h" +#include "Identity.h" +#include "Destination.h" +#include "util.h" #include "api.h" namespace i2p { namespace api { + static std::map g_Destinations; + + void InitI2P (int argc, char* argv[]) + { + i2p::util::config::OptionParser(argc, argv); + i2p::context.Init (); + } + + void StartI2P () + { + std::string logfilePath ("libi2pd.log"); + StartLog (logfilePath); + i2p::data::netdb.Start(); + LogPrint("NetDB started"); + i2p::transport::transports.Start(); + LogPrint("Transports started"); + i2p::tunnel::tunnels.Start(); + LogPrint("Tunnels started"); + } + + void StopI2P () + { + LogPrint("Shutdown started."); + i2p::tunnel::tunnels.Stop(); + LogPrint("Tunnels stoped"); + i2p::transport::transports.Stop(); + LogPrint("Transports stoped"); + i2p::data::netdb.Stop(); + LogPrint("NetDB stoped"); + for (auto it: g_Destinations) + { + it.second->Stop (); + delete it.second; + } + g_Destinations.clear (); + LogPrint("Local destinations deleted"); + + StopLog (); + } } } diff --git a/api/api.h b/api/api.h index 6e615a7e..a4c1b8c2 100644 --- a/api/api.h +++ b/api/api.h @@ -5,6 +5,9 @@ namespace i2p { namespace api { + void InitI2P (int argc, char* argv[]); + void StartI2P (); + void StopI2P (); } } diff --git a/api/filelist.mk b/api/filelist.mk index 8d0665c0..4b098ae3 100644 --- a/api/filelist.mk +++ b/api/filelist.mk @@ -3,21 +3,17 @@ CPP_FILES := ../CryptoConst.cpp ../base64.cpp ../NTCPSession.cpp ../RouterInfo.cpp \ ../Transports.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 ../Destination.cpp \ - ../Identity.cpp ../SSU.cpp ../SSUSession.cpp ../SSUData.cpp ../util.cpp ../Reseed.cpp \ - ../DaemonLinux.cpp ../SSUData.cpp ../aes.cpp ../SOCKS.cpp ../UPnP.cpp ../TunnelPool.cpp \ - ../HTTPProxy.cpp ../AddressBook.cpp ../I2PTunnel.cpp ../SAM.cpp ../ClientContext.cpp \ - ../Datagram.cpp api.cpp + ../Log.cpp ../Garlic.cpp ../Streaming.cpp ../Destination.cpp ../Identity.cpp \ + ../SSU.cpp ../SSUSession.cpp ../SSUData.cpp ../util.cpp ../Reseed.cpp ../SSUData.cpp \ + ../aes.cpp ../TunnelPool.cpp ../AddressBook.cpp ../Datagram.cpp api.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 ../Destination.h ../Identity.h ../SSU.h ../SSUSession.h \ - ../SSUData.h ../util.h ../Reseed.h ../DaemonLinux.h ../SSUData.h ../aes.h ../SOCKS.h \ - ../UPnP.h ../TunnelPool.h ../HTTPProxy.h ../AddressBook.h ../I2PTunnel.h ../version.h \ - ../Signature.h ../SAM.h ../ClientContext.h ../TransportSession.h ../Datagram.h api.h - + ../Streaming.h ../Destination.h ../Identity.h ../SSU.h ../SSUSession.h ../SSUData.h \ + ../util.h ../Reseed.h ../SSUData.h ../aes.h ../TunnelPool.h ../AddressBook.h ../version.h \ + ../Signature.h ../TransportSession.h ../Datagram.h api.h OBJECTS = $(addprefix obj/, $(notdir $(CPP_FILES:.cpp=.o)))