Compare commits
5 Commits
github/for
...
fix-piece-
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e829e09b13 | ||
![]() |
120980100b | ||
![]() |
e64ed2c89d | ||
![]() |
81436aaa66 | ||
![]() |
3bb530e34f |
@@ -1,5 +1,6 @@
|
||||
package com.muwire.core.mesh
|
||||
|
||||
import java.util.logging.Level
|
||||
import java.util.stream.Collectors
|
||||
|
||||
import com.muwire.core.Constants
|
||||
@@ -12,8 +13,10 @@ import com.muwire.core.util.DataUtil
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
import groovy.util.logging.Log
|
||||
import net.i2p.data.Base64
|
||||
|
||||
@Log
|
||||
class MeshManager {
|
||||
|
||||
private static final int EXPIRATION = 60 * 60 * 1000
|
||||
@@ -36,6 +39,7 @@ class MeshManager {
|
||||
synchronized(meshes) {
|
||||
if (meshes.containsKey(infoHash))
|
||||
return meshes.get(infoHash)
|
||||
log.log(Level.INFO,"creating mesh with pieces:$nPieces", new Exception())
|
||||
Pieces pieces = new Pieces(nPieces, Constants.DOWNLOAD_SEQUENTIAL_RATIO)
|
||||
if (fileManager.rootToFiles.containsKey(infoHash)) {
|
||||
for (int i = 0; i < nPieces; i++)
|
||||
|
@@ -12,8 +12,10 @@ import com.muwire.core.connection.Endpoint
|
||||
import com.muwire.core.mesh.Mesh
|
||||
import com.muwire.core.util.DataUtil
|
||||
|
||||
import groovy.util.logging.Log
|
||||
import net.i2p.data.Destination
|
||||
|
||||
@Log
|
||||
class ContentUploader extends Uploader {
|
||||
|
||||
private final File file
|
||||
@@ -42,8 +44,10 @@ class ContentUploader extends Uploader {
|
||||
int endPiece = range.end / (0x1 << pieceSize)
|
||||
for (int i = startPiece; i <= endPiece; i++)
|
||||
satisfiable &= mesh.pieces.isDownloaded(i)
|
||||
log.info("requested range $range.start-$range.end startPiece:$startPiece endPiece:$endPiece satisfiable:$satisfiable my pieces: ${mesh.pieces.getDownloaded()}")
|
||||
}
|
||||
if (!satisfiable) {
|
||||
log.info("416 range not satisfiable")
|
||||
os.write("416 Range Not Satisfiable\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
writeMesh(request.downloader)
|
||||
os.write("\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
@@ -51,6 +55,8 @@ class ContentUploader extends Uploader {
|
||||
return
|
||||
}
|
||||
|
||||
log.info("200 ok")
|
||||
|
||||
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(request.downloader)
|
||||
|
@@ -30,7 +30,7 @@ public class SharedFile {
|
||||
long length = file.length();
|
||||
int rawPieceSize = 0x1 << pieceSize;
|
||||
int rv = (int) (length / rawPieceSize);
|
||||
if (length % pieceSize != 0)
|
||||
if (length % rawPieceSize != 0)
|
||||
rv++;
|
||||
return rv;
|
||||
}
|
||||
|
Reference in New Issue
Block a user