mirror of https://github.com/zlatinb/muwire
parse X-Have on uploader side
parent
0f07562de3
commit
1ee9ccf098
|
@ -2,4 +2,5 @@ package com.muwire.core.upload
|
||||||
|
|
||||||
class ContentRequest extends Request {
|
class ContentRequest extends Request {
|
||||||
Range range
|
Range range
|
||||||
|
boolean have
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets
|
||||||
import com.muwire.core.Constants
|
import com.muwire.core.Constants
|
||||||
import com.muwire.core.InfoHash
|
import com.muwire.core.InfoHash
|
||||||
import com.muwire.core.Persona
|
import com.muwire.core.Persona
|
||||||
|
import com.muwire.core.util.DataUtil
|
||||||
|
|
||||||
import groovy.util.logging.Log
|
import groovy.util.logging.Log
|
||||||
import net.i2p.data.Base64
|
import net.i2p.data.Base64
|
||||||
|
@ -48,8 +49,14 @@ class Request {
|
||||||
def decoded = Base64.decode(encoded)
|
def decoded = Base64.decode(encoded)
|
||||||
downloader = new Persona(new ByteArrayInputStream(decoded))
|
downloader = new Persona(new ByteArrayInputStream(decoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean have = false
|
||||||
|
if (headers.containsKey("X-Have")) {
|
||||||
|
def encoded = headers["X-Have"].trim()
|
||||||
|
have = DataUtil.decodeXHave(encoded).size() > 0
|
||||||
|
}
|
||||||
new ContentRequest( infoHash : infoHash, range : new Range(start, end),
|
new ContentRequest( infoHash : infoHash, range : new Range(start, end),
|
||||||
headers : headers, downloader : downloader)
|
headers : headers, downloader : downloader, have : have)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Request parseHashListRequest(InfoHash infoHash, InputStream is) throws IOException {
|
static Request parseHashListRequest(InfoHash infoHash, InputStream is) throws IOException {
|
||||||
|
|
|
@ -6,6 +6,7 @@ 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.SourceDiscoveredEvent
|
||||||
import com.muwire.core.files.FileManager
|
import com.muwire.core.files.FileManager
|
||||||
|
|
||||||
import groovy.util.logging.Log
|
import groovy.util.logging.Log
|
||||||
|
@ -61,12 +62,16 @@ public class UploadManager {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Request request = Request.parseContentRequest(new InfoHash(infoHashRoot), e.getInputStream())
|
ContentRequest request = Request.parseContentRequest(new InfoHash(infoHashRoot), 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.have)
|
||||||
|
eventBus.publish(new SourceDiscoveredEvent(infoHash : request.infoHash, source : e.destination))
|
||||||
|
|
||||||
Uploader uploader = new ContentUploader(sharedFiles.iterator().next().file, request, e)
|
Uploader uploader = new ContentUploader(sharedFiles.iterator().next().file, request, e)
|
||||||
eventBus.publish(new UploadEvent(uploader : uploader))
|
eventBus.publish(new UploadEvent(uploader : uploader))
|
||||||
try {
|
try {
|
||||||
|
@ -153,6 +158,10 @@ public class UploadManager {
|
||||||
e.close()
|
e.close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.have)
|
||||||
|
eventBus.publish(new SourceDiscoveredEvent(infoHash : request.infoHash, source : e.destination))
|
||||||
|
|
||||||
uploader = new ContentUploader(sharedFiles.iterator().next().file, request, e)
|
uploader = new ContentUploader(sharedFiles.iterator().next().file, request, e)
|
||||||
eventBus.publish(new UploadEvent(uploader : uploader))
|
eventBus.publish(new UploadEvent(uploader : uploader))
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue