|
19 | 19 | import net.i2p.router.Router; |
20 | 20 | import net.i2p.router.RouterContext; |
21 | 21 | import net.i2p.router.RouterLaunch; |
22 | | -import net.i2p.util.OrderedProperties; |
23 | 22 |
|
24 | | -import java.io.File; |
25 | | -import java.io.FileInputStream; |
26 | | -import java.io.IOException; |
27 | | -import java.io.InputStream; |
28 | 23 | import java.text.DecimalFormat; |
29 | | -import java.util.Properties; |
30 | | -import java.util.Random; |
31 | 24 |
|
32 | 25 | /** |
33 | 26 | * Runs the router |
@@ -175,147 +168,7 @@ public void run() { |
175 | 168 | //NativeBigInteger.main(null); |
176 | 169 | //Util.d(MARKER + this + " JBigI speed test finished, launching router"); |
177 | 170 |
|
178 | | - |
179 | | - // Before we launch, fix up any settings that need to be fixed here. |
180 | | - // This should be done in the core, but as of this writing it isn't! |
181 | | - |
182 | | - // Step one. Load the propertites. |
183 | | - Properties props = new OrderedProperties(); |
184 | | - Properties oldprops = new OrderedProperties(); |
185 | | - String wrapName = _myDir + "/router.config"; |
186 | | - try { |
187 | | - InputStream fin = new FileInputStream(new File(wrapName)); |
188 | | - DataHelper.loadProps(props, fin); |
189 | | - } catch(IOException ioe) { |
190 | | - // shouldn't happen... |
191 | | - } |
192 | | - oldprops.putAll(props); |
193 | | - // Step two, check for any port settings, and copy for those that are missing. |
194 | | - int UDPinbound; |
195 | | - int UDPinlocal; |
196 | | - int TCPinbound; |
197 | | - int TCPinlocal; |
198 | | - UDPinbound = Integer.parseInt(props.getProperty("i2np.udp.port", "-1")); |
199 | | - UDPinlocal = Integer.parseInt(props.getProperty("i2np.udp.internalPort", "-1")); |
200 | | - TCPinbound = Integer.parseInt(props.getProperty("i2np.ntcp.port", "-1")); |
201 | | - TCPinlocal = Integer.parseInt(props.getProperty("i2np.ntcp.internalPort", "-1")); |
202 | | - boolean hasUDPinbound = UDPinbound != -1; |
203 | | - boolean hasUDPinlocal = UDPinlocal != -1; |
204 | | - boolean hasTCPinbound = TCPinbound != -1; |
205 | | - boolean hasTCPinlocal = TCPinlocal != -1; |
206 | | - |
207 | | - // check and clear values based on these: |
208 | | - boolean udp = Boolean.parseBoolean(props.getProperty("i2np.udp.enable", "false")); |
209 | | - boolean tcp = Boolean.parseBoolean(props.getProperty("i2np.ntcp.enable", "false")); |
210 | | - |
211 | | - // Fix if both are false. |
212 | | - if(!(udp || tcp)) { |
213 | | - // If both are not on, turn them both on. |
214 | | - props.setProperty("i2np.udp.enable", "true"); |
215 | | - props.setProperty("i2np.ntcp.enable", "true"); |
216 | | - } |
217 | | - |
218 | | - // Fix if we have local but no inbound |
219 | | - if(!hasUDPinbound && hasUDPinlocal) { |
220 | | - // if we got a local port and no external port, set it |
221 | | - hasUDPinbound = true; |
222 | | - UDPinbound = UDPinlocal; |
223 | | - } |
224 | | - if(!hasTCPinbound && hasTCPinlocal) { |
225 | | - // if we got a local port and no external port, set it |
226 | | - hasTCPinbound = true; |
227 | | - TCPinbound = TCPinlocal; |
228 | | - } |
229 | | - |
230 | | - boolean anyUDP = hasUDPinbound || hasUDPinlocal; |
231 | | - boolean anyTCP = hasTCPinbound || hasTCPinlocal; |
232 | | - boolean anyport = anyUDP || anyTCP; |
233 | | - |
234 | | - if(!anyport) { |
235 | | - // generate one for UDPinbound, and fall thru. |
236 | | - // FIX ME: Possibly not the best but should be OK. |
237 | | - Random generator = new Random(System.currentTimeMillis()); |
238 | | - UDPinbound = generator.nextInt(55500) + 10000; |
239 | | - anyUDP = true; |
240 | | - } |
241 | | - |
242 | | - // Copy missing port numbers |
243 | | - if(anyUDP && !anyTCP) { |
244 | | - TCPinbound = UDPinbound; |
245 | | - TCPinlocal = UDPinlocal; |
246 | | - } |
247 | | - if(anyTCP && !anyUDP) { |
248 | | - UDPinbound = TCPinbound; |
249 | | - UDPinlocal = TCPinlocal; |
250 | | - } |
251 | | - // reset for a retest. |
252 | | - hasUDPinbound = UDPinbound != -1; |
253 | | - hasUDPinlocal = UDPinlocal != -1; |
254 | | - hasTCPinbound = TCPinbound != -1; |
255 | | - hasTCPinlocal = TCPinlocal != -1; |
256 | | - anyUDP = hasUDPinbound || hasUDPinlocal; |
257 | | - anyTCP = hasTCPinbound || hasTCPinlocal; |
258 | | - boolean checkAnyUDP = anyUDP && udp; |
259 | | - boolean checkAnyTCP = anyTCP && tcp; |
260 | | - |
261 | | - // Enable things that need to be enabled. |
262 | | - // Disable anything that needs to be disabled. |
263 | | - if(!checkAnyUDP && !checkAnyTCP) { |
264 | | - // enable the one(s) with values. |
265 | | - if(anyUDP) { |
266 | | - udp = true; |
267 | | - } |
268 | | - if(anyTCP) { |
269 | | - tcp = true; |
270 | | - } |
271 | | - } |
272 | | - |
273 | | - if(!udp) { |
274 | | - props.setProperty("i2np.udp.enable", "false"); |
275 | | - props.remove("i2np.udp.port"); |
276 | | - props.remove("i2np.udp.internalPort"); |
277 | | - } else { |
278 | | - props.setProperty("i2np.udp.enable", "true"); |
279 | | - if(hasUDPinbound) { |
280 | | - props.setProperty("i2np.udp.port", Integer.toString(UDPinbound)); |
281 | | - } else { |
282 | | - props.remove("i2np.udp.port"); |
283 | | - } |
284 | | - if(hasUDPinlocal) { |
285 | | - props.setProperty("i2np.udp.internalPort", Integer.toString(UDPinlocal)); |
286 | | - } else { |
287 | | - props.remove("i2np.udp.internalPort"); |
288 | | - } |
289 | | - } |
290 | | - |
291 | | - if(!tcp) { |
292 | | - props.setProperty("i2np.ntcp.enable", "false"); |
293 | | - props.remove("i2np.ntcp.port"); |
294 | | - props.remove("i2np.ntcp.internalPort"); |
295 | | - } else { |
296 | | - props.setProperty("i2np.ntcp.enable", "true"); |
297 | | - if(hasTCPinbound) { |
298 | | - props.setProperty("i2np.ntcp.port", Integer.toString(TCPinbound)); |
299 | | - } else { |
300 | | - props.remove("i2np.ntcp.port"); |
301 | | - } |
302 | | - if(hasTCPinlocal) { |
303 | | - props.setProperty("i2np.ntcp.internalPort", Integer.toString(TCPinlocal)); |
304 | | - } else { |
305 | | - props.remove("i2np.ntcp.internalPort"); |
306 | | - } |
307 | | - } |
308 | | - // WHEW! Now test for any changes. |
309 | | - if(!props.equals(oldprops)) { |
310 | | - // save fixed properties. |
311 | | - try { |
312 | | - DataHelper.storeProps(props, new File(wrapName)); |
313 | | - } catch(IOException ioe) { |
314 | | - // shouldn't happen... |
315 | | - } |
316 | | - } |
317 | | - |
318 | | - // _NOW_ launch the router! |
| 171 | + // Launch the router! |
319 | 172 | RouterLaunch.main(null); |
320 | 173 | synchronized(_stateLock) { |
321 | 174 | if(_state != State.STARTING) { |
|
0 commit comments