diff options
-rw-r--r-- | segget/network.cpp | 2 | ||||
-rw-r--r-- | segget/network.h | 4 | ||||
-rw-r--r-- | segget/network0.conf | 37 | ||||
-rw-r--r-- | segget/segget.cpp | 7 | ||||
-rw-r--r-- | segget/segment.cpp | 6 |
5 files changed, 39 insertions, 17 deletions
diff --git a/segget/network.cpp b/segget/network.cpp index fb849df..ea417ce 100644 --- a/segget/network.cpp +++ b/segget/network.cpp @@ -68,6 +68,8 @@ void Tnetwork::init(uint priority_value){ Tconfig conf("network"+toString(network_num)+".conf"); conf.set("mode","network_mode",network_mode,0,3); conf.set("network_bind","bind_interface",bind_interface); + conf.set("network_bind","bind_local_port",bind_local_port,0,65535); + conf.set("network_bind","bind_local_port_range",bind_local_port_range,1,65535); conf.set("network_connections","max_connections",max_connections,1,MAX_CONNECTS); conf.set("network_connections","connection_timeout",connection_timeout,1,1000); conf.set("network_connections","ftp_response_timeout",ftp_response_timeout,1,-1); diff --git a/segget/network.h b/segget/network.h index f88c9b5..58c77b1 100644 --- a/segget/network.h +++ b/segget/network.h @@ -67,6 +67,8 @@ class Tnetwork{ ulong network_mode; //network_bind string bind_interface; + ulong bind_local_port; + ulong bind_local_port_range; //connections ulong max_connections; ulong connection_timeout; @@ -103,6 +105,8 @@ class Tnetwork{ network_mode(0), //network_bind bind_interface("none"), + bind_local_port(0), + bind_local_port_range(20), //connections max_connections(6), connection_timeout(15), diff --git a/segget/network0.conf b/segget/network0.conf index bc5d71c..bd16fca 100644 --- a/segget/network0.conf +++ b/segget/network0.conf @@ -45,19 +45,31 @@ network_mode=2 # bind_interface=none bind_interface=none -# BIND LOCALPORT -# Pass a long. This sets the local port number of the socket used for connection. -# This can be used in combination with BIND_INTERFACE and you are recommended to -# use BIND_LOCALPORTRANGE as well when this is set. -# Valid port numbers are 1 - 65535. +# BIND_LOCAL_PORT +# This sets the local port number of the socket used for connection. This option +# can be used in combination with BIND_INTERFACE and you are recommended to +# use BIND_LOCAL_PORT_RANGE as well when this is set. Set to 0 - to disable +# binding. Valid port numbers are 1 - 65535. +# Minimum value: 0 (no binding) +# Maximum value: 65535 +# Default: +# bind_local_port=0 +bind_local_port=0 -# BIND_LOCALPORTRANGE -# Pass a long. This is the number of attempts segget should make to find a -# working local port number. It starts with the given BIND_LOCALPORT and adds +# BIND_LOCAL_PORT_RANGE +# If BIND_LOCAL_PORT=0 this option will be ignored. +# This is the number of attempts segget should make to find a +# working local port number. It starts with the given BIND_LOCAL_PORT and adds # one to the number for each retry. Setting this to 1 or below will make segget # do only one try for the exact port number. Port numbers by nature are scarce # resources that will be busy at times so setting this value to something too -# low might cause unnecessary connection setup failures. +# low might cause unnecessary connection setup failures. +# Minimum value: 1 +# Maximum value: 65535 +# Default: +# bind_local_port_range=20 +bind_local_port_range=20 + [network_connections] # NETWORK_MAX_CONNECTIONS @@ -259,13 +271,6 @@ proxy_fetcher_port=3131 # Specify the user and password for authentication on a proxy-fetcher-server. # NOT IMPLEMENTED YET: proxy-fetcher-user=user # NOT IMPLEMENTED YET: proxy-fetcher-password=password -# Set to forbid direct connections to Internet servers if it's possible to use -# proxy-fetcher. -# NOT IMPLEMENTED YET: use-proxy-fetcher-demon-if-possible=1 -# Set to forbid direct connections to Internet servers. -# NOT IMPLEMENTED YET: use-proxy-fetcher-demon-only=0 -# Set to forbid using proxy-fetcher. -# NOT IMPLEMENTED YET: no-proxy-fetcher [network_mirrors] # SYNOPSIS: ONLY_LOCAL_WHEN_POSSIBLE=0 | 1 diff --git a/segget/segget.cpp b/segget/segget.cpp index 09e8eb3..dd5a626 100644 --- a/segget/segget.cpp +++ b/segget/segget.cpp @@ -175,7 +175,6 @@ int download_pkgs(){ struct timeval T; try{ - curl_global_init(CURL_GLOBAL_ALL); cm = curl_multi_init(); // we can optionally limit the total amount of connections this multi handle uses curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, (long)MAX_CONNECTS); @@ -380,6 +379,12 @@ int routine(){ error_log("error while init_connections"); } try{ + // This function is NOT thread-safe => call it before any other thread is launched + curl_global_init(CURL_GLOBAL_ALL); + }catch(...){ + error_log_no_msg("Error in segget.cpp: routine: while calling curl_global_init()"); + } + try{ launch_ui_server_thread(); }catch(...){ error_log_no_msg("Error in segget.cpp launch_ui_server() failed"); diff --git a/segget/segment.cpp b/segget/segment.cpp index 100d8ca..9389820 100644 --- a/segget/segment.cpp +++ b/segget/segment.cpp @@ -158,6 +158,12 @@ int Tsegment::add_easy_handle_to_multi(CURLM *cm, uint network_num){ if ((network_array[network_num].bind_interface!="none") and (network_array[network_num].bind_interface!="")) curl_easy_setopt(easyhandle, CURLOPT_INTERFACE, network_array[network_num].bind_interface.c_str()); + + if (network_array[network_num].bind_local_port){ + curl_easy_setopt(easyhandle, CURLOPT_LOCALPORT, network_array[network_num].bind_local_port); + curl_easy_setopt(easyhandle, CURLOPT_LOCALPORTRANGE, network_array[network_num].bind_local_port_range); + } + //set connection timeout curl_easy_setopt(easyhandle, CURLOPT_CONNECTTIMEOUT, network_array[network_num].connection_timeout); curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, write_data); |