mirror of
https://github.com/binlaab/nanofiles.git
synced 2026-07-01 12:17:21 +02:00
ahora peerdl * no descarga de sí mismo
This commit is contained in:
@@ -165,14 +165,16 @@ public class NFControllerLogicP2P {
|
||||
// TODO: localizar peers con el hash solicitado (o uno concreto) y delegar en
|
||||
// downloadFileFromServers
|
||||
boolean success = false;
|
||||
if (targetPeerNickname == "*") {
|
||||
if (targetPeerNickname.equals("*")) {
|
||||
Map<String, InetSocketAddress[]> peersWithFile = new HashMap<String, InetSocketAddress[]>();
|
||||
try {
|
||||
DirectoryConnector dc = new DirectoryConnector(dirLogic.getDirectoryHostname()); // la verdad que debería poder sacarlo de dirLogic
|
||||
peersWithFile = dc.searchFilesByHash(targetHashSubstring);
|
||||
|
||||
} catch (IOException e) { e.printStackTrace(); }
|
||||
if (peersWithFile.isEmpty()) return false;
|
||||
success = downloadFileFromServers(peersWithFile.values().iterator().next(), peersWithFile.keySet().iterator().next()); // dios
|
||||
|
||||
} else {
|
||||
try {
|
||||
InetSocketAddress[] peerAddr = new InetSocketAddress[] {dirLogic.fetchPeerList().get(targetPeerNickname)};
|
||||
@@ -190,8 +192,8 @@ public class NFControllerLogicP2P {
|
||||
|
||||
success = downloadFileFromServers(peerAddr, found[0].fileHash); // voy a darle el hash entero, más fácil que volver a buscarlo
|
||||
} catch (IOException e) { e.printStackTrace(); }
|
||||
System.out.println("Hemos descargado algo? success = " + success);
|
||||
}
|
||||
System.out.println("Hemos descargado algo? success = " + success);
|
||||
return success;
|
||||
}
|
||||
/**
|
||||
@@ -217,7 +219,6 @@ public class NFControllerLogicP2P {
|
||||
String filename = "";
|
||||
|
||||
NFConnector[] peerConns = new NFConnector[serverAddressList.length];
|
||||
|
||||
for (int i = 0; i < serverAddressList.length; i++) {
|
||||
try {
|
||||
NFConnector nfc = new NFConnector(serverAddressList[i]);
|
||||
|
||||
@@ -349,12 +349,15 @@ public class DirectoryConnector {
|
||||
Map<String, InetSocketAddress[]> results = new LinkedHashMap<String, InetSocketAddress[]>();
|
||||
|
||||
Map<String, InetSocketAddress> peers = getPeerList();
|
||||
InetSocketAddress miIP = peers.get(NanoFiles.peerNickname);
|
||||
|
||||
for (InetSocketAddress addr : peers.values()) {
|
||||
if (miIP == addr) continue;
|
||||
try {
|
||||
NFConnector nfc = new NFConnector(addr);
|
||||
FileInfo[] peerFiles = nfc.getFileList();
|
||||
|
||||
|
||||
// la longitud tiene que ser EXACTAMENTE 1, si es 0 no hay, si es > 1 es ambiguo
|
||||
// y si resulta que dos peers tienen un mismo subhash sin tener el mismo hash?
|
||||
// mando que no se ha podido descargar? comparo contra el hash del primero?
|
||||
|
||||
Reference in New Issue
Block a user