stratum: reduce client algo & socket struct size

to reduce a bit the memory usage... require a make clean!

+ prevent null/local ips from bans.
This commit is contained in:
Tanguy Pruvot 2017-12-17 07:25:25 +01:00
parent ba7873e9f2
commit 39d123a071
5 changed files with 14 additions and 6 deletions

View file

@ -442,7 +442,7 @@ bool client_auth_by_workers(YAAMP_CLIENT *client)
// source = new YAAMP_SOURCE; // source = new YAAMP_SOURCE;
// memset(source, 0, sizeof(YAAMP_SOURCE)); // memset(source, 0, sizeof(YAAMP_SOURCE));
// //
// strncpy(source->ip, client->sock->ip, 1024); // strncpy(source->ip, client->sock->ip, 64);
// source->speed = 1; // source->speed = 1;
// //
// g_list_source.AddTail(source); // g_list_source.AddTail(source);

View file

@ -5,12 +5,12 @@
// int count; // int count;
// double speed; // double speed;
// //
// char ip[1024]; // char ip[64];
//}; //};
struct YAAMP_ALGO struct YAAMP_ALGO
{ {
char name[1024]; char name[64];
YAAMP_HASH_FUNCTION hash_function; YAAMP_HASH_FUNCTION hash_function;
double diff_multiplier; double diff_multiplier;

View file

@ -126,6 +126,10 @@ void client_block_ip(YAAMP_CLIENT *client, const char *reason)
{ {
char buffer[1024]; char buffer[1024];
sprintf(buffer, "iptables -A INPUT -s %s -p tcp --dport %d -j REJECT", client->sock->ip, g_tcp_port); sprintf(buffer, "iptables -A INPUT -s %s -p tcp --dport %d -j REJECT", client->sock->ip, g_tcp_port);
if(strcmp("0.0.0.0", client->sock->ip) == 0) return;
if(strstr(client->sock->ip, "192.168.")) return;
if(strstr(client->sock->ip, "127.0.0.")) return;
int s = system(buffer); int s = system(buffer);
stratumlog("%s: %s blocked (%s)\n", g_stratum_algo, client->sock->ip, reason); stratumlog("%s: %s blocked (%s)\n", g_stratum_algo, client->sock->ip, reason);
} }
@ -134,8 +138,12 @@ void client_block_ipset(YAAMP_CLIENT *client, const char *ipset_name)
{ {
char buffer[1024]; char buffer[1024];
sprintf(buffer, "ipset -q -A %s %s", ipset_name, client->sock->ip); sprintf(buffer, "ipset -q -A %s %s", ipset_name, client->sock->ip);
if(strcmp("0.0.0.0", client->sock->ip) == 0) return;
if(strstr(client->sock->ip, "192.168.")) return;
if(strstr(client->sock->ip, "127.0.0.")) return;
int s = system(buffer); int s = system(buffer);
stratumlog("%s: %s blocked via ipset %s\n", g_stratum_algo, client->sock->ip, ipset_name); stratumlog("%s: %s blocked via ipset %s %s\n", g_stratum_algo, client->sock->ip, ipset_name, client->username);
} }
bool client_reset_multialgo(YAAMP_CLIENT *client, bool first) bool client_reset_multialgo(YAAMP_CLIENT *client, bool first)

View file

@ -24,7 +24,7 @@ YAAMP_SOCKET *socket_initialize(int sock)
memset(&name, 0, len); memset(&name, 0, len);
int res = getpeername(s->sock, (struct sockaddr *)&name, &len); int res = getpeername(s->sock, (struct sockaddr *)&name, &len);
inet_ntop(AF_INET, &name.sin_addr, s->ip, 1024); inet_ntop(AF_INET, &name.sin_addr, s->ip, 64);
res = getsockname(s->sock, (struct sockaddr *)&name, &len); res = getsockname(s->sock, (struct sockaddr *)&name, &len);
s->port = ntohs(name.sin_port); s->port = ntohs(name.sin_port);

View file

@ -3,7 +3,7 @@
struct YAAMP_SOCKET struct YAAMP_SOCKET
{ {
char ip[1024]; char ip[64];
int port; int port;
// pthread_mutex_t mutex; // pthread_mutex_t mutex;