Re-Arranged a few packages a bit

Added a HashCalculator class
This commit is contained in:
Joshua Kissoon 2014-04-05 22:36:46 +05:30
parent 2dde2a75e0
commit 51de9cbc82
11 changed files with 38 additions and 59 deletions

View File

@ -30,9 +30,9 @@ import kademlia.operation.Operation;
import kademlia.operation.KadRefreshOperation;
import kademlia.operation.StoreOperation;
import kademlia.routing.RoutingTable;
import kademlia.serializer.JsonDHTSerializer;
import kademlia.serializer.JsonRoutingTableSerializer;
import kademlia.serializer.JsonSerializer;
import kademlia.util.serializer.JsonDHTSerializer;
import kademlia.util.serializer.JsonRoutingTableSerializer;
import kademlia.util.serializer.JsonSerializer;
/**
* The main Kademlia network management class

View File

@ -13,8 +13,8 @@ import kademlia.core.KadConfiguration;
import kademlia.exceptions.ContentExistException;
import kademlia.exceptions.ContentNotFoundException;
import kademlia.node.NodeId;
import kademlia.serializer.JsonSerializer;
import kademlia.serializer.KadSerializer;
import kademlia.util.serializer.JsonSerializer;
import kademlia.util.serializer.KadSerializer;
/**
* The main Distributed Hash Table class that manages the entire DHT

View File

@ -5,7 +5,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import kademlia.dht.GetParameter;
import kademlia.node.Node;
import kademlia.serializer.JsonSerializer;
import kademlia.util.serializer.JsonSerializer;
/**
* Messages used to send to another node requesting content.

View File

@ -5,7 +5,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import kademlia.dht.StorageEntry;
import kademlia.node.Node;
import kademlia.serializer.JsonSerializer;
import kademlia.util.serializer.JsonSerializer;
/**
* A Message used to send content between nodes

View File

@ -6,7 +6,7 @@ import java.io.IOException;
import kademlia.dht.KadContent;
import kademlia.dht.StorageEntry;
import kademlia.node.Node;
import kademlia.serializer.JsonSerializer;
import kademlia.util.serializer.JsonSerializer;
/**
* A StoreContentMessage used to send a store message to a node

View File

@ -1,47 +0,0 @@
/**
* @author Joshua Kissoon
* @created 20140218
* @desc Serializes a message into a json message
*/
package kademlia.util;
import com.google.gson.Gson;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import kademlia.message.Message;
public class JsonSerializer
{
private final Gson gson;
public JsonSerializer()
{
this.gson = new Gson();
}
/**
* Writes a message to an output stream
*
* @param msg The message to write
* @param out The output stream to write the message to
*/
public void write(Message msg, OutputStream out)
{
try (JsonWriter writer = new JsonWriter(new OutputStreamWriter(out)))
{
writer.beginArray();
this.gson.toJson(msg, msg.getClass(), writer);
writer.endArray();
}
catch (IOException e)
{
}
}
}

View File

@ -0,0 +1,26 @@
package kademlia.util.hashing;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* A class that is used to calculate the hash of strings.
*
* @author Joshua Kissoon
* @since 20140405
*/
public class HashCalculator
{
public static byte[] sha1Hash(String toHash) throws NoSuchAlgorithmException
{
/* Create a MessageDigest */
MessageDigest md = MessageDigest.getInstance("SHA-1");
/* Add password bytes to digest */
md.update(toHash.getBytes());
/* Get the hashed bytes */
return md.digest();
}
}

View File

@ -1,4 +1,4 @@
package kademlia.serializer;
package kademlia.util.serializer;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

View File

@ -1,4 +1,4 @@
package kademlia.serializer;
package kademlia.util.serializer;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

View File

@ -1,4 +1,4 @@
package kademlia.serializer;
package kademlia.util.serializer;
import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;

View File

@ -1,4 +1,4 @@
package kademlia.serializer;
package kademlia.util.serializer;
import java.io.DataInputStream;
import java.io.DataOutputStream;