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