You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.5 KiB

  1. #ifndef _SERVER_H
  2. #define _SERVER_H
  3. #include <ev.h>
  4. #include <time.h>
  5. #include "encrypt.h"
  6. #include "jconf.h"
  7. struct listen_ctx {
  8. ev_io io;
  9. int fd;
  10. struct timeval timeout;
  11. struct sockaddr sock;
  12. };
  13. struct server_ctx {
  14. ev_io io;
  15. int connected;
  16. struct server *server;
  17. };
  18. struct server {
  19. int fd;
  20. char buf[BUF_SIZE]; // server send from, remote recv into
  21. char stage;
  22. int buf_len;
  23. struct timeval timeout;
  24. struct rc4_state *e_ctx;
  25. struct rc4_state *d_ctx;
  26. struct server_ctx *recv_ctx;
  27. struct server_ctx *send_ctx;
  28. struct remote *remote;
  29. };
  30. struct remote_ctx {
  31. ev_io io;
  32. ev_timer watcher;
  33. int connected;
  34. struct remote *remote;
  35. };
  36. struct remote {
  37. int fd;
  38. char buf[BUF_SIZE]; // remote send from, server recv into
  39. int buf_len;
  40. struct remote_ctx *recv_ctx;
  41. struct remote_ctx *send_ctx;
  42. struct server *server;
  43. };
  44. static void accept_cb (EV_P_ ev_io *w, int revents);
  45. static void server_recv_cb (EV_P_ ev_io *w, int revents);
  46. static void server_send_cb (EV_P_ ev_io *w, int revents);
  47. static void remote_recv_cb (EV_P_ ev_io *w, int revents);
  48. static void remote_send_cb (EV_P_ ev_io *w, int revents);
  49. struct remote* new_remote(int fd, struct timeval timeout);
  50. struct remote *connect_to_remote(char *remote_host, char *remote_port, struct timeval timeout);
  51. void free_remote(struct remote *remote);
  52. void close_and_free_remote(EV_P_ struct remote *remote);
  53. struct server* new_server(int fd);
  54. void free_server(struct server *server);
  55. void close_and_free_server(EV_P_ struct server *server);
  56. #endif // _SERVER_H