I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 0f919a0f authored by zzz's avatar zzz
Browse files

Merge branch 'susidns-sort-2' into 'master'

SusiDNS: Reduce memory usage in AddressBean

See merge request !232
parents 7d6e9d20 43988d48
No related branches found
No related tags found
1 merge request!232SusiDNS: Reduce memory usage in AddressBean
Pipeline #2215 failed
...@@ -34,10 +34,12 @@ import net.i2p.data.Base32; ...@@ -34,10 +34,12 @@ import net.i2p.data.Base32;
import net.i2p.data.Base64; import net.i2p.data.Base64;
import net.i2p.data.Certificate; import net.i2p.data.Certificate;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
public class AddressBean public class AddressBean
{ {
private final String name, destination; private final String name;
private final byte[] dest;
private Properties props; private Properties props;
/** available as of Java 6 */ /** available as of Java 6 */
static final boolean haveIDN; static final boolean haveIDN;
...@@ -54,14 +56,32 @@ public class AddressBean ...@@ -54,14 +56,32 @@ public class AddressBean
} }
public AddressBean(String name, String destination) public AddressBean(String name, String destination)
{
this(name, Base64.decode(destination));
}
/**
* @since 0.9.66
*/
public AddressBean(String name, Destination destination)
{
this(name, destination.toByteArray());
}
/**
* @since 0.9.66
*/
public AddressBean(String name, byte[] destination)
{ {
this.name = name; this.name = name;
this.destination = destination; dest = destination;
if (dest == null || dest.length < 387)
throw new IllegalArgumentException();
} }
public String getDestination() public String getDestination()
{ {
return destination; return Base64.encode(dest);
} }
/** /**
...@@ -164,9 +184,6 @@ public class AddressBean ...@@ -164,9 +184,6 @@ public class AddressBean
/** @since 0.8.7 */ /** @since 0.8.7 */
public String getB32() public String getB32()
{ {
byte[] dest = Base64.decode(destination);
if (dest == null)
return "";
byte[] hash = I2PAppContext.getGlobalContext().sha().calculateHash(dest).getData(); byte[] hash = I2PAppContext.getGlobalContext().sha().calculateHash(dest).getData();
return Base32.encode(hash) + ".b32.i2p"; return Base32.encode(hash) + ".b32.i2p";
} }
...@@ -174,9 +191,6 @@ public class AddressBean ...@@ -174,9 +191,6 @@ public class AddressBean
/** @since 0.9 */ /** @since 0.9 */
public String getB64() public String getB64()
{ {
byte[] dest = Base64.decode(destination);
if (dest == null)
return "";
return I2PAppContext.getGlobalContext().sha().calculateHash(dest).toBase64(); return I2PAppContext.getGlobalContext().sha().calculateHash(dest).toBase64();
} }
...@@ -218,16 +232,10 @@ public class AddressBean ...@@ -218,16 +232,10 @@ public class AddressBean
* @since 0.8.7 * @since 0.8.7
*/ */
public String getCert() { public String getCert() {
// (4 / 3) * (pubkey length + signing key length) int type = dest[384] & 0xff;
String cert = destination.substring(512);
if (cert.equals("AAAA"))
return _t("None");
byte[] enc = Base64.decode(cert);
if (enc == null)
// shouldn't happen
return "invalid";
int type = enc[0] & 0xff;
switch (type) { switch (type) {
case Certificate.CERTIFICATE_TYPE_NULL:
return _t("None");
case Certificate.CERTIFICATE_TYPE_HASHCASH: case Certificate.CERTIFICATE_TYPE_HASHCASH:
return _t("Hashcash"); return _t("Hashcash");
case Certificate.CERTIFICATE_TYPE_HIDDEN: case Certificate.CERTIFICATE_TYPE_HIDDEN:
...@@ -246,18 +254,10 @@ public class AddressBean ...@@ -246,18 +254,10 @@ public class AddressBean
* @since 0.9.12 * @since 0.9.12
*/ */
public String getSigType() { public String getSigType() {
// (4 / 3) * (pubkey length + signing key length) int type = dest[384] & 0xff;
String cert = destination.substring(512);
if (cert.equals("AAAA"))
return _t("DSA 1024 bit");
byte[] enc = Base64.decode(cert);
if (enc == null)
// shouldn't happen
return "invalid";
int type = enc[0] & 0xff;
if (type != Certificate.CERTIFICATE_TYPE_KEY) if (type != Certificate.CERTIFICATE_TYPE_KEY)
return _t("DSA 1024 bit"); return _t("DSA 1024 bit");
int st = ((enc[3] & 0xff) << 8) | (enc[4] & 0xff); int st = ((dest[387] & 0xff) << 8) | (dest[388] & 0xff);
if (st == 0) if (st == 0)
return _t("DSA 1024 bit"); return _t("DSA 1024 bit");
SigType stype = SigType.getByCode(st); SigType stype = SigType.getByCode(st);
......
...@@ -204,20 +204,14 @@ public class NamingServiceBean extends AddressbookBean ...@@ -204,20 +204,14 @@ public class NamingServiceBean extends AddressbookBean
continue; continue;
} }
} }
String destination = entry.getValue().toBase64(); AddressBean bean = new AddressBean(name, entry.getValue());
if (destination != null) { if (sortByDate) {
AddressBean bean = new AddressBean(name, destination); Properties p = new Properties();
if (sortByDate) { Destination d = service.lookup(name, searchProps, p);
Properties p = new Properties(); if (d != null && !p.isEmpty())
Destination d = service.lookup(name, searchProps, p); bean.setProperties(p);
if (d != null && !p.isEmpty())
bean.setProperties(p);
}
list.addLast(bean);
} else {
// delete it too?
System.err.println("Bad entry " + name + " in database " + service.getName());
} }
list.addLast(bean);
} }
AddressBean array[] = list.toArray(new AddressBean[list.size()]); AddressBean array[] = list.toArray(new AddressBean[list.size()]);
if (sortByDate) { if (sortByDate) {
...@@ -501,7 +495,7 @@ public class NamingServiceBean extends AddressbookBean ...@@ -501,7 +495,7 @@ public class NamingServiceBean extends AddressbookBean
Destination dest = getNamingService().lookup(this.detail, nsOptions, outProps); Destination dest = getNamingService().lookup(this.detail, nsOptions, outProps);
if (dest == null) if (dest == null)
return null; return null;
AddressBean rv = new AddressBean(this.detail, dest.toBase64()); AddressBean rv = new AddressBean(this.detail, dest);
rv.setProperties(outProps); rv.setProperties(outProps);
return rv; return rv;
} }
...@@ -527,7 +521,7 @@ public class NamingServiceBean extends AddressbookBean ...@@ -527,7 +521,7 @@ public class NamingServiceBean extends AddressbookBean
return null; return null;
List<AddressBean> rv = new ArrayList<AddressBean>(dests.size()); List<AddressBean> rv = new ArrayList<AddressBean>(dests.size());
for (int i = 0; i < dests.size(); i++) { for (int i = 0; i < dests.size(); i++) {
AddressBean ab = new AddressBean(this.detail, dests.get(i).toBase64()); AddressBean ab = new AddressBean(this.detail, dests.get(i));
ab.setProperties(propsList.get(i)); ab.setProperties(propsList.get(i));
rv.add(ab); rv.add(ab);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment