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-22 06:02:41 +00:00
|
|
|
Kademlia kad1 = new Kademlia("JoshuaK", new NodeId("ASF45678947584567463"), 12049);
|
|
|
|
Kademlia kad2 = new Kademlia("Crystal", new NodeId("ASF45678947584567464"), 4585);
|
|
|
|
Kademlia kad3 = new Kademlia("Shameer", new NodeId("ASF45678947584567465"), 8104);
|
|
|
|
Kademlia kad4 = new Kademlia("Lokesh", new NodeId("ASF45678947584567466"), 8335);
|
|
|
|
Kademlia kad5 = new Kademlia("Chandu", new NodeId("ASF45678947584567467"), 13345);
|
|
|
|
|
2014-03-09 15:34:18 +00:00
|
|
|
/* Connecting 2 to 1 */
|
2014-03-22 05:23:05 +00:00
|
|
|
System.out.println("Connecting Nodes 1 & 2");
|
2014-03-22 06:02:41 +00:00
|
|
|
kad2.bootstrap(kad1.getNode());
|
2014-03-22 05:23:05 +00:00
|
|
|
System.out.println(kad1);
|
|
|
|
System.out.println(kad2);
|
2014-03-22 06:02:41 +00:00
|
|
|
|
|
|
|
kad3.bootstrap(kad2.getNode());
|
2014-03-22 05:23:05 +00:00
|
|
|
System.out.println(kad1);
|
|
|
|
System.out.println(kad2);
|
2014-03-22 06:02:41 +00:00
|
|
|
System.out.println(kad3);
|
|
|
|
|
|
|
|
kad4.bootstrap(kad2.getNode());
|
2014-03-22 05:23:05 +00:00
|
|
|
System.out.println(kad1);
|
|
|
|
System.out.println(kad2);
|
|
|
|
System.out.println(kad3);
|
|
|
|
System.out.println(kad4);
|
2014-03-22 06:02:41 +00:00
|
|
|
|
2014-03-22 05:23:05 +00:00
|
|
|
kad5.bootstrap(kad4.getNode());
|
2014-03-22 06:02:41 +00:00
|
|
|
|
2014-03-22 05:23:05 +00:00
|
|
|
System.out.println(kad1);
|
|
|
|
System.out.println(kad2);
|
|
|
|
System.out.println(kad3);
|
|
|
|
System.out.println(kad4);
|
|
|
|
System.out.println(kad5);
|
2014-03-22 06:02:41 +00:00
|
|
|
|
2014-03-10 09:07:08 +00:00
|
|
|
synchronized (this)
|
|
|
|
{
|
2014-03-22 05:23:05 +00:00
|
|
|
System.out.println("\n\n\n\nSTORING CONTENT 1\n\n\n\n");
|
2014-03-10 09:07:08 +00:00
|
|
|
DHTContentImpl c = new DHTContentImpl(kad2.getOwnerId(), "Some Data");
|
|
|
|
System.out.println(c);
|
2014-03-22 06:02:41 +00:00
|
|
|
kad2.put(c);
|
2014-03-22 05:23:05 +00:00
|
|
|
}
|
2014-03-22 06:02:41 +00:00
|
|
|
|
2014-03-22 05:23:05 +00:00
|
|
|
synchronized (this)
|
|
|
|
{
|
|
|
|
System.out.println("\n\n\n\nSTORING CONTENT 2\n\n\n\n");
|
|
|
|
DHTContentImpl c2 = new DHTContentImpl(kad2.getOwnerId(), "Some other Data");
|
|
|
|
System.out.println(c2);
|
2014-03-22 06:02:41 +00:00
|
|
|
kad4.put(c2);
|
2014-03-10 09:07:08 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 15:34:18 +00:00
|
|
|
System.out.println(kad1);
|
|
|
|
System.out.println(kad2);
|
2014-03-22 05:23:05 +00:00
|
|
|
System.out.println(kad3);
|
|
|
|
System.out.println(kad4);
|
|
|
|
System.out.println(kad5);
|
2014-03-22 06:02:41 +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");
|
2014-03-22 05:23:05 +00:00
|
|
|
System.out.println(kad2);
|
2014-03-26 10:53:17 +00:00
|
|
|
kad1.shutdown(true);
|
2014-03-09 15:34:18 +00:00
|
|
|
|
2014-03-22 05:23:05 +00:00
|
|
|
System.out.println("\n\n\nReloading Kad instance from file");
|
|
|
|
Kademlia kadR2 = Kademlia.loadFromFile("JoshuaK");
|
|
|
|
System.out.println(kadR2);
|
2014-03-22 06:02:41 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 15:34:18 +00:00
|
|
|
catch (Exception e)
|
|
|
|
{
|
2014-03-22 05:23:05 +00:00
|
|
|
e.printStackTrace();
|
2014-03-09 15:34:18 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-10 09:07:08 +00:00
|
|
|
|
|
|
|
public static void main(String[] args)
|
|
|
|
{
|
|
|
|
new SaveStateTest();
|
|
|
|
}
|
2014-03-09 15:34:18 +00:00
|
|
|
}
|