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.

60 lines
1.3 KiB

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