Changeset f0eb5663
- Timestamp:
- Jan 2, 2012 2:39:17 PM (9 years ago)
- Branches:
- master
- Children:
- 88cf742
- Parents:
- d8e297dd (diff), 87008f3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/routerconsole/java/src/net/i2p/router/web/LogsHelper.java
rd8e297dd rf0eb5663 13 13 /** @since 0.8.11 */ 14 14 public String getJettyVersion() { 15 return Version.getImplVersion(); 15 return jettyVersion(); 16 } 17 18 /** @since 0.8.13 */ 19 static String jettyVersion() { 20 try { 21 String rv = Version.getImplVersion(); 22 if (rv.startsWith("Jetty/")) 23 rv = rv.substring(6); 24 return rv; 25 } catch (Throwable t) { 26 return "unknown"; 27 } 16 28 } 17 29 -
apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java
rd8e297dd rf0eb5663 377 377 if (!((style.equals("SSU") && cost == 5) || (style.equals("NTCP") && cost == 10))) 378 378 buf.append('[').append(_("cost")).append('=').append("" + cost).append("] "); 379 Properties p = new OrderedProperties(); 380 p.putAll(addr.getOptions()); 381 for (Map.Entry e : p.entrySet()) { 379 Map p = addr.getOptionsMap(); 380 for (Map.Entry e : (Set<Map.Entry>) p.entrySet()) { 382 381 String name = (String) e.getKey(); 383 382 String val = (String) e.getValue(); … … 388 387 if (full) { 389 388 buf.append("<tr><td>" + _("Stats") + ": <br><code>"); 390 for (Iterator iter = info.getOptions().keySet().iterator(); iter.hasNext(); ) { 391 String key = (String)iter.next(); 392 String val = info.getOption(key); 389 Map p = info.getOptionsMap(); 390 for (Map.Entry e : (Set<Map.Entry>) p.entrySet()) { 391 String key = (String) e.getKey(); 392 String val = (String) e.getValue(); 393 393 buf.append(DataHelper.stripHTML(key)).append(" = ").append(DataHelper.stripHTML(val)).append("<br>\n"); 394 394 } … … 413 413 rv |= NTCP; 414 414 } else if (style.equals("SSU")) { 415 if (addr.getOption s().getProperty("iport0") != null)415 if (addr.getOption("iport0") != null) 416 416 rv |= SSUI; 417 417 else -
apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java
rd8e297dd rf0eb5663 18 18 import java.util.concurrent.ConcurrentHashMap; 19 19 20 import net.i2p.CoreVersion; 20 21 import net.i2p.I2PAppContext; 21 22 import net.i2p.data.DataHelper; … … 28 29 import net.i2p.util.Log; 29 30 import net.i2p.util.Translate; 31 import net.i2p.util.VersionComparator; 30 32 31 33 import org.mortbay.jetty.Server; … … 96 98 return false; 97 99 } 100 101 Properties props = pluginProperties(ctx, appName); 102 String minVersion = ConfigClientsHelper.stripHTML(props, "min-i2p-version"); 103 if (minVersion != null && 104 (new VersionComparator()).compare(CoreVersion.VERSION, minVersion) < 0) { 105 String foo = "Plugin " + appName + " requires I2P version " + minVersion + " or higher"; 106 log.error(foo); 107 throw new Exception(foo); 108 } 109 110 minVersion = ConfigClientsHelper.stripHTML(props, "min-java-version"); 111 if (minVersion != null && 112 (new VersionComparator()).compare(System.getProperty("java.version"), minVersion) < 0) { 113 String foo = "Plugin " + appName + " requires Java version " + minVersion + " or higher"; 114 log.error(foo); 115 throw new Exception(foo); 116 } 117 118 String jVersion = LogsHelper.jettyVersion(); 119 minVersion = ConfigClientsHelper.stripHTML(props, "min-jetty-version"); 120 if (minVersion != null && 121 (new VersionComparator()).compare(minVersion, jVersion) > 0) { 122 String foo = "Plugin " + appName + " requires Jetty version " + minVersion + " or higher"; 123 log.error(foo); 124 throw new Exception(foo); 125 } 126 127 String maxVersion = ConfigClientsHelper.stripHTML(props, "max-jetty-version"); 128 if (maxVersion != null && 129 (new VersionComparator()).compare(maxVersion, jVersion) < 0) { 130 String foo = "Plugin " + appName + " requires Jetty version " + maxVersion + " or lower"; 131 log.error(foo); 132 throw new Exception(foo); 133 } 134 98 135 if (log.shouldLog(Log.INFO)) 99 136 log.info("Starting plugin: " + appName); … … 114 151 File clientConfig = new File(pluginDir, "clients.config"); 115 152 if (clientConfig.exists()) { 116 Properties props = new Properties();117 DataHelper.loadProps( props, clientConfig);153 Properties cprops = new Properties(); 154 DataHelper.loadProps(cprops, clientConfig); 118 155 List<ClientAppConfig> clients = ClientAppConfig.getClientApps(clientConfig); 119 156 runClientApps(ctx, pluginDir, clients, "start"); … … 124 161 if (server != null) { 125 162 File consoleDir = new File(pluginDir, "console"); 126 Properties props = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath());163 Properties wprops = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath()); 127 164 File webappDir = new File(consoleDir, "webapps"); 128 165 String fileNames[] = webappDir.list(RouterConsoleRunner.WarFilenameFilter.instance()); … … 139 176 continue; 140 177 } 141 String enabled = props.getProperty(RouterConsoleRunner.PREFIX + warName + ENABLED);178 String enabled = wprops.getProperty(RouterConsoleRunner.PREFIX + warName + ENABLED); 142 179 if (! "false".equals(enabled)) { 143 180 if (log.shouldLog(Log.INFO)) … … 182 219 183 220 // add summary bar link 184 Properties props = pluginProperties(ctx, appName);185 221 String name = ConfigClientsHelper.stripHTML(props, "consoleLinkName_" + Messages.getLanguage(ctx)); 186 222 if (name == null) -
apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java
rd8e297dd rf0eb5663 335 335 return; 336 336 } 337 oldVersion = LogsHelper.jettyVersion(); 338 minVersion = ConfigClientsHelper.stripHTML(props, "min-jetty-version"); 339 if (minVersion != null && 340 (new VersionComparator()).compare(minVersion, oldVersion) > 0) { 341 to.delete(); 342 statusDone("<b>" + _("Plugin requires Jetty version {0} or higher", minVersion) + "</b>"); 343 return; 344 } 345 maxVersion = ConfigClientsHelper.stripHTML(props, "max-jetty-version"); 346 if (maxVersion != null && 347 (new VersionComparator()).compare(maxVersion, oldVersion) < 0) { 348 to.delete(); 349 statusDone("<b>" + _("Plugin requires Jetty version {0} or lower", maxVersion) + "</b>"); 350 return; 351 } 337 352 338 353 // check if it is running first? -
core/java/src/net/i2p/data/DataHelper.java
rd8e297dd rf0eb5663 119 119 throws DataFormatException, IOException { 120 120 Properties props = new OrderedProperties(); 121 readProperties(rawStream, props); 122 return props; 123 } 124 125 /** 126 * Ditto, load into an existing properties 127 * @param props the Properties to load into 128 * @since 0.8.13 129 */ 130 public static Properties readProperties(InputStream rawStream, Properties props) 131 throws DataFormatException, IOException { 121 132 long size = readLong(rawStream, 2); 122 133 byte data[] = new byte[(int) size]; … … 1269 1280 * How to spec as returning the same type as the param? 1270 1281 * DEPRECATED - Only used by RouterInfo. 1282 * 1283 * @return a new list 1271 1284 */ 1272 1285 public static List<? extends DataStructure> sortStructures(Collection<? extends DataStructure> dataStructures) { -
core/java/src/net/i2p/data/DatabaseEntry.java
rd8e297dd rf0eb5663 125 125 * Configure the proof that the entity stands behind the info here 126 126 * 127 * @throws IllegalStateException if already signed 127 128 */ 128 129 public void setSignature(Signature signature) { 130 if (_signature != null) 131 throw new IllegalStateException(); 129 132 _signature = signature; 130 133 } … … 133 136 * Sign the structure using the supplied signing key 134 137 * 138 * @throws IllegalStateException if already signed 135 139 */ 136 140 public void sign(SigningPrivateKey key) throws DataFormatException { 141 if (_signature != null) 142 throw new IllegalStateException(); 137 143 byte[] bytes = getBytes(); 138 144 if (bytes == null) throw new DataFormatException("Not enough data to sign"); -
core/java/src/net/i2p/data/RouterAddress.java
rd8e297dd rf0eb5663 13 13 import java.io.InputStream; 14 14 import java.io.OutputStream; 15 import java.util.Collections; 15 16 import java.util.Date; 16 17 import java.util.Iterator; … … 22 23 /** 23 24 * Defines a method of communicating with a router 25 * 26 * For efficiency, the options methods and structures here are unsynchronized. 27 * Initialize the structure with readBytes(), or call the setOptions(). 28 * Don't change it after that. 29 * 30 * To ensure integrity of the RouterInfo, methods that change an element of the 31 * RouterInfo will throw an IllegalStateException after the RouterInfo is signed. 24 32 * 25 33 * @author jrandom … … 29 37 private Date _expiration; 30 38 private String _transportStyle; 31 private Properties _options;39 private final Properties _options; 32 40 33 41 public RouterAddress() { 34 42 _cost = -1; 43 _options = new OrderedProperties(); 35 44 } 36 45 … … 86 95 * Configure the type of transport that must be used to communicate on this address 87 96 * 97 * @throws IllegalStateException if was already set 88 98 */ 89 99 public void setTransportStyle(String transportStyle) { 100 if (_transportStyle != null) 101 throw new IllegalStateException(); 90 102 _transportStyle = transportStyle; 91 103 } … … 94 106 * Retrieve the transport specific options necessary for communication 95 107 * 108 * @deprecated use getOptionsMap() 109 * @return sorted, non-null, NOT a copy, do not modify 96 110 */ 97 111 public Properties getOptions() { … … 100 114 101 115 /** 102 * Specify the transport specific options necessary for communication 103 * 116 * Retrieve the transport specific options necessary for communication 117 * 118 * @return an unmodifiable view, non-null, sorted 119 * @since 0.8.13 120 */ 121 public Map getOptionsMap() { 122 return Collections.unmodifiableMap(_options); 123 } 124 125 /** 126 * @since 0.8.13 127 */ 128 public String getOption(String opt) { 129 return _options.getProperty(opt); 130 } 131 132 /** 133 * Specify the transport specific options necessary for communication. 134 * Makes a copy. 135 * @param options non-null 136 * @throws IllegalStateException if was already set 104 137 */ 105 138 public void setOptions(Properties options) { 106 _options = options; 107 } 108 139 if (!_options.isEmpty()) 140 throw new IllegalStateException(); 141 _options.putAll(options); 142 } 143 144 /** 145 * @throws IllegalStateException if was already read in 146 */ 109 147 public void readBytes(InputStream in) throws DataFormatException, IOException { 148 if (_transportStyle != null) 149 throw new IllegalStateException(); 110 150 _cost = (int) DataHelper.readLong(in, 1); 111 151 _expiration = DataHelper.readDate(in); … … 116 156 else if (_transportStyle.equals("NTCP")) 117 157 _transportStyle = "NTCP"; 118 _options = DataHelper.readProperties(in);158 DataHelper.readProperties(in, _options); 119 159 } 120 160 121 161 public void writeBytes(OutputStream out) throws DataFormatException, IOException { 122 if ((_cost < 0) || (_transportStyle == null) || (_options == null))162 if ((_cost < 0) || (_transportStyle == null)) 123 163 throw new DataFormatException("Not enough data to write a router address"); 124 164 DataHelper.writeLong(out, 1, _cost); … … 132 172 if ((object == null) || !(object instanceof RouterAddress)) return false; 133 173 RouterAddress addr = (RouterAddress) object; 174 // let's keep this fast as we are putting an address into the RouterInfo set frequently 134 175 return 135 176 _cost == addr._cost && 136 DataHelper.eq(_transportStyle, addr._transportStyle) &&137 DataHelper.eq(_options, addr._options) &&138 DataHelper.eq(_expiration, addr._expiration);177 DataHelper.eq(_transportStyle, addr._transportStyle); 178 //DataHelper.eq(_options, addr._options) && 179 //DataHelper.eq(_expiration, addr._expiration); 139 180 } 140 181 … … 162 203 if (_options != null) { 163 204 buf.append("\n\tOptions: #: ").append(_options.size()); 164 Properties p = new OrderedProperties(); 165 p.putAll(_options); 166 for (Map.Entry e : p.entrySet()) { 205 for (Map.Entry e : _options.entrySet()) { 167 206 String key = (String) e.getKey(); 168 207 String val = (String) e.getValue(); -
core/java/src/net/i2p/data/RouterInfo.java
rd8e297dd rf0eb5663 20 20 import java.util.Iterator; 21 21 import java.util.List; 22 import java.util.Map; 22 23 import java.util.Properties; 23 24 import java.util.Set; … … 32 33 * Defines the data that a router either publishes to the global routing table or 33 34 * provides to trusted peers. 35 * 36 * For efficiency, the methods and structures here are now unsynchronized. 37 * Initialize the RI with readBytes(), or call the setters and then sign() in a single thread. 38 * Don't change it after that. 39 * 40 * To ensure integrity of the RouterInfo, methods that change an element of the 41 * RouterInfo will throw an IllegalStateException after the RouterInfo is signed. 34 42 * 35 43 * @author jrandom … … 42 50 /** may be null to save memory, no longer final */ 43 51 private Set<Hash> _peers; 44 private /* FIXME final FIXME */Properties _options;52 private final Properties _options; 45 53 private volatile boolean _validated; 46 54 private volatile boolean _isValid; … … 68 76 } 69 77 78 /** 79 * Used only by Router and PublishLocalRouterInfoJob. 80 * Copies ONLY the identity and peers. 81 * Does not copy published, addresses, options, or signature. 82 */ 70 83 public RouterInfo(RouterInfo old) { 71 84 this(); 72 85 setIdentity(old.getIdentity()); 73 setPublished(old.getPublished());74 setAddresses(old.getAddresses());86 //setPublished(old.getPublished()); 87 //setAddresses(old.getAddresses()); 75 88 setPeers(old.getPeers()); 76 setOptions(old.getOptions());77 setSignature(old.getSignature());89 //setOptions(old.getOptions()); 90 //setSignature(old.getSignature()); 78 91 // copy over _byteified? 79 92 } … … 91 104 } 92 105 93 private void resetCache() {94 _stringified = null;95 _byteified = null;96 _hashCodeInitialized = false;97 }98 99 106 /** 100 107 * Retrieve the identity of the router represented … … 108 115 * Configure the identity of the router represented 109 116 * 117 * @throws IllegalStateException if RouterInfo is already signed 110 118 */ 111 119 public void setIdentity(RouterIdentity ident) { 120 if (_signature != null) 121 throw new IllegalStateException(); 112 122 _identity = ident; 113 resetCache();114 123 // We only want to cache the bytes for our own RI, which is frequently written. 115 124 // To cache for all RIs doubles the RI memory usage. … … 134 143 * Date on which it was published, in milliseconds since Midnight GMT on Jan 01, 1970 135 144 * 145 * @throws IllegalStateException if RouterInfo is already signed 136 146 */ 137 147 public void setPublished(long published) { 148 if (_signature != null) 149 throw new IllegalStateException(); 138 150 _published = published; 139 resetCache();140 151 } 141 152 … … 144 155 * router can be contacted. 145 156 * 157 * @return unmodifiable view, non-null 146 158 */ 147 159 public Set<RouterAddress> getAddresses() { 148 synchronized (_addresses) { 149 return new HashSet(_addresses); 150 } 160 return Collections.unmodifiableSet(_addresses); 151 161 } 152 162 … … 155 165 * can be contacted. 156 166 * 167 * @throws IllegalStateException if RouterInfo is already signed 157 168 */ 158 169 public void setAddresses(Set<RouterAddress> addresses) { 159 synchronized (_addresses) { 160 _addresses.clear(); 161 if (addresses != null) _addresses.addAll(addresses); 162 } 163 resetCache(); 170 if (_signature != null) 171 throw new IllegalStateException(); 172 _addresses.clear(); 173 if (addresses != null) _addresses.addAll(addresses); 164 174 } 165 175 … … 181 191 * 182 192 * @deprecated Implemented here but unused elsewhere 193 * @throws IllegalStateException if RouterInfo is already signed 183 194 */ 184 195 public void setPeers(Set<Hash> peers) { 196 if (_signature != null) 197 throw new IllegalStateException(); 185 198 if (peers == null || peers.isEmpty()) { 186 199 _peers = null; … … 193 206 _peers.addAll(peers); 194 207 } 195 resetCache(); 196 } 197 198 /** 199 * Retrieve a set of options or statistics that the router can expose 200 * 208 } 209 210 /** 211 * Retrieve a set of options or statistics that the router can expose. 212 * 213 * @deprecated use getOptionsMap() 214 * @return sorted, non-null, NOT a copy, do not modify!!! 201 215 */ 202 216 public Properties getOptions() { 203 if (_options == null) return new Properties(); 204 synchronized (_options) { 205 return (Properties) _options.clone(); 206 } 207 } 217 return _options; 218 } 219 220 /** 221 * Retrieve a set of options or statistics that the router can expose. 222 * 223 * @return an unmodifiable view, non-null, sorted 224 * @since 0.8.13 225 */ 226 public Map getOptionsMap() { 227 return Collections.unmodifiableMap(_options); 228 } 229 208 230 public String getOption(String opt) { 209 if (_options == null) return null; 210 synchronized (_options) { 211 return _options.getProperty(opt); 212 } 213 } 214 215 /** 216 * Configure a set of options or statistics that the router can expose 231 return _options.getProperty(opt); 232 } 233 234 /** 235 * Configure a set of options or statistics that the router can expose. 236 * Makes a copy. 237 * 217 238 * @param options if null, clears current options 239 * @throws IllegalStateException if RouterInfo is already signed 218 240 */ 219 241 public void setOptions(Properties options) { 220 synchronized (_options) {221 _options.clear();222 if (options != null) 223 _options.putAll(options);224 }225 resetCache();242 if (_signature != null) 243 throw new IllegalStateException(); 244 245 _options.clear(); 246 if (options != null) 247 _options.putAll(options); 226 248 } 227 249 … … 235 257 if (_byteified != null) return _byteified; 236 258 if (_identity == null) throw new DataFormatException("Router identity isn't set? wtf!"); 237 if (_addresses == null) throw new DataFormatException("Router addressess isn't set? wtf!");238 if (_options == null) throw new DataFormatException("Router options isn't set? wtf!");239 259 240 260 //long before = Clock.getInstance().now(); 241 ByteArrayOutputStream out = new ByteArrayOutputStream( 6*1024);261 ByteArrayOutputStream out = new ByteArrayOutputStream(2*1024); 242 262 try { 243 263 _identity.writeBytes(out); 244 DataHelper.writeDate(out, new Date(_published)); 264 // avoid thrashing objects 265 //DataHelper.writeDate(out, new Date(_published)); 266 DataHelper.writeLong(out, 8, _published); 245 267 int sz = _addresses.size(); 246 268 if (sz <= 0 || isHidden()) { … … 250 272 DataHelper.writeLong(out, 1, sz); 251 273 Collection<RouterAddress> addresses = _addresses; 252 if (sz > 1) 274 if (sz > 1) { 253 275 // WARNING this sort algorithm cannot be changed, as it must be consistent 254 276 // network-wide. The signature is not checked at readin time, but only 255 277 // later, and the addresses are stored in a Set, not a List. 256 278 addresses = (Collection<RouterAddress>) DataHelper.sortStructures(addresses); 279 } 257 280 for (RouterAddress addr : addresses) { 258 281 addr.writeBytes(out); … … 294 317 * 295 318 */ 296 public synchronizedboolean isValid() {319 public boolean isValid() { 297 320 if (!_validated) doValidate(); 298 321 return _isValid; … … 305 328 */ 306 329 public int getNetworkId() { 307 if (_options == null) return -1; 308 String id = null; 309 synchronized (_options) { 310 id = _options.getProperty(PROP_NETWORK_ID); 311 } 330 String id = _options.getProperty(PROP_NETWORK_ID); 312 331 if (id != null) { 313 332 try { … … 323 342 */ 324 343 public String getCapabilities() { 325 if (_options == null) return ""; 326 String capabilities = null; 327 synchronized (_options) { 328 capabilities = _options.getProperty(PROP_CAPABILITIES); 329 } 344 String capabilities = _options.getProperty(PROP_CAPABILITIES); 330 345 if (capabilities != null) 331 346 return capabilities; … … 359 374 } 360 375 376 /** 377 * @throws IllegalStateException if RouterInfo is already signed 378 */ 361 379 public void addCapability(char cap) { 362 if (_options == null) _options = new OrderedProperties(); 363 synchronized (_options) { 380 if (_signature != null) 381 throw new IllegalStateException(); 382 364 383 String caps = _options.getProperty(PROP_CAPABILITIES); 365 384 if (caps == null) … … 367 386 else if (caps.indexOf(cap) == -1) 368 387 _options.setProperty(PROP_CAPABILITIES, caps + cap); 369 } 370 } 371 388 } 389 390 /** 391 * @throws IllegalStateException if RouterInfo is already signed 392 */ 372 393 public void delCapability(char cap) { 373 if (_options == null) return; 374 synchronized (_options) { 394 if (_signature != null) 395 throw new IllegalStateException(); 396 375 397 String caps = _options.getProperty(PROP_CAPABILITIES); 376 398 int idx; … … 385 407 _options.setProperty(PROP_CAPABILITIES, buf.toString()); 386 408 } 387 }388 409 } 389 410 … … 410 431 */ 411 432 public RouterAddress getTargetAddress(String transportStyle) { 412 synchronized (_addresses) { 413 for (Iterator iter = _addresses.iterator(); iter.hasNext(); ) { 414 RouterAddress addr = (RouterAddress)iter.next(); 415 if (addr.getTransportStyle().equals(transportStyle)) 416 return addr; 417 } 433 for (RouterAddress addr : _addresses) { 434 if (addr.getTransportStyle().equals(transportStyle)) 435 return addr; 418 436 } 419 437 return null; … … 426 444 public List<RouterAddress> getTargetAddresses(String transportStyle) { 427 445 List<RouterAddress> ret = new Vector<RouterAddress>(); 428 synchronized(this._addresses) { 429 for(Object o : this._addresses) { 430 RouterAddress addr = (RouterAddress)o; 431 if(addr.getTransportStyle().equals(transportStyle)) 432 ret.add(addr); 433 } 446 for (RouterAddress addr : _addresses) { 447 if(addr.getTransportStyle().equals(transportStyle)) 448 ret.add(addr); 434 449 } 435 450 return ret; … … 439 454 * Actually validate the signature 440 455 */ 441 private synchronized void doValidate() { 456 private void doValidate() { 457 _isValid = super.verifySignature(); 442 458 _validated = true; 443 _isValid = super.verifySignature();444 459 445 460 if (!_isValid) { … … 460 475 /** 461 476 * This does NOT validate the signature 462 */ 463 public synchronized void readBytes(InputStream in) throws DataFormatException, IOException { 477 * 478 * @throws IllegalStateException if RouterInfo was already read in 479 */ 480 public void readBytes(InputStream in) throws DataFormatException, IOException { 481 if (_signature != null) 482 throw new IllegalStateException(); 464 483 _identity = new RouterIdentity(); 465 484 _identity.readBytes(in); 466 Date when = DataHelper.readDate(in); 467 if (when == null) 468 _published = 0; 469 else 470 _published = when.getTime(); 485 // avoid thrashing objects 486 //Date when = DataHelper.readDate(in); 487 //if (when == null) 488 // _published = 0; 489 //else 490 // _published = when.getTime(); 491 _published = DataHelper.readLong(in, 8); 471 492 int numAddresses = (int) DataHelper.readLong(in, 1); 472 493 for (int i = 0; i < numAddresses; i++) { … … 486 507 } 487 508 } 488 _options = DataHelper.readProperties(in);509 DataHelper.readProperties(in, _options); 489 510 _signature = new Signature(); 490 511 _signature.readBytes(in); 491 512 492 resetCache();493 513 494 514 //_log.debug("Read routerInfo: " + toString()); … … 498 518 * This does NOT validate the signature 499 519 */ 500 public synchronizedvoid writeBytes(OutputStream out) throws DataFormatException, IOException {520 public void writeBytes(OutputStream out) throws DataFormatException, IOException { 501 521 if (_identity == null) throw new DataFormatException("Missing identity"); 502 522 if (_published < 0) throw new DataFormatException("Invalid published date: " + _published); … … 504 524 //if (!isValid()) 505 525 // throw new DataFormatException("Data is not valid"); 506 ByteArrayOutputStream baos = new ByteArrayOutputStream( 512);526 ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); 507 527 baos.write(getBytes()); 508 528 _signature.writeBytes(baos); … … 519 539 return DataHelper.eq(_identity, info.getIdentity()) 520 540 && DataHelper.eq(_signature, info.getSignature()) 521 && _published == info.getPublished() 522 && DataHelper.eq(_addresses, info.getAddresses()) 523 && DataHelper.eq(_options, info.getOptions()) 524 && DataHelper.eq(getPeers(), info.getPeers()); 541 && _published == info.getPublished(); 542 // Let's speed up the NetDB 543 //&& DataHelper.eq(_addresses, info.getAddresses()) 544 //&& DataHelper.eq(_options, info.getOptions()) 545 //&& DataHelper.eq(getPeers(), info.getPeers()); 525 546 } 526 547 … … 542 563 buf.append("\n\tSignature: ").append(_signature); 543 564 buf.append("\n\tPublished on: ").append(new Date(_published)); 544 Set addresses = _addresses; // getAddresses() 545 buf.append("\n\tAddresses: #: ").append(addresses.size()); 546 for (Iterator iter = addresses.iterator(); iter.hasNext();) { 547 RouterAddress addr = (RouterAddress) iter.next(); 565 buf.append("\n\tAddresses: #: ").append(_addresses.size()); 566 for (RouterAddress addr : _addresses) { 548 567 buf.append("\n\t\tAddress: ").append(addr); 549 568 } 550 Set peers = getPeers();569 Set<Hash> peers = getPeers(); 551 570 buf.append("\n\tPeers: #: ").append(peers.size()); 552 for (Iterator iter = peers.iterator(); iter.hasNext();) { 553 Hash hash = (Hash) iter.next(); 571 for (Hash hash : peers) { 554 572 buf.append("\n\t\tPeer hash: ").append(hash); 555 573 } 556 Properties options = _options; // getOptions(); 557 buf.append("\n\tOptions: #: ").append(options.size()); 558 for (Iterator iter = options.keySet().iterator(); iter.hasNext();) { 559 String key = (String) iter.next(); 560 String val = options.getProperty(key); 574 buf.append("\n\tOptions: #: ").append(_options.size()); 575 for (Map.Entry e : _options.entrySet()) { 576 String key = (String) e.getKey(); 577 String val = (String) e.getValue(); 561 578 buf.append("\n\t\t[").append(key).append("] = [").append(val).append("]"); 562 579 } -
router/java/src/net/i2p/router/Blocklist.java
rd8e297dd rf0eb5663 489 489 RouterAddress pa = (RouterAddress) pladdr.get(j); 490 490 if (pa == null) continue; 491 Properties pprops = pa.getOptions(); 492 if (pprops == null) continue; 493 String phost = pprops.getProperty("host"); 491 String phost = pa.getOption("host"); 494 492 if (phost == null) continue; 495 493 if (oldphost != null && oldphost.equals(phost)) continue; -
router/java/src/net/i2p/router/Router.java
rd8e297dd rf0eb5663 61 61 */ 62 62 public class Router implements RouterClock.ClockShiftListener { 63 private finalLog _log;63 private Log _log; 64 64 private final RouterContext _context; 65 65 private final Map<String, String> _config; … … 78 78 /** non-cancellable shutdown has begun */ 79 79 private volatile boolean _shutdownInProgress; 80 private finalI2PThread _gracefulShutdownDetector;81 private finalRouterWatchdog _watchdog;82 private finalThread _watchdogThread;80 private I2PThread _gracefulShutdownDetector; 81 private RouterWatchdog _watchdog; 82 private Thread _watchdogThread; 83 83 84 84 public final static String PROP_CONFIG_FILE = "router.configLocation"; … … 129 129 } 130 130 131 /** 132 * Instantiation only. Starts no threads. Does not install updates. 133 * RouterContext is created but not initialized. 134 * You must call runRouter() after any constructor to start things up. 135 */ 131 136 public Router() { this(null, null); } 137 132 138 public Router(Properties envProps) { this(null, envProps); } 139 133 140 public Router(String configFilename) { this(configFilename, null); } 141 134 142 public Router(String configFilename, Properties envProps) { 135 143 _gracefulExitCode = -1; … … 236 244 saveConfig(); 237 245 } 238 239 // This is here so that we can get the directory location from the context 240 // for the zip file and the base location to unzip to. 241 // If it does an update, it never returns. 242 // I guess it's better to have the other-router check above this, we don't want to 243 // overwrite an existing running router's jar files. Other than ours. 244 installUpdates(); 245 246 // ********* Start no threads before here ********* // 247 } 248 249 /** 250 * Initializes the RouterContext. 251 * Starts some threads. Does not install updates. 252 * All this was in the constructor. 253 * @since 0.8.12 254 */ 255 private void startupStuff() { 246 256 // ********* Start no threads before here ********* // 247 257 // … … 373 383 public RouterContext getContext() { return _context; } 374 384 385 /** 386 * Initializes the RouterContext. 387 * Starts the threads. Does not install updates. 388 */ 375 389 void runRouter() { 390 if (_isAlive) 391 throw new IllegalStateException(); 392 startupStuff(); 376 393 _isAlive = true; 377 394 _started = _context.clock().now(); … … 1267 1284 public static void main(String args[]) { 1268 1285 System.out.println("Starting I2P " + RouterVersion.FULL_VERSION); 1269 // installUpdates() moved to constructor so we can get file locations from the context1270 // installUpdates();1271 1286 //verifyWrapperConfig(); 1272 1287 Router r = new Router(); … … 1274 1289 r.rebuildNewIdentity(); 1275 1290 } else { 1291 // This is here so that we can get the directory location from the context 1292 // for the zip file and the base location to unzip to. 1293 // If it does an update, it never returns. 1294 // I guess it's better to have the other-router check above this, we don't want to 1295 // overwrite an existing running router's jar files. Other than ours. 1296 r.installUpdates(); 1297 // ********* Start no threads before here ********* // 1276 1298 r.runRouter(); 1277 1299 } … … 1282 1304 1283 1305 /** 1306 * Context must be available. 1284 1307 * Unzip update file found in the router dir OR base dir, to the base dir 1285 1308 * -
router/java/src/net/i2p/router/networkdb/PublishLocalRouterInfoJob.java
rd8e297dd rf0eb5663 42 42 if (_log.shouldLog(Log.DEBUG)) 43 43 _log.debug("Old routerInfo contains " + ri.getAddresses().size() 44 + " addresses and " + ri.getOptions ().size() + " options");44 + " addresses and " + ri.getOptionsMap().size() + " options"); 45 45 Properties stats = getContext().statPublisher().publishStatistics(); 46 46 stats.setProperty(RouterInfo.PROP_NETWORK_ID, ""+Router.NETWORK_ID); … … 61 61 if (_log.shouldLog(Log.INFO)) 62 62 _log.info("Newly updated routerInfo is published with " + stats.size() 63 + "/" + ri.getOptions ().size() + " options on "63 + "/" + ri.getOptionsMap().size() + " options on " 64 64 + new Date(ri.getPublished())); 65 65 try { -
router/java/src/net/i2p/router/networkdb/kademlia/FloodfillMonitorJob.java
rd8e297dd rf0eb5663 134 134 happy = false; 135 135 else { 136 Properties props = ra.getOptions(); 137 if (props == null || props.getProperty("ihost0") != null) 136 if (ra.getOption("ihost0") != null) 138 137 happy = false; 139 138 } -
router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java
rd8e297dd rf0eb5663 787 787 if (ra != null) { 788 788 // Introducers change often, introducee will ping introducer for 2 hours 789 Properties props = ra.getOptions(); 790 if (props != null && props.getProperty("ihost0") != null) 789 if (ra.getOption("ihost0") != null) 791 790 return "Peer " + key.toBase64() + " published > 75m ago with SSU Introducers"; 792 791 if (routerInfo.getTargetAddress("NTCP") == null) … … 823 822 throw new IllegalArgumentException("Invalid store attempt - " + err); 824 823 825 //if (_log.shouldLog(Log.DEBUG))826 //_log.debug("RouterInfo " + key.toBase64() + " is stored with "827 // + routerInfo.getOptions().size() + " options on "828 //+ new Date(routerInfo.getPublished()));824 if (_log.shouldLog(Log.DEBUG)) 825 _log.debug("RouterInfo " + key.toBase64() + " is stored with " 826 + routerInfo.getOptionsMap().size() + " options on " 827 + new Date(routerInfo.getPublished())); 829 828 830 829 _context.peerManager().setCapabilities(key, routerInfo.getCapabilities()); -
router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java
rd8e297dd rf0eb5663 702 702 } 703 703 // This is the quick way of doing UDPAddress.getIntroducerCount() > 0 704 Properties props = ra.getOptions(); 705 if (props != null && props.getProperty("ihost0") != null) 704 if (ra.getOption("ihost0") != null) 706 705 l.add(peer); 707 706 } … … 1264 1263 return rv; 1265 1264 for (RouterAddress pa : paddr) { 1266 Properties pprops = pa.getOptions(); 1267 if (pprops == null) continue; 1268 String phost = pprops.getProperty("host"); 1265 String phost = pa.getOption("host"); 1269 1266 if (phost == null) continue; 1270 1267 InetAddress pi; -
router/java/src/net/i2p/router/transport/TransportManager.java
rd8e297dd rf0eb5663 344 344 int port = t.getRequestedPort(); 345 345 if (t.getCurrentAddress() != null) { 346 Properties opts = t.getCurrentAddress().getOptions(); 347 if (opts != null) { 348 String s = opts.getProperty("port"); 346 String s = t.getCurrentAddress().getOption("port"); 349 347 if (s != null) { 350 348 try { … … 352 350 } catch (NumberFormatException nfe) {} 353 351 } 354 }355 352 } 356 353 // Use UDP port for NTCP too - see comment in NTCPTransport.getRequestedPort() for why this is here -
router/java/src/net/i2p/router/transport/ntcp/NTCPAddress.java
rd8e297dd rf0eb5663 58 58 return; 59 59 } 60 String host = addr.getOption s().getProperty(PROP_HOST);60 String host = addr.getOption(PROP_HOST); 61 61 if (host == null) { 62 62 _host = null; … … 64 64 } else { 65 65 _host = host.trim(); 66 String port = addr.getOption s().getProperty(PROP_PORT);66 String port = addr.getOption(PROP_PORT); 67 67 if ( (port != null) && (port.trim().length() > 0) && !("null".equals(port)) ) { 68 68 try { … … 157 157 public boolean equals(RouterAddress addr) { 158 158 if (addr == null) return false; 159 Properties opts = addr.getOptions(); 160 if (opts == null) return false; 161 return ( (_host.equals(opts.getProperty(PROP_HOST))) && 162 (Integer.toString(_port).equals(opts.getProperty(PROP_PORT))) ); 159 return ( (_host.equals(addr.getOption(PROP_HOST))) && 160 (Integer.toString(_port).equals(addr.getOption(PROP_PORT))) ); 163 161 } 164 162 } -
router/java/src/net/i2p/router/transport/udp/UDPAddress.java
rd8e297dd rf0eb5663 65 65 private void parse(RouterAddress addr) { 66 66 if (addr == null) return; 67 Properties opts = addr.getOptions(); 68 _host = opts.getProperty(PROP_HOST); 67 _host = addr.getOption(PROP_HOST); 69 68 if (_host != null) _host = _host.trim(); 70 69 try { 71 String port = opts.getProperty(PROP_PORT);70 String port = addr.getOption(PROP_PORT); 72 71 if (port != null) 73 72 _port = Integer.parseInt(port); … … 75 74 _port = -1; 76 75 } 77 String key = opts.getProperty(PROP_INTRO_KEY);76 String key = addr.getOption(PROP_INTRO_KEY); 78 77 if (key != null) 79 78 _introKey = Base64.decode(key.trim()); 80 79 81 80 for (int i = MAX_INTRODUCERS; i >= 0; i--) { 82 String host = opts.getProperty(PROP_INTRO_HOST_PREFIX + i);81 String host = addr.getOption(PROP_INTRO_HOST_PREFIX + i); 83 82 if (host == null) continue; 84 String port = opts.getProperty(PROP_INTRO_PORT_PREFIX + i);83 String port = addr.getOption(PROP_INTRO_PORT_PREFIX + i); 85 84 if (port == null) continue; 86 String k = opts.getProperty(PROP_INTRO_KEY_PREFIX + i);85 String k = addr.getOption(PROP_INTRO_KEY_PREFIX + i); 87 86 if (k == null) continue; 88 87 byte ikey[] = Base64.decode(k); 89 88 if ( (ikey == null) || (ikey.length != SessionKey.KEYSIZE_BYTES) ) 90 89 continue; 91 String t = opts.getProperty(PROP_INTRO_TAG_PREFIX + i);90 String t = addr.getOption(PROP_INTRO_TAG_PREFIX + i); 92 91 if (t == null) continue; 93 92 int p = -1;
Note: See TracChangeset
for help on using the changeset viewer.