Data: Prep Lease and LeaseSet for subclassing

This commit is contained in:
zzz
2018-10-13 10:41:16 +00:00
parent ee57bd7363
commit f0b3815767
2 changed files with 18 additions and 22 deletions

View File

@ -23,11 +23,9 @@ import net.i2p.util.Clock;
* @author jrandom * @author jrandom
*/ */
public class Lease extends DataStructureImpl { public class Lease extends DataStructureImpl {
private Hash _gateway; protected Hash _gateway;
private TunnelId _tunnelId; protected TunnelId _tunnelId;
private Date _end; protected Date _end;
//private int _numSuccess;
//private int _numFailure;
public Lease() { public Lease() {
} }

View File

@ -60,21 +60,21 @@ import net.i2p.util.RandomSource;
* @author jrandom * @author jrandom
*/ */
public class LeaseSet extends DatabaseEntry { public class LeaseSet extends DatabaseEntry {
private Destination _destination; protected Destination _destination;
private PublicKey _encryptionKey; protected PublicKey _encryptionKey;
private SigningPublicKey _signingKey; protected SigningPublicKey _signingKey;
// Keep leases in the order received, or else signature verification will fail! // Keep leases in the order received, or else signature verification will fail!
private final List<Lease> _leases; protected final List<Lease> _leases;
private boolean _receivedAsPublished; protected boolean _receivedAsPublished;
private boolean _receivedAsReply; private boolean _receivedAsReply;
// Store these since isCurrent() and getEarliestLeaseDate() are called frequently // Store these since isCurrent() and getEarliestLeaseDate() are called frequently
private long _firstExpiration; private long _firstExpiration;
private long _lastExpiration; protected long _lastExpiration;
private List<Lease> _decryptedLeases; private List<Lease> _decryptedLeases;
private boolean _decrypted; private boolean _decrypted;
private boolean _checked; protected boolean _checked;
// cached byte version // cached byte version
private volatile byte _byteified[]; protected volatile byte _byteified[];
/** /**
* Unlimited before 0.6.3; * Unlimited before 0.6.3;
@ -288,23 +288,21 @@ public class LeaseSet extends DatabaseEntry {
return _lastExpiration > now - fudge; return _lastExpiration > now - fudge;
} }
/** without sig! */
protected byte[] getBytes() { protected byte[] getBytes() {
if (_byteified != null) return _byteified; if (_byteified != null) return _byteified;
if ((_destination == null) || (_encryptionKey == null) || (_signingKey == null)) if ((_destination == null) || (_encryptionKey == null) || (_signingKey == null))
return null; return null;
int len = _destination.size() int len = size();
+ PublicKey.KEYSIZE_BYTES // encryptionKey
+ _signingKey.length() // signingKey
+ 1
+ _leases.size() * 44; // leases
ByteArrayOutputStream out = new ByteArrayOutputStream(len); ByteArrayOutputStream out = new ByteArrayOutputStream(len);
try { try {
_destination.writeBytes(out); _destination.writeBytes(out);
_encryptionKey.writeBytes(out); _encryptionKey.writeBytes(out);
_signingKey.writeBytes(out); _signingKey.writeBytes(out);
out.write((byte) _leases.size()); out.write((byte) _leases.size());
for (Lease lease : _leases) for (Lease lease : _leases) {
lease.writeBytes(out); lease.writeBytes(out);
}
} catch (IOException ioe) { } catch (IOException ioe) {
return null; return null;
} catch (DataFormatException dfe) { } catch (DataFormatException dfe) {
@ -361,8 +359,9 @@ public class LeaseSet extends DatabaseEntry {
_encryptionKey.writeBytes(out); _encryptionKey.writeBytes(out);
_signingKey.writeBytes(out); _signingKey.writeBytes(out);
out.write((byte) _leases.size()); out.write((byte) _leases.size());
for (Lease lease : _leases) for (Lease lease : _leases) {
lease.writeBytes(out); lease.writeBytes(out);
}
_signature.writeBytes(out); _signature.writeBytes(out);
} }
@ -374,7 +373,7 @@ public class LeaseSet extends DatabaseEntry {
+ PublicKey.KEYSIZE_BYTES // encryptionKey + PublicKey.KEYSIZE_BYTES // encryptionKey
+ _signingKey.length() // signingKey + _signingKey.length() // signingKey
+ 1 // number of leases + 1 // number of leases
+ _leases.size() * (Hash.HASH_LENGTH + 4 + 8); + _leases.size() * 44;
} }
@Override @Override
@ -388,7 +387,6 @@ public class LeaseSet extends DatabaseEntry {
&& DataHelper.eq(getEncryptionKey(), ls.getEncryptionKey()) && DataHelper.eq(getEncryptionKey(), ls.getEncryptionKey())
&& DataHelper.eq(_signingKey, ls.getSigningKey()) && DataHelper.eq(_signingKey, ls.getSigningKey())
&& DataHelper.eq(_destination, ls.getDestination()); && DataHelper.eq(_destination, ls.getDestination());
} }
/** the destination has enough randomness in it to use it by itself for speed */ /** the destination has enough randomness in it to use it by itself for speed */