summaryrefslogtreecommitdiffstats
path: root/src/peer.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-11-05 18:26:55 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-11-05 18:26:55 +0100
commitf631c10660c7c0bcdbf793bb1588670fb9ea82e6 (patch)
tree280d32d74c48bfde96cc3510df51e50a5609fa31 /src/peer.c
parent0c2f5da1650a295c29001e50384ec2f605055aed (diff)
downloadfastd-f631c10660c7c0bcdbf793bb1588670fb9ea82e6.tar
fastd-f631c10660c7c0bcdbf793bb1588670fb9ea82e6.zip
Implement peer groups
Diffstat (limited to 'src/peer.c')
-rw-r--r--src/peer.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/peer.c b/src/peer.c
index 97c21ed..117d51a 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -259,6 +259,7 @@ fastd_peer_config* fastd_peer_config_new(fastd_context *ctx, fastd_config *conf)
peer->name = NULL;
peer->key = NULL;
+ peer->group = conf->peer_group;
peer->protocol_config = NULL;
peer->next = conf->peers;
@@ -358,6 +359,9 @@ bool fastd_peer_claim_address(fastd_context *ctx, fastd_peer *new_peer, fastd_so
}
bool fastd_peer_config_equal(const fastd_peer_config *peer1, const fastd_peer_config *peer2) {
+ if (peer1->group != peer2->group)
+ return false;
+
if (!strequal(peer1->hostname, peer2->hostname))
return false;
@@ -385,6 +389,21 @@ void fastd_peer_delete(fastd_context *ctx, fastd_peer *peer) {
delete_peer(ctx, peer);
}
+static inline fastd_peer_group* find_peer_group(fastd_peer_group *group, const fastd_peer_group_config *config) {
+ if (group->conf == config)
+ return group;
+
+ fastd_peer_group *child;
+ for (child = group->children; child; child = child->next) {
+ fastd_peer_group *ret = find_peer_group(child, config);
+
+ if (ret)
+ return ret;
+ }
+
+ return NULL;
+}
+
fastd_peer* fastd_peer_add(fastd_context *ctx, fastd_peer_config *peer_conf) {
fastd_peer *peer = malloc(sizeof(fastd_peer));
@@ -392,11 +411,12 @@ fastd_peer* fastd_peer_add(fastd_context *ctx, fastd_peer_config *peer_conf) {
ctx->peers = peer;
peer->config = peer_conf;
+ peer->group = find_peer_group(ctx->peer_group, peer_conf->group);
peer->protocol_state = NULL;
peer->sock = NULL;
setup_peer(ctx, peer);
- pr_verbose(ctx, "adding peer %P", peer);
+ pr_verbose(ctx, "adding peer %P (group `%s')", peer, peer->group->conf->name);
return peer;
}