mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-24 09:23:46 +00:00
Refine APIs for auto-blocking
This commit is contained in:
@@ -259,7 +259,23 @@ clear_block_list()
|
||||
}
|
||||
|
||||
int
|
||||
check_block_list(char *addr, int err_level)
|
||||
check_block_list(char *addr)
|
||||
{
|
||||
size_t addr_len = strlen(addr);
|
||||
|
||||
if (cache_key_exist(block_list, addr, addr_len)) {
|
||||
int *count = NULL;
|
||||
cache_lookup(block_list, addr, addr_len, &count);
|
||||
|
||||
if (count != NULL && *count > MAX_TRIES)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
update_block_list(char *addr, int err_level)
|
||||
{
|
||||
size_t addr_len = strlen(addr);
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@ int get_acl_mode(void);
|
||||
|
||||
void init_block_list();
|
||||
void free_block_list();
|
||||
int check_block_list(char *addr, int err_level);
|
||||
int check_block_list(char *addr);
|
||||
int update_block_list(char *addr, int err_level);
|
||||
int remove_from_block_list(char *addr);
|
||||
|
||||
int outbound_block_match_host(const char *host);
|
||||
|
||||
+2
-3
@@ -327,8 +327,7 @@ report_addr(int fd, int err_level)
|
||||
peer_name = get_peer_name(fd);
|
||||
if (peer_name != NULL) {
|
||||
LOGE("failed to handshake with %s", peer_name);
|
||||
// Block all requests from this IP, if the err# exceeds 128.
|
||||
if (check_block_list(peer_name, err_level)) {
|
||||
if (update_block_list(peer_name, err_level)) {
|
||||
LOGE("add %s to block list", peer_name);
|
||||
}
|
||||
}
|
||||
@@ -1499,7 +1498,7 @@ accept_cb(EV_P_ ev_io *w, int revents)
|
||||
in_white_list = 1;
|
||||
}
|
||||
}
|
||||
if (!in_white_list && check_block_list(peer_name, 0)) {
|
||||
if (!in_white_list && check_block_list(peer_name)) {
|
||||
LOGE("block all requests from %s", peer_name);
|
||||
close(serverfd);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user