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 {
|
} 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");
|
Thread t = new I2PAppThread(new Handler(socket), "I2PSnark incoming connection");
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
@ -227,6 +227,8 @@ public class I2PSnarkUtil {
|
|||||||
Destination addr = peer.getAddress();
|
Destination addr = peer.getAddress();
|
||||||
if (addr == null)
|
if (addr == null)
|
||||||
throw new IOException("Null address");
|
throw new IOException("Null address");
|
||||||
|
if (addr.equals(getMyDestination()))
|
||||||
|
throw new IOException("Attempt to connect to myself");
|
||||||
Hash dest = addr.calculateHash();
|
Hash dest = addr.calculateHash();
|
||||||
if (_shitlist.contains(dest))
|
if (_shitlist.contains(dest))
|
||||||
throw new IOException("Not trying to contact " + dest.toBase64() + ", as they are shitlisted");
|
throw new IOException("Not trying to contact " + dest.toBase64() + ", as they are shitlisted");
|
||||||
@ -300,17 +302,25 @@ public class I2PSnarkUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String getOurIPString() {
|
String getOurIPString() {
|
||||||
if (_manager == null)
|
Destination dest = getMyDestination();
|
||||||
return "unknown";
|
if (dest != null)
|
||||||
I2PSession sess = _manager.getSession();
|
return dest.toBase64();
|
||||||
if (sess != null) {
|
|
||||||
Destination dest = sess.getMyDestination();
|
|
||||||
if (dest != null)
|
|
||||||
return dest.toBase64();
|
|
||||||
}
|
|
||||||
return "unknown";
|
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) */
|
/** Base64 only - static (no naming service) */
|
||||||
static Destination getDestinationFromBase64(String ip) {
|
static Destination getDestinationFromBase64(String ip) {
|
||||||
if (ip == null) return null;
|
if (ip == null) return null;
|
||||||
|
@ -30,6 +30,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.i2p.client.streaming.I2PSocket;
|
import net.i2p.client.streaming.I2PSocket;
|
||||||
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
public class Peer implements Comparable
|
public class Peer implements Comparable
|
||||||
@ -353,6 +354,9 @@ public class Peer implements Comparable
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Read the remote side's hash and peerID fully from " + toString());
|
_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) {
|
if (options != 0) {
|
||||||
// send them something in runConnection() above
|
// send them something in runConnection() above
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
Reference in New Issue
Block a user