forked from I2P_Developers/i2p.i2p
- Fix cases where we weren't using the session for b32 lookup
This commit is contained in:
@ -338,7 +338,7 @@ abstract class ExtensionHandler {
|
||||
System.arraycopy(ids, off, hash, 0, HASH_LENGTH);
|
||||
if (DataHelper.eq(hash, peer.getPeerID().getDestHash()))
|
||||
continue;
|
||||
PeerID pID = new PeerID(hash);
|
||||
PeerID pID = new PeerID(hash, listener.getUtil());
|
||||
peers.add(pID);
|
||||
}
|
||||
// could include ourselves, listener must remove
|
||||
|
@ -1435,5 +1435,13 @@ class PeerCoordinator implements PeerListener
|
||||
return listener.overUpBWLimit(total * 1000 / CHECK_PERIOD);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public I2PSnarkUtil getUtil() {
|
||||
return _util;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@ public class PeerID implements Comparable
|
||||
/** whether we have tried to get the dest from the hash - only do once */
|
||||
private boolean triedDestLookup;
|
||||
private final int hash;
|
||||
private final I2PSnarkUtil util;
|
||||
|
||||
public PeerID(byte[] id, Destination address)
|
||||
{
|
||||
@ -60,6 +61,7 @@ public class PeerID implements Comparable
|
||||
this.port = 6881;
|
||||
this.destHash = address.calculateHash().getData();
|
||||
hash = calculateHash();
|
||||
util = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,13 +95,15 @@ public class PeerID implements Comparable
|
||||
port = 6881;
|
||||
this.destHash = address.calculateHash().getData();
|
||||
hash = calculateHash();
|
||||
util = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PeerID from a destHash
|
||||
* @param util for eventual destination lookup
|
||||
* @since 0.8.1
|
||||
*/
|
||||
public PeerID(byte[] dest_hash) throws InvalidBEncodingException
|
||||
public PeerID(byte[] dest_hash, I2PSnarkUtil util) throws InvalidBEncodingException
|
||||
{
|
||||
// id and address remain null
|
||||
port = 6881;
|
||||
@ -107,6 +111,7 @@ public class PeerID implements Comparable
|
||||
throw new InvalidBEncodingException("bad hash length");
|
||||
destHash = dest_hash;
|
||||
hash = DataHelper.hashCode(dest_hash);
|
||||
this.util = util;
|
||||
}
|
||||
|
||||
public byte[] getID()
|
||||
@ -131,7 +136,7 @@ public class PeerID implements Comparable
|
||||
{
|
||||
if (address == null && destHash != null && !triedDestLookup) {
|
||||
String b32 = Base32.encode(destHash) + ".b32.i2p";
|
||||
address = I2PAppContext.getGlobalContext().namingService().lookup(b32);
|
||||
address = util.getDestination(b32);
|
||||
triedDestLookup = true;
|
||||
}
|
||||
return address;
|
||||
|
@ -207,4 +207,10 @@ interface PeerListener
|
||||
* @since 0.8.4
|
||||
*/
|
||||
void gotPeers(Peer peer, List<PeerID> pIDList);
|
||||
|
||||
/**
|
||||
* Convenience
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public I2PSnarkUtil getUtil();
|
||||
}
|
||||
|
@ -487,7 +487,7 @@ public class TrackerClient implements Runnable {
|
||||
if ((!stop) && !hashes.isEmpty()) {
|
||||
List<Peer> peers = new ArrayList(hashes.size());
|
||||
for (Hash h : hashes) {
|
||||
PeerID pID = new PeerID(h.getData());
|
||||
PeerID pID = new PeerID(h.getData(), _util);
|
||||
peers.add(new Peer(pID, snark.getID(), snark.getInfoHash(), snark.getMetaInfo()));
|
||||
}
|
||||
Collections.shuffle(peers, r);
|
||||
@ -651,7 +651,7 @@ public class TrackerClient implements Runnable {
|
||||
in = new FileInputStream(fetched);
|
||||
|
||||
TrackerInfo info = new TrackerInfo(in, snark.getID(),
|
||||
snark.getInfoHash(), snark.getMetaInfo());
|
||||
snark.getInfoHash(), snark.getMetaInfo(), _util);
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("TrackerClient response: " + info);
|
||||
|
||||
|
@ -47,19 +47,19 @@ class TrackerInfo
|
||||
private int incomplete;
|
||||
|
||||
/** @param metainfo may be null */
|
||||
public TrackerInfo(InputStream in, byte[] my_id, byte[] infohash, MetaInfo metainfo)
|
||||
public TrackerInfo(InputStream in, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util)
|
||||
throws IOException
|
||||
{
|
||||
this(new BDecoder(in), my_id, infohash, metainfo);
|
||||
this(new BDecoder(in), my_id, infohash, metainfo, util);
|
||||
}
|
||||
|
||||
private TrackerInfo(BDecoder be, byte[] my_id, byte[] infohash, MetaInfo metainfo)
|
||||
private TrackerInfo(BDecoder be, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util)
|
||||
throws IOException
|
||||
{
|
||||
this(be.bdecodeMap().getMap(), my_id, infohash, metainfo);
|
||||
this(be.bdecodeMap().getMap(), my_id, infohash, metainfo, util);
|
||||
}
|
||||
|
||||
private TrackerInfo(Map m, byte[] my_id, byte[] infohash, MetaInfo metainfo)
|
||||
private TrackerInfo(Map m, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util)
|
||||
throws IOException
|
||||
{
|
||||
BEValue reason = (BEValue)m.get("failure reason");
|
||||
@ -85,10 +85,10 @@ class TrackerInfo
|
||||
Set<Peer> p;
|
||||
try {
|
||||
// One big string (the official compact format)
|
||||
p = getPeers(bePeers.getBytes(), my_id, infohash, metainfo);
|
||||
p = getPeers(bePeers.getBytes(), my_id, infohash, metainfo, util);
|
||||
} catch (InvalidBEncodingException ibe) {
|
||||
// List of Dictionaries or List of Strings
|
||||
p = getPeers(bePeers.getList(), my_id, infohash, metainfo);
|
||||
p = getPeers(bePeers.getList(), my_id, infohash, metainfo, util);
|
||||
}
|
||||
peers = p;
|
||||
}
|
||||
@ -124,7 +124,7 @@ class TrackerInfo
|
||||
******/
|
||||
|
||||
/** List of Dictionaries or List of Strings */
|
||||
private static Set<Peer> getPeers(List<BEValue> l, byte[] my_id, byte[] infohash, MetaInfo metainfo)
|
||||
private static Set<Peer> getPeers(List<BEValue> l, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util)
|
||||
throws IOException
|
||||
{
|
||||
Set<Peer> peers = new HashSet(l.size());
|
||||
@ -138,7 +138,7 @@ class TrackerInfo
|
||||
try {
|
||||
// Case 2 - compact - A list of 32-byte binary strings (hashes)
|
||||
// This was just for testing and is not the official format
|
||||
peerID = new PeerID(bev.getBytes());
|
||||
peerID = new PeerID(bev.getBytes(), util);
|
||||
} catch (InvalidBEncodingException ibe2) {
|
||||
// don't let one bad entry spoil the whole list
|
||||
//Snark.debug("Discarding peer from list: " + ibe, Snark.ERROR);
|
||||
@ -157,7 +157,7 @@ class TrackerInfo
|
||||
* One big string of concatenated 32-byte hashes
|
||||
* @since 0.8.1
|
||||
*/
|
||||
private static Set<Peer> getPeers(byte[] l, byte[] my_id, byte[] infohash, MetaInfo metainfo)
|
||||
private static Set<Peer> getPeers(byte[] l, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util)
|
||||
throws IOException
|
||||
{
|
||||
int count = l.length / HASH_LENGTH;
|
||||
@ -168,7 +168,7 @@ class TrackerInfo
|
||||
byte[] hash = new byte[HASH_LENGTH];
|
||||
System.arraycopy(l, i * HASH_LENGTH, hash, 0, HASH_LENGTH);
|
||||
try {
|
||||
peerID = new PeerID(hash);
|
||||
peerID = new PeerID(hash, util);
|
||||
} catch (InvalidBEncodingException ibe) {
|
||||
// won't happen
|
||||
continue;
|
||||
|
@ -1,5 +1,7 @@
|
||||
2012-08-27 zzz
|
||||
* i2psnark: Notify threads awaiting DHT replies at shutdown
|
||||
* i2psnark:
|
||||
- Notify threads awaiting DHT replies at shutdown
|
||||
- Fix cases where we weren't using the session for b32 lookup
|
||||
* Reseed: Remove forum.i2p2.de
|
||||
* Streaming: Limit amount of slow-start exponential growth
|
||||
* SSU:
|
||||
|
Reference in New Issue
Block a user