mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-22 10:12:19 +00:00
Content Refresh Operation improvement
- Added the improvement for content refresh operation from the paper, we keep the last time a content was republished, and on content update operations, we only republish if the last republish was before (current time - republishing time interval)
This commit is contained in:
parent
67c12438d1
commit
a2f48d2241
@ -268,6 +268,7 @@ public class Kademlia
|
|||||||
* @return DHTContent The content
|
* @return DHTContent The content
|
||||||
*
|
*
|
||||||
* @throws java.io.IOException
|
* @throws java.io.IOException
|
||||||
|
* @throws kademlia.exceptions.ContentNotFoundException
|
||||||
*/
|
*/
|
||||||
public StorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException
|
public StorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException
|
||||||
{
|
{
|
||||||
|
@ -86,6 +86,10 @@ public class DHT
|
|||||||
if (this.entriesManager.contains(content.getContentMetadata()))
|
if (this.entriesManager.contains(content.getContentMetadata()))
|
||||||
{
|
{
|
||||||
StorageEntryMetadata current = this.entriesManager.get(content.getContentMetadata());
|
StorageEntryMetadata current = this.entriesManager.get(content.getContentMetadata());
|
||||||
|
|
||||||
|
/* update the last republished time */
|
||||||
|
current.updateLastRepublished();
|
||||||
|
|
||||||
if (current.getLastUpdatedTimestamp() >= content.getContentMetadata().getLastUpdatedTimestamp())
|
if (current.getLastUpdatedTimestamp() >= content.getContentMetadata().getLastUpdatedTimestamp())
|
||||||
{
|
{
|
||||||
/* We have the current content, no need to update it! just leave this method now */
|
/* We have the current content, no need to update it! just leave this method now */
|
||||||
|
@ -19,6 +19,9 @@ public class StorageEntryMetadata
|
|||||||
private final int contentHash;
|
private final int contentHash;
|
||||||
private final long updatedTs;
|
private final long updatedTs;
|
||||||
|
|
||||||
|
/* This value is the last time this content was last updated from the network */
|
||||||
|
private long lastRepublished;
|
||||||
|
|
||||||
public StorageEntryMetadata(KadContent content)
|
public StorageEntryMetadata(KadContent content)
|
||||||
{
|
{
|
||||||
this.key = content.getKey();
|
this.key = content.getKey();
|
||||||
@ -26,6 +29,8 @@ public class StorageEntryMetadata
|
|||||||
this.type = content.getType();
|
this.type = content.getType();
|
||||||
this.contentHash = content.hashCode();
|
this.contentHash = content.hashCode();
|
||||||
this.updatedTs = content.getLastUpdatedTimestamp();
|
this.updatedTs = content.getLastUpdatedTimestamp();
|
||||||
|
|
||||||
|
this.lastRepublished = System.currentTimeMillis() / 1000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeId getKey()
|
public NodeId getKey()
|
||||||
@ -84,6 +89,19 @@ public class StorageEntryMetadata
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long lastRepublished()
|
||||||
|
{
|
||||||
|
return this.lastRepublished;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whenever we republish a content or get this content from the network, we update the last republished time
|
||||||
|
*/
|
||||||
|
public void updateLastRepublished()
|
||||||
|
{
|
||||||
|
this.lastRepublished = System.currentTimeMillis() / 1000L;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o)
|
||||||
{
|
{
|
||||||
|
@ -47,14 +47,21 @@ public class ContentRefreshOperation implements Operation
|
|||||||
/* Get a list of all storage entries for content */
|
/* Get a list of all storage entries for content */
|
||||||
List<StorageEntryMetadata> entries = this.dht.getStorageEntries();
|
List<StorageEntryMetadata> entries = this.dht.getStorageEntries();
|
||||||
|
|
||||||
|
/* If a content was last republished before this time, then we need to republish it */
|
||||||
|
final long minRepublishTime = (System.currentTimeMillis() / 1000L) - this.config.restoreInterval();
|
||||||
|
|
||||||
/* For each storage entry, distribute it */
|
/* For each storage entry, distribute it */
|
||||||
for (StorageEntryMetadata e : entries)
|
for (StorageEntryMetadata e : entries)
|
||||||
{
|
{
|
||||||
/**
|
/* Check last update time of this entry and only distribute it if it has been last updated > 1 hour ago */
|
||||||
* @todo - Paper improvement 1 -
|
if (e.lastRepublished() > minRepublishTime)
|
||||||
* Check last update time of this entry and
|
{
|
||||||
* only distribute it if it has been last updated > 1 hour ago
|
continue;
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
/* Set that this content is now republished */
|
||||||
|
e.updateLastRepublished();
|
||||||
|
|
||||||
/* Get the K closest nodes to this entries */
|
/* Get the K closest nodes to this entries */
|
||||||
List<Node> closestNodes = this.localNode.getRoutingTable().findClosest(e.getKey(), this.config.k());
|
List<Node> closestNodes = this.localNode.getRoutingTable().findClosest(e.getKey(), this.config.k());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user