From 654758c14b87d8747b449ef060a8362ed819b2e0 Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Wed, 1 Apr 2020 23:26:54 +0200 Subject: [PATCH] Fix #58 (#99) Fix #58 --- src/clientP2P/ClientDownload.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/clientP2P/ClientDownload.java b/src/clientP2P/ClientDownload.java index f1b44f9..a43a349 100644 --- a/src/clientP2P/ClientDownload.java +++ b/src/clientP2P/ClientDownload.java @@ -35,6 +35,8 @@ import protocolP2P.FilePart; import protocolP2P.SizeRequest; import protocolP2P.SizeResponse; import protocolP2P.ProtocolP2PPacket; +import protocolP2P.DiscoverRequest; +import protocolP2P.DiscoverResponse; import protocolP2P.UpdateRatio; import clientP2P.ClientDownloadPart; import tools.HostItem; @@ -391,6 +393,24 @@ public abstract class ClientDownload extends ServeErrors implements Runnable { // get size setSize(); + // get hostlist from tracker + try { + ProtocolP2PPacket req = createProtocolP2PPacket(new DiscoverRequest(filename)); + req.sendRequest(getHostItemSocket(tracker)); + Payload resp = req.receiveResponse().getPayload(); + if (!(resp instanceof DiscoverResponse)) { + throw new InternalError(); + } + DiscoverResponse p = (DiscoverResponse)resp; + hostList = p.getHostList(); + } catch(IOException e) { + throw new InternalError(); + } catch(RemoteException e) { + throw new InternalError(); + } catch(LocalException e) { + throw new InternalError(); + } + // get hashsum from 1st server in list hash512 = getHashSum512(hostList.get(0)); if (hash512.length == 0) {