Compare commits
13 Commits
github/for
...
muwire-0.6
Author | SHA1 | Date | |
---|---|---|---|
![]() |
853b9f67fc | ||
![]() |
a505a2449a | ||
![]() |
c11d81c6c3 | ||
![]() |
ee5e90c4ab | ||
![]() |
64d2a87d26 | ||
![]() |
f0304dbe7d | ||
![]() |
bdad8d9309 | ||
![]() |
8c110bbae5 | ||
![]() |
2cc1e384bc | ||
![]() |
9337d1b74d | ||
![]() |
16ed5dd346 | ||
![]() |
7b55fc9ed8 | ||
![]() |
d5c8050572 |
@@ -32,7 +32,7 @@ import com.muwire.core.UILoadedEvent
|
|||||||
import com.muwire.core.files.AllFilesLoadedEvent
|
import com.muwire.core.files.AllFilesLoadedEvent
|
||||||
|
|
||||||
class CliLanterna {
|
class CliLanterna {
|
||||||
private static final String MW_VERSION = "0.6.8"
|
private static final String MW_VERSION = "0.6.10"
|
||||||
|
|
||||||
private static volatile Core core
|
private static volatile Core core
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ package com.muwire.clilanterna
|
|||||||
import com.googlecode.lanterna.gui2.TextGUIThread
|
import com.googlecode.lanterna.gui2.TextGUIThread
|
||||||
import com.googlecode.lanterna.gui2.table.TableModel
|
import com.googlecode.lanterna.gui2.table.TableModel
|
||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
|
import com.muwire.core.InfoHash
|
||||||
import com.muwire.core.SharedFile
|
import com.muwire.core.SharedFile
|
||||||
import com.muwire.core.files.AllFilesLoadedEvent
|
import com.muwire.core.files.AllFilesLoadedEvent
|
||||||
import com.muwire.core.files.DirectoryWatchedEvent
|
import com.muwire.core.files.DirectoryWatchedEvent
|
||||||
@@ -72,7 +73,7 @@ class FilesModel {
|
|||||||
sharedFiles.each {
|
sharedFiles.each {
|
||||||
long size = it.getCachedLength()
|
long size = it.getCachedLength()
|
||||||
boolean comment = it.comment != null
|
boolean comment = it.comment != null
|
||||||
boolean certified = core.certificateManager.hasLocalCertificate(it.getInfoHash())
|
boolean certified = core.certificateManager.hasLocalCertificate(new InfoHash(it.getRoot()))
|
||||||
String hits = String.valueOf(it.getHits())
|
String hits = String.valueOf(it.getHits())
|
||||||
String downloaders = String.valueOf(it.getDownloaders().size())
|
String downloaders = String.valueOf(it.getDownloaders().size())
|
||||||
model.addRow(new SharedFileWrapper(it), DataHelper.formatSize2(size, false)+"B", comment, certified, hits, downloaders)
|
model.addRow(new SharedFileWrapper(it), DataHelper.formatSize2(size, false)+"B", comment, certified, hits, downloaders)
|
||||||
|
@@ -268,6 +268,7 @@ public class Core {
|
|||||||
eventBus.register(FileLoadedEvent.class, persisterFolderService)
|
eventBus.register(FileLoadedEvent.class, persisterFolderService)
|
||||||
eventBus.register(FileHashedEvent.class, persisterFolderService)
|
eventBus.register(FileHashedEvent.class, persisterFolderService)
|
||||||
eventBus.register(FileUnsharedEvent.class, persisterFolderService)
|
eventBus.register(FileUnsharedEvent.class, persisterFolderService)
|
||||||
|
eventBus.register(UICommentEvent.class, persisterFolderService)
|
||||||
|
|
||||||
log.info("initializing host cache")
|
log.info("initializing host cache")
|
||||||
File hostStorage = new File(home, "hosts.json")
|
File hostStorage = new File(home, "hosts.json")
|
||||||
@@ -329,7 +330,7 @@ public class Core {
|
|||||||
eventBus.register(UIDownloadResumedEvent.class, downloadManager)
|
eventBus.register(UIDownloadResumedEvent.class, downloadManager)
|
||||||
|
|
||||||
log.info("initializing upload manager")
|
log.info("initializing upload manager")
|
||||||
uploadManager = new UploadManager(eventBus, fileManager, meshManager, downloadManager, props)
|
uploadManager = new UploadManager(eventBus, fileManager, meshManager, downloadManager, persisterFolderService, props)
|
||||||
|
|
||||||
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)
|
||||||
@@ -469,7 +470,7 @@ public class Core {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Core core = new Core(props, home, "0.6.8")
|
Core core = new Core(props, home, "0.6.10")
|
||||||
core.startServices()
|
core.startServices()
|
||||||
|
|
||||||
// ... at the end, sleep or execute script
|
// ... at the end, sleep or execute script
|
||||||
|
@@ -255,7 +255,6 @@ abstract class Connection implements Closeable {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make this mandatory at some point
|
|
||||||
byte[] sig2 = null
|
byte[] sig2 = null
|
||||||
long queryTime = 0
|
long queryTime = 0
|
||||||
if (search.sig2 != null) {
|
if (search.sig2 != null) {
|
||||||
@@ -278,8 +277,10 @@ abstract class Connection implements Closeable {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
log.info("no extended signature in query")
|
log.info("no extended signature in query")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
SearchEvent searchEvent = new SearchEvent(searchTerms : search.keywords,
|
SearchEvent searchEvent = new SearchEvent(searchTerms : search.keywords,
|
||||||
searchHash : infohash,
|
searchHash : infohash,
|
||||||
|
@@ -380,7 +380,7 @@ class ConnectionAcceptor {
|
|||||||
JsonOutput jsonOutput = new JsonOutput()
|
JsonOutput jsonOutput = new JsonOutput()
|
||||||
sharedFiles.each {
|
sharedFiles.each {
|
||||||
it.hit(browser, System.currentTimeMillis(), "Browse Host");
|
it.hit(browser, System.currentTimeMillis(), "Browse Host");
|
||||||
int certificates = certificateManager.getByInfoHash(it.getInfoHash()).size()
|
int certificates = certificateManager.getByInfoHash(new InfoHash(it.getRoot())).size()
|
||||||
def obj = ResultsSender.sharedFileToObj(it, false, certificates)
|
def obj = ResultsSender.sharedFileToObj(it, false, certificates)
|
||||||
def json = jsonOutput.toJson(obj)
|
def json = jsonOutput.toJson(obj)
|
||||||
dos.writeShort((short)json.length())
|
dos.writeShort((short)json.length())
|
||||||
|
@@ -405,8 +405,9 @@ public class Downloader {
|
|||||||
}
|
}
|
||||||
eventBus.publish(
|
eventBus.publish(
|
||||||
new FileDownloadedEvent(
|
new FileDownloadedEvent(
|
||||||
downloadedFile : new DownloadedFile(file.getCanonicalFile(), getInfoHash(), pieceSizePow2, successfulDestinations),
|
downloadedFile : new DownloadedFile(file.getCanonicalFile(), getInfoHash().getRoot(), pieceSizePow2, successfulDestinations),
|
||||||
downloader : Downloader.this))
|
downloader : Downloader.this,
|
||||||
|
infoHash: getInfoHash()))
|
||||||
|
|
||||||
}
|
}
|
||||||
endpoint?.close()
|
endpoint?.close()
|
||||||
|
@@ -70,7 +70,7 @@ class CertificateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onUICreateCertificateEvent(UICreateCertificateEvent e) {
|
void onUICreateCertificateEvent(UICreateCertificateEvent e) {
|
||||||
InfoHash infoHash = e.sharedFile.getInfoHash()
|
InfoHash infoHash = new InfoHash(e.sharedFile.getRoot())
|
||||||
String name = e.sharedFile.getFile().getName()
|
String name = e.sharedFile.getFile().getName()
|
||||||
long timestamp = System.currentTimeMillis()
|
long timestamp = System.currentTimeMillis()
|
||||||
|
|
||||||
|
@@ -51,13 +51,13 @@ abstract class BasePersisterService extends Service{
|
|||||||
if (json.sources != null) {
|
if (json.sources != null) {
|
||||||
List sources = (List)json.sources
|
List sources = (List)json.sources
|
||||||
Set<Destination> sourceSet = sources.stream().map({ d -> new Destination(d.toString())}).collect Collectors.toSet()
|
Set<Destination> sourceSet = sources.stream().map({ d -> new Destination(d.toString())}).collect Collectors.toSet()
|
||||||
DownloadedFile df = new DownloadedFile(file, ih, pieceSize, sourceSet)
|
DownloadedFile df = new DownloadedFile(file, ih.getRoot(), pieceSize, sourceSet)
|
||||||
df.setComment(json.comment)
|
df.setComment(json.comment)
|
||||||
return new FileLoadedEvent(loadedFile : df)
|
return new FileLoadedEvent(loadedFile : df, infoHash: ih)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedFile sf = new SharedFile(file, ih, pieceSize)
|
SharedFile sf = new SharedFile(file, ih.getRoot(), pieceSize)
|
||||||
sf.setComment(json.comment)
|
sf.setComment(json.comment)
|
||||||
if (json.downloaders != null)
|
if (json.downloaders != null)
|
||||||
sf.getDownloaders().addAll(json.downloaders)
|
sf.getDownloaders().addAll(json.downloaders)
|
||||||
@@ -71,18 +71,61 @@ abstract class BasePersisterService extends Service{
|
|||||||
sf.hit(searcher, timestamp, query)
|
sf.hit(searcher, timestamp, query)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new FileLoadedEvent(loadedFile: sf)
|
return new FileLoadedEvent(loadedFile: sf, infoHash: ih)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static FileLoadedEvent fromJsonLite(json) {
|
||||||
|
if (json.file == null || json.length == null || json.root == null)
|
||||||
|
throw new IllegalArgumentException()
|
||||||
|
|
||||||
|
def file = new File(DataUtil.readi18nString(Base64.decode(json.file)))
|
||||||
|
file = file.getCanonicalFile()
|
||||||
|
if (!file.exists() || file.isDirectory())
|
||||||
|
return null
|
||||||
|
long length = Long.valueOf(json.length)
|
||||||
|
if (length != file.length())
|
||||||
|
return null
|
||||||
|
|
||||||
|
byte[] root = Base64.decode(json.root)
|
||||||
|
InfoHash ih = new InfoHash(root)
|
||||||
|
|
||||||
|
int pieceSize = 0
|
||||||
|
if (json.pieceSize != null)
|
||||||
|
pieceSize = json.pieceSize
|
||||||
|
|
||||||
|
if (json.sources != null) {
|
||||||
|
List sources = (List)json.sources
|
||||||
|
Set<Destination> sourceSet = sources.stream().map({ d -> new Destination(d.toString())}).collect Collectors.toSet()
|
||||||
|
DownloadedFile df = new DownloadedFile(file, ih.getRoot(), pieceSize, sourceSet)
|
||||||
|
df.setComment(json.comment)
|
||||||
|
return new FileLoadedEvent(loadedFile : df, infoHash: ih)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SharedFile sf = new SharedFile(file, ih.getRoot(), pieceSize)
|
||||||
|
sf.setComment(json.comment)
|
||||||
|
if (json.downloaders != null)
|
||||||
|
sf.getDownloaders().addAll(json.downloaders)
|
||||||
|
if (json.searchers != null) {
|
||||||
|
json.searchers.each {
|
||||||
|
Persona searcher = null
|
||||||
|
if (it.searcher != null)
|
||||||
|
searcher = new Persona(new ByteArrayInputStream(Base64.decode(it.searcher)))
|
||||||
|
long timestamp = it.timestamp
|
||||||
|
String query = it.query
|
||||||
|
sf.hit(searcher, timestamp, query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new FileLoadedEvent(loadedFile: sf, infoHash: ih)
|
||||||
|
}
|
||||||
|
|
||||||
protected static toJson(SharedFile sf) {
|
protected static toJson(SharedFile sf) {
|
||||||
def json = [:]
|
def json = [:]
|
||||||
json.file = sf.getB64EncodedFileName()
|
json.file = sf.getB64EncodedFileName()
|
||||||
json.length = sf.getCachedLength()
|
json.length = sf.getCachedLength()
|
||||||
InfoHash ih = sf.getInfoHash()
|
json.root = Base64.encode(sf.getRoot())
|
||||||
json.infoHash = sf.getB64EncodedHashRoot()
|
|
||||||
json.pieceSize = sf.getPieceSize()
|
json.pieceSize = sf.getPieceSize()
|
||||||
json.hashList = sf.getB64EncodedHashList()
|
|
||||||
json.comment = sf.getComment()
|
json.comment = sf.getComment()
|
||||||
json.hits = sf.getHits()
|
json.hits = sf.getHits()
|
||||||
json.downloaders = sf.getDownloaders()
|
json.downloaders = sf.getDownloaders()
|
||||||
|
@@ -2,6 +2,7 @@ package com.muwire.core.files
|
|||||||
|
|
||||||
import com.muwire.core.DownloadedFile
|
import com.muwire.core.DownloadedFile
|
||||||
import com.muwire.core.Event
|
import com.muwire.core.Event
|
||||||
|
import com.muwire.core.InfoHash
|
||||||
import com.muwire.core.download.Downloader
|
import com.muwire.core.download.Downloader
|
||||||
|
|
||||||
import net.i2p.data.Destination
|
import net.i2p.data.Destination
|
||||||
@@ -9,4 +10,5 @@ import net.i2p.data.Destination
|
|||||||
class FileDownloadedEvent extends Event {
|
class FileDownloadedEvent extends Event {
|
||||||
Downloader downloader
|
Downloader downloader
|
||||||
DownloadedFile downloadedFile
|
DownloadedFile downloadedFile
|
||||||
|
InfoHash infoHash
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
package com.muwire.core.files
|
package com.muwire.core.files
|
||||||
|
|
||||||
import com.muwire.core.Event
|
import com.muwire.core.Event
|
||||||
|
import com.muwire.core.InfoHash
|
||||||
import com.muwire.core.SharedFile
|
import com.muwire.core.SharedFile
|
||||||
|
|
||||||
class FileHashedEvent extends Event {
|
class FileHashedEvent extends Event {
|
||||||
|
|
||||||
SharedFile sharedFile
|
SharedFile sharedFile
|
||||||
|
InfoHash infoHash
|
||||||
String error
|
String error
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -1,10 +1,12 @@
|
|||||||
package com.muwire.core.files
|
package com.muwire.core.files
|
||||||
|
|
||||||
import com.muwire.core.Event
|
import com.muwire.core.Event
|
||||||
|
import com.muwire.core.InfoHash
|
||||||
import com.muwire.core.SharedFile
|
import com.muwire.core.SharedFile
|
||||||
|
|
||||||
class FileLoadedEvent extends Event {
|
class FileLoadedEvent extends Event {
|
||||||
|
|
||||||
SharedFile loadedFile
|
SharedFile loadedFile
|
||||||
|
InfoHash infoHash
|
||||||
String source
|
String source
|
||||||
}
|
}
|
||||||
|
@@ -75,7 +75,7 @@ class FileManager {
|
|||||||
|
|
||||||
private void addToIndex(SharedFile sf) {
|
private void addToIndex(SharedFile sf) {
|
||||||
log.info("Adding shared file " + sf.getFile())
|
log.info("Adding shared file " + sf.getFile())
|
||||||
InfoHash infoHash = sf.getInfoHash()
|
InfoHash infoHash = new InfoHash(sf.getRoot())
|
||||||
Set<SharedFile> existing = rootToFiles.get(infoHash)
|
Set<SharedFile> existing = rootToFiles.get(infoHash)
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
log.info("adding new root")
|
log.info("adding new root")
|
||||||
@@ -117,7 +117,7 @@ class FileManager {
|
|||||||
|
|
||||||
void onFileUnsharedEvent(FileUnsharedEvent e) {
|
void onFileUnsharedEvent(FileUnsharedEvent e) {
|
||||||
SharedFile sf = e.unsharedFile
|
SharedFile sf = e.unsharedFile
|
||||||
InfoHash infoHash = sf.getInfoHash()
|
InfoHash infoHash = new InfoHash(sf.getRoot())
|
||||||
Set<SharedFile> existing = rootToFiles.get(infoHash)
|
Set<SharedFile> existing = rootToFiles.get(infoHash)
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
existing.remove(sf)
|
existing.remove(sf)
|
||||||
|
@@ -65,7 +65,8 @@ class HasherService {
|
|||||||
} else {
|
} else {
|
||||||
eventBus.publish new FileHashingEvent(hashingFile: f)
|
eventBus.publish new FileHashingEvent(hashingFile: f)
|
||||||
def hash = hasher.hashFile f
|
def hash = hasher.hashFile f
|
||||||
eventBus.publish new FileHashedEvent(sharedFile: new SharedFile(f, hash, FileHasher.getPieceSize(f.length())))
|
eventBus.publish new FileHashedEvent(sharedFile: new SharedFile(f, hash.getRoot(), FileHasher.getPieceSize(f.length())),
|
||||||
|
infoHash : hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -56,17 +56,17 @@ class PersisterFolderService extends BasePersisterService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onFileHashedEvent(FileHashedEvent hashedEvent) {
|
void onFileHashedEvent(FileHashedEvent hashedEvent) {
|
||||||
persistFile(hashedEvent.sharedFile)
|
persistFile(hashedEvent.sharedFile, hashedEvent.infoHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
void onFileDownloadedEvent(FileDownloadedEvent downloadedEvent) {
|
void onFileDownloadedEvent(FileDownloadedEvent downloadedEvent) {
|
||||||
if (core.getMuOptions().getShareDownloadedFiles()) {
|
if (core.getMuOptions().getShareDownloadedFiles()) {
|
||||||
persistFile(downloadedEvent.downloadedFile)
|
persistFile(downloadedEvent.downloadedFile, downloadedEvent.infoHash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get rid of the json of unshared files
|
* Get rid of the json and hashlists of unshared files
|
||||||
* @param unsharedEvent
|
* @param unsharedEvent
|
||||||
*/
|
*/
|
||||||
void onFileUnsharedEvent(FileUnsharedEvent unsharedEvent) {
|
void onFileUnsharedEvent(FileUnsharedEvent unsharedEvent) {
|
||||||
@@ -75,15 +75,24 @@ class PersisterFolderService extends BasePersisterService {
|
|||||||
if(jsonFile.isFile()){
|
if(jsonFile.isFile()){
|
||||||
jsonFile.delete()
|
jsonFile.delete()
|
||||||
}
|
}
|
||||||
|
def hashListPath = getHashListPath(unsharedEvent.unsharedFile)
|
||||||
|
def hashListFile = hashListPath.toFile()
|
||||||
|
if (hashListFile.isFile())
|
||||||
|
hashListFile.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
void onFileLoadedEvent(FileLoadedEvent loadedEvent) {
|
void onFileLoadedEvent(FileLoadedEvent loadedEvent) {
|
||||||
if(loadedEvent.source == "PersisterService"){
|
if(loadedEvent.source == "PersisterService"){
|
||||||
log.info("Migrating persisted file from PersisterService: "
|
log.info("Migrating persisted file from PersisterService: "
|
||||||
+ loadedEvent.loadedFile.file.absolutePath.toString())
|
+ loadedEvent.loadedFile.file.absolutePath.toString())
|
||||||
persistFile(loadedEvent.loadedFile)
|
persistFile(loadedEvent.loadedFile, loadedEvent.infoHash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onUICommentEvent(UICommentEvent e) {
|
||||||
|
persistFile(e.sharedFile,null)
|
||||||
|
}
|
||||||
|
|
||||||
void load() {
|
void load() {
|
||||||
log.fine("Loading...")
|
log.fine("Loading...")
|
||||||
Thread.currentThread().setPriority(Thread.MIN_PRIORITY)
|
Thread.currentThread().setPriority(Thread.MIN_PRIORITY)
|
||||||
@@ -109,10 +118,12 @@ class PersisterFolderService extends BasePersisterService {
|
|||||||
int loaded = 0
|
int loaded = 0
|
||||||
def slurper = new JsonSlurper()
|
def slurper = new JsonSlurper()
|
||||||
Files.walk(location.toPath())
|
Files.walk(location.toPath())
|
||||||
.filter({ it.fileName.endsWith(".json") })
|
.filter({
|
||||||
|
it.getFileName().toString().endsWith(".json")
|
||||||
|
})
|
||||||
.forEach({
|
.forEach({
|
||||||
def parsed = slurper.parse it.toFile()
|
def parsed = slurper.parse it.toFile()
|
||||||
def event = fromJson parsed
|
def event = fromJsonLite parsed
|
||||||
if (event == null) return
|
if (event == null) return
|
||||||
|
|
||||||
log.fine("loaded file $event.loadedFile.file")
|
log.fine("loaded file $event.loadedFile.file")
|
||||||
@@ -125,7 +136,7 @@ class PersisterFolderService extends BasePersisterService {
|
|||||||
listener.publish(new AllFilesLoadedEvent())
|
listener.publish(new AllFilesLoadedEvent())
|
||||||
}
|
}
|
||||||
|
|
||||||
private void persistFile(SharedFile sf) {
|
private void persistFile(SharedFile sf, InfoHash ih) {
|
||||||
persisterExecutor.submit({
|
persisterExecutor.submit({
|
||||||
def jsonPath = getJsonPath(sf)
|
def jsonPath = getJsonPath(sf)
|
||||||
|
|
||||||
@@ -136,7 +147,12 @@ class PersisterFolderService extends BasePersisterService {
|
|||||||
json = JsonOutput.toJson(json)
|
json = JsonOutput.toJson(json)
|
||||||
writer.println json
|
writer.println json
|
||||||
}
|
}
|
||||||
log.fine("Time(ms) to write json: " + (System.currentTimeMillis() - startTime))
|
|
||||||
|
if (ih != null) {
|
||||||
|
def hashListPath = getHashListPath(sf)
|
||||||
|
hashListPath.toFile().bytes = ih.hashList
|
||||||
|
}
|
||||||
|
log.fine("Time(ms) to write json+hashList: " + (System.currentTimeMillis() - startTime))
|
||||||
} as Runnable)
|
} as Runnable)
|
||||||
}
|
}
|
||||||
private Path getJsonPath(SharedFile sf){
|
private Path getJsonPath(SharedFile sf){
|
||||||
@@ -147,4 +163,18 @@ class PersisterFolderService extends BasePersisterService {
|
|||||||
pathHash.substring(CUT_LENGTH) + ".json"
|
pathHash.substring(CUT_LENGTH) + ".json"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Path getHashListPath(SharedFile sf) {
|
||||||
|
def pathHash = sf.getB64PathHash()
|
||||||
|
return Paths.get(
|
||||||
|
location.getAbsolutePath(),
|
||||||
|
pathHash.substring(0, CUT_LENGTH),
|
||||||
|
pathHash.substring(CUT_LENGTH) + ".hashlist"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
InfoHash loadInfoHash(SharedFile sf) {
|
||||||
|
def path = getHashListPath(sf)
|
||||||
|
InfoHash.fromHashList(path.toFile().bytes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -77,11 +77,11 @@ class ResultsSender {
|
|||||||
if (it.getComment() != null) {
|
if (it.getComment() != null) {
|
||||||
comment = DataUtil.readi18nString(Base64.decode(it.getComment()))
|
comment = DataUtil.readi18nString(Base64.decode(it.getComment()))
|
||||||
}
|
}
|
||||||
int certificates = certificateManager.getByInfoHash(it.getInfoHash()).size()
|
int certificates = certificateManager.getByInfoHash(new InfoHash(it.getRoot())).size()
|
||||||
def uiResultEvent = new UIResultEvent( sender : me,
|
def uiResultEvent = new UIResultEvent( sender : me,
|
||||||
name : it.getFile().getName(),
|
name : it.getFile().getName(),
|
||||||
size : length,
|
size : length,
|
||||||
infohash : it.getInfoHash(),
|
infohash : new InfoHash(it.getRoot()),
|
||||||
pieceSize : pieceSize,
|
pieceSize : pieceSize,
|
||||||
uuid : uuid,
|
uuid : uuid,
|
||||||
browse : settings.browseFiles,
|
browse : settings.browseFiles,
|
||||||
@@ -119,7 +119,7 @@ class ResultsSender {
|
|||||||
me.write(os)
|
me.write(os)
|
||||||
os.writeShort((short)results.length)
|
os.writeShort((short)results.length)
|
||||||
results.each {
|
results.each {
|
||||||
int certificates = certificateManager.getByInfoHash(it.getInfoHash()).size()
|
int certificates = certificateManager.getByInfoHash(new InfoHash(it.getRoot())).size()
|
||||||
def obj = sharedFileToObj(it, settings.browseFiles, certificates)
|
def obj = sharedFileToObj(it, settings.browseFiles, certificates)
|
||||||
def json = jsonOutput.toJson(obj)
|
def json = jsonOutput.toJson(obj)
|
||||||
os.writeShort((short)json.length())
|
os.writeShort((short)json.length())
|
||||||
@@ -141,7 +141,7 @@ class ResultsSender {
|
|||||||
os.write("\r\n".getBytes(StandardCharsets.US_ASCII))
|
os.write("\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||||
DataOutputStream dos = new DataOutputStream(new GZIPOutputStream(os))
|
DataOutputStream dos = new DataOutputStream(new GZIPOutputStream(os))
|
||||||
results.each {
|
results.each {
|
||||||
int certificates = certificateManager.getByInfoHash(it.getInfoHash()).size()
|
int certificates = certificateManager.getByInfoHash(new InfoHash(it.getRoot())).size()
|
||||||
def obj = sharedFileToObj(it, settings.browseFiles, certificates)
|
def obj = sharedFileToObj(it, settings.browseFiles, certificates)
|
||||||
def json = jsonOutput.toJson(obj)
|
def json = jsonOutput.toJson(obj)
|
||||||
dos.writeShort((short)json.length())
|
dos.writeShort((short)json.length())
|
||||||
@@ -170,7 +170,7 @@ class ResultsSender {
|
|||||||
obj.type = "Result"
|
obj.type = "Result"
|
||||||
obj.version = 2
|
obj.version = 2
|
||||||
obj.name = encodedName
|
obj.name = encodedName
|
||||||
obj.infohash = Base64.encode(sf.getInfoHash().getRoot())
|
obj.infohash = Base64.encode(sf.getRoot())
|
||||||
obj.size = sf.getCachedLength()
|
obj.size = sf.getCachedLength()
|
||||||
obj.pieceSize = sf.getPieceSize()
|
obj.pieceSize = sf.getPieceSize()
|
||||||
|
|
||||||
|
@@ -83,7 +83,7 @@ class UpdateClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onFileDownloadedEvent(FileDownloadedEvent e) {
|
void onFileDownloadedEvent(FileDownloadedEvent e) {
|
||||||
if (e.downloadedFile.infoHash != updateInfoHash)
|
if (e.infoHash != updateInfoHash)
|
||||||
return
|
return
|
||||||
updateDownloading = false
|
updateDownloading = false
|
||||||
eventBus.publish(new UpdateDownloadedEvent(version : version, signer : signer, text : text))
|
eventBus.publish(new UpdateDownloadedEvent(version : version, signer : signer, text : text))
|
||||||
|
@@ -12,6 +12,7 @@ import com.muwire.core.download.DownloadManager
|
|||||||
import com.muwire.core.download.Downloader
|
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.files.PersisterFolderService
|
||||||
import com.muwire.core.mesh.Mesh
|
import com.muwire.core.mesh.Mesh
|
||||||
import com.muwire.core.mesh.MeshManager
|
import com.muwire.core.mesh.MeshManager
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ import net.i2p.data.Base64
|
|||||||
public class UploadManager {
|
public class UploadManager {
|
||||||
private final EventBus eventBus
|
private final EventBus eventBus
|
||||||
private final FileManager fileManager
|
private final FileManager fileManager
|
||||||
|
private final PersisterFolderService persisterService
|
||||||
private final MeshManager meshManager
|
private final MeshManager meshManager
|
||||||
private final DownloadManager downloadManager
|
private final DownloadManager downloadManager
|
||||||
private final MuWireSettings props
|
private final MuWireSettings props
|
||||||
@@ -34,9 +36,11 @@ public class UploadManager {
|
|||||||
|
|
||||||
public UploadManager(EventBus eventBus, FileManager fileManager,
|
public UploadManager(EventBus eventBus, FileManager fileManager,
|
||||||
MeshManager meshManager, DownloadManager downloadManager,
|
MeshManager meshManager, DownloadManager downloadManager,
|
||||||
|
PersisterFolderService persisterService,
|
||||||
MuWireSettings props) {
|
MuWireSettings props) {
|
||||||
this.eventBus = eventBus
|
this.eventBus = eventBus
|
||||||
this.fileManager = fileManager
|
this.fileManager = fileManager
|
||||||
|
this.persisterService = persisterService
|
||||||
this.meshManager = meshManager
|
this.meshManager = meshManager
|
||||||
this.downloadManager = downloadManager
|
this.downloadManager = downloadManager
|
||||||
this.props = props
|
this.props = props
|
||||||
@@ -162,7 +166,7 @@ public class UploadManager {
|
|||||||
|
|
||||||
InfoHash fullInfoHash
|
InfoHash fullInfoHash
|
||||||
if (downloader == null) {
|
if (downloader == null) {
|
||||||
fullInfoHash = sharedFiles.iterator().next().infoHash
|
fullInfoHash = persisterService.loadInfoHash(sharedFiles.iterator().next())
|
||||||
} else {
|
} else {
|
||||||
byte [] hashList = downloader.getInfoHash().getHashList()
|
byte [] hashList = downloader.getInfoHash().getHashList()
|
||||||
if (hashList != null && hashList.length > 0)
|
if (hashList != null && hashList.length > 0)
|
||||||
|
@@ -10,9 +10,9 @@ public class DownloadedFile extends SharedFile {
|
|||||||
|
|
||||||
private final Set<Destination> sources;
|
private final Set<Destination> sources;
|
||||||
|
|
||||||
public DownloadedFile(File file, InfoHash infoHash, int pieceSize, Set<Destination> sources)
|
public DownloadedFile(File file, byte[] root, int pieceSize, Set<Destination> sources)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
super(file, infoHash, pieceSize);
|
super(file, root, pieceSize);
|
||||||
this.sources = sources;
|
this.sources = sources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@ import java.io.IOException;
|
|||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -18,7 +19,7 @@ import net.i2p.data.Base64;
|
|||||||
public class SharedFile {
|
public class SharedFile {
|
||||||
|
|
||||||
private final File file;
|
private final File file;
|
||||||
private final InfoHash infoHash;
|
private final byte[] root;
|
||||||
private final int pieceSize;
|
private final int pieceSize;
|
||||||
|
|
||||||
private final String cachedPath;
|
private final String cachedPath;
|
||||||
@@ -26,29 +27,18 @@ public class SharedFile {
|
|||||||
|
|
||||||
private String b64PathHash;
|
private String b64PathHash;
|
||||||
private final String b64EncodedFileName;
|
private final String b64EncodedFileName;
|
||||||
private final String b64EncodedHashRoot;
|
|
||||||
private final List<String> b64EncodedHashList;
|
|
||||||
|
|
||||||
private volatile String comment;
|
private volatile String comment;
|
||||||
private final Set<String> downloaders = Collections.synchronizedSet(new HashSet<>());
|
private final Set<String> downloaders = Collections.synchronizedSet(new HashSet<>());
|
||||||
private final Set<SearchEntry> searches = Collections.synchronizedSet(new HashSet<>());
|
private final Set<SearchEntry> searches = Collections.synchronizedSet(new HashSet<>());
|
||||||
|
|
||||||
public SharedFile(File file, InfoHash infoHash, int pieceSize) throws IOException {
|
public SharedFile(File file, byte[] root, int pieceSize) throws IOException {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.infoHash = infoHash;
|
this.root = root;
|
||||||
this.pieceSize = pieceSize;
|
this.pieceSize = pieceSize;
|
||||||
this.cachedPath = file.getAbsolutePath();
|
this.cachedPath = file.getAbsolutePath();
|
||||||
this.cachedLength = file.length();
|
this.cachedLength = file.length();
|
||||||
this.b64EncodedFileName = Base64.encode(DataUtil.encodei18nString(file.toString()));
|
this.b64EncodedFileName = Base64.encode(DataUtil.encodei18nString(file.toString()));
|
||||||
this.b64EncodedHashRoot = Base64.encode(infoHash.getRoot());
|
|
||||||
|
|
||||||
List<String> b64List = new ArrayList<String>();
|
|
||||||
byte[] tmp = new byte[32];
|
|
||||||
for (int i = 0; i < infoHash.getHashList().length / 32; i++) {
|
|
||||||
System.arraycopy(infoHash.getHashList(), i * 32, tmp, 0, 32);
|
|
||||||
b64List.add(Base64.encode(tmp));
|
|
||||||
}
|
|
||||||
this.b64EncodedHashList = b64List;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile() {
|
public File getFile() {
|
||||||
@@ -56,7 +46,7 @@ public class SharedFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getPathHash() throws NoSuchAlgorithmException {
|
public byte[] getPathHash() throws NoSuchAlgorithmException {
|
||||||
var digester = MessageDigest.getInstance("SHA-256");
|
MessageDigest digester = MessageDigest.getInstance("SHA-256");
|
||||||
digester.update(file.getAbsolutePath().getBytes());
|
digester.update(file.getAbsolutePath().getBytes());
|
||||||
return digester.digest();
|
return digester.digest();
|
||||||
}
|
}
|
||||||
@@ -68,8 +58,8 @@ public class SharedFile {
|
|||||||
return b64PathHash;
|
return b64PathHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InfoHash getInfoHash() {
|
public byte[] getRoot() {
|
||||||
return infoHash;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPieceSize() {
|
public int getPieceSize() {
|
||||||
@@ -89,14 +79,6 @@ public class SharedFile {
|
|||||||
return b64EncodedFileName;
|
return b64EncodedFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getB64EncodedHashRoot() {
|
|
||||||
return b64EncodedHashRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getB64EncodedHashList() {
|
|
||||||
return b64EncodedHashList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCachedPath() {
|
public String getCachedPath() {
|
||||||
return cachedPath;
|
return cachedPath;
|
||||||
}
|
}
|
||||||
@@ -135,7 +117,7 @@ public class SharedFile {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return file.hashCode() ^ infoHash.hashCode();
|
return file.hashCode() ^ Arrays.hashCode(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -143,7 +125,7 @@ public class SharedFile {
|
|||||||
if (!(o instanceof SharedFile))
|
if (!(o instanceof SharedFile))
|
||||||
return false;
|
return false;
|
||||||
SharedFile other = (SharedFile)o;
|
SharedFile other = (SharedFile)o;
|
||||||
return file.equals(other.file) && infoHash.equals(other.infoHash);
|
return file.equals(other.file) && Arrays.equals(root, other.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SearchEntry {
|
public static class SearchEntry {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
group = com.muwire
|
group = com.muwire
|
||||||
version = 0.6.8
|
version = 0.6.10
|
||||||
i2pVersion = 0.9.44
|
i2pVersion = 0.9.44
|
||||||
groovyVersion = 2.4.15
|
groovyVersion = 2.4.15
|
||||||
slf4jVersion = 1.7.25
|
slf4jVersion = 1.7.25
|
||||||
|
@@ -363,6 +363,8 @@ class MainFrameModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onFileLoadedEvent(FileLoadedEvent e) {
|
void onFileLoadedEvent(FileLoadedEvent e) {
|
||||||
|
if (e.source == "PersisterService")
|
||||||
|
return
|
||||||
runInsideUIAsync {
|
runInsideUIAsync {
|
||||||
shared << e.loadedFile
|
shared << e.loadedFile
|
||||||
loadedFiles = shared.size()
|
loadedFiles = shared.size()
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.muwire.gui
|
package com.muwire.gui
|
||||||
|
|
||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
|
import com.muwire.core.InfoHash
|
||||||
import com.muwire.core.SharedFile
|
import com.muwire.core.SharedFile
|
||||||
|
|
||||||
import griffon.core.artifact.GriffonModel
|
import griffon.core.artifact.GriffonModel
|
||||||
@@ -21,6 +22,6 @@ class SharedFileModel {
|
|||||||
public void mvcGroupInit(Map<String,String> args) {
|
public void mvcGroupInit(Map<String,String> args) {
|
||||||
searchers.addAll(sf.getSearches())
|
searchers.addAll(sf.getSearches())
|
||||||
downloaders.addAll(sf.getDownloaders())
|
downloaders.addAll(sf.getDownloaders())
|
||||||
certificates.addAll(core.certificateManager.byInfoHash.getOrDefault(sf.infoHash,[]))
|
certificates.addAll(core.certificateManager.byInfoHash.getOrDefault(new InfoHash(sf.getRoot()),[]))
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 37 KiB |
@@ -35,6 +35,7 @@ import javax.swing.tree.TreePath
|
|||||||
|
|
||||||
import com.muwire.core.Constants
|
import com.muwire.core.Constants
|
||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
|
import com.muwire.core.InfoHash
|
||||||
import com.muwire.core.MuWireSettings
|
import com.muwire.core.MuWireSettings
|
||||||
import com.muwire.core.SharedFile
|
import com.muwire.core.SharedFile
|
||||||
import com.muwire.core.download.Downloader
|
import com.muwire.core.download.Downloader
|
||||||
@@ -289,7 +290,7 @@ class MainFrameView {
|
|||||||
closureColumn(header : "Comments", preferredWidth : 50, type : Boolean, read : {it.getComment() != null})
|
closureColumn(header : "Comments", preferredWidth : 50, type : Boolean, read : {it.getComment() != null})
|
||||||
closureColumn(header : "Certified", preferredWidth : 50, type : Boolean, read : {
|
closureColumn(header : "Certified", preferredWidth : 50, type : Boolean, read : {
|
||||||
Core core = application.context.get("core")
|
Core core = application.context.get("core")
|
||||||
core.certificateManager.hasLocalCertificate(it.getInfoHash())
|
core.certificateManager.hasLocalCertificate(new InfoHash(it.getRoot()))
|
||||||
})
|
})
|
||||||
closureColumn(header : "Search Hits", preferredWidth: 50, type : Integer, read : {it.getHits()})
|
closureColumn(header : "Search Hits", preferredWidth: 50, type : Integer, read : {it.getHits()})
|
||||||
closureColumn(header : "Downloaders", preferredWidth: 50, type : Integer, read : {it.getDownloaders().size()})
|
closureColumn(header : "Downloaders", preferredWidth: 50, type : Integer, read : {it.getDownloaders().size()})
|
||||||
@@ -911,7 +912,7 @@ class MainFrameView {
|
|||||||
String roots = ""
|
String roots = ""
|
||||||
for (Iterator<SharedFile> iterator = selectedFiles.iterator(); iterator.hasNext(); ) {
|
for (Iterator<SharedFile> iterator = selectedFiles.iterator(); iterator.hasNext(); ) {
|
||||||
SharedFile selected = iterator.next()
|
SharedFile selected = iterator.next()
|
||||||
String root = Base64.encode(selected.infoHash.getRoot())
|
String root = Base64.encode(selected.getRoot())
|
||||||
roots += root
|
roots += root
|
||||||
if (iterator.hasNext())
|
if (iterator.hasNext())
|
||||||
roots += "\n"
|
roots += "\n"
|
||||||
|
@@ -21,7 +21,6 @@ import com.muwire.core.files.FileTree;
|
|||||||
import com.muwire.core.files.FileTreeCallback;
|
import com.muwire.core.files.FileTreeCallback;
|
||||||
import com.muwire.core.files.FileUnsharedEvent;
|
import com.muwire.core.files.FileUnsharedEvent;
|
||||||
import com.muwire.core.files.UICommentEvent;
|
import com.muwire.core.files.UICommentEvent;
|
||||||
import com.muwire.core.files.UIPersistFilesEvent;
|
|
||||||
import com.muwire.core.util.DataUtil;
|
import com.muwire.core.util.DataUtil;
|
||||||
|
|
||||||
import net.i2p.data.Base64;
|
import net.i2p.data.Base64;
|
||||||
@@ -132,7 +131,6 @@ public class FileManager {
|
|||||||
core.getEventBus().publish(event);
|
core.getEventBus().publish(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
core.getEventBus().publish(new UIPersistFilesEvent());
|
|
||||||
Util.pause();
|
Util.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -89,12 +89,13 @@ public class FilesServlet extends HttpServlet {
|
|||||||
String comment = null;
|
String comment = null;
|
||||||
if (sf.getComment() != null)
|
if (sf.getComment() != null)
|
||||||
comment = DataUtil.readi18nString(Base64.decode(sf.getComment()));
|
comment = DataUtil.readi18nString(Base64.decode(sf.getComment()));
|
||||||
|
InfoHash ih = new InfoHash(sf.getRoot());
|
||||||
FilesTableEntry entry = new FilesTableEntry(sf.getFile().getName(),
|
FilesTableEntry entry = new FilesTableEntry(sf.getFile().getName(),
|
||||||
sf.getInfoHash(),
|
ih,
|
||||||
sf.getCachedPath(),
|
sf.getCachedPath(),
|
||||||
sf.getCachedLength(),
|
sf.getCachedLength(),
|
||||||
comment,
|
comment,
|
||||||
core.getCertificateManager().hasLocalCertificate(sf.getInfoHash()));
|
core.getCertificateManager().hasLocalCertificate(ih));
|
||||||
entries.add(entry);
|
entries.add(entry);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -260,12 +261,13 @@ public class FilesServlet extends HttpServlet {
|
|||||||
sb.append("<Name>").append(Util.escapeHTMLinXML(sf.getFile().getName())).append("</Name>");
|
sb.append("<Name>").append(Util.escapeHTMLinXML(sf.getFile().getName())).append("</Name>");
|
||||||
sb.append("<Path>").append(Util.escapeHTMLinXML(sf.getCachedPath())).append("</Path>");
|
sb.append("<Path>").append(Util.escapeHTMLinXML(sf.getCachedPath())).append("</Path>");
|
||||||
sb.append("<Size>").append(DataHelper.formatSize2Decimal(sf.getCachedLength())).append("B").append("</Size>");
|
sb.append("<Size>").append(DataHelper.formatSize2Decimal(sf.getCachedLength())).append("B").append("</Size>");
|
||||||
sb.append("<InfoHash>").append(Base64.encode(sf.getInfoHash().getRoot())).append("</InfoHash>");
|
sb.append("<InfoHash>").append(Base64.encode(sf.getRoot())).append("</InfoHash>");
|
||||||
if (sf.getComment() != null) {
|
if (sf.getComment() != null) {
|
||||||
String comment = DataUtil.readi18nString(Base64.decode(sf.getComment()));
|
String comment = DataUtil.readi18nString(Base64.decode(sf.getComment()));
|
||||||
sb.append("<Comment>").append(Util.escapeHTMLinXML(comment)).append("</Comment>");
|
sb.append("<Comment>").append(Util.escapeHTMLinXML(comment)).append("</Comment>");
|
||||||
}
|
}
|
||||||
sb.append("<Certified>").append(core.getCertificateManager().hasLocalCertificate(sf.getInfoHash())).append("</Certified>");
|
InfoHash ih = new InfoHash(sf.getRoot());
|
||||||
|
sb.append("<Certified>").append(core.getCertificateManager().hasLocalCertificate(ih)).append("</Certified>");
|
||||||
// TODO: other stuff
|
// TODO: other stuff
|
||||||
sb.append("</File>");
|
sb.append("</File>");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user