Skip to content
This repository was archived by the owner on Aug 4, 2019. It is now read-only.

Commit ab6c6f6

Browse files
committed
Merge pull request #36 from prokopowicz/master
exposed mark methods - made cache expiry configurable
2 parents 9a9cf15 + 795b950 commit ab6c6f6

16 files changed

+30
-47
lines changed

src/blacklist.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "common.h"
44
#include "cidr.h"
55

6-
#include "blacklist.h"
76
#include "check_cidr.h"
87

98
/**
@@ -14,12 +13,16 @@
1413

1514
int initial_blacklist_size = 100;
1615

16+
/**
17+
* externally settable parameter
18+
*
19+
* @param new_size initial size of expandable blacklist cache
20+
*/
21+
1722
void set_initial_blacklist_size(int new_size)
1823
{
1924
initial_blacklist_size = new_size;
2025
}
21-
22-
2326
/**
2427
* Adds the actor to the Repsheet blacklist
2528
*

src/blacklist.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/check_cidr.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@
77
#include "vector.h"
88

99

10-
int CACHED_FOR_SECONDS = 60;
10+
unsigned int cache_expiry = 60;
11+
12+
/**
13+
* externally settable parameter
14+
*
15+
* @param new_expiry number of seconds for caching CIDR blocks before hitting redis again
16+
*/
17+
void set_cache_expiry(unsigned int new_expiry)
18+
{
19+
cache_expiry = new_expiry;
20+
}
1121

1222
int check_and_update_cache(redisContext *context, const char *actor, char *reason, char *list, expanding_vector *ev, time_t *last_update_time)
1323
{
1424
long current_seconds = time(NULL);
1525

16-
if (*last_update_time + CACHED_FOR_SECONDS < current_seconds) {
26+
if (*last_update_time + cache_expiry < current_seconds) {
1727
clear_expanding_vector(ev);
1828
redisReply *listed = redisCommand(context, "SMEMBERS repsheet:cidr:%s", list);
1929
if (listed) {

src/check_cidr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#ifndef CHECK_CIDR
22
#define CHECK_CIDR
33

4-
extern int CACHED_FOR_SECONDS;
5-
64
#include "vector.h"
75
int checkCIDR(redisContext *context, const char *actor, char *reason, char *list, expanding_vector *ev, long *cache_update_time);
8-
96
#endif

src/librepsheet.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
#include "config.h"
77
#include "repsheet.h"
8-
#include "whitelist.h"
9-
#include "blacklist.h"
10-
#include "marked.h"
118

129
/**
1310
* @file librepsheet.c

src/marked.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "repsheet.h"
22
#include "common.h"
3-
#include "marked.h"
43

54
/**
65
* @file marked.c

src/marked.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/repsheet.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,20 @@ int actor_status(redisContext *context, const char *actor, int type, char *reaso
3131
int remote_address(char *connected_address, char *xff_header, char *address);
3232

3333
int blacklist(redisContext *context, const char *actor, int type, const char *reason);
34+
int is_ip_blacklisted(redisContext *context, const char *actor, char *reason);
35+
int is_user_blacklisted(redisContext *context, const char *actor, char *reason);
36+
3437
int whitelist(redisContext *context, const char *actor, int type, const char *reason);
38+
int is_ip_whitelisted(redisContext *context, const char *actor, char *reason);
39+
int is_user_whitelisted(redisContext *context, const char *actor, char *reason);
40+
int is_country_whitelisted(redisContext *context, const char *country_code);
41+
3542
int mark(redisContext *context, const char *actor, int type, const char *reason);
43+
int is_ip_marked(redisContext *context, const char *actor, char *reason);
44+
int is_user_marked(redisContext *context, const char *actor, char *reason);
3645

3746
void set_initial_whitelist_size(int new_size);
3847
void set_initial_blacklist_size(int new_size);
48+
void set_cache_expiry(unsigned int new_expiry);
3949

4050
#endif

src/whitelist.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "common.h"
44
#include "cidr.h"
55
#include "check_cidr.h"
6-
#include "whitelist.h"
76

87

98
/**

src/whitelist.h

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)