summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-11-05 22:48:34 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-11-05 22:48:34 +0100
commit65e60edefc9c9095244b5ee19d302607532174bf (patch)
treee7d8d03f85576977b8b1c59dc617728b1183846c
parent773e84403fae0da82575f04eef911a31267b167a (diff)
downloadfastd-65e60edefc9c9095244b5ee19d302607532174bf.tar
fastd-65e60edefc9c9095244b5ee19d302607532174bf.zip
Only delay initial handshakes for groups with constraints
-rw-r--r--src/peer.c78
1 files changed, 46 insertions, 32 deletions
diff --git a/src/peer.c b/src/peer.c
index 86cf4a1..9624fd5 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -159,6 +159,15 @@ static inline void free_socket(fastd_context *ctx, fastd_peer *peer) {
}
}
+static bool has_group_config_constraints(const fastd_peer_group_config *group) {
+ for (; group; group = group->parent) {
+ if (group->max_connections)
+ return true;
+ }
+
+ return false;
+}
+
void fastd_peer_reset_socket(fastd_context *ctx, fastd_peer *peer) {
if (!fastd_peer_is_socket_dynamic(peer))
return;
@@ -183,6 +192,36 @@ void fastd_peer_reset_socket(fastd_context *ctx, fastd_peer *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;
+}
+
+static inline bool is_group_in(fastd_peer_group *group1, fastd_peer_group *group2) {
+ while (group1) {
+ if (group1 == group2)
+ return true;
+
+ group1 = group1->parent;
+ }
+
+ return false;
+}
+
+static bool is_peer_in_group(fastd_peer *peer, fastd_peer_group *group) {
+ return is_group_in(peer->group, group);
+}
+
static void reset_peer(fastd_context *ctx, fastd_peer *peer) {
if (peer->established)
on_disestablish(ctx, peer);
@@ -227,8 +266,13 @@ static void setup_peer(fastd_context *ctx, fastd_peer *peer) {
if (!peer->protocol_state)
ctx->conf->protocol->init_peer_state(ctx, peer);
- if (!fastd_peer_is_floating(peer) || fastd_peer_is_dynamic(peer))
- fastd_task_schedule_handshake(ctx, peer, fastd_rand(ctx, 0, 3000));
+ if (!fastd_peer_is_floating(peer) || fastd_peer_is_dynamic(peer)) {
+ unsigned delay = 0;
+ if (has_group_config_constraints(peer->group->conf))
+ delay = fastd_rand(ctx, 0, 3000);
+
+ fastd_task_schedule_handshake(ctx, peer, delay);
+ }
}
static void delete_peer(fastd_context *ctx, fastd_peer *peer) {
@@ -389,36 +433,6 @@ 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;
-}
-
-static inline bool is_group_in(fastd_peer_group *group1, fastd_peer_group *group2) {
- while (group1) {
- if (group1 == group2)
- return true;
-
- group1 = group1->parent;
- }
-
- return false;
-}
-
-static bool is_peer_in_group(fastd_peer *peer, fastd_peer_group *group) {
- return is_group_in(peer->group, group);
-}
-
static inline unsigned count_established_group_peers(fastd_context *ctx, fastd_peer_group *group) {
unsigned ret = 0;
fastd_peer *peer;