Skip to content

Commit

Permalink
use RandomSource instead of Random
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedeekay committed Jun 4, 2023
1 parent f0df5d1 commit 90aacc6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
*
*/

import java.util.Random;

import net.i2p.data.Hash;
import net.i2p.data.router.RouterIdentity;
import net.i2p.data.i2np.GarlicMessage;
import net.i2p.data.i2np.I2NPMessage;
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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
*
*/

import java.util.Random;

import net.i2p.data.Hash;
import net.i2p.data.router.RouterIdentity;
import net.i2p.data.i2np.DatabaseStoreMessage;
import net.i2p.data.i2np.I2NPMessage;
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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import net.i2p.data.Hash;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 90aacc6

Please sign in to comment.