コード例 #1
0
ファイル: udprelay.c プロジェクト: wobrea/shadowsocks-libev
int
init_udprelay(const char *server_host, const char *server_port,
#ifdef MODULE_LOCAL
              const struct sockaddr *remote_addr, const int remote_addr_len,
#ifdef MODULE_TUNNEL
              const ss_addr_t tunnel_addr,
#endif
#endif
              int mtu, crypto_t *crypto, int timeout, const char *iface)
{
    // Initialize ev loop
    struct ev_loop *loop = EV_DEFAULT;

    // Initialize MTU
    if (mtu > 0) {
        packet_size = mtu - 1 - 28 - 2 - 64;
        buf_size    = packet_size * 2;
    }

    // Initialize cache
    struct cache *conn_cache;
    cache_create(&conn_cache, MAX_UDP_CONN_NUM, free_cb);

    // ////////////////////////////////////////////////
    // Setup server context

    // Bind to port
    int serverfd = create_server_socket(server_host, server_port);
    if (serverfd < 0) {
        FATAL("[udp] bind() error");
    }
    setnonblocking(serverfd);

    server_ctx_t *server_ctx = new_server_ctx(serverfd);
#ifdef MODULE_REMOTE
    server_ctx->loop = loop;
#endif
    server_ctx->timeout    = max(timeout, MIN_UDP_TIMEOUT);
    server_ctx->crypto     = crypto;
    server_ctx->iface      = iface;
    server_ctx->conn_cache = conn_cache;
#ifdef MODULE_LOCAL
    server_ctx->remote_addr     = remote_addr;
    server_ctx->remote_addr_len = remote_addr_len;
#ifdef MODULE_TUNNEL
    server_ctx->tunnel_addr = tunnel_addr;
#endif
#endif

    ev_io_start(loop, &server_ctx->io);

    server_ctx_list[server_num++] = server_ctx;

    return serverfd;
}
コード例 #2
0
ファイル: udprelay.c プロジェクト: chijiao/shadowsocks-libev
int udprelay_init(const char *server_host, const char *server_port,
#ifdef UDPRELAY_LOCAL
             const char *remote_host, const char *remote_port,
#ifdef UDPRELAY_TUNNEL
             const ss_addr_t tunnel_addr,
#endif
#endif
#ifdef UDPRELAY_REMOTE
             asyncns_t *asyncns,
#endif
             int method, int timeout, const char *iface)
{

    // Inilitialize ev loop
    struct ev_loop *loop = EV_DEFAULT;

    // Inilitialize cache
    struct cache *conn_cache;
    cache_create(&conn_cache, MAX_UDP_CONN_NUM, free_cb);

    //////////////////////////////////////////////////
    // Setup server context

    // Bind to port
    int serverfd = create_server_socket(server_host, server_port);
    if (serverfd < 0)
    {
        FATAL("udprelay bind() error..");
    }
    setnonblocking(serverfd);

    struct server_ctx *server_ctx = new_server_ctx(serverfd);
    server_ctx->timeout = timeout;
    server_ctx->method = method;
    server_ctx->iface = iface;
    server_ctx->conn_cache = conn_cache;
#ifdef UDPRELAY_LOCAL
    server_ctx->remote_host = remote_host;
    server_ctx->remote_port = remote_port;
#ifdef UDPRELAY_TUNNEL
    server_ctx->tunnel_addr = tunnel_addr;
#endif
#endif
#ifdef UDPRELAY_REMOTE
    server_ctx->asyncns = asyncns;
#endif

    ev_io_start(loop, &server_ctx->io);

    return 0;
}
コード例 #3
0
ファイル: udprelay.c プロジェクト: nodje/shadowsocks-libev
int init_udprelay(const char *server_host, const char *server_port,
#ifdef UDPRELAY_LOCAL
                  const struct sockaddr *remote_addr, const int remote_addr_len,
#ifdef UDPRELAY_TUNNEL
                  const ss_addr_t tunnel_addr,
#endif
#endif
                  int method, int auth, int timeout, const char *iface)
{
    // Inilitialize ev loop
    struct ev_loop *loop = EV_DEFAULT;

    // Inilitialize cache
    struct cache *conn_cache;
    cache_create(&conn_cache, MAX_UDP_CONN_NUM, free_cb);

    //////////////////////////////////////////////////
    // Setup server context

    // Bind to port
    int serverfd = create_server_socket(server_host, server_port);
    if (serverfd < 0) {
        FATAL("[udp] bind() error");
    }
    setnonblocking(serverfd);

    struct server_ctx *server_ctx = new_server_ctx(serverfd);
#ifdef UDPRELAY_REMOTE
    server_ctx->loop = loop;
#endif
    server_ctx->auth = auth;
    server_ctx->timeout = max(timeout, MIN_UDP_TIMEOUT);
    server_ctx->method = method;
    server_ctx->iface = iface;
    server_ctx->conn_cache = conn_cache;
#ifdef UDPRELAY_LOCAL
    server_ctx->remote_addr = remote_addr;
    server_ctx->remote_addr_len = remote_addr_len;
#ifdef UDPRELAY_TUNNEL
    server_ctx->tunnel_addr = tunnel_addr;
#endif
#endif

    ev_io_start(loop, &server_ctx->io);

    server_ctx_list[server_num++] = server_ctx;

    return 0;
}
コード例 #4
0
ファイル: udprelay.c プロジェクト: CalixHu/shadowsocksr-libev
int
init_udprelay(const char *server_host, const char *server_port,
#ifdef MODULE_LOCAL
              const struct sockaddr *remote_addr, const int remote_addr_len,
              const ss_addr_t tunnel_addr,
#endif
              int mtu, int timeout, const char *iface,
              cipher_env_t* cipher_env, const char *protocol, const char *protocol_param)
{
    // Initialize ev loop
    struct ev_loop *loop = EV_DEFAULT;

    // Initialize MTU
    if (mtu > 0) {
        packet_size = mtu - 1 - 28 - 2 - 64;
        buf_size    = packet_size * 2;
    }

    // Initialize cache
    struct cache *conn_cache;
    cache_create(&conn_cache, MAX_UDP_CONN_NUM, free_cb);

    // ////////////////////////////////////////////////
    // Setup server context

    // Bind to port
    int serverfd = create_server_socket(server_host, server_port);
    if (serverfd < 0) {
        FATAL("[udp] bind() error");
    }
    setnonblocking(serverfd);

    server_ctx_t *server_ctx = new_server_ctx(serverfd);

    server_ctx->cipher_env = cipher_env;
#ifdef MODULE_REMOTE
    server_ctx->loop = loop;
#endif
    server_ctx->timeout    = max(timeout, MIN_UDP_TIMEOUT);
    server_ctx->iface      = iface;
    server_ctx->conn_cache = conn_cache;
#ifdef MODULE_LOCAL
    server_ctx->remote_addr     = remote_addr;
    server_ctx->remote_addr_len = remote_addr_len;
    //SSR beg
    server_ctx->protocol_plugin = new_obfs_class((char *)protocol);
    if (server_ctx->protocol_plugin) {
        server_ctx->protocol = server_ctx->protocol_plugin->new_obfs();
        server_ctx->protocol_global = server_ctx->protocol_plugin->init_data();
    }

    server_info _server_info;
    memset(&_server_info, 0, sizeof(server_info));
    strcpy(_server_info.host, server_host);
    _server_info.port = atoi(server_port);
    _server_info.g_data = server_ctx->protocol_global;
    _server_info.param = (char *)protocol_param;
    _server_info.key = enc_get_key(cipher_env);
    _server_info.key_len = enc_get_key_len(cipher_env);

    if (server_ctx->protocol_plugin)
        server_ctx->protocol_plugin->set_server_info(server_ctx->protocol, &_server_info);
    //SSR end
    server_ctx->tunnel_addr = tunnel_addr;
#endif

    ev_io_start(loop, &server_ctx->io);

    server_ctx_list[server_num++] = server_ctx;

    return 0;
}
コード例 #5
0
int init_udprelay(const char *server_host, const char *server_port,
#ifdef UDPRELAY_LOCAL
                  const char *remote_host, const char *remote_port,
#ifdef UDPRELAY_TUNNEL
                  const ss_addr_t tunnel_addr,
#endif
#endif
#ifdef UDPRELAY_REMOTE
                  int dns_thread_num,
#endif
                  int method, int timeout, const char *iface)
{
    // Inilitialize ev loop
    struct ev_loop *loop = EV_DEFAULT;

    // Inilitialize cache
    struct cache *conn_cache;
    cache_create(&conn_cache, MAX_UDP_CONN_NUM, free_cb);

    //////////////////////////////////////////////////
    // Setup server context

#ifdef UDPRELAY_REMOTE
    // setup asyncns
    asyncns_t *asyncns;
    if (!(asyncns = asyncns_new(dns_thread_num))) {
        FATAL("[udp] asyncns failed");
    }
    resolve_ctx = malloc(sizeof(struct resolve_ctx));

    int asyncnsfd = asyncns_fd(asyncns);
    ev_io_init(&resolve_ctx->io, query_resolve_cb, asyncnsfd, EV_READ);
    ev_io_start(loop, &resolve_ctx->io);

    resolve_ctx->asyncns = asyncns;
    resolve_ctx->asyncnsfd = asyncnsfd;
#endif

    // Bind to port
    int serverfd = create_server_socket(server_host, server_port);
    if (serverfd < 0) {
        FATAL("[udp] bind() error..");
    }
    setnonblocking(serverfd);

    server_ctx = new_server_ctx(serverfd);
    server_ctx->timeout = min(timeout, MAX_CONNECT_TIMEOUT);
    server_ctx->method = method;
    server_ctx->iface = iface;
    server_ctx->conn_cache = conn_cache;
#ifdef UDPRELAY_LOCAL
    server_ctx->remote_host = remote_host;
    server_ctx->remote_port = remote_port;
#ifdef UDPRELAY_TUNNEL
    server_ctx->tunnel_addr = tunnel_addr;
#endif
#endif
#ifdef UDPRELAY_REMOTE
    server_ctx->asyncns = asyncns;
#endif

    ev_io_start(loop, &server_ctx->io);

    return 0;
}