[vlma-devel] commit: Make the range of the IP bank configurable. (Adrien Grand )
git version control
git at videolan.org
Sat Jun 28 01:46:07 CEST 2008
vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Fri Jun 27 20:39:27 2008 +0200| [23f7819473b2be5fc2ae267b480349a585161f1f]
Make the range of the IP bank configurable.
> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=23f7819473b2be5fc2ae267b480349a585161f1f
---
.../src/main/java/org/videolan/vlma/IpBank.java | 68 ++++++++++++++++----
.../main/java/org/videolan/vlma/daemon/Daemon.java | 12 +---
.../main/java/org/videolan/vlma/daemon/VLMad.java | 31 +++++----
vlma-daemon/src/main/resources/config.properties | 2 +
4 files changed, 73 insertions(+), 40 deletions(-)
diff --git a/vlma-core/src/main/java/org/videolan/vlma/IpBank.java b/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
index 7ab308f..8899ede 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
@@ -20,6 +20,7 @@
package org.videolan.vlma;
+import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
@@ -38,35 +39,30 @@ import org.videolan.vlma.model.program.Program;
* @author SylV
*/
public class IpBank {
+
private static final Logger logger = Logger.getLogger(IpBank.class);
private HashMap<InetAddress, Boolean> usedIps;
private VLMaService vlmaService;
+ private Inet4Address min;
+ private Inet4Address max;
+
/**
* Initializes IP addresses according to the data interface.
*
* @throws UnknownHostException
* address is invalid
*/
- public void initIps(boolean IPsDevel) throws UnknownHostException {
+ public void initIps() throws UnknownHostException {
usedIps = new HashMap<InetAddress, Boolean>();
usedIps.clear();
- int iMin, iMax;
- if (IPsDevel == false) {
- iMin = 100;
- iMax = 120;
- } else {
- iMin = 200;
- iMax = 220;
- }
- for (int i = iMin; i < iMax; i++) {
- for (int j = 1; j < 255; j++) {
- byte[] b = { (byte) 239, (byte) 255, (byte) i, (byte) j };
- usedIps.put(InetAddress.getByAddress(b), Boolean.FALSE);
- }
+
+ for (int ip = ipv42int(min); ip < ipv42int(max); ip++) {
+ usedIps.put(int2ipv4(ip), Boolean.FALSE);
}
+
for (Media m : vlmaService.getMedias()) {
Program p = m.getProgram();
if (p == null || !p.getStreamingStrategy().getProtocol().equals(StreamingStrategy.Protocol.UDP)) {
@@ -110,6 +106,36 @@ public class IpBank {
}
/**
+ * Converts an IPv4 address to an integer.
+ *
+ * @param ip the IPv4 address
+ * @return the associated integer
+ */
+ private int ipv42int(Inet4Address ip) {
+ int result = 0;
+ byte[] t = ip.getAddress();
+ for (int i = 0; i < 4; i++) {
+ result += result * 256 + t[i];
+ }
+ return result;
+ }
+
+ /**
+ * Converts an integer to a IPv4 address.
+ *
+ * @param ip the integer
+ * @return the associated IPv4
+ * @throws UnknownHostException
+ */
+ private Inet4Address int2ipv4 (int ip) throws UnknownHostException {
+ byte[] result = new byte[4];
+ for (int i = 0; i < 4; i++) {
+ result[i] = (byte) ((ip >> (8 * (3 - i))) & 255);
+ }
+ return (Inet4Address) Inet4Address.getByAddress(result);
+ }
+
+ /**
* Sets the VLMa service.
*
* @param vlmaService the vlmaService to set
@@ -118,4 +144,18 @@ public class IpBank {
this.vlmaService = vlmaService;
}
+ /**
+ * @param max the max to set
+ */
+ public void setMax(Inet4Address max) {
+ this.max = max;
+ }
+
+ /**
+ * @param min the min to set
+ */
+ public void setMin(Inet4Address min) {
+ this.min = min;
+ }
+
}
diff --git a/vlma-daemon/src/main/java/org/videolan/vlma/daemon/Daemon.java b/vlma-daemon/src/main/java/org/videolan/vlma/daemon/Daemon.java
index 4f27306..9afa6da 100644
--- a/vlma-daemon/src/main/java/org/videolan/vlma/daemon/Daemon.java
+++ b/vlma-daemon/src/main/java/org/videolan/vlma/daemon/Daemon.java
@@ -35,7 +35,6 @@ public class Daemon {
private IpBank ipBank;
private List<Monitor> monitors;
- private boolean ipsDevel = false;
/**
* Sets the IP bank.
@@ -56,20 +55,11 @@ public class Daemon {
}
/**
- * Sets whether or not VLMa should use development IPs.
- *
- * @param ipsDevel true if VLMa should use development IPs, false otherwise
- */
- public void setIpsDevel(boolean ipsDevel) {
- this.ipsDevel = ipsDevel;
- }
-
- /**
* Runs the daemon.
*/
public void run() {
try {
- ipBank.initIps(ipsDevel);
+ ipBank.initIps();
} catch (UnknownHostException e) {
// TODO Do better?
e.printStackTrace();
diff --git a/vlma-daemon/src/main/java/org/videolan/vlma/daemon/VLMad.java b/vlma-daemon/src/main/java/org/videolan/vlma/daemon/VLMad.java
index 20ab17d..d00e461 100644
--- a/vlma-daemon/src/main/java/org/videolan/vlma/daemon/VLMad.java
+++ b/vlma-daemon/src/main/java/org/videolan/vlma/daemon/VLMad.java
@@ -20,17 +20,19 @@
package org.videolan.vlma.daemon;
+import java.net.Inet4Address;
import java.net.URL;
+import java.net.UnknownHostException;
import jargs.gnu.CmdLineParser;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.SystemConfiguration;
-import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.videolan.vlma.IpBank;
import org.videolan.vlma.VLMa;
import org.videolan.vlma.model.StreamingStrategy;
@@ -54,19 +56,18 @@ public class VLMad {
VLMa.getInstance().addConfiguration(new PropertiesConfiguration(defaultConfFile));
} catch (ConfigurationException e) {
logger.fatal("Unable to load default configuration.", e);
- return;
+ System.exit(2);
}
// parsing of command line
CmdLineParser parser = new CmdLineParser();
CmdLineParser.Option springxml = parser.addStringOption("springxml");
- CmdLineParser.Option IPsDevel = parser.addBooleanOption("IPsDevel");
try {
parser.parse(args);
} catch (CmdLineParser.OptionException e) {
- logger.log(Level.ERROR, "Erreur dans la ligne de commande : " + e.getMessage());
- logger.log(Level.INFO, "Usage: VLMad [{--springxml} daemon.xml]\n");
+ logger.fatal("Erreur dans la ligne de commande : " + e.getMessage());
+ logger.info("Usage: VLMad [{--springxml} daemon.xml]\n");
System.exit(2);
}
@@ -75,16 +76,9 @@ public class VLMad {
springxmlvalue = "daemon.xml";
}
- boolean IPsDevelvalue;
- if (parser.getOptionValue(IPsDevel) != null) {
- IPsDevelvalue = true;
- } else {
- IPsDevelvalue = false;
- }
-
// Launching VLMad
- logger.log(Level.DEBUG, "Starting VLMad");
- logger.log(Level.DEBUG, "Loading Spring application context from XML file: " + springxmlvalue);
+ logger.debug("Starting VLMad");
+ logger.debug("Loading Spring application context from XML file: " + springxmlvalue);
ApplicationContext ac = new ClassPathXmlApplicationContext(springxmlvalue);
StreamingStrategy streamingStrategy = (StreamingStrategy) ac.getBean("streamingStrategy");
String announcement = VLMa.getInstance().getString("vlma.announcement.protocol");
@@ -93,8 +87,15 @@ public class VLMad {
for (String s : announcement.split(","))
streamingStrategy.addAnnouncement(StreamingStrategy.Announcement.valueOf(s));
streamingStrategy.setProtocol(StreamingStrategy.Protocol.valueOf(protocol));
+ IpBank ipBank = (IpBank) ac.getBean("ipBank");
+ try {
+ ipBank.setMin((Inet4Address) Inet4Address.getByName(VLMa.getInstance().getString("vlma.streaming.udp.ipbank.min")));
+ ipBank.setMax((Inet4Address) Inet4Address.getByName(VLMa.getInstance().getString("vlma.streaming.udp.ipbank.max")));
+ } catch (UnknownHostException e) {
+ logger.error("Cannot initialize the IP bank.", e);
+ System.exit(2);
+ }
Daemon daemon = (Daemon) ac.getBean("daemon");
- daemon.setIpsDevel(IPsDevelvalue);
daemon.run();
}
}
diff --git a/vlma-daemon/src/main/resources/config.properties b/vlma-daemon/src/main/resources/config.properties
index 8ddc528..b035492 100644
--- a/vlma-daemon/src/main/resources/config.properties
+++ b/vlma-daemon/src/main/resources/config.properties
@@ -33,5 +33,7 @@ vlma.notification.msn.pass =
vlma.notification.msn.recipients =
vlma.streaming.http.port = 8001
vlma.streaming.protocol = UDP
+vlma.streaming.udp.ipbank.min = 239.127.0.1
+vlma.streaming.udp.ipbank.max = 239.127.255.255
vlma.ui.command.queue.size = 500
vlma.work=${java.io.tmpdir}
More information about the vlma-devel
mailing list