2004-01-28 20:02:12 -05:00
|
|
|
/* Icecast
|
|
|
|
*
|
|
|
|
* This program is distributed under the GNU General Public License, version 2.
|
|
|
|
* A copy of this license is included with this source.
|
|
|
|
*
|
|
|
|
* Copyright 2000-2004, Jack Moffitt <jack@xiph.org,
|
|
|
|
* Michael Smith <msmith@xiph.org>,
|
|
|
|
* oddsock <oddsock@xiph.org>,
|
|
|
|
* Karl Heyes <karl@xiph.org>
|
|
|
|
* and others (see AUTHORS for details).
|
|
|
|
*/
|
|
|
|
|
2003-03-27 12:10:14 -05:00
|
|
|
/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- */
|
2002-08-05 10:48:04 -04:00
|
|
|
/* slave.c
|
|
|
|
* by Ciaran Anscomb <ciaran.anscomb@6809.org.uk>
|
|
|
|
*
|
|
|
|
* Periodically requests a list of streams from a master server
|
|
|
|
* and creates source threads for any it doesn't already have.
|
|
|
|
* */
|
|
|
|
|
2003-07-20 21:58:54 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2002-08-05 10:48:04 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#else
|
|
|
|
#include <winsock2.h>
|
|
|
|
#endif
|
|
|
|
|
2005-12-17 07:41:34 -05:00
|
|
|
#include "compat.h"
|
2002-08-05 10:48:04 -04:00
|
|
|
|
2013-02-23 15:55:58 -05:00
|
|
|
#include <libxml/uri.h>
|
2014-12-02 16:50:57 -05:00
|
|
|
#include "common/thread/thread.h"
|
|
|
|
#include "common/avl/avl.h"
|
|
|
|
#include "common/net/sock.h"
|
|
|
|
#include "common/httpp/httpp.h"
|
2002-08-05 10:48:04 -04:00
|
|
|
|
2003-07-20 21:58:54 -04:00
|
|
|
#include "cfgfile.h"
|
2002-08-05 10:48:04 -04:00
|
|
|
#include "global.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "connection.h"
|
|
|
|
#include "refbuf.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "stats.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "source.h"
|
2002-12-30 02:55:56 -05:00
|
|
|
#include "format.h"
|
2002-08-05 10:48:04 -04:00
|
|
|
|
|
|
|
#define CATMODULE "slave"
|
|
|
|
|
|
|
|
static void *_slave_thread(void *arg);
|
2005-04-18 10:32:26 -04:00
|
|
|
static thread_type *_slave_thread_id;
|
2004-02-19 15:28:21 -05:00
|
|
|
static int slave_running = 0;
|
2007-08-11 13:44:45 -04:00
|
|
|
static volatile int update_settings = 0;
|
2007-10-21 22:29:49 -04:00
|
|
|
static volatile int update_all_mounts = 0;
|
2005-08-26 21:01:29 -04:00
|
|
|
static volatile unsigned int max_interval = 0;
|
2012-07-17 10:03:37 -04:00
|
|
|
static mutex_t _slave_mutex; // protects update_settings, update_all_mounts, max_interval
|
2004-02-02 14:22:11 -05:00
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
relay_server *relay_free (relay_server *relay)
|
2004-02-02 14:22:11 -05:00
|
|
|
{
|
2004-02-19 15:28:21 -05:00
|
|
|
relay_server *next = relay->next;
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("freeing relay %s", relay->localmount);
|
2004-02-19 15:28:21 -05:00
|
|
|
if (relay->source)
|
|
|
|
source_free_source (relay->source);
|
|
|
|
xmlFree (relay->server);
|
|
|
|
xmlFree (relay->mount);
|
|
|
|
xmlFree (relay->localmount);
|
2004-12-09 12:08:52 -05:00
|
|
|
if (relay->username)
|
|
|
|
xmlFree (relay->username);
|
|
|
|
if (relay->password)
|
|
|
|
xmlFree (relay->password);
|
2004-10-22 20:44:29 -04:00
|
|
|
free (relay);
|
2004-02-19 15:28:21 -05:00
|
|
|
return next;
|
2004-02-02 14:22:11 -05:00
|
|
|
}
|
|
|
|
|
2002-08-05 10:48:04 -04:00
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
relay_server *relay_copy (relay_server *r)
|
|
|
|
{
|
|
|
|
relay_server *copy = calloc (1, sizeof (relay_server));
|
2003-03-05 08:03:35 -05:00
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
if (copy)
|
2003-03-05 08:03:35 -05:00
|
|
|
{
|
2007-10-04 12:48:38 -04:00
|
|
|
copy->server = (char *)xmlCharStrdup (r->server);
|
|
|
|
copy->mount = (char *)xmlCharStrdup (r->mount);
|
|
|
|
copy->localmount = (char *)xmlCharStrdup (r->localmount);
|
2004-12-09 12:08:52 -05:00
|
|
|
if (r->username)
|
2007-10-04 12:48:38 -04:00
|
|
|
copy->username = (char *)xmlCharStrdup (r->username);
|
2004-12-09 12:08:52 -05:00
|
|
|
if (r->password)
|
2007-10-04 12:48:38 -04:00
|
|
|
copy->password = (char *)xmlCharStrdup (r->password);
|
2004-02-19 15:28:21 -05:00
|
|
|
copy->port = r->port;
|
|
|
|
copy->mp3metadata = r->mp3metadata;
|
2005-06-08 21:51:47 -04:00
|
|
|
copy->on_demand = r->on_demand;
|
2003-03-05 08:03:35 -05:00
|
|
|
}
|
2004-02-19 15:28:21 -05:00
|
|
|
return copy;
|
|
|
|
}
|
2002-08-05 10:48:04 -04:00
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
|
2004-10-22 20:44:29 -04:00
|
|
|
/* force a recheck of the relays. This will recheck the master server if
|
2007-10-21 22:29:49 -04:00
|
|
|
* this is a slave and rebuild all mountpoints in the stats tree
|
2004-10-22 20:44:29 -04:00
|
|
|
*/
|
2014-11-30 15:32:30 -05:00
|
|
|
void slave_update_all_mounts(void)
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_lock(&_slave_mutex);
|
2004-10-22 20:44:29 -04:00
|
|
|
max_interval = 0;
|
2007-10-21 22:29:49 -04:00
|
|
|
update_all_mounts = 1;
|
2005-05-15 20:16:12 -04:00
|
|
|
update_settings = 1;
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_unlock(&_slave_mutex);
|
2002-08-05 10:48:04 -04:00
|
|
|
}
|
|
|
|
|
2005-05-15 20:16:12 -04:00
|
|
|
|
|
|
|
/* Request slave thread to check the relay list for changes and to
|
|
|
|
* update the stats for the current streams.
|
2004-10-22 20:44:29 -04:00
|
|
|
*/
|
2014-11-30 15:32:30 -05:00
|
|
|
void slave_rebuild_mounts(void)
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_lock(&_slave_mutex);
|
2005-05-15 20:16:12 -04:00
|
|
|
update_settings = 1;
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_unlock(&_slave_mutex);
|
2002-08-05 10:48:04 -04:00
|
|
|
}
|
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
|
|
|
|
void slave_initialize(void)
|
2003-02-07 05:53:38 -05:00
|
|
|
{
|
2004-02-19 15:28:21 -05:00
|
|
|
if (slave_running)
|
|
|
|
return;
|
2003-02-07 05:53:38 -05:00
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
slave_running = 1;
|
2004-10-26 23:29:56 -04:00
|
|
|
max_interval = 0;
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_create (&_slave_mutex);
|
2004-02-19 15:28:21 -05:00
|
|
|
_slave_thread_id = thread_create("Slave Thread", _slave_thread, NULL, THREAD_ATTACHED);
|
|
|
|
}
|
2003-02-12 06:04:26 -05:00
|
|
|
|
2003-02-07 05:53:38 -05:00
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
void slave_shutdown(void)
|
|
|
|
{
|
|
|
|
if (!slave_running)
|
2003-03-14 21:10:19 -05:00
|
|
|
return;
|
2004-02-19 15:28:21 -05:00
|
|
|
slave_running = 0;
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("waiting for slave thread");
|
2004-02-19 15:28:21 -05:00
|
|
|
thread_join (_slave_thread_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-10 17:33:16 -04:00
|
|
|
/* Actually open the connection and do some http parsing, handle any 302
|
|
|
|
* responses within here.
|
2004-02-19 15:28:21 -05:00
|
|
|
*/
|
2007-08-10 17:33:16 -04:00
|
|
|
static client_t *open_relay_connection (relay_server *relay)
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
2007-08-10 17:33:16 -04:00
|
|
|
int redirects = 0;
|
2007-09-02 20:55:27 -04:00
|
|
|
char *server_id = NULL;
|
|
|
|
ice_config_t *config;
|
2004-02-19 15:28:21 -05:00
|
|
|
http_parser_t *parser = NULL;
|
|
|
|
connection_t *con=NULL;
|
2007-08-10 17:33:16 -04:00
|
|
|
char *server = strdup (relay->server);
|
|
|
|
char *mount = strdup (relay->mount);
|
|
|
|
int port = relay->port;
|
|
|
|
char *auth_header;
|
2004-02-19 15:28:21 -05:00
|
|
|
char header[4096];
|
|
|
|
|
2007-09-02 20:55:27 -04:00
|
|
|
config = config_get_config ();
|
|
|
|
server_id = strdup (config->server_id);
|
|
|
|
config_release_config ();
|
|
|
|
|
2007-08-10 17:33:16 -04:00
|
|
|
/* build any authentication header before connecting */
|
|
|
|
if (relay->username && relay->password)
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
2007-08-10 17:33:16 -04:00
|
|
|
char *esc_authorisation;
|
|
|
|
unsigned len = strlen(relay->username) + strlen(relay->password) + 2;
|
|
|
|
|
|
|
|
auth_header = malloc (len);
|
|
|
|
snprintf (auth_header, len, "%s:%s", relay->username, relay->password);
|
|
|
|
esc_authorisation = util_base64_encode(auth_header);
|
|
|
|
free(auth_header);
|
|
|
|
len = strlen (esc_authorisation) + 24;
|
|
|
|
auth_header = malloc (len);
|
|
|
|
snprintf (auth_header, len,
|
|
|
|
"Authorization: Basic %s\r\n", esc_authorisation);
|
|
|
|
free(esc_authorisation);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
auth_header = strdup ("");
|
2004-12-09 12:08:52 -05:00
|
|
|
|
2007-08-10 17:33:16 -04:00
|
|
|
while (redirects < 10)
|
|
|
|
{
|
|
|
|
sock_t streamsock;
|
|
|
|
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_INFO("connecting to %s:%d", server, port);
|
2007-08-10 17:33:16 -04:00
|
|
|
|
2009-03-16 21:45:41 -04:00
|
|
|
streamsock = sock_connect_wto_bind (server, port, relay->bind, 10);
|
2004-02-19 15:28:21 -05:00
|
|
|
if (streamsock == SOCK_ERROR)
|
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_WARN("Failed to connect to %s:%d", server, port);
|
2004-02-19 15:28:21 -05:00
|
|
|
break;
|
2003-02-07 05:53:38 -05:00
|
|
|
}
|
2007-08-10 17:33:16 -04:00
|
|
|
con = connection_create (streamsock, -1, strdup (server));
|
2004-12-09 12:08:52 -05:00
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
/* At this point we may not know if we are relaying an mp3 or vorbis
|
|
|
|
* stream, but only send the icy-metadata header if the relay details
|
|
|
|
* state so (the typical case). It's harmless in the vorbis case. If
|
|
|
|
* we don't send in this header then relay will not have mp3 metadata.
|
|
|
|
*/
|
|
|
|
sock_write(streamsock, "GET %s HTTP/1.0\r\n"
|
2005-12-17 07:27:29 -05:00
|
|
|
"User-Agent: %s\r\n"
|
2009-07-10 21:23:16 -04:00
|
|
|
"Host: %s\r\n"
|
2004-02-19 15:28:21 -05:00
|
|
|
"%s"
|
2004-12-09 12:08:52 -05:00
|
|
|
"%s"
|
2004-02-19 15:28:21 -05:00
|
|
|
"\r\n",
|
2007-08-10 17:33:16 -04:00
|
|
|
mount,
|
2007-09-02 20:55:27 -04:00
|
|
|
server_id,
|
2009-07-10 21:23:16 -04:00
|
|
|
server,
|
2004-12-09 12:08:52 -05:00
|
|
|
relay->mp3metadata?"Icy-MetaData: 1\r\n":"",
|
|
|
|
auth_header);
|
2004-02-19 15:28:21 -05:00
|
|
|
memset (header, 0, sizeof(header));
|
2004-11-11 10:47:33 -05:00
|
|
|
if (util_read_header (con->sock, header, 4096, READ_ENTIRE_HEADER) == 0)
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_ERROR("Header read failed for %s (%s:%d%s)", relay->localmount, server, port, mount);
|
2004-02-19 15:28:21 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
parser = httpp_create_parser();
|
|
|
|
httpp_initialize (parser, NULL);
|
|
|
|
if (! httpp_parse_response (parser, header, strlen(header), relay->localmount))
|
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_ERROR("Error parsing relay request for %s (%s:%d%s)", relay->localmount,
|
2007-08-10 17:33:16 -04:00
|
|
|
server, port, mount);
|
2004-02-19 15:28:21 -05:00
|
|
|
break;
|
|
|
|
}
|
2007-08-10 17:33:16 -04:00
|
|
|
if (strcmp (httpp_getvar (parser, HTTPP_VAR_ERROR_CODE), "302") == 0)
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
2007-08-10 17:33:16 -04:00
|
|
|
/* better retry the connection again but with different details */
|
|
|
|
const char *uri, *mountpoint;
|
|
|
|
int len;
|
2005-08-24 20:07:17 -04:00
|
|
|
|
2007-08-10 17:33:16 -04:00
|
|
|
uri = httpp_getvar (parser, "location");
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_INFO("redirect received %s", uri);
|
2007-08-10 17:33:16 -04:00
|
|
|
if (strncmp (uri, "http://", 7) != 0)
|
|
|
|
break;
|
|
|
|
uri += 7;
|
|
|
|
mountpoint = strchr (uri, '/');
|
|
|
|
free (mount);
|
|
|
|
if (mountpoint)
|
|
|
|
mount = strdup (mountpoint);
|
|
|
|
else
|
|
|
|
mount = strdup ("/");
|
|
|
|
|
|
|
|
len = strcspn (uri, ":/");
|
|
|
|
port = 80;
|
|
|
|
if (uri [len] == ':')
|
|
|
|
port = atoi (uri+len+1);
|
|
|
|
free (server);
|
|
|
|
server = calloc (1, len+1);
|
|
|
|
strncpy (server, uri, len);
|
|
|
|
connection_close (con);
|
|
|
|
httpp_destroy (parser);
|
2005-08-24 20:07:17 -04:00
|
|
|
con = NULL;
|
|
|
|
parser = NULL;
|
|
|
|
}
|
2007-08-10 17:33:16 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
client_t *client = NULL;
|
|
|
|
|
|
|
|
if (httpp_getvar (parser, HTTPP_VAR_ERROR_MESSAGE))
|
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_ERROR("Error from relay request: %s (%s)", relay->localmount,
|
2007-08-10 17:33:16 -04:00
|
|
|
httpp_getvar(parser, HTTPP_VAR_ERROR_MESSAGE));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
global_lock ();
|
|
|
|
if (client_create (&client, con, parser) < 0)
|
|
|
|
{
|
|
|
|
global_unlock ();
|
|
|
|
/* make sure only the client_destory frees these */
|
|
|
|
con = NULL;
|
|
|
|
parser = NULL;
|
|
|
|
client_destroy (client);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
global_unlock ();
|
2009-01-07 21:47:44 -05:00
|
|
|
sock_set_blocking (streamsock, 0);
|
2007-08-10 17:33:16 -04:00
|
|
|
client_set_queue (client, NULL);
|
|
|
|
free (server);
|
|
|
|
free (mount);
|
2007-09-02 20:55:27 -04:00
|
|
|
free (server_id);
|
2007-08-10 17:33:16 -04:00
|
|
|
free (auth_header);
|
|
|
|
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
redirects++;
|
|
|
|
}
|
|
|
|
/* failed, better clean up */
|
|
|
|
free (server);
|
|
|
|
free (mount);
|
2007-09-02 20:55:27 -04:00
|
|
|
free (server_id);
|
2007-08-10 17:33:16 -04:00
|
|
|
free (auth_header);
|
|
|
|
if (con)
|
|
|
|
connection_close (con);
|
|
|
|
if (parser)
|
|
|
|
httpp_destroy (parser);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This does the actual connection for a relay. A thread is
|
|
|
|
* started off if a connection can be acquired
|
|
|
|
*/
|
|
|
|
static void *start_relay_stream (void *arg)
|
|
|
|
{
|
|
|
|
relay_server *relay = arg;
|
|
|
|
source_t *src = relay->source;
|
|
|
|
client_t *client;
|
|
|
|
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_INFO("Starting relayed source at mountpoint \"%s\"", relay->localmount);
|
2007-08-10 17:33:16 -04:00
|
|
|
do
|
|
|
|
{
|
|
|
|
client = open_relay_connection (relay);
|
|
|
|
|
|
|
|
if (client == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
src->client = client;
|
|
|
|
src->parser = client->parser;
|
|
|
|
src->con = client->con;
|
2005-08-24 20:07:17 -04:00
|
|
|
|
|
|
|
if (connection_complete_source (src, 0) < 0)
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_INFO("Failed to complete source initialisation");
|
2007-08-10 17:33:16 -04:00
|
|
|
client_destroy (client);
|
|
|
|
src->client = NULL;
|
|
|
|
continue;
|
2004-02-19 15:28:21 -05:00
|
|
|
}
|
2004-10-22 20:44:29 -04:00
|
|
|
stats_event_inc(NULL, "source_relay_connections");
|
2007-08-10 17:33:16 -04:00
|
|
|
stats_event (relay->localmount, "source_ip", client->con->ip);
|
2004-02-19 15:28:21 -05:00
|
|
|
|
2004-10-22 20:44:29 -04:00
|
|
|
source_main (relay->source);
|
|
|
|
|
2005-06-08 21:51:47 -04:00
|
|
|
if (relay->on_demand == 0)
|
|
|
|
{
|
|
|
|
/* only keep refreshing YP entries for inactive on-demand relays */
|
|
|
|
yp_remove (relay->localmount);
|
|
|
|
relay->source->yp_public = -1;
|
2006-03-14 22:02:08 -05:00
|
|
|
relay->start = time(NULL) + 10; /* prevent busy looping if failing */
|
2007-10-21 22:29:49 -04:00
|
|
|
slave_update_all_mounts();
|
2005-06-08 21:51:47 -04:00
|
|
|
}
|
|
|
|
|
2006-03-14 22:02:08 -05:00
|
|
|
/* we've finished, now get cleaned up */
|
2004-10-22 20:44:29 -04:00
|
|
|
relay->cleanup = 1;
|
2007-08-11 13:44:45 -04:00
|
|
|
slave_rebuild_mounts();
|
2004-10-22 20:44:29 -04:00
|
|
|
|
|
|
|
return NULL;
|
2014-11-30 15:32:30 -05:00
|
|
|
} while (0); /* TODO allow looping through multiple servers */
|
2004-02-19 15:28:21 -05:00
|
|
|
|
2005-06-08 21:51:47 -04:00
|
|
|
if (relay->source->fallback_mount)
|
|
|
|
{
|
|
|
|
source_t *fallback_source;
|
|
|
|
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("failed relay, fallback to %s", relay->source->fallback_mount);
|
2005-06-08 21:51:47 -04:00
|
|
|
avl_tree_rlock(global.source_tree);
|
2014-11-30 15:32:30 -05:00
|
|
|
fallback_source = source_find_mount(relay->source->fallback_mount);
|
2005-06-08 21:51:47 -04:00
|
|
|
|
|
|
|
if (fallback_source != NULL)
|
2014-11-30 15:32:30 -05:00
|
|
|
source_move_clients(relay->source, fallback_source);
|
2005-06-08 21:51:47 -04:00
|
|
|
|
2014-11-30 15:32:30 -05:00
|
|
|
avl_tree_unlock(global.source_tree);
|
2005-06-08 21:51:47 -04:00
|
|
|
}
|
|
|
|
|
2014-11-30 15:32:30 -05:00
|
|
|
source_clear_source(relay->source);
|
2004-10-22 20:44:29 -04:00
|
|
|
|
2006-03-14 22:02:08 -05:00
|
|
|
/* cleanup relay, but prevent this relay from starting up again too soon */
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_lock(&_slave_mutex);
|
|
|
|
thread_mutex_lock(&(config_locks()->relay_lock));
|
2008-07-18 21:57:53 -04:00
|
|
|
relay->source->on_demand = 0;
|
2006-03-14 22:02:08 -05:00
|
|
|
relay->start = time(NULL) + max_interval;
|
2004-10-22 20:44:29 -04:00
|
|
|
relay->cleanup = 1;
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_unlock(&(config_locks()->relay_lock));
|
|
|
|
thread_mutex_unlock(&_slave_mutex);
|
2004-10-22 20:44:29 -04:00
|
|
|
|
|
|
|
return NULL;
|
2004-02-19 15:28:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* wrapper for starting the provided relay stream */
|
|
|
|
static void check_relay_stream (relay_server *relay)
|
|
|
|
{
|
|
|
|
if (relay->source == NULL)
|
|
|
|
{
|
2004-10-22 20:44:29 -04:00
|
|
|
if (relay->localmount[0] != '/')
|
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_WARN("relay mountpoint \"%s\" does not start with /, skipping",
|
2004-10-22 20:44:29 -04:00
|
|
|
relay->localmount);
|
|
|
|
return;
|
|
|
|
}
|
2004-02-19 15:28:21 -05:00
|
|
|
/* new relay, reserve the name */
|
|
|
|
relay->source = source_reserve (relay->localmount);
|
2004-10-22 20:44:29 -04:00
|
|
|
if (relay->source)
|
2006-03-14 22:02:08 -05:00
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("Adding relay source at mountpoint \"%s\"", relay->localmount);
|
2007-10-21 22:29:49 -04:00
|
|
|
if (relay->on_demand)
|
2008-07-18 21:57:53 -04:00
|
|
|
{
|
|
|
|
ice_config_t *config = config_get_config ();
|
2013-04-02 14:46:44 -04:00
|
|
|
mount_proxy *mountinfo = config_find_mount (config, relay->localmount, MOUNT_TYPE_NORMAL);
|
2015-01-06 12:12:56 -05:00
|
|
|
relay->source->on_demand = relay->on_demand;
|
2008-07-18 21:57:53 -04:00
|
|
|
if (mountinfo == NULL)
|
|
|
|
source_update_settings (config, relay->source, mountinfo);
|
|
|
|
config_release_config ();
|
|
|
|
stats_event (relay->localmount, "listeners", "0");
|
2007-10-21 22:29:49 -04:00
|
|
|
slave_update_all_mounts();
|
2008-07-18 21:57:53 -04:00
|
|
|
}
|
2006-03-14 22:02:08 -05:00
|
|
|
}
|
2004-10-22 20:44:29 -04:00
|
|
|
else
|
2009-03-13 22:46:40 -04:00
|
|
|
{
|
|
|
|
if (relay->start == 0)
|
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_WARN("new relay but source \"%s\" already exists", relay->localmount);
|
2009-03-13 22:46:40 -04:00
|
|
|
relay->start = 1;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2004-02-19 15:28:21 -05:00
|
|
|
}
|
2005-06-08 21:51:47 -04:00
|
|
|
do
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
2005-06-08 21:51:47 -04:00
|
|
|
source_t *source = relay->source;
|
2006-03-14 22:02:08 -05:00
|
|
|
/* skip relay if active, not configured or just not time yet */
|
|
|
|
if (relay->source == NULL || relay->running || relay->start > time(NULL))
|
2005-06-08 21:51:47 -04:00
|
|
|
break;
|
2007-10-21 22:29:49 -04:00
|
|
|
/* check if an inactive on-demand relay has a fallback that has listeners */
|
2006-03-14 22:02:08 -05:00
|
|
|
if (relay->on_demand && source->on_demand_req == 0)
|
2005-06-08 21:51:47 -04:00
|
|
|
{
|
|
|
|
relay->source->on_demand = relay->on_demand;
|
|
|
|
|
|
|
|
if (source->fallback_mount && source->fallback_override)
|
|
|
|
{
|
|
|
|
source_t *fallback;
|
|
|
|
avl_tree_rlock (global.source_tree);
|
|
|
|
fallback = source_find_mount (source->fallback_mount);
|
|
|
|
if (fallback && fallback->running && fallback->listeners)
|
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("fallback running %d with %lu listeners", fallback->running, fallback->listeners);
|
2005-06-08 21:51:47 -04:00
|
|
|
source->on_demand_req = 1;
|
|
|
|
}
|
|
|
|
avl_tree_unlock (global.source_tree);
|
|
|
|
}
|
|
|
|
if (source->on_demand_req == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-03-14 22:02:08 -05:00
|
|
|
relay->start = time(NULL) + 5;
|
2007-08-10 17:33:16 -04:00
|
|
|
relay->running = 1;
|
2004-10-22 20:44:29 -04:00
|
|
|
relay->thread = thread_create ("Relay Thread", start_relay_stream,
|
|
|
|
relay, THREAD_ATTACHED);
|
|
|
|
return;
|
2005-06-08 21:51:47 -04:00
|
|
|
|
2006-03-14 22:02:08 -05:00
|
|
|
} while (0);
|
2005-06-08 21:51:47 -04:00
|
|
|
/* the relay thread may of shut down itself */
|
2006-03-14 22:02:08 -05:00
|
|
|
if (relay->cleanup)
|
2004-10-22 20:44:29 -04:00
|
|
|
{
|
2006-03-14 22:02:08 -05:00
|
|
|
if (relay->thread)
|
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("waiting for relay thread for \"%s\"", relay->localmount);
|
2006-03-14 22:02:08 -05:00
|
|
|
thread_join (relay->thread);
|
|
|
|
relay->thread = NULL;
|
|
|
|
}
|
2004-10-22 20:44:29 -04:00
|
|
|
relay->cleanup = 0;
|
|
|
|
relay->running = 0;
|
2005-06-08 21:51:47 -04:00
|
|
|
|
2007-08-10 17:33:16 -04:00
|
|
|
if (relay->on_demand && relay->source)
|
2005-06-08 21:51:47 -04:00
|
|
|
{
|
|
|
|
ice_config_t *config = config_get_config ();
|
2013-04-02 14:46:44 -04:00
|
|
|
mount_proxy *mountinfo = config_find_mount (config, relay->localmount, MOUNT_TYPE_NORMAL);
|
2005-06-08 21:51:47 -04:00
|
|
|
source_update_settings (config, relay->source, mountinfo);
|
|
|
|
config_release_config ();
|
|
|
|
stats_event (relay->localmount, "listeners", "0");
|
|
|
|
}
|
2003-02-07 05:53:38 -05:00
|
|
|
}
|
2004-02-19 15:28:21 -05:00
|
|
|
}
|
|
|
|
|
2003-02-07 05:53:38 -05:00
|
|
|
|
2005-05-07 07:50:07 -04:00
|
|
|
/* compare the 2 relays to see if there are any changes, return 1 if
|
|
|
|
* the relay needs to be restarted, 0 otherwise
|
|
|
|
*/
|
|
|
|
static int relay_has_changed (relay_server *new, relay_server *old)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (strcmp (new->mount, old->mount) != 0)
|
|
|
|
break;
|
|
|
|
if (strcmp (new->server, old->server) != 0)
|
|
|
|
break;
|
|
|
|
if (new->port != old->port)
|
|
|
|
break;
|
2005-05-15 20:16:12 -04:00
|
|
|
if (new->mp3metadata != old->mp3metadata)
|
|
|
|
break;
|
2005-06-08 21:51:47 -04:00
|
|
|
if (new->on_demand != old->on_demand)
|
|
|
|
old->on_demand = new->on_demand;
|
2005-05-07 07:50:07 -04:00
|
|
|
return 0;
|
|
|
|
} while (0);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
/* go through updated looking for relays that are different configured. The
|
|
|
|
* returned list contains relays that should be kept running, current contains
|
|
|
|
* the list of relays to shutdown
|
|
|
|
*/
|
|
|
|
static relay_server *
|
2014-11-30 15:32:30 -05:00
|
|
|
update_relay_set(relay_server **current, relay_server *updated)
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
|
|
|
relay_server *relay = updated;
|
|
|
|
relay_server *existing_relay, **existing_p;
|
|
|
|
relay_server *new_list = NULL;
|
|
|
|
|
|
|
|
while (relay)
|
|
|
|
{
|
2005-04-18 10:32:26 -04:00
|
|
|
existing_relay = *current;
|
|
|
|
existing_p = current;
|
|
|
|
|
|
|
|
while (existing_relay)
|
|
|
|
{
|
|
|
|
/* break out if keeping relay */
|
|
|
|
if (strcmp (relay->localmount, existing_relay->localmount) == 0)
|
2005-05-07 07:50:07 -04:00
|
|
|
if (relay_has_changed (relay, existing_relay) == 0)
|
|
|
|
break;
|
2005-04-18 10:32:26 -04:00
|
|
|
existing_p = &existing_relay->next;
|
|
|
|
existing_relay = existing_relay->next;
|
|
|
|
}
|
|
|
|
if (existing_relay == NULL)
|
|
|
|
{
|
|
|
|
/* new one, copy and insert */
|
|
|
|
existing_relay = relay_copy (relay);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*existing_p = existing_relay->next;
|
|
|
|
}
|
|
|
|
existing_relay->next = new_list;
|
|
|
|
new_list = existing_relay;
|
|
|
|
relay = relay->next;
|
2003-03-14 21:10:19 -05:00
|
|
|
}
|
2004-02-19 15:28:21 -05:00
|
|
|
return new_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* update the relay_list with entries from new_relay_list. Any new relays
|
|
|
|
* are added to the list, and any not listed in the provided new_relay_list
|
2004-10-22 20:44:29 -04:00
|
|
|
* are separated and returned in a separate list
|
2004-02-19 15:28:21 -05:00
|
|
|
*/
|
2004-10-22 20:44:29 -04:00
|
|
|
static relay_server *
|
2004-02-19 15:28:21 -05:00
|
|
|
update_relays (relay_server **relay_list, relay_server *new_relay_list)
|
|
|
|
{
|
2004-10-22 20:44:29 -04:00
|
|
|
relay_server *active_relays, *cleanup_relays;
|
2003-02-25 04:40:34 -05:00
|
|
|
|
2014-11-30 15:32:30 -05:00
|
|
|
active_relays = update_relay_set(relay_list, new_relay_list);
|
2004-02-19 15:28:21 -05:00
|
|
|
|
2004-10-22 20:44:29 -04:00
|
|
|
cleanup_relays = *relay_list;
|
|
|
|
/* re-assign new set */
|
|
|
|
*relay_list = active_relays;
|
|
|
|
|
|
|
|
return cleanup_relays;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-14 22:02:08 -05:00
|
|
|
static void relay_check_streams (relay_server *to_start,
|
|
|
|
relay_server *to_free, int skip_timer)
|
2004-10-22 20:44:29 -04:00
|
|
|
{
|
|
|
|
relay_server *relay;
|
|
|
|
|
|
|
|
while (to_free)
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
2005-05-30 22:48:40 -04:00
|
|
|
if (to_free->source)
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
2005-05-30 22:48:40 -04:00
|
|
|
if (to_free->running)
|
|
|
|
{
|
|
|
|
/* relay has been removed from xml, shut down active relay */
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("source shutdown request on \"%s\"", to_free->localmount);
|
2007-08-10 17:33:16 -04:00
|
|
|
to_free->running = 0;
|
2005-05-30 22:48:40 -04:00
|
|
|
to_free->source->running = 0;
|
|
|
|
thread_join (to_free->thread);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
stats_event (to_free->localmount, NULL, NULL);
|
2004-02-19 15:28:21 -05:00
|
|
|
}
|
2004-10-22 20:44:29 -04:00
|
|
|
to_free = relay_free (to_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
relay = to_start;
|
|
|
|
while (relay)
|
|
|
|
{
|
2006-03-14 22:02:08 -05:00
|
|
|
if (skip_timer)
|
|
|
|
relay->start = 0;
|
2004-10-22 20:44:29 -04:00
|
|
|
check_relay_stream (relay);
|
|
|
|
relay = relay->next;
|
2004-02-19 15:28:21 -05:00
|
|
|
}
|
2003-02-07 05:53:38 -05:00
|
|
|
}
|
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
|
|
|
|
static int update_from_master(ice_config_t *config)
|
|
|
|
{
|
|
|
|
char *master = NULL, *password = NULL, *username= NULL;
|
|
|
|
int port;
|
2003-03-14 21:10:19 -05:00
|
|
|
sock_t mastersock;
|
2004-02-19 15:28:21 -05:00
|
|
|
int ret = 0;
|
2003-03-14 21:10:19 -05:00
|
|
|
char buf[256];
|
2004-02-19 15:28:21 -05:00
|
|
|
do
|
|
|
|
{
|
|
|
|
char *authheader, *data;
|
2004-10-22 20:44:29 -04:00
|
|
|
relay_server *new_relays = NULL, *cleanup_relays;
|
2004-02-19 15:28:21 -05:00
|
|
|
int len, count = 1;
|
2005-06-08 21:51:47 -04:00
|
|
|
int on_demand;
|
2002-08-17 02:25:38 -04:00
|
|
|
|
2014-11-30 15:32:30 -05:00
|
|
|
username = strdup(config->master_username);
|
2004-02-19 15:28:21 -05:00
|
|
|
if (config->master_password)
|
2014-11-30 15:32:30 -05:00
|
|
|
password = strdup(config->master_password);
|
2003-03-05 08:03:35 -05:00
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
if (config->master_server)
|
2014-11-30 15:32:30 -05:00
|
|
|
master = strdup(config->master_server);
|
2003-03-05 08:03:35 -05:00
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
port = config->master_server_port;
|
2003-02-07 06:46:03 -05:00
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
if (password == NULL || master == NULL || port == 0)
|
|
|
|
break;
|
2005-06-08 21:51:47 -04:00
|
|
|
on_demand = config->on_demand;
|
2004-02-19 15:28:21 -05:00
|
|
|
ret = 1;
|
|
|
|
config_release_config();
|
2014-11-30 15:32:30 -05:00
|
|
|
mastersock = sock_connect_wto(master, port, 10);
|
2002-08-09 04:06:00 -04:00
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
if (mastersock == SOCK_ERROR)
|
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_WARN("Relay slave failed to contact master server to fetch stream list");
|
2004-02-19 15:28:21 -05:00
|
|
|
break;
|
|
|
|
}
|
2003-02-07 06:46:03 -05:00
|
|
|
|
2004-10-22 20:44:29 -04:00
|
|
|
len = strlen(username) + strlen(password) + 2;
|
|
|
|
authheader = malloc(len);
|
|
|
|
snprintf (authheader, len, "%s:%s", username, password);
|
2004-02-19 15:28:21 -05:00
|
|
|
data = util_base64_encode(authheader);
|
|
|
|
sock_write (mastersock,
|
|
|
|
"GET /admin/streamlist.txt HTTP/1.0\r\n"
|
|
|
|
"Authorization: Basic %s\r\n"
|
|
|
|
"\r\n", data);
|
|
|
|
free(authheader);
|
|
|
|
free(data);
|
|
|
|
|
2004-08-21 08:56:24 -04:00
|
|
|
if (sock_read_line(mastersock, buf, sizeof(buf)) == 0 ||
|
|
|
|
strncmp (buf, "HTTP/1.0 200", 12) != 0)
|
|
|
|
{
|
|
|
|
sock_close (mastersock);
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_WARN("Master rejected streamlist request");
|
2004-08-21 08:56:24 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
while (sock_read_line(mastersock, buf, sizeof(buf)))
|
|
|
|
{
|
|
|
|
if (!strlen(buf))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (sock_read_line(mastersock, buf, sizeof(buf)))
|
|
|
|
{
|
|
|
|
relay_server *r;
|
|
|
|
if (!strlen(buf))
|
|
|
|
continue;
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("read %d from master \"%s\"", count++, buf);
|
2013-02-23 15:55:58 -05:00
|
|
|
xmlURIPtr parsed_uri = xmlParseURI(buf);
|
|
|
|
if (parsed_uri == NULL) {
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("Error while parsing line from master. Ignoring line.");
|
2013-02-23 15:55:58 -05:00
|
|
|
continue;
|
|
|
|
}
|
2004-02-19 15:28:21 -05:00
|
|
|
r = calloc (1, sizeof (relay_server));
|
|
|
|
if (r)
|
|
|
|
{
|
2013-02-23 15:55:58 -05:00
|
|
|
if (parsed_uri->server != NULL)
|
|
|
|
{
|
|
|
|
r->server = strdup(parsed_uri->server);
|
|
|
|
if (parsed_uri->port == 0)
|
|
|
|
r->port = 80;
|
|
|
|
else
|
|
|
|
r->port = parsed_uri->port;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r->server = (char *)xmlCharStrdup (master);
|
|
|
|
r->port = port;
|
|
|
|
}
|
|
|
|
|
|
|
|
r->mount = strdup(parsed_uri->path);
|
|
|
|
r->localmount = strdup(parsed_uri->path);
|
2004-02-19 15:28:21 -05:00
|
|
|
r->mp3metadata = 1;
|
2005-06-08 21:51:47 -04:00
|
|
|
r->on_demand = on_demand;
|
2004-10-22 20:44:29 -04:00
|
|
|
r->next = new_relays;
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("Added relay host=\"%s\", port=%d, mount=\"%s\"", r->server, r->port, r->mount);
|
2004-10-22 20:44:29 -04:00
|
|
|
new_relays = r;
|
2003-03-14 21:10:19 -05:00
|
|
|
}
|
2013-02-23 15:55:58 -05:00
|
|
|
xmlFreeURI(parsed_uri);
|
2003-02-07 06:46:03 -05:00
|
|
|
}
|
2004-02-19 15:28:21 -05:00
|
|
|
sock_close (mastersock);
|
|
|
|
|
2004-10-22 20:44:29 -04:00
|
|
|
thread_mutex_lock (&(config_locks()->relay_lock));
|
|
|
|
cleanup_relays = update_relays (&global.master_relays, new_relays);
|
|
|
|
|
2006-03-14 22:02:08 -05:00
|
|
|
relay_check_streams (global.master_relays, cleanup_relays, 0);
|
|
|
|
relay_check_streams (NULL, new_relays, 0);
|
2004-10-22 20:44:29 -04:00
|
|
|
|
|
|
|
thread_mutex_unlock (&(config_locks()->relay_lock));
|
|
|
|
|
2004-02-19 15:28:21 -05:00
|
|
|
} while(0);
|
|
|
|
|
|
|
|
if (master)
|
|
|
|
free (master);
|
|
|
|
if (username)
|
|
|
|
free (username);
|
|
|
|
if (password)
|
|
|
|
free (password);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *_slave_thread(void *arg)
|
|
|
|
{
|
|
|
|
ice_config_t *config;
|
2004-10-22 20:44:29 -04:00
|
|
|
unsigned int interval = 0;
|
2003-02-07 05:53:38 -05:00
|
|
|
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_lock(&_slave_mutex);
|
2007-08-11 13:44:45 -04:00
|
|
|
update_settings = 0;
|
2007-10-21 22:29:49 -04:00
|
|
|
update_all_mounts = 0;
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_unlock(&_slave_mutex);
|
2007-08-11 13:44:45 -04:00
|
|
|
|
2007-08-15 22:13:18 -04:00
|
|
|
config = config_get_config();
|
2014-11-30 15:32:30 -05:00
|
|
|
stats_global(config);
|
2007-08-15 22:13:18 -04:00
|
|
|
config_release_config();
|
2014-11-30 15:32:30 -05:00
|
|
|
source_recheck_mounts(1);
|
2005-05-25 23:04:48 -04:00
|
|
|
|
2005-04-18 10:32:26 -04:00
|
|
|
while (1)
|
2004-02-19 15:28:21 -05:00
|
|
|
{
|
2006-03-14 22:02:08 -05:00
|
|
|
relay_server *cleanup_relays = NULL;
|
|
|
|
int skip_timer = 0;
|
2004-10-22 20:44:29 -04:00
|
|
|
|
2005-08-11 19:29:58 -04:00
|
|
|
/* re-read xml file if requested */
|
2012-07-17 10:03:37 -04:00
|
|
|
global_lock();
|
2014-12-07 05:54:34 -05:00
|
|
|
if (global.schedule_config_reread) {
|
|
|
|
config_reread_config();
|
2014-11-30 15:32:30 -05:00
|
|
|
global.schedule_config_reread = 0;
|
2005-08-11 19:29:58 -04:00
|
|
|
}
|
2012-07-17 10:03:37 -04:00
|
|
|
global_unlock();
|
2005-08-11 19:29:58 -04:00
|
|
|
|
2014-11-30 15:32:30 -05:00
|
|
|
thread_sleep(1000000);
|
2005-04-18 10:32:26 -04:00
|
|
|
if (slave_running == 0)
|
|
|
|
break;
|
2006-03-14 22:02:08 -05:00
|
|
|
|
|
|
|
++interval;
|
2004-02-19 15:28:21 -05:00
|
|
|
|
2004-10-22 20:44:29 -04:00
|
|
|
/* only update relays lists when required */
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_lock(&_slave_mutex);
|
2004-10-22 20:44:29 -04:00
|
|
|
if (max_interval <= interval)
|
|
|
|
{
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_DEBUG("checking master stream list");
|
2004-10-22 20:44:29 -04:00
|
|
|
config = config_get_config();
|
2003-03-05 08:03:35 -05:00
|
|
|
|
2006-03-14 22:02:08 -05:00
|
|
|
if (max_interval == 0)
|
|
|
|
skip_timer = 1;
|
2004-10-22 20:44:29 -04:00
|
|
|
interval = 0;
|
|
|
|
max_interval = config->master_update_interval;
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_unlock(&_slave_mutex);
|
2003-02-07 05:53:38 -05:00
|
|
|
|
2004-10-22 20:44:29 -04:00
|
|
|
/* the connection could take some time, so the lock can drop */
|
|
|
|
if (update_from_master (config))
|
|
|
|
config = config_get_config();
|
2004-02-19 15:28:21 -05:00
|
|
|
|
2004-10-22 20:44:29 -04:00
|
|
|
thread_mutex_lock (&(config_locks()->relay_lock));
|
2004-02-19 15:28:21 -05:00
|
|
|
|
2004-10-22 20:44:29 -04:00
|
|
|
cleanup_relays = update_relays (&global.relays, config->relay);
|
2004-02-19 15:28:21 -05:00
|
|
|
|
2004-10-22 20:44:29 -04:00
|
|
|
config_release_config();
|
|
|
|
}
|
|
|
|
else
|
2012-07-17 10:03:37 -04:00
|
|
|
{
|
|
|
|
thread_mutex_unlock(&_slave_mutex);
|
2004-10-22 20:44:29 -04:00
|
|
|
thread_mutex_lock (&(config_locks()->relay_lock));
|
2012-07-17 10:03:37 -04:00
|
|
|
}
|
2006-03-14 22:02:08 -05:00
|
|
|
|
|
|
|
relay_check_streams (global.relays, cleanup_relays, skip_timer);
|
|
|
|
relay_check_streams (global.master_relays, NULL, skip_timer);
|
|
|
|
thread_mutex_unlock (&(config_locks()->relay_lock));
|
|
|
|
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_lock(&_slave_mutex);
|
2005-05-15 20:16:12 -04:00
|
|
|
if (update_settings)
|
|
|
|
{
|
2007-10-21 22:29:49 -04:00
|
|
|
source_recheck_mounts (update_all_mounts);
|
2005-05-15 20:16:12 -04:00
|
|
|
update_settings = 0;
|
2007-10-21 22:29:49 -04:00
|
|
|
update_all_mounts = 0;
|
2005-05-15 20:16:12 -04:00
|
|
|
}
|
2012-07-17 10:03:37 -04:00
|
|
|
thread_mutex_unlock(&_slave_mutex);
|
2003-03-14 21:10:19 -05:00
|
|
|
}
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_INFO("shutting down current relays");
|
2006-03-14 22:02:08 -05:00
|
|
|
relay_check_streams (NULL, global.relays, 0);
|
|
|
|
relay_check_streams (NULL, global.master_relays, 0);
|
2004-10-22 20:44:29 -04:00
|
|
|
|
2014-10-31 04:46:58 -04:00
|
|
|
ICECAST_LOG_INFO("Slave thread shutdown complete");
|
2004-02-19 15:28:21 -05:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
return NULL;
|
2002-08-05 10:48:04 -04:00
|
|
|
}
|
2003-02-07 05:53:38 -05:00
|
|
|
|