fixes
This commit is contained in:
parent
d222acda5d
commit
75ef51315c
@ -46,13 +46,13 @@ public class CLI {
|
||||
String fileID = splitted[1];
|
||||
// TODO not implemented
|
||||
// Zum testen:
|
||||
Identifier fileIDToFind = new Identifier(8, fileID.getBytes());
|
||||
FileIdentifier fileIDToFind = new FileIdentifier(1, fileID.getBytes());
|
||||
node.findValue(fileIDToFind);
|
||||
break;
|
||||
//request fileID
|
||||
case "request":
|
||||
String fileID3 = splitted[1];
|
||||
FileIdentifier fileIDToFind2 = new FileIdentifier(8, fileID3.getBytes());
|
||||
FileIdentifier fileIDToFind2 = new FileIdentifier(1, fileID3.getBytes());
|
||||
node.sendDataReq(fileIDToFind2);
|
||||
break;
|
||||
//leave
|
||||
@ -65,7 +65,7 @@ public class CLI {
|
||||
String data = splitted[2];
|
||||
// TODO not implemented
|
||||
// Zum testen:
|
||||
FileIdentifier fileIDToStore = new FileIdentifier(8, fileID2.getBytes());
|
||||
FileIdentifier fileIDToStore = new FileIdentifier(1, fileID2.getBytes());
|
||||
node.store(fileIDToStore);
|
||||
node.storeData(fileIDToStore,data);
|
||||
break;
|
||||
|
||||
@ -4,25 +4,9 @@ import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class FileIdentifier extends Identifier {
|
||||
|
||||
private String fileID;
|
||||
|
||||
|
||||
public FileIdentifier(int size, byte[] fileID) {
|
||||
super(size, fileID);
|
||||
|
||||
/*//calculate SHA-256 Hash of key
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
md.update(fileID.getBytes());
|
||||
this.fileID = md.digest().toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.fileID;
|
||||
}
|
||||
super(size, fileID);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ public class Identifier {
|
||||
private int size;
|
||||
|
||||
public Identifier(int size, byte[] bytes) {
|
||||
this.size = size;
|
||||
this.size = size;
|
||||
this.bits = BitSet.valueOf(bytes);
|
||||
}
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ public class Node {
|
||||
private Identifier nodeID = Identifier.getRandomIdentifier(ID_BITS);
|
||||
private IRoutingTable routingTable = new RoutingTableImpl(BUCKET_SIZE, this);
|
||||
|
||||
private Map<Identifier, String> data = new HashMap<Identifier, String>();;
|
||||
private Map<FileIdentifier, String> data = new HashMap<FileIdentifier, String>();;
|
||||
|
||||
public Node() {
|
||||
System.setProperty("java.net.preferIPv4Stack", "true");
|
||||
@ -234,8 +234,8 @@ public class Node {
|
||||
|
||||
public void sendData(NodeIdentifier receiver, FileIdentifier fileID) {
|
||||
|
||||
String data = "abcdefghijklmnop"; //TODO this shit does not work for some reason // this.data.get(fileID);
|
||||
//String data = this.data.get(fileID);
|
||||
//String data = "abcdefghijklmnop"; //TODO this shit does not work for some reason // this.data.get(fileID);
|
||||
String data = this.data.get(fileID);
|
||||
if(data == null){
|
||||
//TODO We dont have that data. -> DOES NOT WORK PROPERLY!
|
||||
new Exception().printStackTrace();
|
||||
@ -453,7 +453,7 @@ public class Node {
|
||||
return send(n, MessageType.LEAVE, null, false, null);
|
||||
}
|
||||
|
||||
public void storeData(Identifier id, String data) {
|
||||
public void storeData(FileIdentifier id, String data) {
|
||||
this.data.put(id, data);
|
||||
LOGGER.log(Level.INFO, "Stored Data [{0}] as [{1}])",
|
||||
new Object[] { data, id});
|
||||
|
||||
@ -25,7 +25,7 @@ public class UDPHandler implements Runnable {
|
||||
|
||||
private Node node;
|
||||
|
||||
Map<FileIdentifier, ArrayList<String>> chunklist = new HashMap<FileIdentifier, ArrayList<String>>();
|
||||
HashMap<FileIdentifier, HashMap<Integer,String> > chunklist = new HashMap<FileIdentifier, HashMap<Integer, String> >();
|
||||
|
||||
public UDPHandler(Node node) {
|
||||
this.node = node;
|
||||
@ -58,7 +58,7 @@ public class UDPHandler implements Runnable {
|
||||
result[i] = buffer.get();
|
||||
}
|
||||
return new Identifier(Node.ID_BITS, result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a triple <IP address, port, id> from the channel and returns a
|
||||
@ -243,9 +243,9 @@ public class UDPHandler implements Runnable {
|
||||
|
||||
FileIdentifier fid = new FileIdentifier(8,fileID.getBytes());
|
||||
if(chunklist.get(fid) == null){
|
||||
chunklist.put(fid, new ArrayList<String>());
|
||||
chunklist.put(fid, new HashMap<Integer,String>());
|
||||
}
|
||||
chunklist.get(fid).add(chunkContent);
|
||||
chunklist.get(fid).put(chunkID, chunkContent);
|
||||
|
||||
if(chunklist.get(fid).size() >= chunkCount){
|
||||
LOGGER.log(Level.INFO,"FILE complete file: "+fileID+" count: "+chunkCount+" id: "+chunkID);
|
||||
@ -254,8 +254,10 @@ public class UDPHandler implements Runnable {
|
||||
//TODO Reihenfolge!!!
|
||||
file += chunklist.get(fid).get(i);
|
||||
}
|
||||
//node.store(fid);
|
||||
node.storeData(fid, file);
|
||||
chunklist.remove(fid);
|
||||
LOGGER.log(Level.INFO,"FILE DATA: "+file);
|
||||
}
|
||||
|
||||
// This should be the answer to a prior FIND_NODE -> mark this RPC ID as
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user