implemented find_value but still not finished!
This commit is contained in:
parent
61dc4a1a32
commit
1842cc0b62
@ -1,15 +1,16 @@
|
||||
package message;
|
||||
|
||||
public class MessageType {
|
||||
public final static byte FIND_NODE = 0;
|
||||
public final static byte NODES = 1;
|
||||
public final static byte FIND_NODE = 0;
|
||||
public final static byte NODES = 1;
|
||||
|
||||
public final static byte PING = 10;
|
||||
public final static byte PONG = 11;
|
||||
public final static byte PING = 10;
|
||||
public final static byte PONG = 11;
|
||||
|
||||
public final static byte LEAVE = 2;
|
||||
public final static byte LEAVE = 2;
|
||||
|
||||
public final static byte FIND_VALUE = 4;
|
||||
public final static byte STORE = 5;
|
||||
public final static byte DATA = 6;
|
||||
public final static byte FIND_VALUE = 4;
|
||||
public final static byte STORE = 5;
|
||||
public final static byte DATA = 6;
|
||||
public final static byte VALUE_NODES = 7;
|
||||
}
|
||||
|
||||
@ -147,8 +147,14 @@ public class Node {
|
||||
* An RPC ID (because this is always an answer to a FIND_NODE
|
||||
* RPC)
|
||||
*/
|
||||
void sendClosestNodesTo(NodeIdentifier receiver, Identifier idToFind, Identifier rpcID) {
|
||||
//TODO modify to match FIND_VALUE
|
||||
void sendClosestNodesTo(NodeIdentifier receiver, Identifier idToFind, Identifier rpcID, boolean nodeType) {
|
||||
byte msgtype = 0;
|
||||
if(nodeType) {
|
||||
msgtype = MessageType.NODES;
|
||||
} else {
|
||||
msgtype = MessageType.VALUE_NODES;
|
||||
}
|
||||
|
||||
Set<NodeIdentifier> closeNodes = routingTable.getClosestNodesTo(idToFind);
|
||||
int numNodes = closeNodes.size();
|
||||
|
||||
@ -162,7 +168,7 @@ public class Node {
|
||||
}
|
||||
}
|
||||
|
||||
boolean successful = send(receiver, MessageType.NODES, rpcID,
|
||||
boolean successful = send(receiver, msgtype, rpcID,
|
||||
nodes.array(), false, null);
|
||||
|
||||
if (successful) {
|
||||
|
||||
@ -124,15 +124,10 @@ public class UDPHandler implements Runnable {
|
||||
new Object[] { from.toString() });
|
||||
break;
|
||||
case MessageType.FIND_VALUE:
|
||||
//TODO implement
|
||||
LOGGER.log(Level.INFO, "Received FIND_VALUE from {0}",
|
||||
new Object[] { from.toString() });
|
||||
receiveFindValue(fromID, rpcID);
|
||||
break;
|
||||
case MessageType.STORE:
|
||||
//TODO implemnt
|
||||
receiveStore(fromID, rpcID);
|
||||
LOGGER.log(Level.INFO, "Received STORE from {0}",
|
||||
new Object[] { from.toString() });
|
||||
break;
|
||||
case MessageType.DATA:
|
||||
//TODO implemnt
|
||||
@ -216,18 +211,29 @@ public class UDPHandler implements Runnable {
|
||||
LOGGER.log(Level.INFO, "Received [FIND_NODE {0}] from Node {1}",
|
||||
new Object[] { idToFind, fromID });
|
||||
|
||||
node.sendClosestNodesTo(fromID, idToFind, rpc_id);
|
||||
node.sendClosestNodesTo(fromID, idToFind, rpc_id, true);
|
||||
}
|
||||
|
||||
private void receiveStore(NodeIdentifier fromID, Identifier rpcID) {
|
||||
Identifier fileID = getIDFromBuffer();
|
||||
|
||||
LOGGER.log(Level.INFO, "Received [STORE{0}] from Node {1}",
|
||||
LOGGER.log(Level.INFO, "Received [STORE {0}] from Node {1}",
|
||||
new Object[] { fileID, fromID });
|
||||
|
||||
node.storePair(fileID, fromID);
|
||||
node.receivedRPC(fromID, rpcID);
|
||||
}
|
||||
|
||||
private void receiveFindValue(NodeIdentifier fromID, Identifier rpcID) {
|
||||
Identifier fileID = getIDFromBuffer();
|
||||
|
||||
LOGGER.log(Level.INFO, "Received [FIND VALUE {0}] from Node {1}",
|
||||
new Object[] { fileID, fromID });
|
||||
|
||||
node.sendClosestNodesTo(fromID, fileID, rpcID, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void terminate() {
|
||||
running = false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user