Skip to content

Commit

Permalink
An add 'limit_min_hubs' option
Browse files Browse the repository at this point in the history
Resolves janvidar#69
  • Loading branch information
Tantrix authored and modelrockettier committed Feb 9, 2020
1 parent fe15b4a commit 66e781c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions autotest/test_inf.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ EXO_TEST(inf_limit_hubs_setup,
inf_hub->config->limit_min_hubs_reg = 2;
inf_hub->config->limit_min_hubs_op = 2;
inf_hub->config->limit_max_hubs = 25;
inf_hub->config->limit_min_hubs = 1;

return 1;
} );
Expand Down
3 changes: 2 additions & 1 deletion doc/uhub.conf
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ limit_max_hubs = 0
limit_min_hubs_user = 0
limit_min_hubs_reg = 0
limit_min_hubs_op = 0
limit_min_share = 0
limit_min_hubs = 0
# Example:
# To require users to share at least 1 GB in order to enter the hub:
# limit_min_share = 1024
limit_min_share = 0
limit_max_share = 0
limit_min_slots = 0
limit_max_slots = 0
Expand Down
10 changes: 10 additions & 0 deletions src/core/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,16 @@
<since>0.2.0</since>
</option>

<option name="limit_min_hubs" type="int" default="0">
<check min="0" />
<short>Minimum total hub connections allowed, user/reg/op combined</short>
<description><![CDATA[
Only allow users that are logged into other hubs (regardless of privileges) to enter this hub.
]]></description>
<syntax>0 = off</syntax>
<since>0.5.2</since>
</option>

<option name="limit_min_share" type="int" default="0">
<check min="0" />
<short>Limit minimum share size in megabytes</short>
Expand Down
18 changes: 17 additions & 1 deletion src/core/gen_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (C) 2007-2020, Jan Vidar Krey
*
* THIS FILE IS AUTOGENERATED - DO NOT MODIFY
* Created 2020-02-08 21:04, by config.py
* Created 2020-02-09 10:26, by config.py
*/

void config_defaults(struct hub_config* config)
Expand Down Expand Up @@ -36,6 +36,7 @@ void config_defaults(struct hub_config* config)
config->limit_min_hubs_user = 0;
config->limit_min_hubs_reg = 0;
config->limit_min_hubs_op = 0;
config->limit_min_hubs = 0;
config->limit_min_share = 0;
config->limit_max_share = 0;
config->limit_min_slots = 0;
Expand Down Expand Up @@ -426,6 +427,18 @@ static int apply_config(struct hub_config* config, char* key, char* data, int li
return 0;
}

if (!strcmp(key, "limit_min_hubs"))
{
min = 0;
if (!apply_integer(key, data, &config->limit_min_hubs, &min, 0))
{
LOG_ERROR("Configuration parse error on line %d", line_count);
LOG_ERROR("\"limit_min_hubs\" (integer), default=0");
return -1;
}
return 0;
}

if (!strcmp(key, "limit_min_share"))
{
min = 0;
Expand Down Expand Up @@ -1228,6 +1241,9 @@ void dump_config(struct hub_config* config, int ignore_defaults)
if (!ignore_defaults || config->limit_min_hubs_op != 0)
fprintf(stdout, "limit_min_hubs_op = %d\n", config->limit_min_hubs_op);

if (!ignore_defaults || config->limit_min_hubs != 0)
fprintf(stdout, "limit_min_hubs = %d\n", config->limit_min_hubs);

if (!ignore_defaults || config->limit_min_share != 0)
fprintf(stdout, "limit_min_share = %d\n", config->limit_min_share);

Expand Down
3 changes: 2 additions & 1 deletion src/core/gen_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (C) 2007-2020, Jan Vidar Krey
*
* THIS FILE IS AUTOGENERATED - DO NOT MODIFY
* Created 2020-02-08 21:04, by config.py
* Created 2020-02-09 10:26, by config.py
*/

struct hub_config
Expand Down Expand Up @@ -36,6 +36,7 @@ struct hub_config
int limit_min_hubs_user; /*<<< Minimum concurrent hubs as a guest user (default: 0) */
int limit_min_hubs_reg; /*<<< Minimum concurrent hubs as a registered user (default: 0) */
int limit_min_hubs_op; /*<<< Minimum concurrent hubs as a operator (or admin) (default: 0) */
int limit_min_hubs; /*<<< Minimum total hub connections allowed, user/reg/op combined (default: 0) */
int limit_min_share; /*<<< Limit minimum share size in megabytes (default: 0) */
int limit_max_share; /*<<< Limit maximum share size in megabytes (default: 0) */
int limit_min_slots; /*<<< Limit minimum number of upload slots open per user (default: 0) */
Expand Down
5 changes: 5 additions & 0 deletions src/core/hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,11 @@ size_t hub_get_max_hubs_total(struct hub_info* hub)
return hub->config->limit_max_hubs;
}

size_t hub_get_min_hubs_total(struct hub_info* hub)
{
return hub->config->limit_min_hubs;
}

size_t hub_get_max_hubs_user(struct hub_info* hub)
{
return hub->config->limit_max_hubs_user;
Expand Down
1 change: 1 addition & 0 deletions src/core/hub.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ extern size_t hub_get_min_hubs_op(struct hub_info* hub);
* be logged in to simultaneously regardless of the type of user.
*/
extern size_t hub_get_max_hubs_total(struct hub_info* hub);
extern size_t hub_get_min_hubs_total(struct hub_info* hub);

/**
* Schedule runslice.
Expand Down
3 changes: 2 additions & 1 deletion src/core/inf.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ static int check_limits(struct hub_info* hub, struct hub_user* user, struct adc_

if ((user->limits.hub_count_user < hub_get_min_hubs_user(hub) && hub_get_min_hubs_user(hub)) ||
(user->limits.hub_count_registered < hub_get_min_hubs_reg(hub) && hub_get_min_hubs_reg(hub)) ||
(user->limits.hub_count_operator < hub_get_min_hubs_op(hub) && hub_get_min_hubs_op(hub)))
(user->limits.hub_count_operator < hub_get_min_hubs_op(hub) && hub_get_min_hubs_op(hub)) ||
(user->limits.hub_count_total < hub_get_min_hubs_total(hub) && hub_get_min_hubs_total(hub)))
{
return status_msg_user_hub_limit_low;
}
Expand Down

0 comments on commit 66e781c

Please sign in to comment.