Skip to content

Commit

Permalink
Added namespace support for aggregating relays
Browse files Browse the repository at this point in the history
  • Loading branch information
greenbender committed Feb 25, 2016
1 parent e700da8 commit 8c88c0f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions conf/icecast.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<port>8001</port>
<username>relay</username>
<password>hackme</password>
<namespace>master1</namespace>
<on-demand>1</on-demand>
</master>
-->
Expand Down
33 changes: 33 additions & 0 deletions doc/relaying.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ <h3 id="type-of-relays">Type of Relays</h3>
will also periodically check the master server to see if any new mountpoints have attached and if so will relay those
as well. </p>

<p>This "master-slave" type relay has been extended to support aggregation so that multiple masters can be given
and the slave will "aggregate" all of the mountpoints for those master servers. </p>

<p>The second type of relay is a “single-broadcast” relay. In this case, the slave server is configured with a
server IP, port and mount and only the mountpoint specified is relayed. In order to relay a broadcast stream on
a Shoutcast server, you must use the “single-broadcast” relay and specify a mountpoint of <code>/</code>.</p>
Expand All @@ -61,6 +64,36 @@ <h3 id="setting-up-a-master-slave-relay">Setting Up a Master-Slave Relay</h3>

</div>

<div class="article">
<h3 id="setting-up-a-master-slave-aggregating-relay">Setting Up a Master-Slave Aggregating Relay</h3>
<p>In order to setup a relay of this type all servers (the one you wish to relay and the one doing the relaying)
need to be Icecast 2 servers. The following configuration snippet is used as an example:</p>

<div class="highlight"><pre><code class="language-xml" data-lang="xml"><span class="nt">&lt;master-update-interval&gt;</span>120<span class="nt">&lt;/master-update-interval&gt;</span>
<span class="nt">&lt;master&gt;</span>
<span class="nt">&lt;server&gt;</span>192.168.1.11<span class="nt">&lt;/server&gt;</span>
<span class="nt">&lt;port&gt;</span>8001<span class="nt">&lt;/port&gt;</span>
<span class="nt">&lt;namespace&gt;</span>/upstream1<span class="nt">&lt;/namespace&gt;</span>
<span class="nt">&lt;password&gt;</span>hackme<span class="nt">&lt;/password&gt;</span>
<span class="nt">&lt;on-demand&gt;</span>1<span class="nt">&lt;/on-demand&gt;</span>
<span class="nt">&lt;/master&gt;</span>
<span class="nt">&lt;master&gt;</span>
<span class="nt">&lt;server&gt;</span>192.168.1.12<span class="nt">&lt;/server&gt;</span>
<span class="nt">&lt;port&gt;</span>8001<span class="nt">&lt;/port&gt;</span>
<span class="nt">&lt;password&gt;</span>hackme<span class="nt">&lt;/password&gt;</span>
<span class="nt">&lt;/master&gt;</span>
</code></pre></div>

<p>In this example, this configuration is setup in the server which will be doing the relaying (slave server).
The master servers in this case need not be configured (and actually they are unaware of the relaying being performed)
as relays. When the slave server is started, it will connect to each of the master servers located at 192.168.1.11:8001
and 192.168.1.12:8001 and will begin to relay all mountpoints connected to the master servers. Additionally,
every master-update-interval (120 seconds in this case) the slave server will poll the master servers to see if any new
mountpoints have connected, and if so, the slave server will relay those as well. Note that all mountpoints of the master
server at 192.168.1.11:8001 will have the namespace "/upstream1" prepended to it's mountpoints. </p>

</div>

<div class="article">
<h3 id="setting-up-a-single-broadcast-relay">Setting Up a Single-Broadcast Relay</h3>
<p>In this case, the master server need not be an Icecast 2 server. Supported master servers for a single-broadcast
Expand Down
5 changes: 5 additions & 0 deletions src/cfgfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,11 @@ static void _parse_master(xmlDocPtr doc,
xmlFree(master->password);
master->password = (char *)xmlNodeListGetString(doc,
node->xmlChildrenNode, 1);
} else if (xmlStrcmp(node->name, XMLSTR("namespace")) == 0) {
if (master->namespace)
xmlFree(master->namespace);
master->namespace = (char *)xmlNodeListGetString(doc,
node->xmlChildrenNode, 1);
} else if (xmlStrcmp(node->name, XMLSTR("on-demand")) == 0) {
tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
master->on_demand = util_str_to_bool(tmp);
Expand Down
11 changes: 10 additions & 1 deletion src/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ master_server *master_free (master_server *master)
xmlFree (master->username);
if (master->password)
xmlFree (master->password);
if (master->namespace)
xmlFree(master->namespace);
free (master);
return next;
}
Expand Down Expand Up @@ -686,7 +688,14 @@ static int update_from_master(master_server *master)
}

r->mount = strdup(parsed_uri->path);
r->localmount = strdup(parsed_uri->path);
if (master->namespace)
{
int mountlen = strlen(master->namespace) + strlen(parsed_uri->path) + 1;
r->localmount = malloc(mountlen);
snprintf(r->localmount, mountlen, "%s%s", master->namespace, parsed_uri->path);
} else {
r->localmount = strdup(parsed_uri->path);
}
r->mp3metadata = 1;
r->on_demand = master->on_demand;
r->next = new_relays;
Expand Down
1 change: 1 addition & 0 deletions src/slave.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef struct _master_server {
char *username;
char *password;
int on_demand;
char *namespace;
struct _master_server *next;
} master_server;

Expand Down

0 comments on commit 8c88c0f

Please sign in to comment.