Fix bug #76: added support for multiple server listen ports.

Use server_alt_ports and supply a comma separated list of ports.
This commit is contained in:
Jan Vidar Krey 2010-01-27 23:55:52 +01:00
parent 1faca92167
commit c3ad006d07
4 changed files with 66 additions and 0 deletions

View File

@ -111,6 +111,7 @@
#define DEF_SERVER_BIND_ADDR "any" #define DEF_SERVER_BIND_ADDR "any"
#define DEF_SERVER_PORT 1511 #define DEF_SERVER_PORT 1511
#define DEF_SERVER_BACKLOG 50 #define DEF_SERVER_BACKLOG 50
#define DEF_SERVER_ALT_PORTS ""
#define DEF_HUB_NAME "uhub" #define DEF_HUB_NAME "uhub"
#define DEF_HUB_DESCRIPTION "" #define DEF_HUB_DESCRIPTION ""
#define DEF_HUB_ENABLED 1 #define DEF_HUB_ENABLED 1
@ -184,6 +185,7 @@ void config_defaults(struct hub_config* config)
DEFAULT_STRING (file_rules, DEF_FILE_RULES); DEFAULT_STRING (file_rules, DEF_FILE_RULES);
DEFAULT_INTEGER(server_port, DEF_SERVER_PORT); DEFAULT_INTEGER(server_port, DEF_SERVER_PORT);
DEFAULT_INTEGER(server_listen_backlog, DEF_SERVER_BACKLOG); DEFAULT_INTEGER(server_listen_backlog, DEF_SERVER_BACKLOG);
DEFAULT_STRING (server_alt_ports, DEF_SERVER_ALT_PORTS);
DEFAULT_INTEGER(max_users, DEF_MAX_USERS); DEFAULT_INTEGER(max_users, DEF_MAX_USERS);
DEFAULT_INTEGER(max_chat_history, DEF_MAX_CHAT_HISTORY); DEFAULT_INTEGER(max_chat_history, DEF_MAX_CHAT_HISTORY);
DEFAULT_INTEGER(max_logout_log, DEF_MAX_LOGOUT_LOG); DEFAULT_INTEGER(max_logout_log, DEF_MAX_LOGOUT_LOG);
@ -255,6 +257,7 @@ static int apply_config(struct hub_config* config, char* key, char* data, int li
GET_STR (server_bind_addr); GET_STR (server_bind_addr);
GET_INT (server_port); GET_INT (server_port);
GET_INT (server_listen_backlog); GET_INT (server_listen_backlog);
GET_STR (server_alt_ports);
GET_STR (hub_name); GET_STR (hub_name);
GET_STR (hub_description); GET_STR (hub_description);
GET_BOOL(hub_enabled); GET_BOOL(hub_enabled);
@ -328,6 +331,7 @@ static int apply_config(struct hub_config* config, char* key, char* data, int li
void free_config(struct hub_config* config) void free_config(struct hub_config* config)
{ {
hub_free(config->server_bind_addr); hub_free(config->server_bind_addr);
hub_free(config->server_alt_ports);
hub_free(config->file_motd); hub_free(config->file_motd);
hub_free(config->file_acl); hub_free(config->file_acl);
hub_free(config->file_rules); hub_free(config->file_rules);
@ -406,6 +410,7 @@ void dump_config(struct hub_config* config, int ignore_defaults)
DUMP_STR (server_bind_addr, DEF_SERVER_BIND_ADDR); DUMP_STR (server_bind_addr, DEF_SERVER_BIND_ADDR);
DUMP_INT (server_port, DEF_SERVER_PORT); DUMP_INT (server_port, DEF_SERVER_PORT);
DUMP_INT (server_listen_backlog, DEF_SERVER_BACKLOG); DUMP_INT (server_listen_backlog, DEF_SERVER_BACKLOG);
DUMP_STR (server_alt_ports, DEF_SERVER_ALT_PORTS);
DUMP_STR (hub_name, DEF_HUB_NAME); DUMP_STR (hub_name, DEF_HUB_NAME);
DUMP_STR (hub_description, DEF_HUB_DESCRIPTION); DUMP_STR (hub_description, DEF_HUB_DESCRIPTION);
DUMP_BOOL(hub_enabled, DEF_HUB_ENABLED); DUMP_BOOL(hub_enabled, DEF_HUB_ENABLED);

View File

@ -25,6 +25,7 @@ struct hub_config
int server_port; /**<<< "Server port to bind to (default: 1511)" */ int server_port; /**<<< "Server port to bind to (default: 1511)" */
char* server_bind_addr; /**<<< "Server bind address (default: '0.0.0.0' or '::')" */ char* server_bind_addr; /**<<< "Server bind address (default: '0.0.0.0' or '::')" */
int server_listen_backlog; /**<<< "Server listen backlog (default: 50)" */ int server_listen_backlog; /**<<< "Server listen backlog (default: 50)" */
char* server_alt_ports; /**<<< "Comma separated list of alternative ports to listen to (default: '')" */
int hub_enabled; /**<<< "Is server enabled (default: 1)" */ int hub_enabled; /**<<< "Is server enabled (default: 1)" */
int show_banner; /**<<< "Show banner on connect (default: 1)" */ int show_banner; /**<<< "Show banner on connect (default: 1)" */
int max_users; /**<<< "Maximum number of users allowed on the hub (default: 500)" */ int max_users; /**<<< "Maximum number of users allowed on the hub (default: 500)" */

View File

@ -496,6 +496,62 @@ static struct net_connection* start_listening_socket(const char* bind_addr, uint
return server; return server;
} }
struct server_alt_port_data
{
struct hub_info* hub;
struct hub_config* config;
};
static int server_alt_port_start_one(char* line, int count, void* ptr)
{
struct server_alt_port_data* data = (struct server_alt_port_data*) ptr;
int port = uhub_atoi(line);
struct net_connection* con = start_listening_socket(data->config->server_bind_addr, port, data->config->server_listen_backlog, data->hub);
if (con)
{
list_append(data->hub->server_alt_ports, con);
LOG_INFO("Listening on alternate port %d...", port);
return 0;
}
return -1;
}
static void server_alt_port_start(struct hub_info* hub, struct hub_config* config)
{
if (!config->server_alt_ports || !*config->server_alt_ports)
return;
hub->server_alt_ports = (struct linked_list*) list_create();
struct server_alt_port_data data;
data.hub = hub;
data.config = config;
string_split(config->server_alt_ports, ",", &data, server_alt_port_start_one);
}
static void server_alt_port_clear(void* ptr)
{
struct net_connection* con = (struct net_connection*) ptr;
if (con)
{
net_con_close(con);
hub_free(con);
}
}
static void server_alt_port_stop(struct hub_info* hub)
{
if (hub->server_alt_ports)
{
list_clear(hub->server_alt_ports, &server_alt_port_clear);
list_destroy(hub->server_alt_ports);
}
}
struct hub_info* hub_start_service(struct hub_config* config) struct hub_info* hub_start_service(struct hub_config* config)
{ {
struct hub_info* hub = 0; struct hub_info* hub = 0;
@ -596,6 +652,8 @@ struct hub_info* hub_start_service(struct hub_config* config)
return 0; return 0;
} }
server_alt_port_start(hub, config);
hub->status = hub_status_running; hub->status = hub_status_running;
g_hub = hub; g_hub = hub;
@ -610,6 +668,7 @@ void hub_shutdown_service(struct hub_info* hub)
event_queue_shutdown(hub->queue); event_queue_shutdown(hub->queue);
net_con_close(hub->server); net_con_close(hub->server);
hub_free(hub->server); hub_free(hub->server);
server_alt_port_stop(hub);
uman_shutdown(hub); uman_shutdown(hub);
hub->status = hub_status_stopped; hub->status = hub_status_stopped;
hub_free(hub->sendbuf); hub_free(hub->sendbuf);

View File

@ -91,6 +91,7 @@ struct hub_logout_info
struct hub_info struct hub_info
{ {
struct net_connection* server; struct net_connection* server;
struct linked_list* server_alt_ports;
struct hub_stats stats; struct hub_stats stats;
struct event_queue* queue; struct event_queue* queue;
struct hub_config* config; struct hub_config* config;