summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/pol/complete.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-04-20 15:20:10 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-04-20 15:20:10 +0000
commit4bfd6c07281847405e127e9588376fcf20d07a7e (patch)
tree17b4f02e6802499ad51f4712104be4554f0c777e /src/ipcpd/normal/pol/complete.c
parenta3048addc6a6f4284ade5c024ae42db5719f509a (diff)
parentb3f13ce940382cf449a244b2ff65dbf36ce2fe4b (diff)
downloadouroboros-4bfd6c07281847405e127e9588376fcf20d07a7e.tar.gz
ouroboros-4bfd6c07281847405e127e9588376fcf20d07a7e.zip
Merged in dstaesse/ouroboros/be-complete (pull request #489)
ipcpd: Build complete graph with gam
Diffstat (limited to 'src/ipcpd/normal/pol/complete.c')
-rw-r--r--src/ipcpd/normal/pol/complete.c71
1 files changed, 50 insertions, 21 deletions
diff --git a/src/ipcpd/normal/pol/complete.c b/src/ipcpd/normal/pol/complete.c
index 6c0be9ec..20a2dafb 100644
--- a/src/ipcpd/normal/pol/complete.c
+++ b/src/ipcpd/normal/pol/complete.c
@@ -40,6 +40,8 @@
#include <stdlib.h>
#include <assert.h>
+#define COMPLETE_REFRESH 1000 /* ms */
+
struct complete {
struct nbs * nbs;
struct ae * ae;
@@ -69,6 +71,11 @@ static void * listener(void * o)
return (void *) 0;
}
+static void path_reset(char * path)
+{
+ path[strlen(MEMBERS_PATH)] = '\0';
+}
+
static void * allocator(void * o)
{
qosspec_t qs;
@@ -77,6 +84,12 @@ static void * allocator(void * o)
ssize_t i;
struct complete * complete;
struct conn conn;
+ uint64_t addr;
+ char path[RIB_MAX_PATH_LEN];
+ struct timespec to = {(COMPLETE_REFRESH / 1000),
+ (COMPLETE_REFRESH % 1000) * 1000000};
+
+ strcpy(path, MEMBERS_PATH);
complete = (struct complete *) o;
@@ -86,31 +99,47 @@ static void * allocator(void * o)
/* FIXME: implement QoS specs */
qs.cube = QOS_CUBE_BE;
- /* FIXME: subscribe to members to keep the graph complete. */
- len = rib_children("/" MEMBERS_NAME, &children);
- for (i = 0; i < len; ++i) {
- if (strcmp(children[i], ipcpi.name) != 0) {
- if (connmgr_alloc(complete->ae,
- children[i],
- &qs,
- &conn)) {
- log_warn("Failed to get a conn to neighbor.");
- free(children[i]);
- continue;
- }
-
- if (nbs_add(complete->nbs, conn)) {
- log_err("Failed to add neighbor.");
- free(children[i]);
- continue;
+ while (true) {
+ len = rib_children(MEMBERS_PATH, &children);
+ for (i = 0; i < len; ++i) {
+ if (strcmp(children[i], ipcpi.name) != 0) {
+ path_reset(path);
+ rib_path_append(path, children[i]);
+ if (rib_read(path, &addr,
+ sizeof(addr)) !=
+ sizeof(addr)) {
+ log_err("Failed to read address.");
+ free(children[i]);
+ continue;
+ }
+
+ if (nbs_has(complete->nbs, addr)) {
+ free(children[i]);
+ continue;
+ }
+
+ if (connmgr_alloc(complete->ae, children[i],
+ &qs, &conn)) {
+ log_warn("Failed conn to neighbor.");
+ free(children[i]);
+ continue;
+ }
+
+ if (nbs_add(complete->nbs, conn)) {
+ log_err("Failed to add neighbor.");
+ free(children[i]);
+ continue;
+ }
}
+ free(children[i]);
}
- free(children[i]);
- }
- if (len > 0)
- free(children);
+ if (len > 0)
+ free(children);
+
+ nanosleep(&to, NULL);
+ }
return (void *) 0;
}