diff options
author | ambrop7 <ambrop7@1a93d707-3861-5ebc-ad3b-9740d49b5140> | 2013-01-22 18:49:47 +0400 |
---|---|---|
committer | ambrop7 <ambrop7@1a93d707-3861-5ebc-ad3b-9740d49b5140> | 2013-01-22 18:49:47 +0400 |
commit | c7d42bc280ad0ef0be91ba0a7c750dbfa3e8dc49 (patch) | |
tree | 2d4abf43f9320020413915c088b7c69e7bfb3eec /client | |
parent | 2ba003366db9251ef4e08f51655d5cd430ddf82a (diff) |
client: make max_peers adjustible at runtime via command line
Diffstat (limited to 'client')
-rw-r--r-- | client/client.c | 18 | ||||
-rw-r--r-- | client/client.h | 2 |
2 files changed, 17 insertions, 3 deletions
diff --git a/client/client.c b/client/client.c index ce96f0a..707a919 100644 --- a/client/client.c +++ b/client/client.c @@ -119,6 +119,7 @@ struct { int igmp_group_membership_interval; int igmp_last_member_query_time; int allow_peer_talk_without_ssl; + int max_peers; } options; // bind addresses @@ -686,6 +687,7 @@ void print_help (const char *name) " [--igmp-group-membership-interval <ms>]\n" " [--igmp-last-member-query-time <ms>]\n" " [--allow-peer-talk-without-ssl]\n" + " [--max-peers <number>]\n" "Address format is a.b.c.d:port (IPv4) or [addr]:port (IPv6).\n", name ); @@ -736,6 +738,7 @@ int parse_arguments (int argc, char *argv[]) options.igmp_group_membership_interval = DEFAULT_IGMP_GROUP_MEMBERSHIP_INTERVAL; options.igmp_last_member_query_time = DEFAULT_IGMP_LAST_MEMBER_QUERY_TIME; options.allow_peer_talk_without_ssl = 0; + options.max_peers = DEFAULT_MAX_PEERS; int have_fragmentation_latency = 0; @@ -1109,6 +1112,17 @@ int parse_arguments (int argc, char *argv[]) } i++; } + else if (!strcmp(arg, "--max-peers")) { + if (1 >= argc - i) { + fprintf(stderr, "%s: requires an argument\n", arg); + return 0; + } + if ((options.max_peers = atoi(argv[i + 1])) <= 0) { + fprintf(stderr, "%s: wrong argument\n", arg); + return 0; + } + i++; + } else if (!strcmp(arg, "--allow-peer-talk-without-ssl")) { options.allow_peer_talk_without_ssl = 1; } @@ -1279,7 +1293,7 @@ void signal_handler (void *unused) void peer_add (peerid_t id, int flags, const uint8_t *cert, int cert_len) { ASSERT(server_ready) - ASSERT(num_peers < MAX_PEERS) + ASSERT(num_peers < options.max_peers) ASSERT(!find_peer_by_id(id)) ASSERT(id != my_id) ASSERT(cert_len >= 0) @@ -2744,7 +2758,7 @@ void server_handler_newclient (void *user, peerid_t peer_id, int flags, const ui } // check if there is spece for the peer - if (num_peers >= MAX_PEERS) { + if (num_peers >= options.max_peers) { BLog(BLOG_WARNING, "server: newclient: no space for new peer (maximum number reached)"); return; } diff --git a/client/client.h b/client/client.h index 8e197ed..595ed59 100644 --- a/client/client.h +++ b/client/client.h @@ -58,7 +58,7 @@ #define TCP_MAX_PASSWORD_LISTENER_CLIENTS 50 // maximum number of peers -#define MAX_PEERS 256 +#define DEFAULT_MAX_PEERS 256 // maximum number of peer's MAC addresses to remember #define PEER_DEFAULT_MAX_MACS 16 // maximum number of multicast addresses per peer |