mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-21 17:52:21 +00:00
Cleaned up the code a bit
- Removed some unnecessary exception throwing
This commit is contained in:
parent
64dfdda1c3
commit
baeb656050
@ -222,7 +222,10 @@ public class KadServer
|
||||
{
|
||||
receiver = this.receivers.remove(comm);
|
||||
TimerTask task = (TimerTask) tasks.remove(comm);
|
||||
task.cancel();
|
||||
if (task != null)
|
||||
{
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -297,6 +300,11 @@ public class KadServer
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!KadServer.this.isRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
unregister(comm);
|
||||
|
@ -48,7 +48,7 @@ public class MessageFactory
|
||||
case StoreContentMessage.CODE:
|
||||
return new StoreContentMessage(in);
|
||||
default:
|
||||
System.out.println(this.localNode + " - No Message handler found for message. Code: " + code);
|
||||
//System.out.println(this.localNode + " - No Message handler found for message. Code: " + code);
|
||||
return new SimpleMessage(in);
|
||||
|
||||
}
|
||||
@ -67,7 +67,7 @@ public class MessageFactory
|
||||
case StoreContentMessage.CODE:
|
||||
return new StoreContentReceiver(server, this.localNode, this.dht);
|
||||
default:
|
||||
System.out.println("No receiver found for message. Code: " + code);
|
||||
//System.out.println("No receiver found for message. Code: " + code);
|
||||
return new SimpleReceiver();
|
||||
}
|
||||
}
|
||||
|
@ -297,6 +297,8 @@ public class ContentLookupOperation implements Operation, Receiver
|
||||
|
||||
/**
|
||||
* @return The list of all content found during the lookup operation
|
||||
*
|
||||
* @throws kademlia.exceptions.ContentNotFoundException
|
||||
*/
|
||||
public StorageEntry getContentFound() throws ContentNotFoundException
|
||||
{
|
||||
|
@ -39,7 +39,6 @@ public class NodeLookupOperation implements Operation, Receiver
|
||||
|
||||
private final KadServer server;
|
||||
private final KademliaNode localNode;
|
||||
private final NodeId lookupId;
|
||||
private final KadConfiguration config;
|
||||
|
||||
private boolean error;
|
||||
@ -68,7 +67,6 @@ public class NodeLookupOperation implements Operation, Receiver
|
||||
{
|
||||
this.server = server;
|
||||
this.localNode = localNode;
|
||||
this.lookupId = lookupId;
|
||||
this.config = config;
|
||||
|
||||
this.lookupMessage = new NodeLookupMessage(localNode.getNode(), lookupId);
|
||||
@ -79,7 +77,6 @@ public class NodeLookupOperation implements Operation, Receiver
|
||||
*/
|
||||
this.comparator = new KeyComparator(lookupId);
|
||||
this.nodes = new TreeMap(this.comparator);
|
||||
//this.nodes = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,11 +114,17 @@ public class NodeLookupOperation implements Operation, Receiver
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (error)
|
||||
{
|
||||
/* If we still haven't received any responses by then, do a routing timeout */
|
||||
throw new RoutingException("Lookup Timeout.");
|
||||
}
|
||||
|
||||
/**
|
||||
* There is no need to throw an exception here!
|
||||
* If the operation times out means we didn't get replies from all nodes,
|
||||
* so lets just simply return the K-Closest nodes we knoe
|
||||
*/
|
||||
// if (error)
|
||||
// {
|
||||
// /* If we still haven't received any responses by then, do a routing timeout */
|
||||
// throw new RoutingException("Node Lookup Timeout.");
|
||||
// }
|
||||
|
||||
/* Now after we've finished, we would have an idea of offline nodes, lets update our routing table */
|
||||
this.localNode.getRoutingTable().setUnresponsiveContacts(this.getFailedNodes());
|
||||
@ -300,11 +303,11 @@ public class NodeLookupOperation implements Operation, Receiver
|
||||
public synchronized void timeout(int comm) throws IOException
|
||||
{
|
||||
/* Get the node associated with this communication */
|
||||
Node n = this.messagesTransiting.get(new Integer(comm));
|
||||
Node n = this.messagesTransiting.get(comm);
|
||||
|
||||
if (n == null)
|
||||
{
|
||||
throw new UnknownMessageException("Unknown comm: " + comm);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Mark this node as failed and inform the routing table that it is unresponsive */
|
||||
|
Loading…
Reference in New Issue
Block a user