summaryrefslogtreecommitdiffstats
path: root/src/Server/ConnectionManager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Server/ConnectionManager.h')
-rw-r--r--src/Server/ConnectionManager.h54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/Server/ConnectionManager.h b/src/Server/ConnectionManager.h
index 7d97edc..710665d 100644
--- a/src/Server/ConnectionManager.h
+++ b/src/Server/ConnectionManager.h
@@ -20,38 +20,38 @@
#ifndef MAD_SERVER_CONNECTIONMANAGER_H_
#define MAD_SERVER_CONNECTIONMANAGER_H_
-#include <list>
-#include <vector>
-#include <map>
-#include <set>
-
#include <Common/Configurable.h>
#include <Common/HostInfo.h>
#include <Common/Initializable.h>
#include <Common/RequestManager.h>
-#include <Net/IPAddress.h>
+#include <list>
+#include <vector>
+#include <map>
+#include <set>
+
+#include <boost/asio.hpp>
namespace Mad {
namespace Net {
+class Connection;
class Listener;
-class ServerConnection;
class Packet;
}
namespace Server {
-class ConnectionManager : public Common::Configurable, public Common::Initializable {
+class ConnectionManager : public Common::Configurable, public Common::Initializable, boost::noncopyable {
private:
- class Connection : public Common::Connection {
+ class ServerConnection : public Common::Connection {
public:
enum ConnectionType {
- DAEMON, CLIENT
+ UNKNOWN = 0, DAEMON, CLIENT
};
private:
- Net::ServerConnection *connection;
+ boost::shared_ptr<Net::Connection> connection;
ConnectionType type;
Common::HostInfo *hostInfo;
@@ -59,14 +59,13 @@ class ConnectionManager : public Common::Configurable, public Common::Initializa
virtual bool send(const Net::Packet &packet);
public:
- Connection(Net::ServerConnection *connection0);
- virtual ~Connection();
+ ServerConnection(boost::shared_ptr<Net::Connection> connection0);
bool isConnected() const;
virtual bool disconnect();
- virtual void* getCertificate(size_t *size) const;
- virtual void* getPeerCertificate(size_t *size) const;
+ //virtual void* getCertificate(size_t *size) const;
+ //virtual void* getPeerCertificate(size_t *size) const;
ConnectionType getConnectionType() const {
return type;
@@ -77,10 +76,15 @@ class ConnectionManager : public Common::Configurable, public Common::Initializa
}
bool isIdentified() const {
- return hostInfo;
+ return (type != UNKNOWN);
+ }
+
+ void identify() {
+ type = CLIENT;
}
void identify(Common::HostInfo *info) {
+ type = DAEMON;
hostInfo = info;
}
};
@@ -89,17 +93,13 @@ class ConnectionManager : public Common::Configurable, public Common::Initializa
std::string x509TrustFile, x509CrlFile, x509CertFile, x509KeyFile;
- std::vector<Net::IPAddress> listenerAddresses;
- std::list<Net::Listener*> listeners;
+ std::vector<boost::asio::ip::tcp::endpoint> listenerAddresses;
+ std::list<boost::shared_ptr<Net::Listener> > listeners;
- std::set<Connection*> connections;
+ std::set<boost::shared_ptr<ServerConnection> > connections;
std::map<std::string,Common::HostInfo> daemonInfo;
- // Prevent shallow copy
- ConnectionManager(const ConnectionManager &o);
- ConnectionManager& operator=(const ConnectionManager &o);
-
void updateState(Common::HostInfo *hostInfo, Common::HostInfo::State state);
void updateStateFinished(const Common::Request&) {
// TODO Error handling (updateStateFinished)
@@ -107,8 +107,8 @@ class ConnectionManager : public Common::Configurable, public Common::Initializa
ConnectionManager() {}
- void newConnectionHandler(Net::ServerConnection *con);
- void disconnectHandler(Connection *con);
+ void handleNewConnection(boost::shared_ptr<Net::Connection> con);
+ void handleDisconnect(boost::shared_ptr<ServerConnection> con);
protected:
virtual bool handleConfigEntry(const Common::ConfigEntry &entry, bool handled);
@@ -122,10 +122,12 @@ class ConnectionManager : public Common::Configurable, public Common::Initializa
return &connectionManager;
}
- Common::Connection* getDaemonConnection(const std::string &name) const throw (Net::Exception&);
+ boost::shared_ptr<Common::Connection> getDaemonConnection(const std::string &name) const throw (Net::Exception&);
std::string getDaemonName(const Common::Connection *con) const throw (Net::Exception&);
void identifyDaemonConnection(Common::Connection *con, const std::string &name) throw (Net::Exception&);
+ void identifyClientConnection(Common::Connection *con) throw (Net::Exception&);
+
std::vector<Common::HostInfo> getDaemonList() const;
};