redirect exceptions in result sender to log
This commit is contained in:
@@ -11,6 +11,7 @@ import java.util.concurrent.Executor
|
|||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import java.util.concurrent.ThreadFactory
|
import java.util.concurrent.ThreadFactory
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
import java.util.logging.Level
|
||||||
import java.util.stream.Collectors
|
import java.util.stream.Collectors
|
||||||
|
|
||||||
import com.muwire.core.DownloadedFile
|
import com.muwire.core.DownloadedFile
|
||||||
@@ -83,50 +84,54 @@ class ResultsSender {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
byte [] tmp = new byte[InfoHash.SIZE]
|
|
||||||
JsonOutput jsonOutput = new JsonOutput()
|
|
||||||
Endpoint endpoint = null;
|
|
||||||
try {
|
try {
|
||||||
endpoint = connector.connect(target)
|
byte [] tmp = new byte[InfoHash.SIZE]
|
||||||
DataOutputStream os = new DataOutputStream(endpoint.getOutputStream())
|
JsonOutput jsonOutput = new JsonOutput()
|
||||||
os.write("POST $uuid\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
|
Endpoint endpoint = null;
|
||||||
me.write(os)
|
try {
|
||||||
os.writeShort((short)results.length)
|
endpoint = connector.connect(target)
|
||||||
results.each {
|
DataOutputStream os = new DataOutputStream(endpoint.getOutputStream())
|
||||||
byte [] name = it.getFile().getName().getBytes(StandardCharsets.UTF_8)
|
os.write("POST $uuid\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||||
def baos = new ByteArrayOutputStream()
|
me.write(os)
|
||||||
def daos = new DataOutputStream(baos)
|
os.writeShort((short)results.length)
|
||||||
daos.writeShort((short) name.length)
|
results.each {
|
||||||
daos.write(name)
|
byte [] name = it.getFile().getName().getBytes(StandardCharsets.UTF_8)
|
||||||
daos.flush()
|
def baos = new ByteArrayOutputStream()
|
||||||
String encodedName = Base64.encode(baos.toByteArray())
|
def daos = new DataOutputStream(baos)
|
||||||
def obj = [:]
|
daos.writeShort((short) name.length)
|
||||||
obj.type = "Result"
|
daos.write(name)
|
||||||
obj.version = oobInfohash ? 2 : 1
|
daos.flush()
|
||||||
obj.name = encodedName
|
String encodedName = Base64.encode(baos.toByteArray())
|
||||||
obj.infohash = Base64.encode(it.getInfoHash().getRoot())
|
def obj = [:]
|
||||||
obj.size = it.getFile().length()
|
obj.type = "Result"
|
||||||
obj.pieceSize = it.getPieceSize()
|
obj.version = oobInfohash ? 2 : 1
|
||||||
if (!oobInfohash) {
|
obj.name = encodedName
|
||||||
byte [] hashList = it.getInfoHash().getHashList()
|
obj.infohash = Base64.encode(it.getInfoHash().getRoot())
|
||||||
def hashListB64 = []
|
obj.size = it.getFile().length()
|
||||||
for (int i = 0; i < hashList.length / InfoHash.SIZE; i++) {
|
obj.pieceSize = it.getPieceSize()
|
||||||
System.arraycopy(hashList, InfoHash.SIZE * i, tmp, 0, InfoHash.SIZE)
|
if (!oobInfohash) {
|
||||||
hashListB64 << Base64.encode(tmp)
|
byte [] hashList = it.getInfoHash().getHashList()
|
||||||
|
def hashListB64 = []
|
||||||
|
for (int i = 0; i < hashList.length / InfoHash.SIZE; i++) {
|
||||||
|
System.arraycopy(hashList, InfoHash.SIZE * i, tmp, 0, InfoHash.SIZE)
|
||||||
|
hashListB64 << Base64.encode(tmp)
|
||||||
|
}
|
||||||
|
obj.hashList = hashListB64
|
||||||
}
|
}
|
||||||
obj.hashList = hashListB64
|
|
||||||
|
if (it instanceof DownloadedFile)
|
||||||
|
obj.sources = it.sources.stream().map({dest -> dest.toBase64()}).collect(Collectors.toSet())
|
||||||
|
|
||||||
|
def json = jsonOutput.toJson(obj)
|
||||||
|
os.writeShort((short)json.length())
|
||||||
|
os.write(json.getBytes(StandardCharsets.US_ASCII))
|
||||||
}
|
}
|
||||||
|
os.flush()
|
||||||
if (it instanceof DownloadedFile)
|
} finally {
|
||||||
obj.sources = it.sources.stream().map({dest -> dest.toBase64()}).collect(Collectors.toSet())
|
endpoint?.close()
|
||||||
|
|
||||||
def json = jsonOutput.toJson(obj)
|
|
||||||
os.writeShort((short)json.length())
|
|
||||||
os.write(json.getBytes(StandardCharsets.US_ASCII))
|
|
||||||
}
|
}
|
||||||
os.flush()
|
} catch (Exception e) {
|
||||||
} finally {
|
log.log(Level.WARNING, "problem sending results",e)
|
||||||
endpoint?.close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user