From 843abb60dd307599ee2286a209ae161d745621a4 Mon Sep 17 00:00:00 2001 From: EinMByte Date: Sun, 2 Aug 2015 19:59:16 +0200 Subject: [PATCH] Make i2pcontrol password configurable. --- ClientContext.cpp | 3 ++- i2pcontrol/I2PControl.cpp | 4 ++-- i2pcontrol/I2PControl.h | 4 +++- i2pcontrol/I2PControlServer.cpp | 10 ++++------ i2pcontrol/I2PControlServer.h | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ClientContext.cpp b/ClientContext.cpp index 9ffd2303..9b4f7f17 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -116,7 +116,8 @@ namespace client if(i2pcontrolPort) { m_I2PControlService = new I2PControlService( i2p::util::config::GetArg("-i2pcontroladdress", "127.0.0.1"), - i2pcontrolPort + i2pcontrolPort, + i2p::util::config::GetArg("-i2pcontrolpassword", I2P_CONTROL_DEFAULT_PASSWORD) ); m_I2PControlService->Start(); LogPrint("I2PControl started"); diff --git a/i2pcontrol/I2PControl.cpp b/i2pcontrol/I2PControl.cpp index 38eecf42..656560de 100644 --- a/i2pcontrol/I2PControl.cpp +++ b/i2pcontrol/I2PControl.cpp @@ -100,8 +100,8 @@ void I2PControlSession::Response::setId(const std::string& identifier) id = identifier; } -I2PControlSession::I2PControlSession(boost::asio::io_service& ios) - : password(I2P_CONTROL_DEFAULT_PASSWORD), tokens(), tokensMutex(), +I2PControlSession::I2PControlSession(boost::asio::io_service& ios, const std::string& pass) + : password(pass), tokens(), tokensMutex(), service(ios), shutdownTimer(ios), expireTokensTimer(ios) { // Method handlers diff --git a/i2pcontrol/I2PControl.h b/i2pcontrol/I2PControl.h index c7563288..eb9b3eab 100644 --- a/i2pcontrol/I2PControl.h +++ b/i2pcontrol/I2PControl.h @@ -108,10 +108,12 @@ public: /** * Sets up the appropriate handlers. + * @param pass the password required to authenticate (i.e. obtains a token) * @param ios the parent io_service object, must remain valid throughout * the lifetime of this I2PControlSession. */ - I2PControlSession(boost::asio::io_service& ios); + I2PControlSession(boost::asio::io_service& ios, + const std::string& pass = I2P_CONTROL_DEFAULT_PASSWORD); /** * Starts the I2PControlSession. diff --git a/i2pcontrol/I2PControlServer.cpp b/i2pcontrol/I2PControlServer.cpp index 79b599be..5c956112 100644 --- a/i2pcontrol/I2PControlServer.cpp +++ b/i2pcontrol/I2PControlServer.cpp @@ -6,12 +6,10 @@ #include "util/Timestamp.h" #include "version.h" -namespace i2p -{ -namespace client -{ - I2PControlService::I2PControlService(const std::string& address, int port) - : m_Session(std::make_shared(m_Service)), +namespace i2p { +namespace client { + I2PControlService::I2PControlService(const std::string& address, int port, const std::string& pass) + : m_Session(std::make_shared(m_Service, pass)), m_IsRunning(false), m_Thread(nullptr), m_Acceptor(m_Service, boost::asio::ip::tcp::endpoint( boost::asio::ip::address::from_string(address), port) diff --git a/i2pcontrol/I2PControlServer.h b/i2pcontrol/I2PControlServer.h index 8f3a3782..2eb13654 100644 --- a/i2pcontrol/I2PControlServer.h +++ b/i2pcontrol/I2PControlServer.h @@ -21,7 +21,7 @@ typedef std::array I2PControlBuffer; class I2PControlService { public: - I2PControlService(const std::string& address, int port); + I2PControlService(const std::string& address, int port, const std::string& pass); ~I2PControlService (); void Start ();