Skip to content

Commit

Permalink
Making the DHT use binary divisions
Browse files Browse the repository at this point in the history
  • Loading branch information
fireduck64 committed Dec 18, 2018
1 parent 9ce4ff2 commit 8f20b6c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/ChannelGlobals.java
Expand Up @@ -14,9 +14,11 @@ public class ChannelGlobals
public static final String NODE_TAG = "node";


public static final int LONG_RANGE_POINTS=2;
public static final int SHORT_RANGE_POINTS=2;
//public static final int LONG_RANGE_POINTS=2;
//public static final int SHORT_RANGE_POINTS=2;
public static final int NEAR_POINTS=4;
public static final int RING_DIVISONS=6;


public static final int DHT_ELEMENT_SIZE = snowblossom.lib.Globals.BLOCKCHAIN_HASH_LEN;

Expand All @@ -25,4 +27,5 @@ public class ChannelGlobals
public static final long MAX_DATA_PEER_AGE=2L * 86400L * 1000L;



}
22 changes: 18 additions & 4 deletions src/DHTMaintainer.java
Expand Up @@ -100,7 +100,7 @@ public void runPass() throws Exception
}
logger.info("Connected peers: " + connected_peers);
logger.info("New connections: " + connect_map.keySet());
int desired_peers = ChannelGlobals.NEAR_POINTS + ChannelGlobals.LONG_RANGE_POINTS + ChannelGlobals.SHORT_RANGE_POINTS;
int desired_peers = ChannelGlobals.NEAR_POINTS + ChannelGlobals.RING_DIVISONS * 2;
int to_close_count = connected_peers.size() - desired_peers;
while ((to_close_count > 0) && (extra_peers.size() > 0))
{
Expand Down Expand Up @@ -144,7 +144,21 @@ private Map<AddressSpecHash, LocalPeerInfo> pickTargetsFromDB()
// Close neighbors
target_map.putAll( getClosestValid( node.getNodeID().getBytes(), ChannelGlobals.NEAR_POINTS));

double long_wedge = 1.0 / ChannelGlobals.LONG_RANGE_POINTS;

double ring_dist= 0.5;
for(int i=0; i<ChannelGlobals.RING_DIVISONS; i++)
{

ByteString t_high = HashMath.shiftHashOnRing( node.getNodeID().getBytes(), ring_dist);
ByteString t_low = HashMath.shiftHashOnRing( node.getNodeID().getBytes(), -ring_dist);

target_map.putAll( getClosestValid( t_high, 1));
target_map.putAll( getClosestValid( t_low, 1));

ring_dist = ring_dist / 2.0;
}

/*double long_wedge = 1.0 / ChannelGlobals.LONG_RANGE_POINTS;
// long range regional peers
// Point 0 is me, so don't bother with that
Expand All @@ -163,7 +177,7 @@ private Map<AddressSpecHash, LocalPeerInfo> pickTargetsFromDB()
{
ByteString target = HashMath.shiftHashOnRing( node.getNodeID().getBytes(), -long_wedge/2.0 + short_wedge * i);
target_map.putAll( getClosestValid( target, 1));
}
}*/

// TODO - if we have a really full ring then the short range peers might not be very close to the target
// and that peer won't have any way to get closer without just doing close neighbors to close neighbor hops
Expand Down Expand Up @@ -310,7 +324,7 @@ public PruneThread()

public void runPass()
{
if (node.getPeerManager().getPeersWithReason("DHT").size() > ChannelGlobals.NEAR_POINTS)
if (node.getPeerManager().getPeersWithReason("DHT").size() > ChannelGlobals.NEAR_POINTS + ChannelGlobals.RING_DIVISONS)
{
byte[] b = new byte[1];

Expand Down
1 change: 0 additions & 1 deletion test/DHTTest.java
Expand Up @@ -52,7 +52,6 @@ public void testDHTReadWrite()

Random rnd = new Random();
byte[] id_bytes = new byte[16];


int b_match = 0;
for(int i=0; i<100; i++)
Expand Down

0 comments on commit 8f20b6c

Please sign in to comment.