Compare commits

..

No commits in common. "429e0cfeaaae2b535dfc989744a0b1e525db22fb" and "97248c37723ea6c5b03511d8ab77de57c4af15c8" have entirely different histories.

6 changed files with 2 additions and 79 deletions

View File

@ -89,9 +89,6 @@ void why2_chat_set_client_server_key(char *key); //SET KEY USED FOR ENCRYPTION B
char *why2_chat_get_client_server_key(void);
void why2_chat_deallocate_client_server_key(void);
void __why2_chat_set_server(why2_bool value); //IF PROGRAM IS SERVER-SIDE
why2_bool __why2_chat_is_server(void); //IF PROGRAM IS SERVER-SIDE
void __why2_set_asking_password(why2_bool value); //IF HASH SHOULD BE SENT INSTEAD OF NORMAL MESSAGE
why2_bool __why2_get_asking_password(void);

View File

@ -26,6 +26,4 @@ min_username_length = 4 # Minimal username length
max_username_tries = 3 # Times asking client for username (if client tries to use invalid username)
max_password_tries = 3 # Same as above but for invalid password
max_message_length = 100 # Maximal message length
min_message_delay = 250 # Minimal ms delay between user messages (to prevent spamming)
max_message_delay_violations = 4 # Maximal 'spam' messages that can be sent in row without getting disconnected
max_message_length = 100 # Maximal message length

View File

@ -25,7 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
why2_bool asking_password = 0;
why2_bool asking_username = 0;
why2_bool is_server = 0;
char *client_server_key = NULL;
void why2_chat_set_client_server_key(char *key)
@ -44,16 +43,6 @@ void why2_chat_deallocate_client_server_key(void)
client_server_key = NULL;
}
void __why2_chat_set_server(why2_bool value)
{
is_server = value;
}
why2_bool __why2_chat_is_server(void)
{
return is_server;
}
void __why2_set_asking_password(why2_bool value)
{
asking_password = value;

View File

@ -35,7 +35,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int main(void)
{
__why2_chat_set_server(1);
why2_check_version(); //CHECK FOR UPDATES
why2_chat_init_authority(); //CREATE AUTHORITY DIRECTORY
why2_chat_init_keys(); //CREATE ECC KEY

View File

@ -35,7 +35,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int main(void)
{
__why2_chat_set_server(1);
why2_check_version(); //CHECK FOR UPDATES
why2_chat_init_server_config(); //CREATE server.toml CONFIGURATION
why2_chat_init_keys(); //CREATE ECC KEY

View File

@ -21,7 +21,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
@ -51,8 +50,6 @@ typedef struct _connection_node
char *username;
unsigned long id;
char *key; //EACH USER WILL USE DIFFERENT KEY FOR COMMUNICATION
struct timespec last_message_time; //USED TO PREVENT SPAMMING
unsigned char spam_violations; //SPAM MESSAGES IN ROW
} connection_node_t; //SINGLE LINKED LIST
typedef struct _read_socket_raw_thread_node
@ -70,8 +67,6 @@ enum ENCRYPTION_DECRYPTION
why2_list_t connection_list = WHY2_LIST_EMPTY;
why2_list_t waiting_list = WHY2_LIST_EMPTY;
why2_node_t *find_connection(int connection);
char *get_string_from_json(struct json_object *json, char *string)
{
struct json_object *object;
@ -251,55 +246,6 @@ char *read_socket_raw(int socket, char *key)
recv(socket, wait_buffer, 1, MSG_PEEK);
why2_deallocate(wait_buffer);
//PREVENT FROM SPAMMING
if (__why2_chat_is_server())
{
//VARIABLES
int minimal_delay_ns = server_config_int("min_message_delay") * 1000000;
struct timespec current_time;
why2_node_t *node = find_connection(socket);
connection_node_t *client_node;
if (node != NULL)
{
client_node = (connection_node_t*) node -> value;
//GET TIME
clock_gettime(CLOCK_MONOTONIC, &current_time);
//NOT THE FIRST MESSAGE
if (client_node -> last_message_time.tv_nsec != -1)
{
int64_t difference = (current_time.tv_sec - client_node -> last_message_time.tv_sec) * 1000000000LL + (current_time.tv_nsec - client_node -> last_message_time.tv_nsec);
if (difference < minimal_delay_ns) //USER IS SPAMMING
{
//CHECK IF USER REACHED MAXIMUM VIOLATIONS
if (client_node -> spam_violations > server_config_int("max_message_delay_violations")) return NULL;
//WAIT UNTIL MINIMAL DELAY IS ACHIEVED
struct timespec sleep_time =
{
.tv_sec = (minimal_delay_ns - difference) / 1000000000,
.tv_nsec = (minimal_delay_ns - difference) % 1000000000
};
nanosleep(&sleep_time, NULL); //SLEEP
//ADD VIOLATION
client_node -> spam_violations++;
} else //USER IS NOT SPAMMING
{
//RESET VIOLATIONS
client_node -> spam_violations = 0;
}
}
//WRITE NEW TIME
clock_gettime(CLOCK_MONOTONIC, &client_node -> last_message_time); //GET TIME
}
}
//FIND THE RECEIVED SIZE
ioctl(socket, FIONREAD, &content_size);
@ -329,9 +275,6 @@ char *read_socket_raw(int socket, char *key)
encrypt_decrypt_message(&output, key, DECRYPTION); //DECRYPT
//REMOVE NON-ASCII
remove_non_ascii(&output);
//VALIDATE JSON FORMAT
struct json_object *json = json_tokener_parse(output);
if (json == NULL)
@ -954,9 +897,7 @@ void *why2_communicate_thread(void *arg)
pthread_self(),
why2_strdup(username),
get_latest_id(),
client_server_key,
{ -1, -1 },
0
client_server_key
};
why2_list_push(&connection_list, &node, sizeof(node)); //ADD TO LIST