Refactor / cleanup:

* Reduce visibility of classes and methods
* Remove unused methods and commented-out code
*
This commit is contained in:
HungryHobo
2011-03-16 19:09:57 +00:00
parent 4718424d11
commit ec0b072fca
24 changed files with 63 additions and 131 deletions

View File

@@ -98,7 +98,7 @@ public class Util {
return getHumanReadableSize(totalBytes);
}
public static String getHumanReadableSize(long numBytes) {
private static String getHumanReadableSize(long numBytes) {
String language = Translate.getLanguage(I2PAppContext.getGlobalContext());
int unit = (63-Long.numberOfLeadingZeros(numBytes)) / 10; // 0 if totalBytes<1K, 1 if 1K<=totalBytes<1M, etc.
double value = (double)numBytes / (1<<(10*unit));

View File

@@ -55,8 +55,8 @@ import net.i2p.util.Log;
* <code>&lt;message ID&gt;.meta</code>.
*/
public class EmailFolder extends Folder<Email> {
protected static final String EMAIL_FILE_EXTENSION = ".mail";
protected static final String METADATA_FILE_EXTENSION = ".meta";
private static final String EMAIL_FILE_EXTENSION = ".mail";
private static final String METADATA_FILE_EXTENSION = ".meta";
private Log log = new Log(EmailFolder.class);
private PasswordHolder passwordHolder;

View File

@@ -40,9 +40,10 @@ import net.i2p.util.Log;
* @param <T> The type of objects the folder can store.
*/
public abstract class Folder<T> implements Iterable<T> {
private Log log = new Log(Folder.class);
protected File storageDir;
protected String fileExtension;
private Log log = new Log(Folder.class);
private String fileExtension;
protected Folder(File storageDir, String fileExtension) {
this.storageDir = storageDir;

View File

@@ -43,11 +43,11 @@ import net.i2p.util.Log;
/**
* Migrates the address book, email identities, and all emails to the encrypted format.
*/
public class MigrateTo026 {
class MigrateTo026 {
private Log log = new Log(MigrateTo026.class);
private PasswordCache passwordCache;
public void migrateIfNeeded(Configuration configuration) {
void migrateIfNeeded(Configuration configuration) {
log.debug("Migrating any pre-0.2.6 files...");
passwordCache = new PasswordCache(configuration);

View File

@@ -55,16 +55,4 @@ public interface DHT {
int getNumPeers();
DhtPeerStats getPeerStats();
void start();
void requestShutdown();
/**
* Waits <code>timeout</code> milliseconds for the DHT engine to exit
* after {@link #requestShutdown()} has been called.
* @param timeout
* @throws InterruptedException
*/
void awaitShutdown(long timeout) throws InterruptedException;
}

View File

@@ -147,12 +147,6 @@ class KBucket extends AbstractBucket {
peers.add(0, peer);
}
void noResponse(KademliaPeer peer) {
if (!replacementCache.isEmpty())
if (peers.remove(peer))
peers.add(replacementCache.remove(0));
}
/**
* Adds a peer to the head of the replacement cache, or makes
* it the head if it exists in the replacement cache.

View File

@@ -412,7 +412,7 @@ public class KademliaDHT extends I2PBoteThread implements DHT, PacketListener {
* "refresh all k-buckets further away than the closest neighbor. This refresh is just a
* lookup of a random key that is within that k-bucket range."
*/
public void refreshAll() {
private void refreshAll() {
for (KBucket bucket: Util.synchronizedCopy(bucketManager))
refresh(bucket);
}
@@ -639,11 +639,6 @@ public class KademliaDHT extends I2PBoteThread implements DHT, PacketListener {
i2pReceiver.removePacketListener(this);
}
@Override
public void awaitShutdown(long timeout) throws InterruptedException {
join(timeout);
}
@Override
public void requestShutdown() {
super.requestShutdown();

View File

@@ -26,14 +26,14 @@ import net.i2p.data.Destination;
import net.i2p.data.Hash;
import net.i2p.util.Log;
public class KademliaPeer extends Destination {
class KademliaPeer extends Destination {
private Log log = new Log(KademliaPeer.class);
private Hash destinationHash;
private long firstSeen;
private volatile int consecutiveTimeouts;
private long lockedUntil;
public KademliaPeer(Destination destination, long lastReception) {
KademliaPeer(Destination destination, long lastReception) {
// initialize the Destination part of the KademliaPeer
setCertificate(destination.getCertificate());
setSigningPublicKey(destination.getSigningPublicKey());
@@ -47,11 +47,11 @@ public class KademliaPeer extends Destination {
firstSeen = lastReception;
}
public KademliaPeer(Destination destination) {
KademliaPeer(Destination destination) {
this(destination, System.currentTimeMillis());
}
public KademliaPeer(String peerFileEntry) throws DataFormatException {
KademliaPeer(String peerFileEntry) throws DataFormatException {
this(new Destination(peerFileEntry));
}
@@ -75,10 +75,6 @@ public class KademliaPeer extends Destination {
return consecutiveTimeouts;
}
long getLockedUntil() {
return lockedUntil;
}
boolean isLocked() {
return lockedUntil > System.currentTimeMillis();
}

View File

@@ -39,7 +39,7 @@ import net.i2p.data.Hash;
* Stores information on Kademlia peers.
* @see DhtPeerStats
*/
public class KademliaPeerStats implements DhtPeerStats {
class KademliaPeerStats implements DhtPeerStats {
private List<String> header;
private List<List<String>> data;

View File

@@ -26,7 +26,7 @@ import java.math.BigInteger;
import net.i2p.data.DataHelper;
import net.i2p.data.Hash;
public class KademliaUtil {
class KademliaUtil {
/**
* Calculates the Kademlia distance (XOR distance) between two hashes.
@@ -35,7 +35,7 @@ public class KademliaUtil {
* @param key1
* @param key2
*/
public static BigInteger getDistance(Hash key1, Hash key2) {
static BigInteger getDistance(Hash key1, Hash key2) {
// This shouldn't be a performance bottleneck, so save some mem by not using Hash.cachedXor
byte[] xoredData = DataHelper.xor(key1.getData(), key2.getData());
return new BigInteger(1, xoredData);

View File

@@ -27,7 +27,7 @@ import java.util.Comparator;
import net.i2p.data.Destination;
import net.i2p.data.Hash;
public class PeerDistanceComparator implements Comparator<Destination> {
class PeerDistanceComparator implements Comparator<Destination> {
private Hash reference;
PeerDistanceComparator(Hash reference) {

View File

@@ -67,7 +67,7 @@ import net.i2p.util.Log;
* </ol>
* </ol>
*/
public class ReplicateThread extends I2PBoteThread implements PacketListener {
class ReplicateThread extends I2PBoteThread implements PacketListener {
private static final int SEND_TIMEOUT_MINUTES = 5; // the maximum amount of time to wait for a store request to be sent
private static final int WAIT_TIME_SECONDS = 5; // amount of time to wait after sending a store request
@@ -84,7 +84,7 @@ public class ReplicateThread extends I2PBoteThread implements PacketListener {
// to be replicated instead of the DHT item.
private volatile boolean replicationRunning; // true when replication is active
public ReplicateThread(Destination localDestination, I2PSendQueue sendQueue, I2PPacketDispatcher i2pReceiver, BucketManager bucketManager) {
ReplicateThread(Destination localDestination, I2PSendQueue sendQueue, I2PPacketDispatcher i2pReceiver, BucketManager bucketManager) {
super("ReplicateThd");
this.localDestination = localDestination;
this.sendQueue = sendQueue;

View File

@@ -33,12 +33,12 @@ import net.i2p.util.Log;
* from the local destination.<br/>
* The closest peer is at index 0, the most distant peer is at index <code>n-1</code>.
*/
public class SBucket extends AbstractBucket {
class SBucket extends AbstractBucket {
private Log log = new Log(SBucket.class);
private PeerDistanceComparator distanceComparator;
private BucketSection[] sections; // used for refreshing the s-bucket
public SBucket(Hash localDestinationHash) {
SBucket(Hash localDestinationHash) {
super(KademliaConstants.S);
distanceComparator = new PeerDistanceComparator(localDestinationHash);
@@ -148,7 +148,7 @@ public class SBucket extends AbstractBucket {
private BigInteger end;
private long lastLookupTime;
public BucketSection(BigInteger start, BigInteger end, long lastLookupTime) {
private BucketSection(BigInteger start, BigInteger end, long lastLookupTime) {
this.start = start;
this.end = end;
this.lastLookupTime = lastLookupTime;
@@ -166,7 +166,7 @@ public class SBucket extends AbstractBucket {
return end;
}
public boolean contains(Hash key) {
private boolean contains(Hash key) {
BigInteger keyValue = new BigInteger(1, key.getData());
return (start.compareTo(keyValue)<=0 && keyValue.compareTo(end)<0);
}

View File

@@ -108,7 +108,7 @@ public abstract class I2PBotePacket {
* @param data
* @throws MalformedPacketException If the byte array does not contain a valid <code>I2PBotePacket</code>.
*/
public static I2PBotePacket createPacket(byte[] data) throws MalformedPacketException {
private static I2PBotePacket createPacket(byte[] data) throws MalformedPacketException {
if (CommunicationPacket.isPrefixValid(data))
return CommunicationPacket.createPacket(data);
else

View File

@@ -33,13 +33,13 @@ import net.i2p.util.Log;
public abstract class DhtStorablePacket extends DataPacket {
private static Log log = new Log(DhtStorablePacket.class);
public DhtStorablePacket() {
protected DhtStorablePacket() {
}
/**
* @see i2p.bote.packet.DataPacket#DataPacket(byte[])
*/
public DhtStorablePacket(byte[] data) {
protected DhtStorablePacket(byte[] data) {
super(data);
}

View File

@@ -100,9 +100,6 @@ public class EmailPacketDeleteRequest extends DeleteRequest {
else
return null;
}
public Collection<? extends DeleteRequest> toIndividualRequests() {
return Collections.singleton(this);
}
@Override
public String toString() {

View File

@@ -87,10 +87,6 @@ public class IndexPacketDeleteRequest extends DeleteRequest {
return entries.get(dhtKey);
}
public void remove(Hash dhtKey) {
entries.remove(dhtKey);
}
public int getNumEntries() {
return entries.size();
}

View File

@@ -28,19 +28,20 @@ import net.i2p.data.Hash;
*/
public class IndexPacketEntry {
public Hash emailPacketKey;
public Hash delVerificationHash;
public long storeTime; // milliseconds since 1-1-1970
Hash delVerificationHash;
/**
* Constructs an <code>IndexPacketEntry</code> with a time stamp of 0.
* @param emailPacketKey
* @param delVerificationHash
*/
public IndexPacketEntry(Hash emailPacketKey, Hash delVerificationHash) {
IndexPacketEntry(Hash emailPacketKey, Hash delVerificationHash) {
this(emailPacketKey, delVerificationHash, 0);
}
public IndexPacketEntry(Hash emailPacketKey, Hash delVerificationHash, long storeTime) {
IndexPacketEntry(Hash emailPacketKey, Hash delVerificationHash, long storeTime) {
this.emailPacketKey = emailPacketKey;
this.delVerificationHash = delVerificationHash;
this.storeTime = storeTime;

View File

@@ -35,7 +35,7 @@ import java.net.PasswordAuthentication;
*
* @author sponge
*/
public class ProxyRequest {
class ProxyRequest {
private URLConnection c = null;
private HttpURLConnection h = null;
@@ -43,7 +43,7 @@ public class ProxyRequest {
/**
* Instance
*/
public ProxyRequest() {
ProxyRequest() {
}
/**
@@ -56,17 +56,13 @@ public class ProxyRequest {
* @param iProxyPort An integer that indicates the proxy port or -1 to indicate the default port for the protocol.
* @return HTTPURLConnection or null
*/
public HttpURLConnection doURLRequest(String strURL, String header, String strProxy, int iProxyPort, String user, String pass) {
HttpURLConnection doURLRequest(String strURL, String header, String strProxy, int iProxyPort, String user, String pass) {
try {
URL url = null;
// System.out.println("HTTP Request: " + strURL);
URL urlOriginal = new URL(strURL);
if((null != strProxy) && (0 < strProxy.length())) {
URL urlProxy = new URL(urlOriginal.getProtocol(), strProxy, iProxyPort, strURL); // The original URL is passed as "the file on the host".
//System.out.println("Using Proxy: " + strProxy);
//if(-1 != iProxyPort) {
// System.out.println("Using Proxy Port: " + iProxyPort);
//}
url = urlProxy;
} else {
url = urlOriginal;

View File

@@ -56,7 +56,7 @@ import net.i2p.util.Log;
*
* @author sponge
*/
public class SeedlessAnnounce extends I2PBoteThread {
class SeedlessAnnounce extends I2PBoteThread {
private Log log = new Log(SeedlessAnnounce.class);
private long interval; // in milliseconds
private long lastSeedlessAnnounce = 0;
@@ -72,7 +72,7 @@ public class SeedlessAnnounce extends I2PBoteThread {
* @param seedlessScrapeServers
* @param interval In minutes
*/
public SeedlessAnnounce(I2PSocketManager socketManager, SeedlessScrapeServers seedlessScrapeServers, int interval) {
SeedlessAnnounce(I2PSocketManager socketManager, SeedlessScrapeServers seedlessScrapeServers, int interval) {
super("SeedlsAnounc");
this.socketManager = socketManager;
this.seedlessScrapeServers = seedlessScrapeServers;
@@ -80,7 +80,7 @@ public class SeedlessAnnounce extends I2PBoteThread {
}
@Override
public void doStep() {
protected void doStep() {
lastTime = lastSeedlessAnnounce;
timeSinceLastCheck = System.currentTimeMillis() - lastTime;
if (lastTime == 0 || timeSinceLastCheck > this.interval) {
@@ -90,16 +90,12 @@ public class SeedlessAnnounce extends I2PBoteThread {
}
}
public long getInterval() {
return interval;
}
private synchronized void doSeedlessAnnounce() {
List<String> seedlessServers = seedlessScrapeServers.getSeedlessServers();
if(seedlessServers.isEmpty()) {
// try again in a minute.
log.error("SeedlessServers.isEmpty, will retry shortly.");
lastSeedlessAnnounce = System.currentTimeMillis() - (getInterval() - TimeUnit.MINUTES.toMillis(1));
lastSeedlessAnnounce = System.currentTimeMillis() - (interval - TimeUnit.MINUTES.toMillis(1));
return;
}
// Announce to 10 servers.
@@ -181,7 +177,7 @@ public class SeedlessAnnounce extends I2PBoteThread {
}
if(!didsomething) {
// try again in 1 minute.
lastSeedlessAnnounce = System.currentTimeMillis() - (getInterval() - TimeUnit.MINUTES.toMillis(1));
lastSeedlessAnnounce = System.currentTimeMillis() - (interval - TimeUnit.MINUTES.toMillis(1));
return;
}

View File

@@ -36,7 +36,7 @@ import net.i2p.router.RouterContext;
import net.i2p.router.startup.ClientAppConfig;
import net.i2p.util.Log;
public class SeedlessParameters {
class SeedlessParameters {
private static final String DEFAULT_HOST = "localhost";
private static final String DEFAULT_PORT = "7657";
private static SeedlessParameters instance;
@@ -53,13 +53,13 @@ public class SeedlessParameters {
private SeedlessParameters() {
}
public static SeedlessParameters getInstance() {
static SeedlessParameters getInstance() {
if (instance == null)
instance = new SeedlessParameters();
return instance;
}
public boolean isSeedlessAvailable() {
boolean isSeedlessAvailable() {
if (!ready)
init();
return ready;
@@ -199,23 +199,23 @@ public class SeedlessParameters {
}
}
public String getSeedlessUrl() {
String getSeedlessUrl() {
return svcURL;
}
public String getPeersRequestHeader() {
String getPeersRequestHeader() {
return peersReqHeader;
}
public String getPeersLocateHeader() {
String getPeersLocateHeader() {
return peersLocHeader;
}
public String getServersLocateHeader() {
String getServersLocateHeader() {
return serversLocHeader;
}
public String getConsolePassword() {
String getConsolePassword() {
return cpass;
}

View File

@@ -36,7 +36,7 @@ import net.i2p.util.Log;
*
* @author sponge
*/
public class SeedlessRequestPeers extends I2PBoteThread {
class SeedlessRequestPeers extends I2PBoteThread {
private Log log = new Log(SeedlessRequestPeers.class);
private SeedlessParameters seedlessParameters;
private long interval; // in milliseconds
@@ -48,15 +48,15 @@ public class SeedlessRequestPeers extends I2PBoteThread {
*
* @param interval In minutes
*/
public SeedlessRequestPeers(SeedlessParameters seedlessParameters, int interval) {
SeedlessRequestPeers(SeedlessParameters seedlessParameters, int interval) {
super("SeedlsReqPrs");
this.seedlessParameters = seedlessParameters;
this.interval = TimeUnit.MINUTES.toMillis(interval);
}
@Override
public void doStep() {
lastTime = getlastSeedlessRequestPeers();
protected void doStep() {
lastTime = lastSeedlessRequestPeers;
timeSinceLastCheck = System.currentTimeMillis() - lastTime;
if (lastTime == 0 || timeSinceLastCheck > this.interval) {
doSeedlessRequestPeers();
@@ -65,15 +65,7 @@ public class SeedlessRequestPeers extends I2PBoteThread {
}
}
public long getInterval() {
return interval;
}
public synchronized long getlastSeedlessRequestPeers() {
return lastSeedlessRequestPeers;
}
public synchronized void doSeedlessRequestPeers() {
private synchronized void doSeedlessRequestPeers() {
HttpURLConnection h;
log.debug("doSeedlessRequestPeers");
try {

View File

@@ -45,7 +45,7 @@ import net.i2p.util.Log;
*
* @author sponge
*/
public class SeedlessScrapePeers extends I2PBoteThread {
class SeedlessScrapePeers extends I2PBoteThread {
private Log log = new Log(SeedlessScrapePeers.class);
private SeedlessParameters seedlessParameters;
private long interval; // in milliseconds
@@ -58,7 +58,7 @@ public class SeedlessScrapePeers extends I2PBoteThread {
*
* @param interval In minutes
*/
public SeedlessScrapePeers(SeedlessParameters seedlessParameters, int interval) {
SeedlessScrapePeers(SeedlessParameters seedlessParameters, int interval) {
super("SeedlsScpPrs");
this.seedlessParameters = seedlessParameters;
this.interval = TimeUnit.MINUTES.toMillis(interval);
@@ -66,8 +66,8 @@ public class SeedlessScrapePeers extends I2PBoteThread {
}
@Override
public void doStep() {
lastTime = getlastSeedlessScrapePeers();
protected void doStep() {
lastTime = lastSeedlessScrapePeers;
timeSinceLastCheck = System.currentTimeMillis() - lastTime;
if (lastTime == 0 || timeSinceLastCheck > this.interval) {
doSeedlessScrapePeers();
@@ -75,15 +75,8 @@ public class SeedlessScrapePeers extends I2PBoteThread {
awaitShutdownRequest(interval - timeSinceLastCheck, TimeUnit.MILLISECONDS);
}
}
public long getInterval() {
return interval;
}
public synchronized long getlastSeedlessScrapePeers() {
return lastSeedlessScrapePeers;
}
public synchronized void doSeedlessScrapePeers() {
private synchronized void doSeedlessScrapePeers() {
HttpURLConnection h;
int i;
String foo;
@@ -128,32 +121,19 @@ public class SeedlessScrapePeers extends I2PBoteThread {
}
}
// BotePeers = ip32s;
log.debug("doSeedlessScrapePeers Done.");
/* BotePeers = dht.injectPeers(BotePeers);
peerManager.injectPeers(BotePeers);
BotePeers = null; // garbage now.*/
lastSeedlessScrapePeers = System.currentTimeMillis();
}
/** Returns <code>null</code> if the peer was not found. */
private Destination lookup(String b32Peer) {
Destination destination = I2PAppContext.getGlobalContext().namingService().lookup(b32Peer);
/* depreciated
Destination destination;
try {
destination = I2PTunnel.destFromName(b32Peer);
} catch (DataFormatException e) {
log.error("Cannot look up B32 destination: <" + b32Peer + ">", e);
return null;
}
*/
if (destination == null)
log.warn ("Can't find peer in floodfill: " + b32Peer);
return destination;
}
public synchronized List<Destination> getPeers() {
synchronized List<Destination> getPeers() {
return peers;
}
}

View File

@@ -45,7 +45,7 @@ import net.i2p.util.Log;
*
* @author sponge
*/
public class SeedlessScrapeServers extends I2PBoteThread {
class SeedlessScrapeServers extends I2PBoteThread {
private Log log = new Log(SeedlessScrapeServers.class);
private SeedlessParameters seedlessParameters;
private long interval; // in milliseconds
@@ -58,14 +58,14 @@ public class SeedlessScrapeServers extends I2PBoteThread {
* @param seedlessParameters
* @param interval In minutes
*/
public SeedlessScrapeServers(SeedlessParameters seedlessParameters, int interval) {
SeedlessScrapeServers(SeedlessParameters seedlessParameters, int interval) {
super("SeedlsScpSvr");
this.seedlessParameters = seedlessParameters;
this.interval = TimeUnit.MINUTES.toMillis(interval);
}
@Override
public void doStep() {
protected void doStep() {
lastTime = lastSeedlessScrapeServers;
timeSinceLastCheck = System.currentTimeMillis() - lastTime;
if (lastTime == 0 || timeSinceLastCheck > this.interval) {
@@ -75,7 +75,7 @@ public class SeedlessScrapeServers extends I2PBoteThread {
}
}
public synchronized void doSeedlessScrapeServers() {
private synchronized void doSeedlessScrapeServers() {
HttpURLConnection h;
int i;
String foo;
@@ -117,7 +117,7 @@ public class SeedlessScrapeServers extends I2PBoteThread {
lastSeedlessScrapeServers = System.currentTimeMillis();
}
public synchronized List<String> getSeedlessServers() {
synchronized List<String> getSeedlessServers() {
return seedlessServers;
}
}