issue #4: prevent connections to self, select random nodes to connect to
This commit is contained in:
@ -52,6 +52,7 @@ public class InternalContext {
|
||||
private final int port;
|
||||
private long networkNonceTrialsPerByte = 1000;
|
||||
private long networkExtraBytes = 1000;
|
||||
private long clientNonce;
|
||||
|
||||
public InternalContext(BitmessageContext.Builder builder) {
|
||||
this.inventory = builder.inventory;
|
||||
@ -60,6 +61,7 @@ public class InternalContext {
|
||||
this.addressRepository = builder.addressRepo;
|
||||
this.messageRepository = builder.messageRepo;
|
||||
this.proofOfWorkEngine = builder.proofOfWorkEngine;
|
||||
this.clientNonce = Security.randomNonce();
|
||||
|
||||
port = builder.port;
|
||||
streams = builder.streams;
|
||||
@ -212,6 +214,14 @@ public class InternalContext {
|
||||
}
|
||||
}
|
||||
|
||||
public long getClientNonce() {
|
||||
return clientNonce;
|
||||
}
|
||||
|
||||
public void setClientNonce(long clientNonce) {
|
||||
this.clientNonce = clientNonce;
|
||||
}
|
||||
|
||||
public interface ContextHolder {
|
||||
void setContext(InternalContext context);
|
||||
}
|
||||
|
@ -230,4 +230,8 @@ public class Security {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static long randomNonce() {
|
||||
return RANDOM.nextLong();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user