forked from I2P_Developers/i2p.i2p
Several connect-to-self checks
This commit is contained in:
@ -137,6 +137,11 @@ public class ConnectionAcceptor implements Runnable
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (socket.getPeerDestination().equals(_util.getMyDestination())) {
|
||||
_util.debug("Incoming connection from myself", Snark.ERROR);
|
||||
try { socket.close(); } catch (IOException ioe) {}
|
||||
continue;
|
||||
}
|
||||
Thread t = new I2PAppThread(new Handler(socket), "I2PSnark incoming connection");
|
||||
t.start();
|
||||
}
|
||||
|
@ -227,6 +227,8 @@ public class I2PSnarkUtil {
|
||||
Destination addr = peer.getAddress();
|
||||
if (addr == null)
|
||||
throw new IOException("Null address");
|
||||
if (addr.equals(getMyDestination()))
|
||||
throw new IOException("Attempt to connect to myself");
|
||||
Hash dest = addr.calculateHash();
|
||||
if (_shitlist.contains(dest))
|
||||
throw new IOException("Not trying to contact " + dest.toBase64() + ", as they are shitlisted");
|
||||
@ -300,17 +302,25 @@ public class I2PSnarkUtil {
|
||||
}
|
||||
|
||||
String getOurIPString() {
|
||||
if (_manager == null)
|
||||
return "unknown";
|
||||
I2PSession sess = _manager.getSession();
|
||||
if (sess != null) {
|
||||
Destination dest = sess.getMyDestination();
|
||||
Destination dest = getMyDestination();
|
||||
if (dest != null)
|
||||
return dest.toBase64();
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return dest or null
|
||||
* @since 0.8.4
|
||||
*/
|
||||
Destination getMyDestination() {
|
||||
if (_manager == null)
|
||||
return null;
|
||||
I2PSession sess = _manager.getSession();
|
||||
if (sess != null)
|
||||
return sess.getMyDestination();
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Base64 only - static (no naming service) */
|
||||
static Destination getDestinationFromBase64(String ip) {
|
||||
if (ip == null) return null;
|
||||
|
@ -30,6 +30,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.i2p.client.streaming.I2PSocket;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
public class Peer implements Comparable
|
||||
@ -353,6 +354,9 @@ public class Peer implements Comparable
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Read the remote side's hash and peerID fully from " + toString());
|
||||
|
||||
if (DataHelper.eq(my_id, bs))
|
||||
throw new IOException("Connected to myself");
|
||||
|
||||
if (options != 0) {
|
||||
// send them something in runConnection() above
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
|
Reference in New Issue
Block a user