From b503a70fca019368399038cde649b3ef8df85bb9 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 18 Sep 2008 14:51:48 +0200 Subject: Flexiblere ?bertragung von Host-Listen --- src/Core/ConfigManager.cpp | 2 +- src/Core/ConfigManager.h | 7 ++-- src/Core/ConnectionManager.cpp | 16 ++++---- src/Core/ConnectionManager.h | 6 +-- src/Core/DaemonInfo.h | 45 ---------------------- .../RequestHandlers/DaemonListRequestHandler.cpp | 10 +---- 6 files changed, 19 insertions(+), 67 deletions(-) delete mode 100644 src/Core/DaemonInfo.h (limited to 'src/Core') diff --git a/src/Core/ConfigManager.cpp b/src/Core/ConfigManager.cpp index d42db35..4484420 100644 --- a/src/Core/ConfigManager.cpp +++ b/src/Core/ConfigManager.cpp @@ -32,7 +32,7 @@ bool ConfigManager::parseLine(const std::vector §ion, const std return false; } else if(Common::Util::tolower(key) == "daemon") { - daemons.push_back(DaemonInfo(value)); + daemons.push_back(Common::HostInfo(value)); } else if(Common::Util::tolower(key) == "listen") { try { diff --git a/src/Core/ConfigManager.h b/src/Core/ConfigManager.h index e089358..7178887 100644 --- a/src/Core/ConfigManager.h +++ b/src/Core/ConfigManager.h @@ -20,9 +20,10 @@ #ifndef MAD_CORE_CONFIGMANAGER_H_ #define MAD_CORE_CONFIGMANAGER_H_ -#include "DaemonInfo.h" #include +#include #include + #include #include @@ -38,7 +39,7 @@ class ConfigManager : public Common::ConfigManager { uint16_t methods; std::vector listeners; - std::vector daemons; + std::vector daemons; std::string x509TrustFile, x509CrlFile, x509CertFile, x509KeyFile; @@ -57,7 +58,7 @@ class ConfigManager : public Common::ConfigManager { } const std::vector& getListenerAddresses() const {return listeners;} - const std::vector& getDaemonList() const {return daemons;} + const std::vector& getDaemonList() const {return daemons;} const std::string& getX509TrustFile() const {return x509TrustFile;} const std::string& getX509CrlFile() const {return x509CrlFile;} diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index 3007fd6..546d097 100644 --- a/src/Core/ConnectionManager.cpp +++ b/src/Core/ConnectionManager.cpp @@ -98,9 +98,9 @@ ConnectionManager::ConnectionManager() { refreshPollfds(); - const std::vector& daemons = configManager->getDaemonList(); + const std::vector& daemons = configManager->getDaemonList(); - for(std::vector::const_iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon) { + for(std::vector::const_iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon) { daemonInfo.insert(std::make_pair(daemon->getName(), *daemon)); identifiedDaemonConnections.insert(std::make_pair(daemon->getName(), 0)); } @@ -131,6 +131,8 @@ void ConnectionManager::handleConnections(std::list& con for(std::map::iterator idCon = identifiedDaemonConnections.begin(); idCon != identifiedDaemonConnections.end(); ++idCon) { if(idCon->second == *con) { idCon->second = 0; + + daemonInfo[idCon->first].setStatus(Common::HostInfo::INACTIVE); break; } } @@ -193,17 +195,17 @@ void ConnectionManager::identifyDaemonConnection(Net::Connection *connection, co } idCon->second = *con; + daemonInfo[idCon->first].setStatus(Common::HostInfo::RUNNING); connection->setIdentified(); Common::Logger::log("Identified as '" + name + "'."); } -std::map ConnectionManager::getDaemonList() const { - std::map ret; +std::vector ConnectionManager::getDaemonList() const { + std::vector ret; - for(std::map::const_iterator con = identifiedDaemonConnections.begin(); con != identifiedDaemonConnections.end(); ++con) { - if(con->second) - ret.insert(std::make_pair(con->first, daemonInfo.at(con->first))); + for(std::map::const_iterator daemon = daemonInfo.begin(); daemon != daemonInfo.end(); ++daemon) { + ret.push_back(daemon->second); } return ret; diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h index be9beb9..0832b5a 100644 --- a/src/Core/ConnectionManager.h +++ b/src/Core/ConnectionManager.h @@ -26,8 +26,8 @@ #include #include -#include "DaemonInfo.h" #include +#include #include namespace Mad { @@ -50,7 +50,7 @@ class ConnectionManager { std::list daemonConnections; std::list clientConnections; - std::map daemonInfo; + std::map daemonInfo; std::map identifiedDaemonConnections; std::vector pollfds; @@ -85,7 +85,7 @@ class ConnectionManager { Net::Connection* getDaemonConnection(const std::string &name) const throw (Common::Exception&); void identifyDaemonConnection(Net::Connection *connection, const std::string &name) throw (Common::Exception&); - std::map getDaemonList() const; + std::vector getDaemonList() const; }; } diff --git a/src/Core/DaemonInfo.h b/src/Core/DaemonInfo.h deleted file mode 100644 index 0377c57..0000000 --- a/src/Core/DaemonInfo.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * DaemonInfo.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef MAD_CORE_DAEMONINFO_H_ -#define MAD_CORE_DAEMONINFO_H_ - -#include - -namespace Mad { -namespace Core { - -class DaemonInfo { - private: - std::string name; - std::string ip; - - public: - DaemonInfo(const std::string& name0) : name(name0) {} - - const std::string& getName() const {return name;} - - void setIP(const std::string& ip0) {ip = ip0;} - const std::string& getIP() const {return ip;} -}; - -} -} - -#endif /* MAD_CORE_DAEMONINFO_H_ */ diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.cpp b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp index 2a6b119..cec1c5a 100644 --- a/src/Core/RequestHandlers/DaemonListRequestHandler.cpp +++ b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace Mad { namespace Core { @@ -39,13 +39,7 @@ void DaemonListRequestHandler::handlePacket(Net::Connection *connection, const N // TODO Require authentication - std::map daemons = ConnectionManager::getConnectionManager()->getDaemonList(); - std::vector names; - - for(std::map::iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon) - names.push_back(daemon->first); - - connection->send(Net::Packets::NameListPacket(Net::Packet::OK, packet.getRequestId(), names)); + connection->send(Net::Packets::HostListPacket(Net::Packet::OK, packet.getRequestId(), ConnectionManager::getConnectionManager()->getDaemonList())); signalFinished().emit(); } -- cgit v1.2.3