2014-03-09 15:34:18 +00:00
|
|
|
package kademlia.tests;
|
|
|
|
|
|
|
|
import kademlia.core.Kademlia;
|
|
|
|
import kademlia.node.NodeId;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Testing the save and retrieve state operations
|
|
|
|
*
|
|
|
|
* @author Joshua Kissoon
|
|
|
|
* @since 20140309
|
|
|
|
*/
|
|
|
|
public class SaveStateTest
|
|
|
|
{
|
|
|
|
|
2014-03-10 09:07:08 +00:00
|
|
|
public SaveStateTest()
|
2014-03-09 15:34:18 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
/* Setting up 2 Kad networks */
|
2014-03-10 09:07:08 +00:00
|
|
|
Kademlia kad1 = new Kademlia("JoshuaK", new NodeId("ASF45678947584567467"), 7529);
|
|
|
|
Kademlia kad2 = new Kademlia("Crystal", new NodeId("ASERTKJDHGVHERJHGFLK"), 7532);
|
2014-03-09 15:34:18 +00:00
|
|
|
|
|
|
|
/* Connecting 2 to 1 */
|
|
|
|
System.out.println("Connecting Kad 1 and Kad 2");
|
|
|
|
kad1.connect(kad2.getNode());
|
2014-03-10 09:07:08 +00:00
|
|
|
|
|
|
|
synchronized (this)
|
|
|
|
{
|
|
|
|
DHTContentImpl c = new DHTContentImpl(kad2.getOwnerId(), "Some Data");
|
|
|
|
System.out.println(c);
|
|
|
|
kad2.put(c);
|
|
|
|
}
|
|
|
|
|
2014-03-09 15:34:18 +00:00
|
|
|
System.out.println(kad1);
|
|
|
|
System.out.println(kad2);
|
2014-03-10 09:07:08 +00:00
|
|
|
|
2014-03-09 15:34:18 +00:00
|
|
|
/* Shutting down kad1 and restarting it */
|
|
|
|
System.out.println("\n\n\nShutting down Kad instance");
|
|
|
|
kad1.shutdown();
|
|
|
|
|
2014-03-10 08:15:13 +00:00
|
|
|
System.out.println("\n\n\nReloading down Kad instance from file");
|
|
|
|
Kademlia kad3 = Kademlia.loadFromFile("JoshuaK");
|
|
|
|
System.out.println(kad3);
|
2014-03-09 15:34:18 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();;
|
|
|
|
}
|
|
|
|
}
|
2014-03-10 09:07:08 +00:00
|
|
|
|
|
|
|
public static void main(String[] args)
|
|
|
|
{
|
|
|
|
new SaveStateTest();
|
|
|
|
}
|
2014-03-09 15:34:18 +00:00
|
|
|
}
|