Added option to run without the assumption of PlanetLab Vservers. We still assume...
[distributedratelimiting.git] / drl / config.c
index 261ce0c..23ee36e 100644 (file)
@@ -101,6 +101,49 @@ int get_eligible_leaves(drl_instance_t *instance) {
     return 0;
 }
 
+int parse_leaves(drl_instance_t *instance, char *leafstring) {
+    int count = 1;
+    int i;
+    char *comma = leafstring;
+    leaf_t *leaves = NULL;
+    map_handle leaf_map;
+    
+    while ((comma = strchr(comma, ',')) != NULL) {
+        count += 1;
+        comma++;
+    }
+
+    leaf_map = allocate_map();
+    if (leaf_map == NULL) {
+        return ENOMEM;
+    }
+
+    leaves = malloc(count * sizeof(leaf_t));
+    if (leaves == NULL) {
+        return ENOMEM;
+    }
+    memset(leaves, 0, count * sizeof(leaf_t));
+
+    comma = leafstring;
+    for (i = 0; i < count; ++i) {
+        leaves[i].xid = (uint32_t) strtol(comma, NULL, 16);
+        leaves[i].parent = NULL;
+        leaves[i].drop_prob = 0.0;
+        leaves[i].delay = 0;
+
+        printlog(LOG_DEBUG, "Read leaf - hex: %x, dec: %d\n", leaves[i].xid, leaves[i].xid);
+
+        comma = strchr(comma, ',');
+        comma++;
+    }
+
+    instance->leaf_map = leaf_map;
+    instance->leaves = leaves;
+    instance->leaf_count = count;
+
+    return 0;
+}
+
 static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) {
     xmlChar *id;
     xmlChar *limit;
@@ -119,7 +162,9 @@ static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) {
     ident_peer *current = NULL;
 
     /* The struct has been memsetted to 0, this is just to be safe. */
+#ifdef BUILD_ZOOKEEPER
     common->zk_host = NULL;
+#endif
     common->peers = NULL;
     common->members = NULL;
     common->next = NULL;
@@ -311,11 +356,12 @@ static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) {
         } else if ((!xmlStrcmp(fields->name, (const xmlChar *) "zkhost"))) {
             xmlChar *host = xmlNodeListGetString(doc, fields->children, 1);
 
+#ifdef BUILD_ZOOKEEPER
             common->zk_host = strdup((const char *) host);
             if (common->zk_host == NULL) {
                 return ENOMEM;
             }
-
+#endif
             xmlFree(host);
         }
         fields = fields->next;
@@ -326,11 +372,12 @@ static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) {
         return EINVAL;
     }
 
+#ifdef BUILD_ZOOKEEPER
     if (common->membership == ZOOKEEPER && common->zk_host == NULL) {
         printlog(LOG_CRITICAL, "Group membership protocol ZOOKEEPER requires a zkhost field.\n");
         return EINVAL;
     }
-
+#endif
     /* No errors. */
     return 0;
 }