Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacement buckets #26

Open
wants to merge 70 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
d2e85ba
Implemented replacement buckets
kaleem-peeroo Feb 8, 2023
56dc55f
Added k-value in k-buckets when used in routing table
kaleem-peeroo Feb 8, 2023
997a0f8
Added limits to k-bucket and replacement bucket and updated addReplac…
kaleem-peeroo Feb 8, 2023
e32360d
Added size check for removeReplacement()
kaleem-peeroo Feb 8, 2023
2b19041
Added refreshBuckets template to fill in later
kaleem-peeroo Feb 8, 2023
93e1735
refresh buckets added in config
srene Feb 9, 2023
a4ad16e
Implemented refreshBuckets() in RoutingTable
kaleem-peeroo Feb 22, 2023
d125576
Made nodeIdToNode() public and implemented checkAndReplaceLast() in K…
kaleem-peeroo Mar 1, 2023
33a572a
Changed neighbours data structure to list from treemap
kaleem-peeroo Mar 8, 2023
3cebe0c
Made routingTable protected instead of private
kaleem-peeroo Mar 8, 2023
4016a04
Updated checkAndReplaceLast() function. Added routing table to KBucke…
kaleem-peeroo Mar 8, 2023
9e67501
init commit blocks and samples
srene Jan 26, 2023
b0fe98e
block class
srene Feb 2, 2023
b882c2a
block iterator
srene Feb 2, 2023
52cf2b0
traffic generator sample
srene Feb 2, 2023
3fb4cd0
traffic sample generator
srene Feb 3, 2023
ff8cdf4
iterator fix
srene Feb 8, 2023
8feef21
sample rem size
srene Feb 8, 2023
4c011fa
block get random samples id func
srene Feb 8, 2023
0d8b62f
samples publish/query generator
srene Feb 8, 2023
8b3e5c3
disable get log after first found
srene Feb 8, 2023
def54f3
sample id using row and column
srene Feb 10, 2023
fba5b94
traffic generator sample renamed
srene Feb 10, 2023
3dd644d
das lookup operation + protocol class
srene Feb 16, 2023
f0e41d9
get logger
srene Feb 16, 2023
3c3180a
region-based sample placement config and fixes
oascigil Feb 16, 2023
8a8208f
Update README.md
harnen Feb 16, 2023
6e2dd1e
new message
srene Feb 16, 2023
1bc5bf3
das protocolbuilder address
srene Feb 21, 2023
eebf7ec
kad protocol refactor
srene Feb 21, 2023
bdc2343
sample pull from builder
srene Feb 21, 2023
b8f5d6e
block builder wip
srenevic14 Feb 22, 2023
5bd63e3
pull built samples from builder done
srene Feb 22, 2023
20442a4
sample region fix wip
srene Feb 22, 2023
24a4ff4
region calculation fix
srenevic14 Feb 22, 2023
0b5bb20
interface between Das protocol and kademlia protocol to send found no…
srene Feb 23, 2023
7778ffc
search table for lookups
srenevic14 Feb 23, 2023
381dfda
advertise new block instead sample by smample
srenevic14 Feb 23, 2023
63c0367
das lookup wip
srenevic14 Feb 24, 2023
65895d8
new messages
srene Feb 24, 2023
50c1d13
check if sample is part of a block
srene Feb 24, 2023
3aebf6f
get all objects from store
srene Feb 24, 2023
fc4f51a
new messages
srene Feb 24, 2023
8895aec
initial period no new sample blocks, only lookups
srene Feb 24, 2023
761751c
init block samples hashmap fix
srene Feb 24, 2023
5e29f51
init block samples hashmap fix
srene Feb 24, 2023
4f9ec12
revert block
srene Feb 24, 2023
98081d6
block id as parameter
srene Feb 24, 2023
c212f94
fix blockid
srene Feb 24, 2023
c3946a7
complete random lookup done
srene Feb 24, 2023
296531a
random sampling refactor wip
srene Mar 1, 2023
ed62af1
missing file
srenevic14 Mar 1, 2023
97ab4f9
random sampling refactor wip
srenevic14 Mar 2, 2023
094894a
randon sampling operation completed
srene Mar 2, 2023
2a18394
cleaning code
srene Mar 8, 2023
91068c4
reduce samples creation
srene Mar 8, 2023
11d6b25
random sampling gettin only n samples per node
srene Mar 9, 2023
0919026
adding comments
srene Mar 9, 2023
7043cc6
find logging
Countermatt Feb 22, 2023
ebc32d9
full operation loggin - move to operation
Countermatt Feb 23, 2023
a4016ed
correct first comma bug KademliaObserver log
Countermatt Mar 1, 2023
4f53852
modify to have all operation
Countermatt Mar 1, 2023
d900142
config file for malicious DAS protocol scenario
oascigil Mar 13, 2023
93d540a
Malicious DAS protocol implementation
oascigil Mar 13, 2023
b449a67
Bump json from 20200518 to 20230227 in /simulator (#30)
dependabot[bot] Apr 17, 2023
0250e99
samples with double id assignment by row and column reference
srene Apr 18, 2023
ec56df8
kademlia find operation callbacks
srene Apr 24, 2023
469a57b
operation logging extension
srene Apr 24, 2023
379c814
Made nodeIdToNode() public and implemented checkAndReplaceLast() in K…
kaleem-peeroo Mar 1, 2023
1f90b7e
Removed duplicated function.
kaleem-peeroo May 9, 2023
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
7 changes: 6 additions & 1 deletion simulator/config/kademlia.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ TRAFFIC_STEP 300000 #10000000/SIZE
OBSERVER_STEP 100000
#Turbulence module is executed every TURBULENCE_STEP enabling churning
TURBULENCE_STEP (SIM_TIME*20)/SIZE #100000000/SIZE

#Every REFRESH_STEP nodes check a random bucket for dead nodes
REFRESH_STEP 100000

# add network config parameters to simulation
random.seed 24680
Expand Down Expand Up @@ -71,6 +72,10 @@ control.0traffic peersim.kademlia.TrafficGenerator
control.0traffic.protocol 3kademlia
control.0traffic.step TRAFFIC_STEP

#refresh buckets
control.1 peersim.kademlia.RefreshBuckets
control.1.step REFRESH_STEP

# turbulence
#control.2turbolenceAdd peersim.kademlia.Turbulence
#control.2turbolenceAdd.protocol 3kademlia
Expand Down
88 changes: 85 additions & 3 deletions simulator/src/main/java/peersim/kademlia/KBucket.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package peersim.kademlia;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.TreeMap;
import peersim.core.CommonState;
import peersim.core.Node;

/**
* This class implements a kademlia k-bucket. Function for the management of the neighbours update
Expand All @@ -12,30 +16,108 @@
* @version 1.0
*/
public class KBucket implements Cloneable {
// Replacement bucket
protected List<BigInteger> replacements;

// k-bucket array
protected TreeMap<BigInteger, Long> neighbours = null;

// empty costructor
// k-bucket size, max replacement bucket size
protected int k, maxReplacements;

// empty constructor
public KBucket() {
neighbours = new TreeMap<BigInteger, Long>();
replacements = new ArrayList<BigInteger>();
}

public KBucket(int k, int maxReplacements) {
neighbours = new TreeMap<BigInteger, Long>();
replacements = new ArrayList<BigInteger>();
this.k = k;
this.maxReplacements = maxReplacements;
}

public void checkAndReplaceLast() {
if (neighbours.size() == 0 || CommonState.getTime() == 0)
// Entry has moved, don't replace it.
return;

// System.out.println("Replace node "+neighbours.get(neighbours.size()-1)+" at
// "+CommonState.getTime());

// Get a random node
Random random = new Random();

int min = 0;
int max = neighbours.size();
BigInteger randomIndex = new BigInteger(String.valueOf(random.nextInt(max - min + 1) + min));

// KademliaProtocol object to access nodeIDtoNode()
KademliaProtocol kProtocol = new KademliaProtocol(null);

Node node = kProtocol.nodeIdtoNode(randomIndex);

// System.out.println("Replace node "+neighbours.get(neighbours.size()-1)+" at
// "+CommonState.getTime());

// System.out.println("checkAndReplaceLast "+remote.getNode().getId()+" at
// "+CommonState.getTime()+" at "+rTable.nodeId);

if (node.getFailState() != Node.OK) {
// Still the last entry.
removeNeighbour(randomIndex);

if (replacements.size() > 0) {
// Random rand = new Random();
// BigInteger n = replacements.get(rand.nextInt(replacements.size()));
BigInteger n = replacements.get(CommonState.r.nextInt(replacements.size()));
addNeighbour(n);
removeReplacement(n);
}
}
}

// add a neighbour to this k-bucket
public boolean addNeighbour(BigInteger node) {
long time = CommonState.getTime();
if (neighbours.size() < KademliaCommonConfig.K) { // k-bucket isn't full
if (neighbours.size() < k) { // k-bucket isn't full

neighbours.put(node, time); // add neighbour to the tail of the list
removeReplacement(node);

return true;

} else {

addReplacement(node);

return false;
}
return false;
}

// remove a neighbour from this k-bucket
public void removeNeighbour(BigInteger node) {
neighbours.remove(node);
}

public void addReplacement(BigInteger node) {
if (!replacements.contains(node)) {
replacements.add(0, node);

if (replacements.size() > maxReplacements) {
// Replacements is full - remove the last item
replacements.remove(replacements.size() - 1);
}
}
}

public void removeReplacement(BigInteger node) {
if (replacements.size() > 0) {
replacements.remove(node);
}
}

public Object clone() {
KBucket dolly = new KBucket();
for (BigInteger node : neighbours.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void _init() {
* @param searchNodeId BigInteger
* @return Node
*/
private Node nodeIdtoNode(BigInteger searchNodeId) {
public Node nodeIdtoNode(BigInteger searchNodeId) {
if (searchNodeId == null) return null;

int inf = 0;
Expand Down Expand Up @@ -499,6 +499,11 @@ public RoutingTable getRoutingTable() {
return this.routingTable;
}

public void refreshBuckets() {
// logger.warning("Calling refreshbuckets");
routingTable.refreshBuckets();
}

/** Set the protocol ID for this node. */
public void setProtocolID(int protocolID) {
this.kademliaid = protocolID;
Expand Down
28 changes: 28 additions & 0 deletions simulator/src/main/java/peersim/kademlia/RefreshBuckets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package peersim.kademlia;

import peersim.core.Control;
import peersim.core.Network;
import peersim.core.Node;

public class RefreshBuckets implements Control {

private String prefix;

// ______________________________________________________________________________________________
public RefreshBuckets(String prefix) {
this.prefix = prefix;
}

// ______________________________________________________________________________________________
public boolean execute() {
for (int i = 0; i < Network.size(); i++) {
Node iNode = Network.get(i);
if (iNode.getFailState() == Node.OK) {
KademliaProtocol iKad = iNode.getKademliaProtocol();
iKad.refreshBuckets();
}
}

return false;
}
} // End of class
29 changes: 20 additions & 9 deletions simulator/src/main/java/peersim/kademlia/RoutingTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import peersim.core.CommonState;

/**
* Gives an implementation for the rounting table component of a kademlia node
Expand All @@ -20,7 +21,7 @@ public class RoutingTable implements Cloneable {
protected TreeMap<Integer, KBucket> k_buckets = null;

// number of k-buckets
protected int nBuckets;
protected int kBuckets;

// bucket size
protected int k;
Expand All @@ -34,21 +35,21 @@ public class RoutingTable implements Cloneable {
// ______________________________________________________________________________________________
/** instanciates a new empty routing table with the specified size */
// public RoutingTable() {
public RoutingTable(int nBuckets, int k, int maxReplacements) {
public RoutingTable(int kBuckets, int k, int maxReplacements) {

k_buckets = new TreeMap<Integer, KBucket>();
// initialize k-bukets
// initialize k-buckets

this.nBuckets = nBuckets;
this.kBuckets = kBuckets;

this.k = k;

this.maxReplacements = maxReplacements;

bucketMinDistance = KademliaCommonConfig.BITS - nBuckets;
bucketMinDistance = KademliaCommonConfig.BITS - kBuckets;

for (int i = 0; i <= nBuckets; i++) {
k_buckets.put(i, new KBucket());
for (int i = 0; i <= kBuckets; i++) {
k_buckets.put(i, new KBucket(k, maxReplacements));
}
}

Expand Down Expand Up @@ -137,13 +138,23 @@ public BigInteger[] getNeighbours(final BigInteger key, final BigInteger src) {

// ______________________________________________________________________________________________
public Object clone() {
RoutingTable dolly = new RoutingTable(nBuckets, k, maxReplacements);
RoutingTable dolly = new RoutingTable(kBuckets, k, maxReplacements);
for (int i = 0; i < k_buckets.size(); i++) {
k_buckets.put(i, new KBucket()); // (KBucket) k_buckets.get(i).clone());
k_buckets.put(i, new KBucket(k, maxReplacements)); // (KBucket) k_buckets.get(i).clone());
}
return dolly;
}

public void refreshBuckets() {
KBucket b = k_buckets.get(CommonState.r.nextInt(kBuckets));

// Replace the last item in kbucket if its full
if (b != null && b.neighbours.size() > 0) {
b.checkAndReplaceLast();
return;
}
}

// ______________________________________________________________________________________________
/**
* print a string representation of the table
Expand Down