i2ptunnel: Save access list as B64 to save space

Convert access list to B32 and sort in UI
Remove blank lines in get/set
This commit is contained in:
zzz
2021-10-05 09:34:57 -04:00
parent a7a59a2b1b
commit 0cb30a085c
2 changed files with 53 additions and 3 deletions

View File

@@ -2,7 +2,9 @@ package net.i2p.i2ptunnel.ui;
import java.io.File;
import java.io.IOException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -14,6 +16,7 @@ import net.i2p.I2PAppContext;
import net.i2p.I2PException;
import net.i2p.client.I2PClient;
import net.i2p.crypto.SigType;
import net.i2p.data.Base32;
import net.i2p.data.Base64;
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
@@ -855,8 +858,35 @@ public class GeneralHelper {
return 0;
}
/**
* @return entries sorted, converted to b32, separated by newlines, or ""
*/
public String getAccessList(int tunnel) {
return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
String val = getProperty(tunnel, "i2cp.accessList", "");
if (val.length() > 0) {
// Convert B64 to B32 for display
String[] vals = DataHelper.split(val, ",");
for (int i = 0; i < vals.length; i++) {
String v = vals[i];
if (v.length() == 44) {
byte[] b = Base64.decode(v);
if (b != null)
vals[i] = Base32.encode(b) + ".b32.i2p";
}
}
Arrays.sort(vals, Collator.getInstance());
StringBuilder buf = new StringBuilder(val.length() * 3 / 2);
for (int i = 0; i < vals.length; i++) {
String v = vals[i];
if (v.length() == 0)
continue;
buf.append(vals[i]);
if (i != vals.length - 1)
buf.append('\n');
}
val = buf.toString();
}
return val;
}
/**

View File

@@ -19,6 +19,7 @@ import net.i2p.crypto.EncType;
import net.i2p.crypto.KeyGenerator;
import net.i2p.crypto.KeyPair;
import net.i2p.crypto.SigType;
import net.i2p.data.Base32;
import net.i2p.data.Base64;
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
@@ -466,8 +467,27 @@ public class TunnelConfig {
}
public void setAccessList(String val) {
if (val != null)
_otherOptions.put("i2cp.accessList", val.trim().replace("\r\n", ",").replace("\n", ",").replace(" ", ","));
if (val != null) {
val = val.trim().replace("\r\n", ",").replace("\n", ",").replace(" ", ",");
// Convert to B64 to save space
String[] vals = DataHelper.split(val, ",");
StringBuilder buf = new StringBuilder(val.length());
for (int i = 0; i < vals.length; i++) {
String v = vals[i];
int len = v.length();
if (len == 0)
continue;
if (len == 60 && v.endsWith(".b32.i2p")) {
byte[] b = Base32.decode(v.substring(0, 52));
if (b != null)
v = Base64.encode(b);
}
buf.append(v);
if (i != vals.length - 1)
buf.append(',');
}
_otherOptions.put("i2cp.accessList", buf.toString());
}
}
public void setJumpList(String val) {