mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-22 02:02:21 +00:00
Updated the JKademliaNode class to inherit the KademliaNode interface
This commit is contained in:
parent
a24eef8091
commit
66616a7afd
@ -40,7 +40,7 @@ import kademlia.util.serializer.JsonSerializer;
|
|||||||
* @todo Handle IPv6 Addresses
|
* @todo Handle IPv6 Addresses
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JKademliaNode
|
public class JKademliaNode implements KademliaNode
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Kademlia Attributes */
|
/* Kademlia Attributes */
|
||||||
@ -99,9 +99,7 @@ public class JKademliaNode
|
|||||||
this.startRefreshOperation();
|
this.startRefreshOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Schedule the recurring refresh operation
|
|
||||||
*/
|
|
||||||
public final void startRefreshOperation()
|
public final void startRefreshOperation()
|
||||||
{
|
{
|
||||||
this.refreshOperationTimer = new Timer(true);
|
this.refreshOperationTimer = new Timer(true);
|
||||||
@ -124,6 +122,7 @@ public class JKademliaNode
|
|||||||
refreshOperationTimer.schedule(refreshOperationTTask, this.config.restoreInterval(), this.config.restoreInterval());
|
refreshOperationTimer.schedule(refreshOperationTTask, this.config.restoreInterval(), this.config.restoreInterval());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final void stopRefreshOperation()
|
public final void stopRefreshOperation()
|
||||||
{
|
{
|
||||||
/* Close off the timer tasks */
|
/* Close off the timer tasks */
|
||||||
@ -223,47 +222,31 @@ public class JKademliaNode
|
|||||||
return new JKademliaNode(ownerId, inode, ikad.getPort(), idht, irtbl, iconfig);
|
return new JKademliaNode(ownerId, inode, ikad.getPort(), idht, irtbl, iconfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @return Node The local node for this system
|
|
||||||
*/
|
|
||||||
public Node getNode()
|
public Node getNode()
|
||||||
{
|
{
|
||||||
return this.localNode;
|
return this.localNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @return The KadServer used to send/receive messages
|
|
||||||
*/
|
|
||||||
public KadServer getServer()
|
public KadServer getServer()
|
||||||
{
|
{
|
||||||
return this.server;
|
return this.server;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @return The DHT for this kad instance
|
|
||||||
*/
|
|
||||||
public DHT getDHT()
|
public DHT getDHT()
|
||||||
{
|
{
|
||||||
return this.dht;
|
return this.dht;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @return The current KadConfiguration object being used
|
|
||||||
*/
|
|
||||||
public KadConfiguration getCurrentConfiguration()
|
public KadConfiguration getCurrentConfiguration()
|
||||||
{
|
{
|
||||||
return this.config;
|
return this.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Connect to an existing peer-to-peer network.
|
|
||||||
*
|
|
||||||
* @param n The known node in the peer-to-peer network
|
|
||||||
*
|
|
||||||
* @throws RoutingException If the bootstrap node could not be contacted
|
|
||||||
* @throws IOException If a network error occurred
|
|
||||||
* @throws IllegalStateException If this object is closed
|
|
||||||
* */
|
|
||||||
public synchronized final void bootstrap(Node n) throws IOException, RoutingException
|
public synchronized final void bootstrap(Node n) throws IOException, RoutingException
|
||||||
{
|
{
|
||||||
long startTime = System.nanoTime();
|
long startTime = System.nanoTime();
|
||||||
@ -273,34 +256,14 @@ public class JKademliaNode
|
|||||||
this.statistician.setBootstrapTime(endTime - startTime);
|
this.statistician.setBootstrapTime(endTime - startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Stores the specified value under the given key
|
|
||||||
* This value is stored on K nodes on the network, or all nodes if there are > K total nodes in the network
|
|
||||||
*
|
|
||||||
* @param content The content to put onto the DHT
|
|
||||||
*
|
|
||||||
* @return Integer How many nodes the content was stored on
|
|
||||||
*
|
|
||||||
* @throws java.io.IOException
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public int put(KadContent content) throws IOException
|
public int put(KadContent content) throws IOException
|
||||||
{
|
{
|
||||||
return this.put(new StorageEntry(content));
|
return this.put(new StorageEntry(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Stores the specified value under the given key
|
public int put(StorageEntry entry) throws IOException
|
||||||
* This value is stored on K nodes on the network, or all nodes if there are > K total nodes in the network
|
|
||||||
*
|
|
||||||
* @param entry The StorageEntry with the content to put onto the DHT
|
|
||||||
*
|
|
||||||
* @return Integer How many nodes the content was stored on
|
|
||||||
*
|
|
||||||
* @throws java.io.IOException
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private int put(StorageEntry entry) throws IOException
|
|
||||||
{
|
{
|
||||||
StoreOperation sop = new StoreOperation(this.server, this, entry, this.dht, this.config);
|
StoreOperation sop = new StoreOperation(this.server, this, entry, this.dht, this.config);
|
||||||
sop.execute();
|
sop.execute();
|
||||||
@ -309,28 +272,13 @@ public class JKademliaNode
|
|||||||
return sop.numNodesStoredAt();
|
return sop.numNodesStoredAt();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Store a content on the local node's DHT
|
|
||||||
*
|
|
||||||
* @param content The content to put on the DHT
|
|
||||||
*
|
|
||||||
* @throws java.io.IOException
|
|
||||||
*/
|
|
||||||
public void putLocally(KadContent content) throws IOException
|
public void putLocally(KadContent content) throws IOException
|
||||||
{
|
{
|
||||||
this.dht.store(new StorageEntry(content));
|
this.dht.store(new StorageEntry(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Get some content stored on the DHT
|
|
||||||
*
|
|
||||||
* @param param The parameters used to search for the content
|
|
||||||
*
|
|
||||||
* @return DHTContent The content
|
|
||||||
*
|
|
||||||
* @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
|
||||||
{
|
{
|
||||||
if (this.dht.contains(param))
|
if (this.dht.contains(param))
|
||||||
@ -348,39 +296,25 @@ public class JKademliaNode
|
|||||||
return clo.getContentFound();
|
return clo.getContentFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Allow the user of the System to call refresh even out of the normal Kad refresh timing
|
|
||||||
*
|
|
||||||
* @throws java.io.IOException
|
|
||||||
*/
|
|
||||||
public void refresh() throws IOException
|
public void refresh() throws IOException
|
||||||
{
|
{
|
||||||
new KadRefreshOperation(this.server, this, this.dht, this.config).execute();
|
new KadRefreshOperation(this.server, this, this.dht, this.config).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @return String The ID of the owner of this local network
|
|
||||||
*/
|
|
||||||
public String getOwnerId()
|
public String getOwnerId()
|
||||||
{
|
{
|
||||||
return this.ownerId;
|
return this.ownerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @return Integer The port on which this kad instance is running
|
|
||||||
*/
|
|
||||||
public int getPort()
|
public int getPort()
|
||||||
{
|
{
|
||||||
return this.udpPort;
|
return this.udpPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Here we handle properly shutting down the Kademlia instance
|
|
||||||
*
|
|
||||||
* @param saveState Whether to save the application state or not
|
|
||||||
*
|
|
||||||
* @throws java.io.FileNotFoundException
|
|
||||||
*/
|
|
||||||
public void shutdown(final boolean saveState) throws IOException
|
public void shutdown(final boolean saveState) throws IOException
|
||||||
{
|
{
|
||||||
/* Shut down the server */
|
/* Shut down the server */
|
||||||
@ -396,12 +330,8 @@ public class JKademliaNode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Saves the node state to a text file
|
public void saveKadState() throws IOException
|
||||||
*
|
|
||||||
* @throws java.io.FileNotFoundException
|
|
||||||
*/
|
|
||||||
private void saveKadState() throws IOException
|
|
||||||
{
|
{
|
||||||
DataOutputStream dout;
|
DataOutputStream dout;
|
||||||
|
|
||||||
@ -450,17 +380,13 @@ public class JKademliaNode
|
|||||||
return nodeStateFolder.toString();
|
return nodeStateFolder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @return The routing table for this node.
|
|
||||||
*/
|
|
||||||
public RoutingTable getRoutingTable()
|
public RoutingTable getRoutingTable()
|
||||||
{
|
{
|
||||||
return this.routingTable;
|
return this.routingTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @return The statistician that manages all statistics
|
|
||||||
*/
|
|
||||||
public KadStatistician getStatistician()
|
public KadStatistician getStatistician()
|
||||||
{
|
{
|
||||||
return this.statistician;
|
return this.statistician;
|
||||||
|
Loading…
Reference in New Issue
Block a user