mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
remove tcp stuff
This commit is contained in:
parent
c25f266cb3
commit
e045ccafb3
3 changed files with 24 additions and 160 deletions
|
@ -16,10 +16,6 @@ struct network_con_s {
|
|||
int connected;
|
||||
};
|
||||
|
||||
struct network_con_s network_array[ARRAY_NETWORK_LEN];
|
||||
|
||||
pthread_mutex_t tcp_array_mutex;
|
||||
|
||||
/**
|
||||
* Add tcp connection.
|
||||
* @param ipv4
|
||||
|
@ -35,20 +31,6 @@ int add_tcp_conncection(char *ipv4, int port);
|
|||
*/
|
||||
int run_server(int port);
|
||||
|
||||
/**
|
||||
* Insert tcp connection to tcp array.
|
||||
* @param entry
|
||||
* @return
|
||||
*/
|
||||
int insert_to_tcp_array(struct network_con_s entry);
|
||||
|
||||
/**
|
||||
* Checks if a tcp address is already contained in the database.
|
||||
* @param entry
|
||||
* @return
|
||||
*/
|
||||
int tcp_array_contains_address(struct sockaddr_in entry);
|
||||
|
||||
/**
|
||||
* Send message via tcp to all other hosts.
|
||||
* @param msg
|
||||
|
|
|
@ -30,7 +30,6 @@ void daemon_shutdown() {
|
|||
pthread_mutex_destroy(&probe_array_mutex);
|
||||
pthread_mutex_destroy(&client_array_mutex);
|
||||
pthread_mutex_destroy(&ap_array_mutex);
|
||||
pthread_mutex_destroy(&tcp_array_mutex);
|
||||
}
|
||||
|
||||
void signal_handler(int sig) {
|
||||
|
@ -67,11 +66,6 @@ int init_mutex() {
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(&tcp_array_mutex, NULL) != 0) {
|
||||
fprintf(stderr, "Mutex init failed!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(&denied_array_mutex, NULL) != 0) {
|
||||
fprintf(stderr, "Mutex init failed!\n");
|
||||
return 1;
|
||||
|
|
|
@ -13,18 +13,8 @@
|
|||
|
||||
LIST_HEAD(tcp_sock_list);
|
||||
|
||||
int tcp_array_insert(struct network_con_s entry);
|
||||
|
||||
int tcp_array_delete(struct sockaddr_in entry);
|
||||
|
||||
int tcp_array_contains_address_help(struct sockaddr_in entry);
|
||||
|
||||
void print_tcp_entry(struct network_con_s entry);
|
||||
|
||||
int tcp_list_contains_address(struct sockaddr_in entry);
|
||||
|
||||
int tcp_entry_last = -1;
|
||||
|
||||
static struct uloop_fd server;
|
||||
struct client *next_client = NULL;
|
||||
|
||||
|
@ -37,7 +27,8 @@ struct client {
|
|||
};
|
||||
|
||||
static void client_close(struct ustream *s) {
|
||||
struct client *cl = container_of(s, struct client, s.stream);
|
||||
struct client *cl = container_of(s,
|
||||
struct client, s.stream);
|
||||
|
||||
fprintf(stderr, "Connection closed\n");
|
||||
ustream_free(s);
|
||||
|
@ -58,14 +49,14 @@ static void client_notify_state(struct ustream *s) {
|
|||
|
||||
fprintf(stderr, "eof!, pending: %d, total: %d\n", s->w.data_bytes, cl->ctr);
|
||||
|
||||
// TODO: REMOVE CLIENT FROM LIST! OR NOT?
|
||||
if (!s->w.data_bytes)
|
||||
return client_close(s);
|
||||
|
||||
}
|
||||
|
||||
static void client_to_server_close(struct ustream *s) {
|
||||
struct network_con_s *con = container_of(s, struct network_con_s , stream.stream);
|
||||
struct network_con_s *con = container_of(s,
|
||||
struct network_con_s, stream.stream);
|
||||
|
||||
fprintf(stderr, "Connection to SERVER closed\n");
|
||||
ustream_free(s);
|
||||
|
@ -75,7 +66,8 @@ static void client_to_server_close(struct ustream *s) {
|
|||
}
|
||||
|
||||
static void client_to_server_state(struct ustream *s) {
|
||||
struct client *cl = container_of(s, struct client, s.stream);
|
||||
struct client *cl = container_of(s,
|
||||
struct client, s.stream);
|
||||
|
||||
if (!s->eof)
|
||||
return;
|
||||
|
@ -96,14 +88,11 @@ static void client_read_cb(struct ustream *s, int bytes) {
|
|||
if (!str)
|
||||
break;
|
||||
|
||||
//printf("RECEIVED String: %s\n", str);
|
||||
|
||||
if (network_config.use_symm_enc) {
|
||||
char *base64_dec_str = malloc(B64_DECODE_LEN(strlen(str)));
|
||||
int base64_dec_length = b64_decode(str, base64_dec_str, B64_DECODE_LEN(strlen(str)));
|
||||
char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length);
|
||||
|
||||
printf("NETRWORK RECEIVED: %s\n", dec);
|
||||
free(base64_dec_str);
|
||||
handle_network_msg(dec);
|
||||
free(dec);
|
||||
|
@ -176,7 +165,8 @@ static void connect_cb(struct uloop_fd *f, unsigned int events) {
|
|||
return;
|
||||
}
|
||||
|
||||
struct network_con_s *entry = container_of(f, struct network_con_s, fd);
|
||||
struct network_con_s *entry = container_of(f,
|
||||
struct network_con_s, fd);
|
||||
|
||||
fprintf(stderr, "Connection established\n");
|
||||
uloop_fd_delete(&entry->fd);
|
||||
|
@ -186,7 +176,6 @@ static void connect_cb(struct uloop_fd *f, unsigned int events) {
|
|||
|
||||
ustream_fd_init(&entry->stream, entry->fd.fd);
|
||||
entry->connected = 1;
|
||||
printf("NEW TCP CONNECTION!!!\n");
|
||||
}
|
||||
|
||||
int add_tcp_conncection(char *ipv4, int port) {
|
||||
|
@ -212,32 +201,16 @@ int add_tcp_conncection(char *ipv4, int port) {
|
|||
free(tcp_entry);
|
||||
return -1;
|
||||
}
|
||||
printf("Trying to add tcp socket to ULOOP!\n");
|
||||
tcp_entry->fd.cb = connect_cb;
|
||||
uloop_fd_add(&tcp_entry->fd, ULOOP_WRITE | ULOOP_EDGE_TRIGGER);
|
||||
|
||||
printf("NEW TCP CONNECTION!!! to %s:%d\n", ipv4, port);
|
||||
printf("New TCP connection to %s:%d\n", ipv4, port);
|
||||
list_add(&tcp_entry->list, &tcp_sock_list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int insert_to_tcp_array(struct network_con_s entry) {
|
||||
pthread_mutex_lock(&tcp_array_mutex);
|
||||
|
||||
int ret = tcp_array_insert(entry);
|
||||
pthread_mutex_unlock(&tcp_array_mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void print_tcp_entry(struct network_con_s entry) {
|
||||
printf("Conenctin to Port: %d\n", entry.sock_addr.sin_port);
|
||||
}
|
||||
|
||||
void send_tcp(char *msg) {
|
||||
pthread_mutex_lock(&tcp_array_mutex);
|
||||
|
||||
if (network_config.use_symm_enc) {
|
||||
int length_enc;
|
||||
size_t msglen = strlen(msg);
|
||||
|
@ -249,9 +222,7 @@ void send_tcp(char *msg) {
|
|||
|
||||
list_for_each_entry(con, &tcp_sock_list, list)
|
||||
{
|
||||
printf("TRYING TO SEND!\n");
|
||||
if (con->connected) {
|
||||
//if(ustream_printf(&con->stream.stream, "%s", base64_enc_str) == 0) {
|
||||
if (ustream_write(&con->stream.stream, base64_enc_str, base64_enc_length, 0) == 0) {
|
||||
//TODO: ERROR HANDLING!
|
||||
}
|
||||
|
@ -262,15 +233,11 @@ void send_tcp(char *msg) {
|
|||
free(base64_enc_str);
|
||||
free(enc);
|
||||
} else {
|
||||
for (int i = 0; i <= tcp_entry_last; i++) {
|
||||
//if (send(network_array[i].sockfd, msg, strlen(msg), 0) < 0) {
|
||||
struct network_con_s *con;
|
||||
|
||||
list_for_each_entry(con, &tcp_sock_list, list)
|
||||
{
|
||||
printf("TRYING TO SEND!\n");
|
||||
if(con->connected)
|
||||
{
|
||||
if (con->connected) {
|
||||
if (ustream_printf(&con->stream.stream, "%s", msg) == 0) {
|
||||
//TODO: ERROR HANDLING!
|
||||
}
|
||||
|
@ -278,80 +245,6 @@ void send_tcp(char *msg) {
|
|||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&tcp_array_mutex);
|
||||
}
|
||||
|
||||
|
||||
void print_tcp_array() {
|
||||
printf("--------Connections------\n");
|
||||
for (int i = 0; i <= tcp_entry_last; i++) {
|
||||
print_tcp_entry(network_array[i]);
|
||||
}
|
||||
printf("------------------\n");
|
||||
}
|
||||
|
||||
int tcp_array_insert(struct network_con_s entry) {
|
||||
if (tcp_entry_last == -1) {
|
||||
network_array[0] = entry;
|
||||
tcp_entry_last++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i <= tcp_entry_last; i++) {
|
||||
if (entry.sock_addr.sin_addr.s_addr < network_array[i].sock_addr.sin_addr.s_addr) {
|
||||
break;
|
||||
}
|
||||
if (entry.sock_addr.sin_addr.s_addr == network_array[i].sock_addr.sin_addr.s_addr) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
for (int j = tcp_entry_last; j >= i; j--) {
|
||||
if (j + 1 <= ARRAY_NETWORK_LEN) {
|
||||
network_array[j + 1] = network_array[j];
|
||||
}
|
||||
}
|
||||
network_array[i] = entry;
|
||||
|
||||
if (tcp_entry_last < ARRAY_NETWORK_LEN) {
|
||||
tcp_entry_last++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tcp_array_delete(struct sockaddr_in entry) {
|
||||
int i;
|
||||
int found_in_array = 0;
|
||||
|
||||
if (tcp_entry_last == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i <= tcp_entry_last; i++) {
|
||||
if (entry.sin_addr.s_addr == network_array[i].sock_addr.sin_addr.s_addr) {
|
||||
found_in_array = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = i; j < tcp_entry_last; j++) {
|
||||
network_array[j] = network_array[j + 1];
|
||||
}
|
||||
|
||||
if (tcp_entry_last > -1 && found_in_array) {
|
||||
tcp_entry_last--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tcp_array_contains_address(struct sockaddr_in entry) {
|
||||
pthread_mutex_lock(&tcp_array_mutex);
|
||||
|
||||
int ret = tcp_array_contains_address_help(entry);
|
||||
pthread_mutex_unlock(&tcp_array_mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int tcp_list_contains_address(struct sockaddr_in entry) {
|
||||
struct network_con_s *con;
|
||||
|
@ -360,24 +253,19 @@ int tcp_list_contains_address(struct sockaddr_in entry) {
|
|||
{
|
||||
if(entry.sin_addr.s_addr == con->sock_addr.sin_addr.s_addr)
|
||||
{
|
||||
printf("FOUND TCP ENTRY!!!\n");
|
||||
return 1;
|
||||
}
|
||||
printf("NOT FOUND!!!\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tcp_array_contains_address_help(struct sockaddr_in entry) {
|
||||
if (tcp_entry_last == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i <= tcp_entry_last; i++) {
|
||||
if (entry.sin_addr.s_addr == network_array[i].sock_addr.sin_addr.s_addr) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_tcp_array() {
|
||||
struct network_con_s *con;
|
||||
|
||||
printf("--------Connections------\n");
|
||||
list_for_each_entry(con, &tcp_sock_list, list)
|
||||
{
|
||||
printf("Conenctin to Port: %d, Connected: %s\n", con->sock_addr.sin_port, con->connected ? "True" : "False");
|
||||
}
|
||||
printf("------------------\n");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue