forked from I2P_Developers/i2p.i2p
i2psnark:
- Respond to get_peers with an empty peers list instead of a nodes list if the requester was the only peer (ticket #1279) - Fix sendError() (still unused)
This commit is contained in:
@ -36,7 +36,7 @@ public interface DHT {
|
|||||||
public void ping(Destination dest, int port);
|
public void ping(Destination dest, int port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get peers for a torrent, and announce to the closest node we find.
|
* Get peers for a torrent, and announce to the closest annMax nodes we find.
|
||||||
* Blocking!
|
* Blocking!
|
||||||
* Caller should run in a thread.
|
* Caller should run in a thread.
|
||||||
*
|
*
|
||||||
|
@ -10,6 +10,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -305,7 +306,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get peers for a torrent, and announce to the closest node we find.
|
* Get peers for a torrent, and announce to the closest annMax nodes we find.
|
||||||
* This is an iterative lookup in the DHT.
|
* This is an iterative lookup in the DHT.
|
||||||
* Blocking!
|
* Blocking!
|
||||||
* Caller should run in a thread.
|
* Caller should run in a thread.
|
||||||
@ -821,16 +822,20 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
// All errors use the response port.
|
// All errors use the response port.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Unused
|
||||||
|
*
|
||||||
* @param nInfo who to send it to
|
* @param nInfo who to send it to
|
||||||
* @return success
|
* @return success
|
||||||
*/
|
*/
|
||||||
private boolean sendError(NodeInfo nInfo, MsgID msgID, int err, String msg) {
|
private boolean sendError(NodeInfo nInfo, MsgID msgID, int err, String msg) {
|
||||||
if (_log.shouldLog(Log.INFO))
|
if (_log.shouldLog(Log.INFO))
|
||||||
_log.info("Sending error " + msg + " to: " + nInfo);
|
_log.info("Sending error " + msg + " to: " + nInfo);
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>(4);
|
||||||
Map<String, Object> resps = new HashMap<String, Object>();
|
List<Object> error = new ArrayList(2);
|
||||||
map.put("r", resps);
|
error.add(Integer.valueOf(err));
|
||||||
return sendResponse(nInfo, msgID, map);
|
error.add(msg);
|
||||||
|
map.put("e", error);
|
||||||
|
return sendError(nInfo, msgID, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Low-level send methods
|
// Low-level send methods
|
||||||
@ -917,7 +922,8 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param toPort the query port, we will increment here
|
* Unused
|
||||||
|
*
|
||||||
* @return success
|
* @return success
|
||||||
*/
|
*/
|
||||||
private boolean sendError(NodeInfo nInfo, MsgID msgID, Map<String, Object> map) {
|
private boolean sendError(NodeInfo nInfo, MsgID msgID, Map<String, Object> map) {
|
||||||
@ -1250,8 +1256,11 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
_log.info("Stored new OB token: " + token + " for: " + nInfo);
|
_log.info("Stored new OB token: " + token + " for: " + nInfo);
|
||||||
|
|
||||||
List<Hash> peers = _tracker.getPeers(ih, MAX_WANT);
|
List<Hash> peers = _tracker.getPeers(ih, MAX_WANT);
|
||||||
|
// Check this before removing him, so we don't needlessly send nodes
|
||||||
|
// if he's the only one on the torrent.
|
||||||
|
boolean noPeers = peers.isEmpty();
|
||||||
peers.remove(nInfo.getHash()); // him
|
peers.remove(nInfo.getHash()); // him
|
||||||
if (peers.isEmpty()) {
|
if (noPeers) {
|
||||||
// similar to find node, but with token
|
// similar to find node, but with token
|
||||||
// get closest from DHT
|
// get closest from DHT
|
||||||
List<NodeInfo> nodes = _knownNodes.findClosest(ih, K);
|
List<NodeInfo> nodes = _knownNodes.findClosest(ih, K);
|
||||||
@ -1263,9 +1272,14 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
}
|
}
|
||||||
sendNodes(nInfo, msgID, token, nodeArray);
|
sendNodes(nInfo, msgID, token, nodeArray);
|
||||||
} else {
|
} else {
|
||||||
List<byte[]> hashes = new ArrayList<byte[]>(peers.size());
|
List<byte[]> hashes;
|
||||||
for (Hash peer : peers) {
|
if (peers.isEmpty()) {
|
||||||
hashes.add(peer.getData());
|
hashes = Collections.EMPTY_LIST;
|
||||||
|
} else {
|
||||||
|
hashes = new ArrayList<byte[]>(peers.size());
|
||||||
|
for (Hash peer : peers) {
|
||||||
|
hashes.add(peer.getData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sendPeers(nInfo, msgID, token, hashes);
|
sendPeers(nInfo, msgID, token, hashes);
|
||||||
}
|
}
|
||||||
@ -1406,6 +1420,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
// Errors.....
|
// Errors.....
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param error 1st item is error code, 2nd is message string
|
||||||
* @throws NPE, and others too
|
* @throws NPE, and others too
|
||||||
*/
|
*/
|
||||||
private void receiveError(ReplyWaiter waiter, List<BEValue> error) throws InvalidBEncodingException {
|
private void receiveError(ReplyWaiter waiter, List<BEValue> error) throws InvalidBEncodingException {
|
||||||
|
Reference in New Issue
Block a user