mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-22 02:02:21 +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
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* @throws kademlia.exceptions.ContentNotFoundException
|
||||
*/
|
||||
public StorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException
|
||||
{
|
||||
|
@ -86,6 +86,10 @@ public class DHT
|
||||
if (this.entriesManager.contains(content.getContentMetadata()))
|
||||
{
|
||||
StorageEntryMetadata current = this.entriesManager.get(content.getContentMetadata());
|
||||
|
||||
/* update the last republished time */
|
||||
current.updateLastRepublished();
|
||||
|
||||
if (current.getLastUpdatedTimestamp() >= content.getContentMetadata().getLastUpdatedTimestamp())
|
||||
{
|
||||
/* 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 long updatedTs;
|
||||
|
||||
/* This value is the last time this content was last updated from the network */
|
||||
private long lastRepublished;
|
||||
|
||||
public StorageEntryMetadata(KadContent content)
|
||||
{
|
||||
this.key = content.getKey();
|
||||
@ -26,6 +29,8 @@ public class StorageEntryMetadata
|
||||
this.type = content.getType();
|
||||
this.contentHash = content.hashCode();
|
||||
this.updatedTs = content.getLastUpdatedTimestamp();
|
||||
|
||||
this.lastRepublished = System.currentTimeMillis() / 1000L;
|
||||
}
|
||||
|
||||
public NodeId getKey()
|
||||
@ -84,6 +89,19 @@ public class StorageEntryMetadata
|
||||
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
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
@ -47,14 +47,21 @@ public class ContentRefreshOperation implements Operation
|
||||
/* Get a list of all storage entries for content */
|
||||
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 (StorageEntryMetadata e : entries)
|
||||
{
|
||||
/**
|
||||
* @todo - Paper improvement 1 -
|
||||
* Check last update time of this entry and
|
||||
* only distribute it if it has been last updated > 1 hour ago
|
||||
*/
|
||||
/* Check last update time of this entry and only distribute it if it has been last updated > 1 hour ago */
|
||||
if (e.lastRepublished() > minRepublishTime)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Set that this content is now republished */
|
||||
e.updateLastRepublished();
|
||||
|
||||
/* Get the K closest nodes to this entries */
|
||||
List<Node> closestNodes = this.localNode.getRoutingTable().findClosest(e.getKey(), this.config.k());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user