diff options
author | randomdan <randomdan@localhost> | 2010-03-02 19:02:23 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2010-03-02 19:02:23 +0000 |
commit | 24384005a5fdd0e7ce2fc8d24841479310b53c47 (patch) | |
tree | b0fd6e00f1653a17ad4d0dfa51e995b478929002 | |
parent | A few fixes and mark requests for replication (diff) | |
download | netfs-24384005a5fdd0e7ce2fc8d24841479310b53c47.tar.bz2 netfs-24384005a5fdd0e7ce2fc8d24841479310b53c47.tar.xz netfs-24384005a5fdd0e7ce2fc8d24841479310b53c47.zip |
Config with basic site map
-rw-r--r-- | netfs/daemon.cpp | 2 | ||||
-rw-r--r-- | netfs/daemon.xml | 20 | ||||
-rw-r--r-- | netfs/daemonConfig.cpp | 24 | ||||
-rw-r--r-- | netfs/daemonConfig.h | 19 |
4 files changed, 55 insertions, 10 deletions
diff --git a/netfs/daemon.cpp b/netfs/daemon.cpp index 9d0e4f7..691b681 100644 --- a/netfs/daemon.cpp +++ b/netfs/daemon.cpp @@ -158,7 +158,7 @@ createListeners(DaemonGlobalStatePtr dgs, SocketSet & lsocks) hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; struct addrinfo *result, *rp; - if (getaddrinfo(NULL, dgs->config->tcpPort.c_str(), &hints, &result) == 0) { + if (getaddrinfo(NULL, dgs->config->self->tcpPort.c_str(), &hints, &result) == 0) { for (rp = result; rp != NULL; rp = rp->ai_next) { int sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if (sfd == -1) { diff --git a/netfs/daemon.xml b/netfs/daemon.xml index 2454ff6..72d4ad6 100644 --- a/netfs/daemon.xml +++ b/netfs/daemon.xml @@ -1,9 +1,23 @@ <config> - <tcpPort>4000</tcpPort> + <hosts> + <host> + <self>true</self> + <tcpPort>4000</tcpPort> + <name>akira.random.lan</name> + </host> + <host> + <tcpPort>4000</tcpPort> + <name>vmware2.random.lan</name> + </host> + </hosts> <exports> <export> - <name>tmp</name> - <root>/tmp</root> + <name>test</name> + <root>/tmp/netfsTest</root> + <replicate> + <name>akira.random.lan</name> + <name>vmware2.random.lan</name> + </replicate> </export> </exports> </config> diff --git a/netfs/daemonConfig.cpp b/netfs/daemonConfig.cpp index 520cec1..ad3621d 100644 --- a/netfs/daemonConfig.cpp +++ b/netfs/daemonConfig.cpp @@ -10,18 +10,34 @@ DaemonConfig::Load(const char * path) return dc; } -DaemonConfig::DaemonConfig(xmlNodePtr conf) : - tcpPort(xmlGetNodeValue(conf, "tcpPort")) +DaemonConfig::DaemonConfig(xmlNodePtr conf) { + foreachxml(hos, xmlGetNode(conf, "hosts"), "hosts") { + HostPtr h = new Host(hos); + hosts[h->name] = h; + if (h->self) { + self = h; + } + } foreachxml(exp, xmlGetNode(conf, "exports"), "export") { - ExportPtr e = new Export(exp); + ExportPtr e = new Export(exp, hosts); exports[e->name] = e; } } -DaemonConfig::Export::Export(xmlNodePtr exp) : +DaemonConfig::Export::Export(xmlNodePtr exp, const HostMap & hosts) : root(xmlGetNodeValue(exp, "root")), name(xmlGetNodeValue(exp, "name")) { + foreachxml(rep, xmlGetNode(exp, "replicate"), "name") { + replicate.insert(hosts.find(xmlGetNodeValue(rep))->second); + } +} + +DaemonConfig::Host::Host(xmlNodePtr hos) : + tcpPort(xmlGetNodeValue(hos, "tcpPort")), + name(xmlGetNodeValue(hos, "name")), + self(strcmp(xmlGetNodeValue(hos, "self", "false"), "true") == 0) +{ } diff --git a/netfs/daemonConfig.h b/netfs/daemonConfig.h index d15fade..223436c 100644 --- a/netfs/daemonConfig.h +++ b/netfs/daemonConfig.h @@ -3,17 +3,31 @@ #include <string> #include <map> +#include <set> #include "smartpointer.h" #include "xml.h" class DaemonConfig : public virtual IsRefCounted { public: + class Host : public virtual IsRefCounted { + public: + Host(xmlNodePtr); + + std::string tcpPort; + std::string name; + bool self; + }; + typedef SmartPointer<Host> HostPtr; + typedef std::map<std::string, HostPtr> HostMap; + typedef std::set<HostPtr> HostSet; + class Export : public virtual IsRefCounted { public: - Export(xmlNodePtr); + Export(xmlNodePtr, const HostMap &); std::string root; std::string name; + HostSet replicate; }; typedef SmartPointer<Export> ExportPtr; typedef std::map<std::string, ExportPtr> ExportMap; @@ -22,8 +36,9 @@ class DaemonConfig : public virtual IsRefCounted { static SmartPointer<DaemonConfig> Load(const char * path); - std::string tcpPort; ExportMap exports; + HostMap hosts; + HostPtr self; }; typedef SmartPointer<DaemonConfig> DaemonConfigPtr; |