mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-22 10:12:19 +00:00
Content deletion from a node that is no longer one of the K-Closest is working!
This commit is contained in:
parent
d9fdcc57fd
commit
219e6073ed
@ -12,6 +12,7 @@ import java.util.NoSuchElementException;
|
|||||||
import kademlia.core.Configuration;
|
import kademlia.core.Configuration;
|
||||||
import kademlia.core.GetParameter;
|
import kademlia.core.GetParameter;
|
||||||
import kademlia.exceptions.ContentExistException;
|
import kademlia.exceptions.ContentExistException;
|
||||||
|
import kademlia.exceptions.ContentNotFoundException;
|
||||||
import kademlia.node.NodeId;
|
import kademlia.node.NodeId;
|
||||||
import kademlia.serializer.JsonSerializer;
|
import kademlia.serializer.JsonSerializer;
|
||||||
|
|
||||||
@ -156,6 +157,36 @@ public class DHT
|
|||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a content from local storage
|
||||||
|
*
|
||||||
|
* @param content The Content to Remove
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws kademlia.exceptions.ContentNotFoundException
|
||||||
|
*/
|
||||||
|
public void remove(KadContent content) throws ContentNotFoundException
|
||||||
|
{
|
||||||
|
this.remove(new StorageEntry(content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(StorageEntry entry) throws ContentNotFoundException
|
||||||
|
{
|
||||||
|
String folder = this.getContentStorageFolderName(entry.getKey());
|
||||||
|
File file = new File(folder + File.separator + entry.hashCode() + ".kct");
|
||||||
|
|
||||||
|
entriesManager.remove(entry);
|
||||||
|
|
||||||
|
if (file.exists())
|
||||||
|
{
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new ContentNotFoundException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the folder for which a content should be stored
|
* Get the name of the folder for which a content should be stored
|
||||||
*
|
*
|
||||||
|
@ -7,6 +7,7 @@ import java.util.Map;
|
|||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import kademlia.core.GetParameter;
|
import kademlia.core.GetParameter;
|
||||||
import kademlia.exceptions.ContentExistException;
|
import kademlia.exceptions.ContentExistException;
|
||||||
|
import kademlia.exceptions.ContentNotFoundException;
|
||||||
import kademlia.node.NodeId;
|
import kademlia.node.NodeId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,6 +160,23 @@ class StorageEntryManager
|
|||||||
return entriesRet;
|
return entriesRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void remove(KadContent content) throws ContentNotFoundException
|
||||||
|
{
|
||||||
|
this.remove(new StorageEntry(content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(StorageEntry entry) throws ContentNotFoundException
|
||||||
|
{
|
||||||
|
if (contains(entry))
|
||||||
|
{
|
||||||
|
this.entries.get(entry.getKey()).remove(entry);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new ContentNotFoundException("This content does not exist in the Storage Entries");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
21
src/kademlia/exceptions/ContentNotFoundException.java
Normal file
21
src/kademlia/exceptions/ContentNotFoundException.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package kademlia.exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception used to indicate that a content does not exist on the DHT
|
||||||
|
*
|
||||||
|
* @author Joshua Kissoon
|
||||||
|
* @created 20140322
|
||||||
|
*/
|
||||||
|
public class ContentNotFoundException extends Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
public ContentNotFoundException()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentNotFoundException(String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import kademlia.core.Configuration;
|
|||||||
import kademlia.core.KadServer;
|
import kademlia.core.KadServer;
|
||||||
import kademlia.dht.DHT;
|
import kademlia.dht.DHT;
|
||||||
import kademlia.dht.StorageEntry;
|
import kademlia.dht.StorageEntry;
|
||||||
|
import kademlia.exceptions.ContentNotFoundException;
|
||||||
import kademlia.message.Message;
|
import kademlia.message.Message;
|
||||||
import kademlia.message.StoreContentMessage;
|
import kademlia.message.StoreContentMessage;
|
||||||
import kademlia.node.Node;
|
import kademlia.node.Node;
|
||||||
@ -69,9 +70,19 @@ public class ContentRefreshOperation implements Operation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Delete any content on this node that this node is not one of the K-Closest nodes to */
|
||||||
* @todo Delete any content on this node that this node is not one of the K-Closest nodes to
|
try
|
||||||
*/
|
{
|
||||||
|
if (!closestNodes.contains(this.localNode))
|
||||||
|
{
|
||||||
|
this.dht.remove(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ContentNotFoundException cnfe)
|
||||||
|
{
|
||||||
|
/* It would be weird if the content is not found here */
|
||||||
|
System.err.println("ContentRefreshOperation: Removing content from local node, content not found... Message: " + cnfe.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user