* i2psnark:

- Drop incoming connections on HTTP port
   - Define port 6881 in one place
   - Don't let random DHT port be 6881
   - Exception tweak
This commit is contained in:
zzz
2013-10-24 20:52:37 +00:00
parent 80fdf4e917
commit 9d3925eb20
6 changed files with 25 additions and 11 deletions

View File

@ -129,7 +129,7 @@ class ConnectionAcceptor implements Runnable
public int getPort()
{
return 6881; // serverSocket.getLocalPort();
return TrackerClient.PORT; // serverSocket.getLocalPort();
}
public void run()
@ -166,10 +166,18 @@ class ConnectionAcceptor implements Runnable
try { socket.close(); } catch (IOException ioe) {}
continue;
}
int bad = _badCounter.count(socket.getPeerDestination().calculateHash());
Hash h = socket.getPeerDestination().calculateHash();
if (socket.getLocalPort() == 80) {
_badCounter.increment(h);
if (_log.shouldLog(Log.WARN))
_log.error("Dropping incoming HTTP from " + h);
try { socket.close(); } catch (IOException ioe) {}
continue;
}
int bad = _badCounter.count(h);
if (bad >= MAX_BAD) {
if (_log.shouldLog(Log.WARN))
_log.warn("Rejecting connection from " + socket.getPeerDestination().calculateHash() +
_log.warn("Rejecting connection from " + h +
" after " + bad + " failures, max is " + MAX_BAD);
try { socket.close(); } catch (IOException ioe) {}
continue;

View File

@ -56,7 +56,7 @@ abstract class ExtensionHandler {
}
// include the map even if empty so the far-end doesn't NPE
handshake.put("m", m);
handshake.put("p", Integer.valueOf(6881));
handshake.put("p", Integer.valueOf(TrackerClient.PORT));
handshake.put("v", "I2PSnark");
handshake.put("reqq", Integer.valueOf(5));
return BEncoder.bencode(handshake);

View File

@ -324,6 +324,8 @@ public class I2PSnarkUtil {
if (_banlist.contains(dest))
throw new IOException("Not trying to contact " + dest.toBase64() + ", as they are banlisted");
try {
// TODO opts.setPort(xxx); connect(addr, opts)
// DHT moved above 6881 in 0.9.9
I2PSocket rv = _manager.connect(addr);
if (rv != null)
_banlist.remove(dest);
@ -331,7 +333,9 @@ public class I2PSnarkUtil {
} catch (I2PException ie) {
_banlist.add(dest);
_context.simpleScheduler().addEvent(new Unbanlist(dest), 10*60*1000);
throw new IOException("Unable to reach the peer " + peer + ": " + ie.getMessage());
IOException ioe = new IOException("Unable to reach the peer " + peer);
ioe.initCause(ie);
throw ioe;
}
}

View File

@ -58,7 +58,7 @@ class PeerID implements Comparable
{
this.id = id;
this.address = address;
this.port = 6881;
this.port = TrackerClient.PORT;
this.destHash = address.calculateHash().getData();
hash = calculateHash();
util = null;
@ -92,7 +92,7 @@ class PeerID implements Comparable
if (address == null)
throw new InvalidBEncodingException("Invalid destination [" + bevalue.getString() + "]");
port = 6881;
port = TrackerClient.PORT;
this.destHash = address.calculateHash().getData();
hash = calculateHash();
util = null;
@ -106,7 +106,7 @@ class PeerID implements Comparable
public PeerID(byte[] dest_hash, I2PSnarkUtil util) throws InvalidBEncodingException
{
// id and address remain null
port = 6881;
port = TrackerClient.PORT;
if (dest_hash.length != 32)
throw new InvalidBEncodingException("bad hash length");
destHash = dest_hash;

View File

@ -86,6 +86,7 @@ public class TrackerClient implements Runnable {
private final static int LONG_SLEEP = 30*60*1000; // sleep a while after lots of fails
private final static long MIN_TRACKER_ANNOUNCE_INTERVAL = 15*60*1000;
private final static long MIN_DHT_ANNOUNCE_INTERVAL = 10*60*1000;
public static final int PORT = 6881;
private final I2PSnarkUtil _util;
private final MetaInfo meta;
@ -135,7 +136,7 @@ public class TrackerClient implements Runnable {
this.coordinator = coordinator;
this.snark = snark;
this.port = 6881; //(port == -1) ? 9 : port;
this.port = PORT; //(port == -1) ? 9 : port;
this.infoHash = urlencode(snark.getInfoHash());
this.peerID = urlencode(snark.getID());
this.trackers = new ArrayList(2);

View File

@ -43,6 +43,7 @@ import net.i2p.util.I2PAppThread;
import net.i2p.util.Log;
import net.i2p.util.SimpleTimer2;
import org.klomp.snark.TrackerClient;
import org.klomp.snark.bencode.BDecoder;
import org.klomp.snark.bencode.BEncoder;
import org.klomp.snark.bencode.BEValue;
@ -176,7 +177,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
// Construct my NodeInfo
// Pick ports over a big range to marginally increase security
// If we add a search DHT, adjust to stay out of each other's way
_qPort = 2555 + ctx.random().nextInt(61111);
_qPort = TrackerClient.PORT + 10 + ctx.random().nextInt(65535 - 20 - TrackerClient.PORT);
_rPort = _qPort + 1;
if (SECURE_NID) {
_myNID = NodeInfo.generateNID(session.getMyDestination().calculateHash(), _qPort, _context.random());
@ -756,7 +757,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
Map<String, Object> args = new HashMap();
args.put("info_hash", ih.getData());
// port ignored
args.put("port", Integer.valueOf(6881));
args.put("port", Integer.valueOf(TrackerClient.PORT));
args.put("token", token.getData());
map.put("a", args);
// an announce need not be signed, we have a token