source partial uploads from incompletes file
This commit is contained in:
@@ -217,7 +217,7 @@ public class Core {
|
|||||||
eventBus.register(SourceDiscoveredEvent.class, downloadManager)
|
eventBus.register(SourceDiscoveredEvent.class, downloadManager)
|
||||||
|
|
||||||
log.info("initializing upload manager")
|
log.info("initializing upload manager")
|
||||||
UploadManager uploadManager = new UploadManager(eventBus, fileManager, meshManager)
|
UploadManager uploadManager = new UploadManager(eventBus, fileManager, meshManager, downloadManager)
|
||||||
|
|
||||||
log.info("initializing connection establisher")
|
log.info("initializing connection establisher")
|
||||||
connectionEstablisher = new ConnectionEstablisher(eventBus, i2pConnector, props, connectionManager, hostCache)
|
connectionEstablisher = new ConnectionEstablisher(eventBus, i2pConnector, props, connectionManager, hostCache)
|
||||||
|
@@ -6,6 +6,8 @@ import com.muwire.core.EventBus
|
|||||||
import com.muwire.core.InfoHash
|
import com.muwire.core.InfoHash
|
||||||
import com.muwire.core.SharedFile
|
import com.muwire.core.SharedFile
|
||||||
import com.muwire.core.connection.Endpoint
|
import com.muwire.core.connection.Endpoint
|
||||||
|
import com.muwire.core.download.DownloadManager
|
||||||
|
import com.muwire.core.download.Downloader
|
||||||
import com.muwire.core.download.SourceDiscoveredEvent
|
import com.muwire.core.download.SourceDiscoveredEvent
|
||||||
import com.muwire.core.files.FileManager
|
import com.muwire.core.files.FileManager
|
||||||
import com.muwire.core.mesh.Mesh
|
import com.muwire.core.mesh.Mesh
|
||||||
@@ -19,13 +21,16 @@ public class UploadManager {
|
|||||||
private final EventBus eventBus
|
private final EventBus eventBus
|
||||||
private final FileManager fileManager
|
private final FileManager fileManager
|
||||||
private final MeshManager meshManager
|
private final MeshManager meshManager
|
||||||
|
private final DownloadManager downloadManager
|
||||||
|
|
||||||
public UploadManager() {}
|
public UploadManager() {}
|
||||||
|
|
||||||
public UploadManager(EventBus eventBus, FileManager fileManager, MeshManager meshManager) {
|
public UploadManager(EventBus eventBus, FileManager fileManager,
|
||||||
|
MeshManager meshManager, DownloadManager downloadManager) {
|
||||||
this.eventBus = eventBus
|
this.eventBus = eventBus
|
||||||
this.fileManager = fileManager
|
this.fileManager = fileManager
|
||||||
this.meshManager = meshManager
|
this.meshManager = meshManager
|
||||||
|
this.downloadManager = downloadManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processGET(Endpoint e) throws IOException {
|
public void processGET(Endpoint e) throws IOException {
|
||||||
@@ -49,8 +54,10 @@ public class UploadManager {
|
|||||||
log.info("Responding to upload request for root $infoHashString")
|
log.info("Responding to upload request for root $infoHashString")
|
||||||
|
|
||||||
byte [] infoHashRoot = Base64.decode(infoHashString)
|
byte [] infoHashRoot = Base64.decode(infoHashString)
|
||||||
|
InfoHash infoHash = new InfoHash(infoHashRoot)
|
||||||
Set<SharedFile> sharedFiles = fileManager.getSharedFiles(infoHashRoot)
|
Set<SharedFile> sharedFiles = fileManager.getSharedFiles(infoHashRoot)
|
||||||
if (sharedFiles == null || sharedFiles.isEmpty()) {
|
Downloader downloader = downloadManager.downloaders.get(infoHash)
|
||||||
|
if (downloader == null && (sharedFiles == null || sharedFiles.isEmpty())) {
|
||||||
log.info "file not found"
|
log.info "file not found"
|
||||||
e.getOutputStream().write("404 File Not Found\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
|
e.getOutputStream().write("404 File Not Found\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||||
e.getOutputStream().flush()
|
e.getOutputStream().flush()
|
||||||
@@ -66,7 +73,7 @@ public class UploadManager {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentRequest request = Request.parseContentRequest(new InfoHash(infoHashRoot), e.getInputStream())
|
ContentRequest request = Request.parseContentRequest(infoHash, e.getInputStream())
|
||||||
if (request.downloader != null && request.downloader.destination != e.destination) {
|
if (request.downloader != null && request.downloader.destination != e.destination) {
|
||||||
log.info("Downloader persona doesn't match their destination")
|
log.info("Downloader persona doesn't match their destination")
|
||||||
e.close()
|
e.close()
|
||||||
@@ -76,10 +83,18 @@ public class UploadManager {
|
|||||||
if (request.have)
|
if (request.have)
|
||||||
eventBus.publish(new SourceDiscoveredEvent(infoHash : request.infoHash, source : e.destination))
|
eventBus.publish(new SourceDiscoveredEvent(infoHash : request.infoHash, source : e.destination))
|
||||||
|
|
||||||
SharedFile file = sharedFiles.iterator().next();
|
Mesh mesh
|
||||||
Mesh mesh = meshManager.getOrCreate(request.infoHash, file.NPieces)
|
File file
|
||||||
|
if (downloader != null) {
|
||||||
|
mesh = meshManager.get(infoHash)
|
||||||
|
file = downloader.incompleteFile
|
||||||
|
} else {
|
||||||
|
SharedFile sharedFile = sharedFiles.iterator().next();
|
||||||
|
mesh = meshManager.getOrCreate(request.infoHash, sharedFile.NPieces)
|
||||||
|
file = sharedFile.file
|
||||||
|
}
|
||||||
|
|
||||||
Uploader uploader = new ContentUploader(file.file, request, e, mesh)
|
Uploader uploader = new ContentUploader(file, request, e, mesh)
|
||||||
eventBus.publish(new UploadEvent(uploader : uploader))
|
eventBus.publish(new UploadEvent(uploader : uploader))
|
||||||
try {
|
try {
|
||||||
uploader.respond()
|
uploader.respond()
|
||||||
@@ -97,8 +112,10 @@ public class UploadManager {
|
|||||||
log.info("Responding to hashlist request for root $infoHashString")
|
log.info("Responding to hashlist request for root $infoHashString")
|
||||||
|
|
||||||
byte [] infoHashRoot = Base64.decode(infoHashString)
|
byte [] infoHashRoot = Base64.decode(infoHashString)
|
||||||
|
InfoHash infoHash = new InfoHash(infoHashRoot)
|
||||||
|
Downloader downloader = downloadManager.downloaders.get(infoHash)
|
||||||
Set<SharedFile> sharedFiles = fileManager.getSharedFiles(infoHashRoot)
|
Set<SharedFile> sharedFiles = fileManager.getSharedFiles(infoHashRoot)
|
||||||
if (sharedFiles == null || sharedFiles.isEmpty()) {
|
if (downloader == null && (sharedFiles == null || sharedFiles.isEmpty())) {
|
||||||
log.info "file not found"
|
log.info "file not found"
|
||||||
e.getOutputStream().write("404 File Not Found\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
|
e.getOutputStream().write("404 File Not Found\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||||
e.getOutputStream().flush()
|
e.getOutputStream().flush()
|
||||||
@@ -114,13 +131,30 @@ public class UploadManager {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Request request = Request.parseHashListRequest(new InfoHash(infoHashRoot), e.getInputStream())
|
Request request = Request.parseHashListRequest(infoHash, e.getInputStream())
|
||||||
if (request.downloader != null && request.downloader.destination != e.destination) {
|
if (request.downloader != null && request.downloader.destination != e.destination) {
|
||||||
log.info("Downloader persona doesn't match their destination")
|
log.info("Downloader persona doesn't match their destination")
|
||||||
e.close()
|
e.close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Uploader uploader = new HashListUploader(e, sharedFiles.iterator().next().infoHash, request)
|
|
||||||
|
InfoHash fullInfoHash
|
||||||
|
if (downloader == null) {
|
||||||
|
fullInfoHash = sharedFiles.iterator().next().infoHash
|
||||||
|
} else {
|
||||||
|
byte [] hashList = downloader.getInfoHash().getHashList()
|
||||||
|
if (hashList != null && hashList.length > 0)
|
||||||
|
fullInfoHash = downloader.getInfoHash()
|
||||||
|
else {
|
||||||
|
log.info("infohash not found in downloader")
|
||||||
|
e.getOutputStream().write("404 File Not Found\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||||
|
e.getOutputStream().flush()
|
||||||
|
e.close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Uploader uploader = new HashListUploader(e, fullInfoHash, request)
|
||||||
eventBus.publish(new UploadEvent(uploader : uploader))
|
eventBus.publish(new UploadEvent(uploader : uploader))
|
||||||
try {
|
try {
|
||||||
uploader.respond()
|
uploader.respond()
|
||||||
@@ -142,8 +176,10 @@ public class UploadManager {
|
|||||||
log.info("Responding to upload request for root $infoHashString")
|
log.info("Responding to upload request for root $infoHashString")
|
||||||
|
|
||||||
infoHashRoot = Base64.decode(infoHashString)
|
infoHashRoot = Base64.decode(infoHashString)
|
||||||
|
infoHash = new InfoHash(infoHashRoot)
|
||||||
sharedFiles = fileManager.getSharedFiles(infoHashRoot)
|
sharedFiles = fileManager.getSharedFiles(infoHashRoot)
|
||||||
if (sharedFiles == null || sharedFiles.isEmpty()) {
|
downloader = downloadManager.downloaders.get(infoHash)
|
||||||
|
if (downloader == null && (sharedFiles == null || sharedFiles.isEmpty())) {
|
||||||
log.info "file not found"
|
log.info "file not found"
|
||||||
e.getOutputStream().write("404 File Not Found\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
|
e.getOutputStream().write("404 File Not Found\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||||
e.getOutputStream().flush()
|
e.getOutputStream().flush()
|
||||||
@@ -168,11 +204,19 @@ public class UploadManager {
|
|||||||
|
|
||||||
if (request.have)
|
if (request.have)
|
||||||
eventBus.publish(new SourceDiscoveredEvent(infoHash : request.infoHash, source : e.destination))
|
eventBus.publish(new SourceDiscoveredEvent(infoHash : request.infoHash, source : e.destination))
|
||||||
|
|
||||||
SharedFile file = sharedFiles.iterator().next();
|
Mesh mesh
|
||||||
Mesh mesh = meshManager.getOrCreate(request.infoHash, file.NPieces)
|
File file
|
||||||
|
if (downloader != null) {
|
||||||
uploader = new ContentUploader(file.file, request, e, mesh)
|
mesh = meshManager.get(infoHash)
|
||||||
|
file = downloader.incompleteFile
|
||||||
|
} else {
|
||||||
|
SharedFile sharedFile = sharedFiles.iterator().next();
|
||||||
|
mesh = meshManager.getOrCreate(request.infoHash, sharedFile.NPieces)
|
||||||
|
file = sharedFile.file
|
||||||
|
}
|
||||||
|
|
||||||
|
uploader = new ContentUploader(file, request, e, mesh)
|
||||||
eventBus.publish(new UploadEvent(uploader : uploader))
|
eventBus.publish(new UploadEvent(uploader : uploader))
|
||||||
try {
|
try {
|
||||||
uploader.respond()
|
uploader.respond()
|
||||||
|
Reference in New Issue
Block a user