From 0cb30a085cdd094df01d35c28fbb5ca3141c613d Mon Sep 17 00:00:00 2001 From: zzz <zzz@i2pmail.org> Date: Tue, 5 Oct 2021 09:34:57 -0400 Subject: [PATCH] i2ptunnel: Save access list as B64 to save space Convert access list to B32 and sort in UI Remove blank lines in get/set --- .../net/i2p/i2ptunnel/ui/GeneralHelper.java | 32 ++++++++++++++++++- .../net/i2p/i2ptunnel/ui/TunnelConfig.java | 24 ++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) 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 d7161110f8..29f8e05428 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 c676f83342..f7eb3cdcb4 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) { -- GitLab