forked from I2P_Developers/i2p.i2p
Tunnels: Change class of TunnelPoolSettings random key
from Hash to SessionKey. It's not a Hash.
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.Properties;
|
||||
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.SessionKey;
|
||||
import net.i2p.util.ConcurrentHashSet;
|
||||
import net.i2p.util.NativeBigInteger;
|
||||
import net.i2p.util.RandomSource;
|
||||
@@ -31,7 +32,7 @@ public class TunnelPoolSettings {
|
||||
private boolean _allowZeroHop;
|
||||
private int _IPRestriction;
|
||||
private final Properties _unknownOptions;
|
||||
private Hash _randomKey;
|
||||
private SessionKey _randomKey;
|
||||
private int _priority;
|
||||
private final Set<Hash> _aliases;
|
||||
private Hash _aliasOf;
|
||||
@@ -255,7 +256,7 @@ public class TunnelPoolSettings {
|
||||
*
|
||||
* @return non-null
|
||||
*/
|
||||
public Hash getRandomKey() { return _randomKey; }
|
||||
public SessionKey getRandomKey() { return _randomKey; }
|
||||
|
||||
/** what user supplied name was given to the client connected (can be null) */
|
||||
public String getDestinationNickname() { return _destinationNickname; }
|
||||
@@ -324,8 +325,8 @@ public class TunnelPoolSettings {
|
||||
_priority = Math.min(max, Math.max(MIN_PRIORITY, getInt(value, def)));
|
||||
} else if (name.equalsIgnoreCase(prefix + PROP_RANDOM_KEY)) {
|
||||
byte[] rk = Base64.decode(value);
|
||||
if (rk != null && rk.length == Hash.HASH_LENGTH)
|
||||
_randomKey = new Hash(rk);
|
||||
if (rk != null && rk.length == SessionKey.KEYSIZE_BYTES)
|
||||
_randomKey = new SessionKey(rk);
|
||||
} else
|
||||
_unknownOptions.setProperty(name.substring(prefix.length()), value);
|
||||
}
|
||||
@@ -375,10 +376,10 @@ public class TunnelPoolSettings {
|
||||
}
|
||||
|
||||
// used for strict peer ordering
|
||||
private static Hash generateRandomKey() {
|
||||
byte hash[] = new byte[Hash.HASH_LENGTH];
|
||||
RandomSource.getInstance().nextBytes(hash);
|
||||
return new Hash(hash);
|
||||
private static SessionKey generateRandomKey() {
|
||||
byte data[] = new byte[SessionKey.KEYSIZE_BYTES];
|
||||
RandomSource.getInstance().nextBytes(data);
|
||||
return new SessionKey(data);
|
||||
}
|
||||
|
||||
private static final boolean getBoolean(String str, boolean defaultValue) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import net.i2p.crypto.SipHashInline;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.SessionKey;
|
||||
import net.i2p.data.router.RouterAddress;
|
||||
import net.i2p.data.router.RouterInfo;
|
||||
import net.i2p.router.ClientManagerFacade;
|
||||
@@ -482,7 +483,7 @@ public class ProfileOrganizer {
|
||||
* 7: return only from group 3
|
||||
*</pre>
|
||||
*/
|
||||
public void selectFastPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, Hash randomKey, Slice subTierMode) {
|
||||
public void selectFastPeers(int howMany, Set<Hash> exclude, Set<Hash> matches, SessionKey randomKey, Slice subTierMode) {
|
||||
getReadLock();
|
||||
try {
|
||||
if (subTierMode != Slice.SLICE_ALL) {
|
||||
@@ -1351,7 +1352,7 @@ public class ProfileOrganizer {
|
||||
*</pre>
|
||||
*/
|
||||
private void locked_selectPeers(Map<Hash, PeerProfile> peers, int howMany, Set<Hash> toExclude,
|
||||
Set<Hash> matches, Hash randomKey, Slice subTierMode) {
|
||||
Set<Hash> matches, SessionKey randomKey, Slice subTierMode) {
|
||||
List<Hash> all = new ArrayList<Hash>(peers.keySet());
|
||||
byte[] rk = randomKey.getData();
|
||||
// we use the first half of the random key here,
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.Set;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.SessionKey;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.TunnelInfo;
|
||||
import net.i2p.router.TunnelManagerFacade;
|
||||
@@ -84,7 +85,7 @@ class ClientPeerSelector extends TunnelPeerSelector {
|
||||
// For a 2-hop tunnel, the first hop comes from subtiers 0-1 and the last from subtiers 2-3.
|
||||
// For a longer tunnels, the first hop comes from subtier 0, the middle from subtiers 2-3, and the last from subtier 1.
|
||||
rv = new ArrayList<Hash>(length + 1);
|
||||
Hash randomKey = settings.getRandomKey();
|
||||
SessionKey randomKey = settings.getRandomKey();
|
||||
// OBEP or IB last hop
|
||||
// group 0 or 1 if two hops, otherwise group 0
|
||||
Set<Hash> lastHopExclude;
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.i2p.crypto.SipHashInline;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.SessionKey;
|
||||
import net.i2p.data.router.RouterIdentity;
|
||||
import net.i2p.data.router.RouterInfo;
|
||||
import net.i2p.router.LeaseSetKeys;
|
||||
@@ -640,9 +641,9 @@ public abstract class TunnelPeerSelector extends ConnectChecker {
|
||||
****/
|
||||
|
||||
/** see HashComparator */
|
||||
protected void orderPeers(List<Hash> rv, Hash hash) {
|
||||
protected void orderPeers(List<Hash> rv, SessionKey key) {
|
||||
if (rv.size() > 1)
|
||||
Collections.sort(rv, new HashComparator(hash));
|
||||
Collections.sort(rv, new HashComparator(key));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -670,8 +671,8 @@ public abstract class TunnelPeerSelector extends ConnectChecker {
|
||||
*
|
||||
* @param h container for sort keys, not used as a Hash
|
||||
*/
|
||||
private HashComparator(Hash h) {
|
||||
byte[] b = h.getData();
|
||||
private HashComparator(SessionKey k) {
|
||||
byte[] b = k.getData();
|
||||
// we use the first half of the random key in ProfileOrganizer.getSubTier(),
|
||||
// so use the last half here
|
||||
k0 = DataHelper.fromLong8(b, 16);
|
||||
|
||||
Reference in New Issue
Block a user