published flag and timestamp in shared files

This commit is contained in:
Zlatin Balevsky
2020-03-08 15:46:36 +00:00
parent bcd24e56ac
commit 366a2ef841
2 changed files with 32 additions and 1 deletions

View File

@ -47,7 +47,7 @@ abstract class BasePersisterService extends Service{
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()
@ -94,10 +94,19 @@ abstract class BasePersisterService extends Service{
if (json.pieceSize != null)
pieceSize = json.pieceSize
boolean published = false
long publishedTimestamp = -1
if (json.published != null && json.published) {
published = true
publishedTimestamp = json.publishedTimestamp
}
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)
if (published)
df.publish(publishedTimestamp)
df.setComment(json.comment)
return new FileLoadedEvent(loadedFile : df, infoHash: ih)
}
@ -105,6 +114,8 @@ abstract class BasePersisterService extends Service{
SharedFile sf = new SharedFile(file, ih.getRoot(), pieceSize)
sf.setComment(json.comment)
if (published)
sf.published(publishedTimestamp)
if (json.downloaders != null)
sf.getDownloaders().addAll(json.downloaders)
if (json.searchers != null) {
@ -146,6 +157,11 @@ abstract class BasePersisterService extends Service{
if (sf instanceof DownloadedFile) {
json.sources = sf.sources.stream().map( {d -> d.toBase64()}).collect(Collectors.toList())
}
if (sf.isPublished()) {
json.published = true
json.publishedTimestamp = sf.getPublishedTimestamp()
}
json
}

View File

@ -31,6 +31,8 @@ public class SharedFile {
private volatile String comment;
private final Set<String> downloaders = Collections.synchronizedSet(new HashSet<>());
private final Set<SearchEntry> searches = Collections.synchronizedSet(new HashSet<>());
private volatile boolean published;
private volatile long publishedTimestamp;
public SharedFile(File file, byte[] root, int pieceSize) throws IOException {
this.file = file;
@ -114,6 +116,19 @@ public class SharedFile {
public void addDownloader(String name) {
downloaders.add(name);
}
public void publish(long timestamp) {
published = true;
publishedTimestamp = timestamp;
}
public boolean isPublished() {
return published;
}
public long getPublishedTimestamp() {
return publishedTimestamp;
}
@Override
public int hashCode() {