From 90aacc6746b57944cc6ec37829fd3ef1b9dadf3c Mon Sep 17 00:00:00 2001 From: idk Date: Sun, 4 Jun 2023 18:23:17 +0000 Subject: [PATCH] use RandomSource instead of Random --- .../src/net/i2p/router/message/GarlicMessageHandler.java | 9 ++++----- .../kademlia/FloodfillDatabaseLookupMessageHandler.java | 5 ++--- .../kademlia/FloodfillDatabaseStoreMessageHandler.java | 5 ++--- .../i2p/router/networkdb/kademlia/StartExplorersJob.java | 4 ++-- .../net/i2p/router/tunnel/InboundMessageDistributor.java | 5 ++--- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/router/java/src/net/i2p/router/message/GarlicMessageHandler.java b/router/java/src/net/i2p/router/message/GarlicMessageHandler.java index 478531156b..b608e399c9 100644 --- a/router/java/src/net/i2p/router/message/GarlicMessageHandler.java +++ b/router/java/src/net/i2p/router/message/GarlicMessageHandler.java @@ -8,8 +8,6 @@ * */ -import java.util.Random; - import net.i2p.data.Hash; import net.i2p.data.router.RouterIdentity; import net.i2p.data.i2np.GarlicMessage; @@ -17,6 +15,7 @@ import net.i2p.router.HandlerJobBuilder; import net.i2p.router.Job; import net.i2p.router.RouterContext; +import net.i2p.util.RandomSource; /** * HandlerJobBuilder to build jobs to handle GarlicMessages @@ -35,9 +34,9 @@ public class GarlicMessageHandler implements HandlerJobBuilder { public GarlicMessageHandler(RouterContext context) { _context = context; - _msgIDBloomXorLocal = new Random().nextLong(); - _msgIDBloomXorRouter = new Random().nextLong(); - _msgIDBloomXorTunnel = new Random().nextLong(); + _msgIDBloomXorLocal = RandomSource.getInstance().nextLong(); + _msgIDBloomXorRouter = RandomSource.getInstance().nextLong(); + _msgIDBloomXorTunnel = RandomSource.getInstance().nextLong(); } public GarlicMessageHandler(RouterContext context, long msgIDBloomXorLocal, long msgIDBloomXorRouter, long msgIDBloomXorTunnel) { diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillDatabaseLookupMessageHandler.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillDatabaseLookupMessageHandler.java index 851c9ad9fe..c0eff241ef 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillDatabaseLookupMessageHandler.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillDatabaseLookupMessageHandler.java @@ -8,8 +8,6 @@ * */ -import java.util.Random; - import net.i2p.data.Hash; import net.i2p.data.router.RouterIdentity; import net.i2p.data.i2np.DatabaseLookupMessage; @@ -18,6 +16,7 @@ import net.i2p.router.Job; import net.i2p.router.RouterContext; import net.i2p.util.Log; +import net.i2p.util.RandomSource; /** * Build a HandleDatabaseLookupMessageJob whenever a DatabaseLookupMessage arrives @@ -27,7 +26,7 @@ public class FloodfillDatabaseLookupMessageHandler implements HandlerJobBuilder private RouterContext _context; private FloodfillNetworkDatabaseFacade _facade; private Log _log; - private final long _msgIDBloomXor = new Random().nextLong(); + private final long _msgIDBloomXor = RandomSource.getInstance().nextLong(); public FloodfillDatabaseLookupMessageHandler(RouterContext context, FloodfillNetworkDatabaseFacade facade) { _context = context; diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillDatabaseStoreMessageHandler.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillDatabaseStoreMessageHandler.java index 0cc170a906..5af3c2db40 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillDatabaseStoreMessageHandler.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillDatabaseStoreMessageHandler.java @@ -8,8 +8,6 @@ * */ -import java.util.Random; - import net.i2p.data.Hash; import net.i2p.data.router.RouterIdentity; import net.i2p.data.i2np.DatabaseStoreMessage; @@ -17,6 +15,7 @@ import net.i2p.router.HandlerJobBuilder; import net.i2p.router.Job; import net.i2p.router.RouterContext; +import net.i2p.util.RandomSource; /** * Create a HandleDatabaseStoreMessageJob whenever a DatabaseStoreMessage arrives @@ -25,7 +24,7 @@ public class FloodfillDatabaseStoreMessageHandler implements HandlerJobBuilder { private RouterContext _context; private FloodfillNetworkDatabaseFacade _facade; - private final long _msgIDBloomXor = new Random().nextLong(); + private final long _msgIDBloomXor = RandomSource.getInstance().nextLong(); public FloodfillDatabaseStoreMessageHandler(RouterContext context, FloodfillNetworkDatabaseFacade facade) { _context = context; diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/StartExplorersJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/StartExplorersJob.java index 7663e06a98..f15ea6e762 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/StartExplorersJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/StartExplorersJob.java @@ -9,7 +9,6 @@ */ import java.util.HashSet; -import java.util.Random; import java.util.Set; import net.i2p.data.Hash; @@ -18,6 +17,7 @@ import net.i2p.router.Router; import net.i2p.router.RouterContext; import net.i2p.util.Log; +import net.i2p.util.RandomSource; import net.i2p.util.SystemVersion; /** @@ -59,7 +59,7 @@ class StartExplorersJob extends JobImpl { private static final long MAX_LAG = 100; private static final long MAX_MSG_DELAY = 1500; - private final long _msgIDBloomXor = new Random().nextLong(); + private final long _msgIDBloomXor = RandomSource.getInstance().nextLong(); public StartExplorersJob(RouterContext context, KademliaNetworkDatabaseFacade facade) { super(context); diff --git a/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java b/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java index 0775f96445..f68dd2e2df 100644 --- a/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java +++ b/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java @@ -1,7 +1,5 @@ package net.i2p.router.tunnel; -import java.util.Random; - import net.i2p.data.DatabaseEntry; import net.i2p.data.Hash; import net.i2p.data.LeaseSet; @@ -25,6 +23,7 @@ import net.i2p.router.message.GarlicMessageReceiver; import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade; import net.i2p.util.Log; +import net.i2p.util.RandomSource; /** * When a message arrives at the inbound tunnel endpoint, this distributor @@ -58,7 +57,7 @@ public InboundMessageDistributor(RouterContext ctx, Hash client) { _msgIDBloomXor = clienttps.getMsgIdBloomXor(); } else { _clientNickname = "NULL/Expl"; - _msgIDBloomXor = new Random().nextLong(); + _msgIDBloomXor = RandomSource.getInstance().nextLong(); if (_log.shouldLog(Log.DEBUG)) _log.debug("Initializing null or exploratory InboundMessageDistributor"); }