Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions simulator/config/dasprotocoldht1k.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protocol.3kademlia.reportMsg true
protocol.3kademlia.BITS 256
protocol.3kademlia.NBUCKETS 17
protocol.3kademlia.FINDMODE 1
protocol.3kademlia.N 1

#Kademlia protocol with 256 bits identifiers and 17 buckets in the routing table.
#Use FINDMODE 1 to send FINDMODE messages looking for distance to specific node instead of sending the id of the node like in DEVP2P
Expand Down
15 changes: 13 additions & 2 deletions simulator/src/main/java/peersim/kademlia/KademliaProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.math.BigInteger;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.TreeMap;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
Expand Down Expand Up @@ -41,6 +42,8 @@ public class KademliaProtocol implements Cloneable, EDProtocol {
// VARIABLE PARAMETERS
/** The parameter name for K. */
final String PAR_K = "K";
/** The parameter name for N replicas when PUT operation. */
final String PAR_N = "N";
/** The parameter name for ALPHA. */
final String PAR_ALPHA = "ALPHA";
/** The parameter name for BITS. */
Expand Down Expand Up @@ -91,6 +94,7 @@ public class KademliaProtocol implements Cloneable, EDProtocol {

private boolean msgReport;

private int N;
/**
* Replicate this object by returning an identical copy. It is called by the initializer and do
* not fill any particular field.
Expand Down Expand Up @@ -148,6 +152,10 @@ private void _init() {
KademliaCommonConfig.FINDMODE =
Configuration.getInt(prefix + "." + PAR_FINDMODE, KademliaCommonConfig.FINDMODE);

N = Configuration.getInt(prefix + "." + PAR_N, KademliaCommonConfig.K);

// N number of replicas in PUT_OPERATION can not be higher than K closest nodes.
if (N > KademliaCommonConfig.K) N = KademliaCommonConfig.K;
_ALREADY_INSTALLED = true;
}

Expand Down Expand Up @@ -274,8 +282,11 @@ private void handleResponse(Message m, int myPid) {
== KademliaCommonConfig.ALPHA) { // No new neighbor and no outstanding requests
// Search operation finished
if (fop instanceof PutOperation) {
// Create and send a put request to all neighbors in the neighbors list
for (BigInteger id : fop.getNeighboursList()) {
// Create and send a put request to N neighbors from the K closest in the neighbors list
List<BigInteger> kclosest = fop.getNeighboursList();
List<BigInteger> selectedNodes = kclosest.subList(0, N);
for (BigInteger id : selectedNodes) {

// Create a put request
Message request = new Message(Message.MSG_PUT);
request.operationId = m.operationId;
Expand Down