Skip to content

Commit 8c88c0f

Browse files
committed
Added namespace support for aggregating relays
1 parent e700da8 commit 8c88c0f

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

conf/icecast.xml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
<port>8001</port>
119119
<username>relay</username>
120120
<password>hackme</password>
121+
<namespace>master1</namespace>
121122
<on-demand>1</on-demand>
122123
</master>
123124
-->

doc/relaying.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ <h3 id="type-of-relays">Type of Relays</h3>
3535
will also periodically check the master server to see if any new mountpoints have attached and if so will relay those
3636
as well. </p>
3737

38+
<p>This "master-slave" type relay has been extended to support aggregation so that multiple masters can be given
39+
and the slave will "aggregate" all of the mountpoints for those master servers. </p>
40+
3841
<p>The second type of relay is a “single-broadcast” relay. In this case, the slave server is configured with a
3942
server IP, port and mount and only the mountpoint specified is relayed. In order to relay a broadcast stream on
4043
a Shoutcast server, you must use the “single-broadcast” relay and specify a mountpoint of <code>/</code>.</p>
@@ -61,6 +64,36 @@ <h3 id="setting-up-a-master-slave-relay">Setting Up a Master-Slave Relay</h3>
6164

6265
</div>
6366

67+
<div class="article">
68+
<h3 id="setting-up-a-master-slave-aggregating-relay">Setting Up a Master-Slave Aggregating Relay</h3>
69+
<p>In order to setup a relay of this type all servers (the one you wish to relay and the one doing the relaying)
70+
need to be Icecast 2 servers. The following configuration snippet is used as an example:</p>
71+
72+
<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>
73+
<span class="nt">&lt;master&gt;</span>
74+
<span class="nt">&lt;server&gt;</span>192.168.1.11<span class="nt">&lt;/server&gt;</span>
75+
<span class="nt">&lt;port&gt;</span>8001<span class="nt">&lt;/port&gt;</span>
76+
<span class="nt">&lt;namespace&gt;</span>/upstream1<span class="nt">&lt;/namespace&gt;</span>
77+
<span class="nt">&lt;password&gt;</span>hackme<span class="nt">&lt;/password&gt;</span>
78+
<span class="nt">&lt;on-demand&gt;</span>1<span class="nt">&lt;/on-demand&gt;</span>
79+
<span class="nt">&lt;/master&gt;</span>
80+
<span class="nt">&lt;master&gt;</span>
81+
<span class="nt">&lt;server&gt;</span>192.168.1.12<span class="nt">&lt;/server&gt;</span>
82+
<span class="nt">&lt;port&gt;</span>8001<span class="nt">&lt;/port&gt;</span>
83+
<span class="nt">&lt;password&gt;</span>hackme<span class="nt">&lt;/password&gt;</span>
84+
<span class="nt">&lt;/master&gt;</span>
85+
</code></pre></div>
86+
87+
<p>In this example, this configuration is setup in the server which will be doing the relaying (slave server).
88+
The master servers in this case need not be configured (and actually they are unaware of the relaying being performed)
89+
as relays. When the slave server is started, it will connect to each of the master servers located at 192.168.1.11:8001
90+
and 192.168.1.12:8001 and will begin to relay all mountpoints connected to the master servers. Additionally,
91+
every master-update-interval (120 seconds in this case) the slave server will poll the master servers to see if any new
92+
mountpoints have connected, and if so, the slave server will relay those as well. Note that all mountpoints of the master
93+
server at 192.168.1.11:8001 will have the namespace "/upstream1" prepended to it's mountpoints. </p>
94+
95+
</div>
96+
6497
<div class="article">
6598
<h3 id="setting-up-a-single-broadcast-relay">Setting Up a Single-Broadcast Relay</h3>
6699
<p>In this case, the master server need not be an Icecast 2 server. Supported master servers for a single-broadcast

src/cfgfile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,11 @@ static void _parse_master(xmlDocPtr doc,
16441644
xmlFree(master->password);
16451645
master->password = (char *)xmlNodeListGetString(doc,
16461646
node->xmlChildrenNode, 1);
1647+
} else if (xmlStrcmp(node->name, XMLSTR("namespace")) == 0) {
1648+
if (master->namespace)
1649+
xmlFree(master->namespace);
1650+
master->namespace = (char *)xmlNodeListGetString(doc,
1651+
node->xmlChildrenNode, 1);
16471652
} else if (xmlStrcmp(node->name, XMLSTR("on-demand")) == 0) {
16481653
tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
16491654
master->on_demand = util_str_to_bool(tmp);

src/slave.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ master_server *master_free (master_server *master)
7272
xmlFree (master->username);
7373
if (master->password)
7474
xmlFree (master->password);
75+
if (master->namespace)
76+
xmlFree(master->namespace);
7577
free (master);
7678
return next;
7779
}
@@ -686,7 +688,14 @@ static int update_from_master(master_server *master)
686688
}
687689

688690
r->mount = strdup(parsed_uri->path);
689-
r->localmount = strdup(parsed_uri->path);
691+
if (master->namespace)
692+
{
693+
int mountlen = strlen(master->namespace) + strlen(parsed_uri->path) + 1;
694+
r->localmount = malloc(mountlen);
695+
snprintf(r->localmount, mountlen, "%s%s", master->namespace, parsed_uri->path);
696+
} else {
697+
r->localmount = strdup(parsed_uri->path);
698+
}
690699
r->mp3metadata = 1;
691700
r->on_demand = master->on_demand;
692701
r->next = new_relays;

src/slave.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef struct _master_server {
2121
char *username;
2222
char *password;
2323
int on_demand;
24+
char *namespace;
2425
struct _master_server *next;
2526
} master_server;
2627

0 commit comments

Comments
 (0)