Changeset f61183d2


Ignore:
Timestamp:
Feb 29, 2012 6:09:16 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
538427c2
Parents:
48551f06
Message:
  • DataStructures?:
    • Remove static logs
    • Sort addresses in RouterInfo? at initialization only; change from Set to List to save space
    • Remove unused counters in Lease to save space
    • Increase max leases to 16
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/DataHelper.java

    r48551f06 rf61183d2  
    13001300        //}
    13011301        ArrayList<DataStructure> rv = new ArrayList(dataStructures);
    1302         Collections.sort(rv, new DataStructureComparator());
     1302        sortStructureList(rv);
    13031303        return rv;
     1304    }
     1305
     1306    /**
     1307     *  See above.
     1308     *  DEPRECATED - Only used by RouterInfo.
     1309     *
     1310     *  @since 0.9
     1311     */
     1312    static void sortStructureList(List<? extends DataStructure> dataStructures) {
     1313        Collections.sort(dataStructures, new DataStructureComparator());
    13041314    }
    13051315
  • core/java/src/net/i2p/data/LeaseSet.java

    r48551f06 rf61183d2  
    5757 */
    5858public class LeaseSet extends DatabaseEntry {
    59     private final static Log _log = new Log(LeaseSet.class);
    6059    private Destination _destination;
    6160    private PublicKey _encryptionKey;
     
    7271    private boolean _checked;
    7372
    74     /** This seems like plenty  */
    75     public final static int MAX_LEASES = 6;
     73    /**
     74     *  Unlimited before 0.6.3;
     75     *  6 as of 0.6.3;
     76     *  Increased in version 0.9.
     77     *
     78     *  Leasesets larger than 6 should be used with caution,
     79     *  as each lease adds 44 bytes, and routers older than version 0.9
     80     *  will not be able to connect as they will throw an exception in
     81     *  readBytes(). Also, the churn will be quite rapid, leading to
     82     *  frequent netdb stores and transmission on existing connections.
     83     *
     84     *  However we increase it now in case some hugely popular eepsite arrives.
     85     *  Strategies elsewhere in the router to efficiently handle
     86     *  large leasesets are TBD.
     87     */
     88    public static final int MAX_LEASES = 16;
     89    private static final int OLD_MAX_LEASES = 6;
    7690
    7791    public LeaseSet() {
    78         _leases = new ArrayList(MAX_LEASES);
     92        _leases = new ArrayList(OLD_MAX_LEASES);
    7993        _firstExpiration = Long.MAX_VALUE;
    8094    }
     
    355369     */
    356370    public void encrypt(SessionKey key) {
    357         if (_log.shouldLog(Log.WARN))
    358             _log.warn("encrypting lease: " + _destination.calculateHash());
     371        //if (_log.shouldLog(Log.WARN))
     372        //    _log.warn("encrypting lease: " + _destination.calculateHash());
    359373        try {
    360374            encryp(key);
    361375        } catch (DataFormatException dfe) {
    362             _log.error("Error encrypting lease: " + _destination.calculateHash());
     376            Log log = I2PAppContext.getGlobalContext().logManager().getLog(LeaseSet.class);
     377            log.error("Error encrypting lease: " + _destination.calculateHash());
    363378        } catch (IOException ioe) {
    364             _log.error("Error encrypting lease: " + _destination.calculateHash());
     379            Log log = I2PAppContext.getGlobalContext().logManager().getLog(LeaseSet.class);
     380            log.error("Error encrypting lease: " + _destination.calculateHash());
    365381        }
    366382    }
     
    421437     */
    422438    private void decrypt(SessionKey key) throws DataFormatException, IOException {
    423         if (_log.shouldLog(Log.WARN))
    424             _log.warn("decrypting lease: " + _destination.calculateHash());
     439        //if (_log.shouldLog(Log.WARN))
     440        //    _log.warn("decrypting lease: " + _destination.calculateHash());
    425441        int size = _leases.size();
    426442        if (size < 2)
     
    469485                _decrypted = true;
    470486            } catch (DataFormatException dfe) {
    471                 _log.error("Error decrypting lease: " + _destination.calculateHash() + dfe);
     487                Log log = I2PAppContext.getGlobalContext().logManager().getLog(LeaseSet.class);
     488                log.error("Error decrypting lease: " + _destination.calculateHash() + dfe);
    472489            } catch (IOException ioe) {
    473                 _log.error("Error decrypting lease: " + _destination.calculateHash() + ioe);
     490                Log log = I2PAppContext.getGlobalContext().logManager().getLog(LeaseSet.class);
     491                log.error("Error decrypting lease: " + _destination.calculateHash() + ioe);
    474492            }
    475493        }
  • core/java/src/net/i2p/data/RouterInfo.java

    r48551f06 rf61183d2  
    1414import java.io.InputStream;
    1515import java.io.OutputStream;
     16import java.util.ArrayList;
    1617import java.util.Collection;
    1718import java.util.Collections;
     
    2526import java.util.Vector;
    2627
     28import net.i2p.I2PAppContext;
    2729import net.i2p.crypto.SHA256Generator;
    2830import net.i2p.util.Clock;
     
    4446 */
    4547public class RouterInfo extends DatabaseEntry {
    46     private final static Log _log = new Log(RouterInfo.class);
    4748    private RouterIdentity _identity;
    4849    private volatile long _published;
    49     private final Set<RouterAddress> _addresses;
     50    /**
     51     *  Addresses must be sorted by SHA256.
     52     *  When an RI is created, they are sorted in setAddresses().
     53     *  Save addresses in the order received so we need not resort.
     54     */
     55    private final List<RouterAddress> _addresses;
    5056    /** may be null to save memory, no longer final */
    5157    private Set<Hash> _peers;
     
    7278   
    7379    public RouterInfo() {
    74         _addresses = new HashSet(2);
     80        _addresses = new ArrayList(2);
    7581        _options = new OrderedProperties();
    7682    }
     
    157163     * @return unmodifiable view, non-null
    158164     */
    159     public Set<RouterAddress> getAddresses() {
    160             return Collections.unmodifiableSet(_addresses);
     165    public Collection<RouterAddress> getAddresses() {
     166            return Collections.unmodifiableCollection(_addresses);
    161167    }
    162168
     
    165171     * can be contacted.
    166172     *
    167      * @throws IllegalStateException if RouterInfo is already signed
    168      */
    169     public void setAddresses(Set<RouterAddress> addresses) {
    170         if (_signature != null)
    171             throw new IllegalStateException();
    172         _addresses.clear();
    173         if (addresses != null) _addresses.addAll(addresses);
     173     * Warning - Sorts the addresses here. Do not modify any address
     174     *           after calling this, as the sort order is based on the
     175     *           hash of the entire address structure.
     176     *
     177     * @param addresses may be null
     178     * @throws IllegalStateException if RouterInfo is already signed or addresses previously set
     179     */
     180    public void setAddresses(Collection<RouterAddress> addresses) {
     181        if (_signature != null || !_addresses.isEmpty())
     182            throw new IllegalStateException();
     183        if (addresses != null) {
     184            _addresses.addAll(addresses);
     185            if (_addresses.size() > 1) {
     186                // WARNING this sort algorithm cannot be changed, as it must be consistent
     187                // network-wide. The signature is not checked at readin time, but only
     188                // later, and the addresses are stored in a Set, not a List.
     189                DataHelper.sortStructureList(_addresses);
     190            }
     191        }
    174192    }
    175193
     
    271289            } else {
    272290                DataHelper.writeLong(out, 1, sz);
    273                 Collection<RouterAddress> addresses = _addresses;
    274                 if (sz > 1) {
    275                     // WARNING this sort algorithm cannot be changed, as it must be consistent
    276                     // network-wide. The signature is not checked at readin time, but only
    277                     // later, and the addresses are stored in a Set, not a List.
    278                     addresses = (Collection<RouterAddress>) DataHelper.sortStructures(addresses);
    279                 }
    280                 for (RouterAddress addr : addresses) {
     291                for (RouterAddress addr : _addresses) {
    281292                    addr.writeBytes(out);
    282293                }
     
    459470
    460471        if (!_isValid) {
     472            Log log = I2PAppContext.getGlobalContext().logManager().getLog(RouterInfo.class);
    461473            byte data[] = null;
    462474            try {
    463475                data = getBytes();
    464476            } catch (DataFormatException dfe) {
    465                 _log.error("Error validating", dfe);
     477                log.error("Error validating", dfe);
    466478                return;
    467479            }
    468             if (_log.shouldLog(Log.ERROR))
    469                 _log.error("Invalid [" + SHA256Generator.getInstance().calculateHash(data).toBase64()
    470                            + (_log.shouldLog(Log.WARN) ? ("]\n" + toString()) : ""),
     480            log.error("Invalid [" + SHA256Generator.getInstance().calculateHash(data).toBase64()
     481                           + (log.shouldLog(Log.WARN) ? ("]\n" + toString()) : ""),
    471482                           new Exception("Signature failed"));
    472483        }
  • router/java/src/net/i2p/router/Blocklist.java

    r48551f06 rf61183d2  
    480480        RouterInfo pinfo = _context.netDb().lookupRouterInfoLocally(peer);
    481481        if (pinfo == null) return rv;
    482         Set<RouterAddress> paddr = pinfo.getAddresses();
    483         if (paddr == null || paddr.isEmpty())
    484             return rv;
    485482        String oldphost = null;
    486         List<RouterAddress> pladdr = new ArrayList(paddr);
    487483        // for each peer address
    488         for (int j = 0; j < paddr.size(); j++) {
    489             RouterAddress pa = (RouterAddress) pladdr.get(j);
    490             if (pa == null) continue;
     484        for (RouterAddress pa : pinfo.getAddresses()) {
    491485            String phost = pa.getOption("host");
    492486            if (phost == null) continue;
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java

    r48551f06 rf61183d2  
    217217                    _log.warn("Verify failed (older) for " + _key);
    218218                if (_log.shouldLog(Log.INFO))
    219                     _log.info("Rcvd older lease: " + dsm.getEntry());
     219                    _log.info("Rcvd older data: " + dsm.getEntry());
    220220            } else if (_message instanceof DatabaseSearchReplyMessage) {
    221221                // assume 0 old, all new, 0 invalid, 0 dup
  • router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseStoreMessageJob.java

    r48551f06 rf61183d2  
    99 */
    1010
     11import java.util.Collection;
    1112import java.util.Date;
    12 import java.util.Set;
    1313
    1414import net.i2p.data.DatabaseEntry;
    1515import net.i2p.data.Hash;
    1616import net.i2p.data.LeaseSet;
     17import net.i2p.data.RouterAddress;
    1718import net.i2p.data.RouterIdentity;
    1819import net.i2p.data.RouterInfo;
     
    146147                                _log.warn("Blocklisting new peer " + key + ' ' + ri);
    147148                    } else {
    148                         Set oldAddr = prevNetDb.getAddresses();
    149                         Set newAddr = ri.getAddresses();
    150                         if (newAddr != null && (!newAddr.equals(oldAddr)) &&
     149                        Collection<RouterAddress> oldAddr = prevNetDb.getAddresses();
     150                        Collection<RouterAddress> newAddr = ri.getAddresses();
     151                        if ((!newAddr.equals(oldAddr)) &&
    151152                            (!getContext().shitlist().isShitlistedForever(key)) &&
    152153                            getContext().blocklist().isBlocklisted(key) &&
  • router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java

    r48551f06 rf61183d2  
    88import java.text.DecimalFormatSymbols;
    99import java.util.ArrayList;
     10import java.util.Collection;
    1011import java.util.Collections;
    1112import java.util.HashMap;
     
    12591260        if (pinfo == null)
    12601261            return rv;
    1261         Set<RouterAddress> paddr = pinfo.getAddresses();
     1262        Collection<RouterAddress> paddr = pinfo.getAddresses();
    12621263        if (paddr == null)
    12631264            return rv;
Note: See TracChangeset for help on using the changeset viewer.