diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java index d7161110f8376bfe57b9f305f45fec0da9964f3f..29f8e054285c6e156a417c5b59ed9961c847318d 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java @@ -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; } /** diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java index c676f83342a5425ee74247c2b63089936be9e6c7..f7eb3cdcb49b3cf05ed785aa3b0df9a23037bdd2 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java @@ -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) {