summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-03-29 14:42:37 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2017-03-29 14:42:37 +0200
commite43fd05ba896ad5b4ac390f6097d6e6a06308f28 (patch)
tree326d07c63210916306825b40407116018a6b6bad /src/ipcpd
parent9097a5446c31b83ec224b3e1403a319b24025346 (diff)
downloadouroboros-e43fd05ba896ad5b4ac390f6097d6e6a06308f28.tar.gz
ouroboros-e43fd05ba896ad5b4ac390f6097d6e6a06308f28.zip
ipcpd: normal: Make graph undirected
This turns the directed graph into an undirected one. Only one side of the flow creates an FSDB entry. The graph structure creates an edge object for every vertex involved when an edge is updated or removed.
Diffstat (limited to 'src/ipcpd')
-rw-r--r--src/ipcpd/normal/graph.c38
-rw-r--r--src/ipcpd/normal/graph.h2
-rw-r--r--src/ipcpd/normal/routing.c4
3 files changed, 37 insertions, 7 deletions
diff --git a/src/ipcpd/normal/graph.c b/src/ipcpd/normal/graph.c
index 5fd6fcb6..5de7c15b 100644
--- a/src/ipcpd/normal/graph.c
+++ b/src/ipcpd/normal/graph.c
@@ -1,7 +1,7 @@
/*
* Ouroboros - Copyright (C) 2016 - 2017
*
- * Graph structure
+ * Undirected graph structure
*
* Dimitri Staessens <dimitri.staessens@ugent.be>
* Sander Vrijders <sander.vrijders@ugent.be>
@@ -205,6 +205,7 @@ int graph_update_edge(struct graph * graph,
struct vertex * v;
struct edge * e;
struct vertex * nb;
+ struct edge * nb_e;
assert(graph);
@@ -237,9 +238,9 @@ int graph_update_edge(struct graph * graph,
e = add_edge(v, nb);
if (e == NULL) {
if (list_is_empty(&v->edges))
- del_vertex(graph, v);
+ del_vertex(graph, v);
if (list_is_empty(&nb->edges))
- del_vertex(graph, v);
+ del_vertex(graph, nb);
pthread_mutex_unlock(&graph->lock);
log_err("Failed to add edge.");
return -ENOMEM;
@@ -248,6 +249,23 @@ int graph_update_edge(struct graph * graph,
e->qs = qs;
+ nb_e = find_edge_by_addr(nb, s_addr);
+ if (nb_e == NULL) {
+ nb_e = add_edge(nb, v);
+ if (nb_e == NULL) {
+ del_edge(e);
+ if (list_is_empty(&v->edges))
+ del_vertex(graph, v);
+ if (list_is_empty(&nb->edges))
+ del_vertex(graph, nb);
+ pthread_mutex_unlock(&graph->lock);
+ log_err("Failed to add edge.");
+ return -ENOMEM;
+ }
+ }
+
+ nb_e->qs = qs;
+
pthread_mutex_unlock(&graph->lock);
return 0;
@@ -260,6 +278,7 @@ int graph_del_edge(struct graph * graph,
struct vertex * v;
struct edge * e;
struct vertex * nb;
+ struct edge * nb_e;
assert(graph);
@@ -286,14 +305,21 @@ int graph_del_edge(struct graph * graph,
return -1;
}
+ nb_e = find_edge_by_addr(nb, s_addr);
+ if (nb_e == NULL) {
+ pthread_mutex_unlock(&graph->lock);
+ log_err("No such edge.");
+ return -1;
+ }
+
del_edge(e);
+ del_edge(nb_e);
/* Removing vertex if it was the last edge */
if (list_is_empty(&v->edges))
- del_vertex(graph, v);
-
+ del_vertex(graph, v);
if (list_is_empty(&nb->edges))
- del_vertex(graph, v);
+ del_vertex(graph, nb);
pthread_mutex_unlock(&graph->lock);
diff --git a/src/ipcpd/normal/graph.h b/src/ipcpd/normal/graph.h
index 70be8626..44496bc3 100644
--- a/src/ipcpd/normal/graph.h
+++ b/src/ipcpd/normal/graph.h
@@ -1,7 +1,7 @@
/*
* Ouroboros - Copyright (C) 2016 - 2017
*
- * Graph structure
+ * Undirected graph structure
*
* Dimitri Staessens <dimitri.staessens@ugent.be>
* Sander Vrijders <sander.vrijders@ugent.be>
diff --git a/src/ipcpd/normal/routing.c b/src/ipcpd/normal/routing.c
index bf736311..bd41b489 100644
--- a/src/ipcpd/normal/routing.c
+++ b/src/ipcpd/normal/routing.c
@@ -157,6 +157,10 @@ static int routing_neighbor_event(enum nb_event event,
size_t len;
uint8_t * data;
+ /* Only announce the flow if our address is bigger */
+ if (ipcpi.dt_addr < conn.conn_info.addr)
+ return 0;
+
path[0] = '\0';
sprintf(fso_name, "%" PRIu64 "-%" PRIu64,
ipcpi.dt_addr, conn.conn_info.addr);