diff --git a/core/src/main/groovy/com/muwire/core/mesh/Mesh.groovy b/core/src/main/groovy/com/muwire/core/mesh/Mesh.groovy index 2fd5546f..e6e0faf7 100644 --- a/core/src/main/groovy/com/muwire/core/mesh/Mesh.groovy +++ b/core/src/main/groovy/com/muwire/core/mesh/Mesh.groovy @@ -1,7 +1,7 @@ package com.muwire.core.mesh import com.muwire.core.InfoHash - +import com.muwire.core.Persona import com.muwire.core.download.Pieces import net.i2p.data.Destination @@ -9,7 +9,7 @@ import net.i2p.util.ConcurrentHashSet class Mesh { private final InfoHash infoHash - private final Set sources = new ConcurrentHashSet<>() + private final Set sources = new ConcurrentHashSet<>() private final Pieces pieces Mesh(InfoHash infoHash, Pieces pieces) { @@ -17,8 +17,8 @@ class Mesh { this.pieces = pieces } - Set getRandom(int n, Destination exclude) { - List tmp = new ArrayList<>(sources) + Set getRandom(int n, Persona exclude) { + List tmp = new ArrayList<>(sources) tmp.remove(exclude) Collections.shuffle(tmp) if (tmp.size() < n) diff --git a/core/src/main/groovy/com/muwire/core/mesh/MeshManager.groovy b/core/src/main/groovy/com/muwire/core/mesh/MeshManager.groovy index 0239acd8..67aadfdd 100644 --- a/core/src/main/groovy/com/muwire/core/mesh/MeshManager.groovy +++ b/core/src/main/groovy/com/muwire/core/mesh/MeshManager.groovy @@ -38,6 +38,6 @@ class MeshManager { Mesh mesh = meshes.get(e.infoHash) if (mesh == null) return - mesh.sources.add(e.source.destination) + mesh.sources.add(e.source) } } diff --git a/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy b/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy index c4d433ee..8d48ac65 100644 --- a/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy +++ b/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy @@ -7,6 +7,7 @@ import java.nio.file.Files import java.nio.file.StandardOpenOption import java.util.stream.Collectors +import com.muwire.core.Persona import com.muwire.core.connection.Endpoint import com.muwire.core.mesh.Mesh import com.muwire.core.util.DataUtil @@ -32,7 +33,7 @@ class ContentUploader extends Uploader { Range range = request.getRange() if (range.start >= file.length() || range.end >= file.length()) { os.write("416 Range Not Satisfiable\r\n".getBytes(StandardCharsets.US_ASCII)) - writeMesh() + writeMesh(request.downloader) os.write("\r\n".getBytes(StandardCharsets.US_ASCII)) os.flush() return @@ -40,7 +41,7 @@ class ContentUploader extends Uploader { os.write("200 OK\r\n".getBytes(StandardCharsets.US_ASCII)) os.write("Content-Range: $range.start-$range.end\r\n".getBytes(StandardCharsets.US_ASCII)) - writeMesh() + writeMesh(request.downloader) os.write("\r\n".getBytes(StandardCharsets.US_ASCII)) FileChannel channel @@ -62,11 +63,11 @@ class ContentUploader extends Uploader { } } - private void writeMesh() { + private void writeMesh(Persona toExclude) { String xHave = DataUtil.encodeXHave(mesh.pieces.getDownloaded(), mesh.pieces.nPieces) endpoint.getOutputStream().write("X-Have: $xHave\r\n".getBytes(StandardCharsets.US_ASCII)) - Set sources = mesh.getRandom(3, endpoint.destination) + Set sources = mesh.getRandom(3, toExclude) String xAlts = sources.stream().map({ it.toBase64() }).collect(Collectors.joining(",")) endpoint.getOutputStream().write("X-Alt: $xAlts\r\n".getBytes(StandardCharsets.US_ASCII)) }