issue #4: prevent connections to self, select random nodes to connect to

This commit is contained in:
2015-06-13 17:37:55 +02:00
parent bd5bf76904
commit ed0d1c2911
4 changed files with 21 additions and 4 deletions

View File

@ -102,7 +102,10 @@ public class Connection implements Runnable {
switch (msg.getPayload().getCommand()) {
case VERSION:
Version payload = (Version) msg.getPayload();
if (payload.getVersion() >= BitmessageContext.CURRENT_VERSION) {
if (payload.getNonce() == ctx.getClientNonce()) {
LOG.info("Tried to connect to self, disconnecting.");
disconnect();
} else if (payload.getVersion() >= BitmessageContext.CURRENT_VERSION) {
this.version = payload.getVersion();
this.streams = payload.getStreams();
send(new VerAck());
@ -120,8 +123,8 @@ public class Connection implements Runnable {
}
break;
default:
throw new RuntimeException("Command 'version' or 'verack' expected, but was "
+ msg.getPayload().getCommand());
throw new RuntimeException("Command 'version' or 'verack' expected, but was '"
+ msg.getPayload().getCommand() + "'");
}
}
if (socket.isClosed()) state = DISCONNECTED;