From 2681c4b42ffab076f24c24d891f69be8d49ec546 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Tue, 7 Jul 2015 13:35:55 +0000 Subject: [PATCH] Streaming: New config to add to DSA-only list --- .../streaming/impl/I2PSocketManagerFull.java | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/streaming/java/src/net/i2p/client/streaming/impl/I2PSocketManagerFull.java b/apps/streaming/java/src/net/i2p/client/streaming/impl/I2PSocketManagerFull.java index 452f715db4..280c1549d9 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/impl/I2PSocketManagerFull.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/impl/I2PSocketManagerFull.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.StringTokenizer; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -106,6 +107,11 @@ public class I2PSocketManagerFull implements I2PSocketManager { } } + /** cache of the property to detect changes */ + private static volatile String _userDsaList = ""; + private static final Set<Hash> _userDsaOnly = new ConcurrentHashSet<Hash>(4); + private static final String PROP_DSALIST = "i2p.streaming.dsalist"; + /** * How long to wait for the client app to accept() before sending back CLOSE? * This includes the time waiting in the queue. Currently set to 5 seconds. @@ -478,8 +484,9 @@ public class I2PSocketManagerFull implements I2PSocketManager { // pick the subsession here I2PSession session = _session; if (!_subsessions.isEmpty()) { + updateUserDsaList(); Hash h = peer.calculateHash(); - if (_dsaOnly.contains(h)) { + if (_dsaOnly.contains(h) || (!_userDsaOnly.isEmpty() && _userDsaOnly.contains(h))) { // FIXME just taking the first one for now for (I2PSession sess : _subsessions) { if (sess.getMyDestination().getSigType() == SigType.DSA_SHA1) { @@ -503,6 +510,40 @@ public class I2PSocketManagerFull implements I2PSocketManager { return socket; } + /** + * Update the global user DSA-only list. + * This does not affect the hardcoded DSA_ONLY_HASHES list above, + * the user can only add, not remove. + * + * @since 0.9.21 + */ + private void updateUserDsaList() { + String hashes = _context.getProperty(PROP_DSALIST, ""); + if (!_userDsaList.equals(hashes)) { + // rebuild _userDsaOnly when property changes + synchronized(_userDsaOnly) { + if (hashes.length() > 0) { + Set<Hash> newSet = new HashSet<Hash>(); + StringTokenizer tok = new StringTokenizer(hashes, ",; "); + while (tok.hasMoreTokens()) { + String hashstr = tok.nextToken(); + Hash hh = ConvertToHash.getHash(hashstr); + if (hh != null) + newSet.add(hh); + else + _log.error("Bad " + PROP_DSALIST + " entry: " + hashstr); + } + _userDsaOnly.addAll(newSet); + _userDsaOnly.retainAll(newSet); + _userDsaList = hashes; + } else { + _userDsaOnly.clear(); + _userDsaList = ""; + } + } + } + } + /** * Create a new connected socket. Blocks until the socket is created, * unless the connectDelay option (i2p.streaming.connectDelay) is -- GitLab