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.

101 lines
3.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
6 years ago
10 years ago
10 years ago
10 years ago
  1. /*
  2. * shadowsocks.h - Header files of library interfaces
  3. *
  4. * Copyright (C) 2013 - 2019, Max Lv <max.c.lv@gmail.com>
  5. *
  6. * This file is part of the shadowsocks-libev.
  7. * shadowsocks-libev is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * shadowsocks-libev is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with shadowsocks-libev; see the file COPYING. If not, see
  19. * <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef _SHADOWSOCKS_H
  22. #define _SHADOWSOCKS_H
  23. typedef struct {
  24. /* Required */
  25. char *remote_host; // hostname or ip of remote server
  26. char *local_addr; // local ip to bind
  27. char *method; // encryption method
  28. char *password; // password of remote server
  29. int remote_port; // port number of remote server
  30. int local_port; // port number of local server
  31. int timeout; // connection timeout
  32. /* Optional, set NULL if not valid */
  33. char *acl; // file path to acl
  34. char *log; // file path to log
  35. int fast_open; // enable tcp fast open
  36. int mode; // enable udp relay
  37. int mtu; // MTU of interface
  38. int mptcp; // enable multipath TCP
  39. int verbose; // verbose mode
  40. } profile_t;
  41. /* An example profile
  42. *
  43. * const profile_t EXAMPLE_PROFILE = {
  44. * .remote_host = "example.com",
  45. * .local_addr = "127.0.0.1",
  46. * .method = "bf-cfb",
  47. * .password = "barfoo!",
  48. * .remote_port = 8338,
  49. * .local_port = 1080,
  50. * .timeout = 600;
  51. * .acl = NULL,
  52. * .log = NULL,
  53. * .fast_open = 0,
  54. * .mode = 0,
  55. * .verbose = 0
  56. * };
  57. */
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. typedef void (*ss_local_callback)(int socks_fd, int udp_fd, void *data);
  62. /*
  63. * Create and start a shadowsocks local server.
  64. *
  65. * Calling this function will block the current thread forever if the server
  66. * starts successfully.
  67. *
  68. * Make sure start the server in a separate process to avoid any potential
  69. * memory and socket leak.
  70. *
  71. * If failed, -1 is returned. Errors will output to the log file.
  72. */
  73. int start_ss_local_server(profile_t profile);
  74. /*
  75. * Create and start a shadowsocks local server, specifying a callback.
  76. *
  77. * The callback is invoked when the local server has started successfully. It passes the SOCKS
  78. * server and UDP relay file descriptors, along with any supplied user data.
  79. *
  80. * Returns -1 on failure.
  81. */
  82. int start_ss_local_server_with_callback(profile_t profile, ss_local_callback callback, void *udata);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. // To stop the service on posix system, just kill the daemon process
  87. // kill(pid, SIGKILL);
  88. // Otherwise, If you start the service in a thread, you may need to send a signal SIGUSER1 to the thread.
  89. // pthread_kill(pthread_t, SIGUSR1);
  90. #endif // _SHADOWSOCKS_H