From 1d89026a9504789b5e8c34af11316f01a3d38be0 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sun, 28 Dec 2014 10:55:16 +0000
Subject: [PATCH] made some icecast parameters tunable using flags

---
 node/icecast_config.go | 59 +++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/node/icecast_config.go b/node/icecast_config.go
index 746a1dec..c9174b9e 100644
--- a/node/icecast_config.go
+++ b/node/icecast_config.go
@@ -3,6 +3,7 @@ package node
 import (
 	"bytes"
 	"encoding/xml"
+	"flag"
 	"io"
 	"io/ioutil"
 	"log"
@@ -15,15 +16,22 @@ import (
 )
 
 var (
+	icecastAdminPwFile = "/etc/icecast/.admin_pw"
+	icecastAdminPw     string
+
 	// The per-node icecast client limit is set to a very high
 	// value in order to disable the enforcement at the icecast
-	// level (if everything goes well, the front-end traffic
-	// management code should know better).
-	// TODO: make it a flag anyway.
+	// level (the front-end traffic management code should know
+	// better).
+	//icecastMaxClients    = flag.Int("icecast-max-clients", 10000, "maximum number of Icecast clients")
 	maxClients = 10000
 
-	icecastAdminPwFile = "/etc/icecast/.admin_pw"
-	icecastAdminPw     string
+	// Icecast tunables.
+	icecastQueueSize     = flag.Int("icecast-queue-size", 1<<20, "Icecast queue size (bytes)")
+	icecastClientTimeout = flag.Int("icecast-client-timeout", 30, "Icecast client timeout (s)")
+	icecastHeaderTimeout = flag.Int("icecast-header-timeout", 15, "Icecast header timeout (s)")
+	icecastSourceTimeout = flag.Int("icecast-source-timeout", 60, "Icecast source timeout (s)")
+	icecastBurstSize     = flag.Int("icecast-burst-size", 131072, "Icecast connection burst size (bytes)")
 )
 
 // Return the global Icecast admin password. If it does not exist,
@@ -44,15 +52,13 @@ func getIcecastAdminPassword() string {
 }
 
 type iceLimitsConfig struct {
-	Clients int `xml:"clients"`
-	Sources int `xml:"sources"`
-	// Threadpool     int `xml:"threadpool"`
+	Clients       int `xml:"clients"`
+	Sources       int `xml:"sources"`
 	QueueSize     int `xml:"queue-size"`
 	ClientTimeout int `xml:"client-timeout"`
 	HeaderTimeout int `xml:"header-timeout"`
 	SourceTimeout int `xml:"source-timeout"`
-	// BurstOnConnect int `xml:"burst-on-connect"`
-	BurstSize int `xml:"burst-size"`
+	BurstSize     int `xml:"burst-size"`
 }
 
 type iceAuthenticationConfig struct {
@@ -97,16 +103,16 @@ type iceRelayConfig struct {
 }
 
 type iceMountConfig struct {
-	Name     string `xml:"mount-name"`
-	Username string `xml:"username"`
-	Password string `xml:"password"`
-	// MaxListeners     int    `xml:"max-listeners"`
+	Name             string `xml:"mount-name"`
+	Username         string `xml:"username"`
+	Password         string `xml:"password"`
 	FallbackMount    string `xml:"fallback-mount,omitempty"`
 	FallbackOverride int    `xml:"fallback-override,omitempty"`
 	Hidden           int    `xml:"hidden"`
-	// NoYp             int    `xml:"no-yp"`
-	OnConnect    string `xml:"on-connect,omitempty"`
-	OnDisconnect string `xml:"on-disconnect,omitempty"`
+	OnConnect        string `xml:"on-connect,omitempty"`
+	OnDisconnect     string `xml:"on-disconnect,omitempty"`
+	// Public           int    `xml:"no-yp"`
+	// MaxListeners     int    `xml:"max-listeners"`
 }
 
 // Configuration of the local Icecast daemon. This is a write-only
@@ -137,9 +143,6 @@ type icecastConfig struct {
 // to a file for persistence. It is not really meant to be used by the
 // operator.
 //
-// TODO: Some of the parameters should probably be command-line flags,
-// so that it is possible to set them on a per-host basis.
-//
 func newIcecastConfig(publicIp string) *icecastConfig {
 	// We don't use the global source password, but icecast is
 	// happier if it's set, so we just use a random password every
@@ -150,15 +153,13 @@ func newIcecastConfig(publicIp string) *icecastConfig {
 	return &icecastConfig{
 		XMLName: xml.Name{"", "icecast"},
 		Limits: iceLimitsConfig{
-			Clients: maxClients,
-			Sources: maxClients / 2,
-			// Threadpool:     16,
-			QueueSize:     1 << 20,
-			ClientTimeout: 30,
-			HeaderTimeout: 15,
-			SourceTimeout: 60,
-			// BurstOnConnect: 1,
-			BurstSize: 131072,
+			Clients:       maxClients,
+			Sources:       maxClients / 2,
+			QueueSize:     *icecastQueueSize,
+			ClientTimeout: *icecastClientTimeout,
+			HeaderTimeout: *icecastHeaderTimeout,
+			SourceTimeout: *icecastSourceTimeout,
+			BurstSize:     *icecastBurstSize,
 		},
 		Auth: iceAuthenticationConfig{
 			SourcePassword: sourcePw,
-- 
GitLab