diff --git a/ClientContext.cpp b/ClientContext.cpp index db1c8e6a..3e69510c 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -8,6 +8,12 @@ #include "Identity.h" #include "ClientContext.h" +#ifdef ANDROID +# include "to_string.h" +#else +# define to_string(x) std::to_string(x) +#endif + namespace i2p { namespace client @@ -292,7 +298,7 @@ namespace client template std::string ClientContext::GetI2CPOption (const Section& section, const std::string& name, const Type& value) const { - return section.second.get (boost::property_tree::ptree::path_type (name, '/'), std::to_string (value)); + return section.second.get (boost::property_tree::ptree::path_type (name, '/'), to_string (value)); } template diff --git a/Daemon.h b/Daemon.h index 977d9258..6b154ee4 100644 --- a/Daemon.h +++ b/Daemon.h @@ -52,7 +52,7 @@ namespace i2p void run (); }; #else - class DaemonLinux : public Daemon_Singleton + class DaemonLinux : public Daemon_Singleton { public: static DaemonLinux& Instance() diff --git a/DaemonLinux.cpp b/DaemonLinux.cpp index 1cc0fa85..4aceff07 100644 --- a/DaemonLinux.cpp +++ b/DaemonLinux.cpp @@ -74,9 +74,11 @@ namespace i2p } // point std{in,out,err} descriptors to /dev/null - stdin = freopen("/dev/null", "r", stdin); +#ifndef ANDROID + stdin = freopen("/dev/null", "r", stdin); stdout = freopen("/dev/null", "w", stdout); stderr = freopen("/dev/null", "w", stderr); +#endif } // Pidfile @@ -92,7 +94,12 @@ namespace i2p LogPrint(eLogError, "Daemon: could not create pid file ", pidfile, ": ", strerror(errno)); return false; } +#ifndef ANDROID if (lockf(pidFH, F_TLOCK, 0) != 0) +#else + //TODO ANDROID actually need to read man for this, blindly took a solution from . -anon5 + if (fcntl(pidFH, 1, 0) < 0) +#endif { LogPrint(eLogError, "Daemon: could not lock pid file ", pidfile, ": ", strerror(errno)); return false; diff --git a/HTTP.cpp b/HTTP.cpp index a23f5a72..dbb115af 100644 --- a/HTTP.cpp +++ b/HTTP.cpp @@ -10,6 +10,13 @@ #include #include +#ifdef ANDROID +# include "to_string.h" +# include +#else +# define to_string(x) std::to_string(x) +#endif + namespace i2p { namespace http { const std::vector HTTP_METHODS = { @@ -180,7 +187,11 @@ namespace http { out += user + "@"; } if (port) { - out += host + ":" + std::to_string(port); +#ifndef ANDROID + out += host + ":" + to_string(port); +#else + out += host + ":" + tostr::to_string(port); +#endif } else { out += host; } @@ -338,7 +349,11 @@ namespace http { if (status == "OK" && code != 200) status = HTTPCodeToStatus(code); // update if (body.length() > 0 && headers.count("Content-Length") == 0) - add_header("Content-Length", std::to_string(body.length()).c_str()); +#ifndef ANDROID + add_header("Content-Length", to_string(body.length()).c_str()); +#else + add_header("Content-Length", tostr::to_string(body.length()).c_str()); +#endif /* build response */ std::stringstream ss; ss << version << " " << code << " " << status << CRLF; diff --git a/HTTPServer.cpp b/HTTPServer.cpp index a48536a7..583c02da 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -25,6 +25,12 @@ // For image and info #include "version.h" +#ifdef ANDROID +# include "to_string.h" +#else +# define to_string(x) std::to_string(x) +#endif + namespace i2p { namespace http { const char *itoopieFavicon = @@ -230,8 +236,8 @@ namespace http { clientTunnelCount += i2p::tunnel::tunnels.CountInboundTunnels(); size_t transitTunnelCount = i2p::tunnel::tunnels.CountTransitTunnels(); - s << "Client Tunnels: " << std::to_string(clientTunnelCount) << " "; - s << "Transit Tunnels: " << std::to_string(transitTunnelCount) << "
\r\n"; + s << "Client Tunnels: " << to_string(clientTunnelCount) << " "; + s << "Transit Tunnels: " << to_string(transitTunnelCount) << "
\r\n"; } void ShowJumpServices (std::stringstream& s, const std::string& address) diff --git a/I2PControl.cpp b/I2PControl.cpp index c87db150..bad25f37 100644 --- a/I2PControl.cpp +++ b/I2PControl.cpp @@ -25,6 +25,12 @@ #include "version.h" #include "I2PControl.h" +#ifdef ANDROID +# include "to_string.h" +#else +# define to_string(x) std::to_string(x) +#endif + namespace i2p { namespace client @@ -315,7 +321,7 @@ namespace client } InsertParam (results, "API", api); results << ","; - std::string token = std::to_string(i2p::util::GetSecondsSinceEpoch ()); + std::string token = to_string(i2p::util::GetSecondsSinceEpoch ()); m_Tokens.insert (token); InsertParam (results, "Token", token); } diff --git a/Reseed.cpp b/Reseed.cpp index 6f27891d..b707429a 100644 --- a/Reseed.cpp +++ b/Reseed.cpp @@ -17,6 +17,12 @@ #include "util.h" +#ifdef ANDROID +# include "to_string.h" +#else +# define to_string(x) std::to_string(x) +#endif + namespace i2p { namespace data @@ -373,7 +379,7 @@ namespace data boost::asio::io_service service; boost::system::error_code ecode; auto it = boost::asio::ip::tcp::resolver(service).resolve ( - boost::asio::ip::tcp::resolver::query (u.host_, std::to_string (u.port_)), ecode); + boost::asio::ip::tcp::resolver::query (u.host_, to_string (u.port_)), ecode); if (!ecode) { boost::asio::ssl::context ctx(service, boost::asio::ssl::context::sslv23); diff --git a/RouterContext.cpp b/RouterContext.cpp index 5fa32a13..34d49553 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -12,6 +12,12 @@ #include "Family.h" #include "RouterContext.h" +#ifdef ANDROID +# include "to_string.h" +#else +# define to_string(x) std::to_string(x) +#endif + namespace i2p { RouterContext context; @@ -56,7 +62,7 @@ namespace i2p routerInfo.AddNTCPAddress (host.c_str(), port); routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC - routerInfo.SetProperty ("netId", std::to_string (I2PD_NET_ID)); + routerInfo.SetProperty ("netId", to_string (I2PD_NET_ID)); routerInfo.SetProperty ("router.version", I2P_VERSION); routerInfo.CreateBuffer (m_Keys); m_RouterInfo.SetRouterIdentity (GetIdentity ()); diff --git a/qt/.gitignore b/qt/.gitignore new file mode 100644 index 00000000..e3a93c87 --- /dev/null +++ b/qt/.gitignore @@ -0,0 +1,2 @@ +/build-i2pd_qt-Android_armeabi_v7a_GCC_4_9_Qt_5_6_0-Debug/ +/build-i2pd_qt-Desktop_Qt_5_6_0_GCC_64bit-Debug/ diff --git a/qt/i2pd_qt/i2pd_qt.pro b/qt/i2pd_qt/i2pd_qt.pro new file mode 100644 index 00000000..f247cee4 --- /dev/null +++ b/qt/i2pd_qt/i2pd_qt.pro @@ -0,0 +1,153 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2016-06-14T04:53:04 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = i2pd_qt +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp \ + ../../HTTPServer.cpp ../../I2PControl.cpp ../../UPnP.cpp ../../Daemon.cpp ../../Config.cpp \ + ../../AddressBook.cpp \ + ../../api.cpp \ + ../../Base.cpp \ + ../../BOB.cpp \ + ../../ClientContext.cpp \ + ../../Crypto.cpp \ + ../../DaemonLinux.cpp \ + ../../DaemonWin32.cpp \ + ../../Datagram.cpp \ + ../../Destination.cpp \ + ../../Family.cpp \ + ../../FS.cpp \ + ../../Garlic.cpp \ + ../../HTTP.cpp \ + ../../HTTPProxy.cpp \ + ../../I2CP.cpp \ + ../../I2NPProtocol.cpp \ + ../../I2PEndian.cpp \ + ../../I2PService.cpp \ + ../../I2PTunnel.cpp \ + ../../Identity.cpp \ + ../../LeaseSet.cpp \ + ../../Log.cpp \ + ../../NetDb.cpp \ + ../../NetDbRequests.cpp \ + ../../NTCPSession.cpp \ + ../../Profiling.cpp \ + ../../Reseed.cpp \ + ../../RouterContext.cpp \ + ../../RouterInfo.cpp \ + ../../SAM.cpp \ + ../../Signature.cpp \ + ../../SOCKS.cpp \ + ../../SSU.cpp \ + ../../SSUData.cpp \ + ../../SSUSession.cpp \ + ../../stdafx.cpp \ + ../../Streaming.cpp \ + ../../TransitTunnel.cpp \ + ../../Transports.cpp \ + ../../Tunnel.cpp \ + ../../TunnelEndpoint.cpp \ + ../../TunnelGateway.cpp \ + ../../TunnelPool.cpp \ + ../../util.cpp \ + ../../../android-ifaddrs/ifaddrs.c + +HEADERS += mainwindow.h \ + ../../HTTPServer.h ../../I2PControl.h ../../UPnP.h ../../Daemon.h ../../Config.h \ + to_string.h \ + ../../AddressBook.h \ + ../../api.h \ + ../../Base.h \ + ../../BOB.h \ + ../../ClientContext.h \ + ../../Crypto.h \ + ../../Datagram.h \ + ../../Destination.h \ + ../../Family.h \ + ../../FS.h \ + ../../Garlic.h \ + ../../HTTP.h \ + ../../HTTPProxy.h \ + ../../I2CP.h \ + ../../I2NPProtocol.h \ + ../../I2PEndian.h \ + ../../I2PService.h \ + ../../I2PTunnel.h \ + ../../Identity.h \ + ../../LeaseSet.h \ + ../../LittleBigEndian.h \ + ../../Log.h \ + ../../NetDb.h \ + ../../NetDbRequests.h \ + ../../NTCPSession.h \ + ../../Profiling.h \ + ../../Queue.h \ + ../../Reseed.h \ + ../../RouterContext.h \ + ../../RouterInfo.h \ + ../../SAM.h \ + ../../Signature.h \ + ../../SOCKS.h \ + ../../SSU.h \ + ../../SSUData.h \ + ../../SSUSession.h \ + ../../stdafx.h \ + ../../Streaming.h \ + ../../Timestamp.h \ + ../../TransitTunnel.h \ + ../../Transports.h \ + ../../TransportSession.h \ + ../../Tunnel.h \ + ../../TunnelBase.h \ + ../../TunnelConfig.h \ + ../../TunnelEndpoint.h \ + ../../TunnelGateway.h \ + ../../TunnelPool.h \ + ../../util.h \ + ../../version.h \ + ../../../android-ifaddrs/ifaddrs.h + +FORMS += mainwindow.ui + +CONFIG += mobility + +MOBILITY = + +LIBS += -lz + +android { +message("Using Android settings") +DEFINES += ANDROID=1 +# git clone https://github.com/emileb/Boost-for-Android-Prebuilt.git +# git clone https://github.com/anon5/OpenSSL-for-Android-Prebuilt.git +# git clone https://github.com/anon5/android-ifaddrs.git +INCLUDEPATH += /home/anon5/git/Boost-for-Android-Prebuilt/boost_1_53_0/include \ + /home/anon5/git/OpenSSL-for-Android-Prebuilt/openssl-1.0.2/include \ + ../../../android-ifaddrs/ +equals(ANDROID_TARGET_ARCH, armeabi-v7a){ +LIBS += -L/home/anon5/git/Boost-for-Android-Prebuilt/boost_1_53_0/armeabi-v7a/lib \ + -L/home/anon5/git/OpenSSL-for-Android-Prebuilt/openssl-1.0.2/armeabi-v7a/lib \ +-lcrypto \ +-lssl \ +-lboost_system-gcc-mt-1_53 \ +-lboost_date_time-gcc-mt-1_53 \ +-lboost_filesystem-gcc-mt-1_53 \ +-lboost_program_options-gcc-mt-1_53 +} +} + +linux:!android { +message("Using Linux settings") +LIBS += -lcrypto -lssl -lboost_system -lboost_date_time -lboost_filesystem -lboost_program_options -lpthread +} + diff --git a/qt/i2pd_qt/main.cpp b/qt/i2pd_qt/main.cpp new file mode 100644 index 00000000..db5c39e5 --- /dev/null +++ b/qt/i2pd_qt/main.cpp @@ -0,0 +1,21 @@ +#include "mainwindow.h" +#include +#include +#include "../../Daemon.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + + w.show(); + + if (Daemon.init(argc, argv)) + { + if (Daemon.start()) + Daemon.run (); + Daemon.stop(); + } + + return a.exec(); +} diff --git a/qt/i2pd_qt/mainwindow.cpp b/qt/i2pd_qt/mainwindow.cpp new file mode 100644 index 00000000..49d64fce --- /dev/null +++ b/qt/i2pd_qt/mainwindow.cpp @@ -0,0 +1,14 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} diff --git a/qt/i2pd_qt/mainwindow.h b/qt/i2pd_qt/mainwindow.h new file mode 100644 index 00000000..a3948a91 --- /dev/null +++ b/qt/i2pd_qt/mainwindow.h @@ -0,0 +1,22 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/qt/i2pd_qt/mainwindow.ui b/qt/i2pd_qt/mainwindow.ui new file mode 100644 index 00000000..7ebf8731 --- /dev/null +++ b/qt/i2pd_qt/mainwindow.ui @@ -0,0 +1,21 @@ + + MainWindow + + + + 0 + 0 + 800 + 480 + + + + MainWindow + + + + + + + + diff --git a/qt/i2pd_qt/to_string.h b/qt/i2pd_qt/to_string.h new file mode 100644 index 00000000..a4bcf480 --- /dev/null +++ b/qt/i2pd_qt/to_string.h @@ -0,0 +1,19 @@ +#ifndef TO_STRING_H +#define TO_STRING_H + +#include +#include + +namespace tostr { +template +std::string to_string(T value) +{ + std::ostringstream os ; + os << value ; + return os.str() ; +} +} + +using namespace tostr; + +#endif // TO_STRING_H