[freenet-cvs] r16900 - trunk/freenet/src/freenet/clients/http

robert at freenetproject.org robert at freenetproject.org
Sat Jan 5 00:11:33 UTC 2008


Author: robert
Date: 2008-01-05 00:11:32 +0000 (Sat, 05 Jan 2008)
New Revision: 16900

Modified:
   trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
Log:
make this network interface bind lazy-and-at-init time (for the possible exception)


Modified: trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java	2008-01-04 23:57:59 UTC (rev 16899)
+++ trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java	2008-01-05 00:11:32 UTC (rev 16900)
@@ -53,6 +53,7 @@
 
 	final int port;
 	String bindTo;
+	private String allowedHosts;
 	final AllowedHosts allowedFullAccess;
 	final BucketFactory bf;
 	NetworkInterface networkInterface;
@@ -363,31 +364,40 @@
 		if(SSL.available()) {
 			ssl = fproxyConfig.getBoolean("ssl");
 		}
+		
+		this.allowedHosts=fproxyConfig.getString("allowedHosts");
 
 		if(!enabled) {
 			Logger.normal(core, "Not starting FProxy as it's disabled");
 			System.out.println("Not starting FProxy as it's disabled");
 		} else {
-			if(ssl) {
-				this.networkInterface = SSLNetworkInterface.create(port, this.bindTo, fproxyConfig.getString("allowedHosts"), core.getExecutor(), true);
-			} else {
-				this.networkInterface = NetworkInterface.create(port, this.bindTo, fproxyConfig.getString("allowedHosts"), core.getExecutor(), true);
-			}
+			maybeGetNetworkInterface();
 			myThread = new Thread(this, "SimpleToadletServer");
 			myThread.setDaemon(true);
 		}
-
 	}
+	
+	private void maybeGetNetworkInterface() throws IOException {
+		if (this.networkInterface!=null) return;
+		if(ssl) {
+			this.networkInterface = SSLNetworkInterface.create(port, this.bindTo, allowedHosts, core.getExecutor(), true);
+		} else {
+			this.networkInterface = NetworkInterface.create(port, this.bindTo, allowedHosts, core.getExecutor(), true);
+		}
+	}		
 
 	public boolean doRobots() {
 		return doRobots;
 	}
 	
 	public void start() {
-		if(myThread != null) {
+		if(myThread != null) try {
+			maybeGetNetworkInterface();
 			myThread.start();
 			Logger.normal(this, "Starting FProxy on "+bindTo+ ':' +port);
 			System.out.println("Starting FProxy on "+bindTo+ ':' +port);
+		} catch (IOException e) {
+			Logger.error(this, "Could not bind network port for FProxy?", e);
 		}
 	}
 	




More information about the cvs mailing list