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