mirror of
https://github.com/binlaab/nanofiles.git
synced 2026-07-01 18:26:30 +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
|
// TODO: localizar peers con el hash solicitado (o uno concreto) y delegar en
|
||||||
// downloadFileFromServers
|
// downloadFileFromServers
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
if (targetPeerNickname == "*") {
|
if (targetPeerNickname.equals("*")) {
|
||||||
Map<String, InetSocketAddress[]> peersWithFile = new HashMap<String, InetSocketAddress[]>();
|
Map<String, InetSocketAddress[]> peersWithFile = new HashMap<String, InetSocketAddress[]>();
|
||||||
try {
|
try {
|
||||||
DirectoryConnector dc = new DirectoryConnector(dirLogic.getDirectoryHostname()); // la verdad que debería poder sacarlo de dirLogic
|
DirectoryConnector dc = new DirectoryConnector(dirLogic.getDirectoryHostname()); // la verdad que debería poder sacarlo de dirLogic
|
||||||
peersWithFile = dc.searchFilesByHash(targetHashSubstring);
|
peersWithFile = dc.searchFilesByHash(targetHashSubstring);
|
||||||
|
|
||||||
} catch (IOException e) { e.printStackTrace(); }
|
} catch (IOException e) { e.printStackTrace(); }
|
||||||
|
if (peersWithFile.isEmpty()) return false;
|
||||||
success = downloadFileFromServers(peersWithFile.values().iterator().next(), peersWithFile.keySet().iterator().next()); // dios
|
success = downloadFileFromServers(peersWithFile.values().iterator().next(), peersWithFile.keySet().iterator().next()); // dios
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
InetSocketAddress[] peerAddr = new InetSocketAddress[] {dirLogic.fetchPeerList().get(targetPeerNickname)};
|
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
|
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(); }
|
} catch (IOException e) { e.printStackTrace(); }
|
||||||
System.out.println("Hemos descargado algo? success = " + success);
|
|
||||||
}
|
}
|
||||||
|
System.out.println("Hemos descargado algo? success = " + success);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -217,7 +219,6 @@ public class NFControllerLogicP2P {
|
|||||||
String filename = "";
|
String filename = "";
|
||||||
|
|
||||||
NFConnector[] peerConns = new NFConnector[serverAddressList.length];
|
NFConnector[] peerConns = new NFConnector[serverAddressList.length];
|
||||||
|
|
||||||
for (int i = 0; i < serverAddressList.length; i++) {
|
for (int i = 0; i < serverAddressList.length; i++) {
|
||||||
try {
|
try {
|
||||||
NFConnector nfc = new NFConnector(serverAddressList[i]);
|
NFConnector nfc = new NFConnector(serverAddressList[i]);
|
||||||
|
|||||||
@@ -349,12 +349,15 @@ public class DirectoryConnector {
|
|||||||
Map<String, InetSocketAddress[]> results = new LinkedHashMap<String, InetSocketAddress[]>();
|
Map<String, InetSocketAddress[]> results = new LinkedHashMap<String, InetSocketAddress[]>();
|
||||||
|
|
||||||
Map<String, InetSocketAddress> peers = getPeerList();
|
Map<String, InetSocketAddress> peers = getPeerList();
|
||||||
|
InetSocketAddress miIP = peers.get(NanoFiles.peerNickname);
|
||||||
|
|
||||||
for (InetSocketAddress addr : peers.values()) {
|
for (InetSocketAddress addr : peers.values()) {
|
||||||
|
if (miIP == addr) continue;
|
||||||
try {
|
try {
|
||||||
NFConnector nfc = new NFConnector(addr);
|
NFConnector nfc = new NFConnector(addr);
|
||||||
FileInfo[] peerFiles = nfc.getFileList();
|
FileInfo[] peerFiles = nfc.getFileList();
|
||||||
|
|
||||||
|
|
||||||
// la longitud tiene que ser EXACTAMENTE 1, si es 0 no hay, si es > 1 es ambiguo
|
// 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?
|
// 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?
|
// mando que no se ha podido descargar? comparo contra el hash del primero?
|
||||||
|
|||||||
Reference in New Issue
Block a user