} vpn_packet_t;
typedef struct listen_socket_t {
- struct event ev_tcp;
- struct event ev_udp;
int tcp;
int udp;
+ thread_t tcp_thread;
thread_t udp_thread;
sockaddr_t sa;
} listen_socket_t;
extern void handle_incoming_vpn_data(void *);
extern void finish_connecting(struct connection_t *);
extern void do_outgoing_connection(struct connection_t *);
-extern void handle_new_meta_connection(int, short, void *);
+extern void handle_new_meta_connection(void *);
extern int setup_listen_socket(const sockaddr_t *);
extern int setup_vpn_in_socket(const sockaddr_t *);
extern void send_packet(const struct node_t *, vpn_packet_t *);
continue;
}
- event_set(&listen_socket[listen_sockets].ev_tcp,
- listen_socket[listen_sockets].tcp,
- EV_READ|EV_PERSIST,
- handle_new_meta_connection, NULL);
- if(event_add(&listen_socket[listen_sockets].ev_tcp, NULL) < 0) {
- logger(LOG_ERR, "event_add failed: %s", strerror(errno));
+ memcpy(&listen_socket[listen_sockets].sa, aip->ai_addr, aip->ai_addrlen);
+
+ if(!thread_create(&listen_socket[listen_sockets].tcp_thread, handle_new_meta_connection, &listen_socket[listen_sockets])) {
+ logger(LOG_ERR, "thread_create failed: %s", strerror(errno));
abort();
}
free(hostname);
}
- memcpy(&listen_socket[listen_sockets].sa, aip->ai_addr, aip->ai_addrlen);
listen_sockets++;
if(listen_sockets >= MAXSOCKETS) {
}
for(i = 0; i < listen_sockets; i++) {
- event_del(&listen_socket[i].ev_tcp);
- event_del(&listen_socket[i].ev_udp);
close(listen_socket[i].tcp);
close(listen_socket[i].udp);
+ thread_destroy(&listen_socket[i].tcp_thread);
thread_destroy(&listen_socket[i].udp_thread);
}
accept a new tcp connect and create a
new connection
*/
-void handle_new_meta_connection(int sock, short events, void *data) {
+void handle_new_meta_connection(void *data) {
+ listen_socket_t *l = data;
connection_t *c;
sockaddr_t sa;
int fd;
socklen_t len = sizeof sa;
- fd = accept(sock, &sa.sa, &len);
+ while(true) {
+ fd = accept(l->tcp, &sa.sa, &len);
- if(fd < 0) {
- logger(LOG_ERR, "Accepting a new connection failed: %s", sockstrerror(sockerrno));
- return;
- }
+ if(fd < 0) {
+ logger(LOG_ERR, "Accepting a new connection failed: %s", sockstrerror(sockerrno));
+ return;
+ }
- sockaddrunmap(&sa);
+ sockaddrunmap(&sa);
- c = new_connection();
- c->name = xstrdup("<unknown>");
- c->outcipher = myself->connection->outcipher;
- c->outdigest = myself->connection->outdigest;
- c->outmaclength = myself->connection->outmaclength;
- c->outcompression = myself->connection->outcompression;
+ c = new_connection();
+ c->name = xstrdup("<unknown>");
+ c->outcipher = myself->connection->outcipher;
+ c->outdigest = myself->connection->outdigest;
+ c->outmaclength = myself->connection->outmaclength;
+ c->outcompression = myself->connection->outcompression;
- c->address = sa;
- c->hostname = sockaddr2hostname(&sa);
- c->socket = fd;
- c->last_ping_time = time(NULL);
+ c->address = sa;
+ c->hostname = sockaddr2hostname(&sa);
+ c->socket = fd;
+ c->last_ping_time = time(NULL);
- ifdebug(CONNECTIONS) logger(LOG_NOTICE, "Connection from %s", c->hostname);
+ ifdebug(CONNECTIONS) logger(LOG_NOTICE, "Connection from %s", c->hostname);
- configure_tcp(c);
+ configure_tcp(c);
- connection_add(c);
+ connection_add(c);
- c->allow_request = ID;
- send_id(c);
+ c->allow_request = ID;
+ send_id(c);
- if(!thread_create(&c->thread, handle_meta_connection_data, c)) {
- logger(LOG_ERR, "create_thread() failed: %s", strerror(errno));
- abort();
+ if(!thread_create(&c->thread, handle_meta_connection_data, c)) {
+ logger(LOG_ERR, "create_thread() failed: %s", strerror(errno));
+ abort();
+ }
}
}