Fix few bugs

This commit is contained in:
anthonyraymond 2018-02-17 02:02:14 +01:00
parent bcdd1a6138
commit 991d578c2f
10 changed files with 32 additions and 14 deletions

View file

@ -180,7 +180,6 @@ public class SeedManager {
public void stop() {
this.isSeeding = false;
this.bandwidthDispatcher = null;
if (client != null) {
this.client.stop();
this.publisher.publishEvent(new GlobalSeedStoppedEvent());

View file

@ -85,6 +85,7 @@ public class BandwidthDispatcher implements BandwidthDispatcherFacade, Runnable
// refresh bandwidth every 1200000 milliseconds (20 minutes)
if (this.threadLoopCounter == 1200000 / this.threadPauseInterval) {
this.refreshCurrentBandwidth();
this.threadLoopCounter = 0;
}
// This method as to run as fast as possible to avoid blocking other ones. Because we wan't this loop

View file

@ -144,7 +144,7 @@ public class TorrentFileProvider extends FileAlterationListenerAdaptor {
public void moveToArchiveFolder(final String torrentInfoHash) {
final Optional<File> first = this.torrentFiles.entrySet().stream()
.filter(entry -> entry.getValue().getHexInfoHash().equals(torrentInfoHash))
.filter(entry -> entry.getValue().getTorrentInfoHash().value().equals(torrentInfoHash))
.map(Map.Entry::getKey)
.findFirst();
if (first.isPresent()) {

View file

@ -66,6 +66,7 @@ public class Client implements TorrentFileChangeAware, ClientFacade {
this.announcerExecutor.execute(req, this.announceResponseCallback);
try {
this.lock.writeLock().lock();
this.currentlySeedingAnnouncer.removeIf(an -> an.equals(req.getAnnouncer())); // remove the last recorded event
this.currentlySeedingAnnouncer.add(req.getAnnouncer());
} finally {
this.lock.writeLock().unlock();

View file

@ -8,7 +8,7 @@ import org.araymond.joal.core.torrent.torrent.MockedTorrent;
import org.araymond.joal.core.ttorrent.client.announcer.exceptions.TooMuchAnnouncesFailedInARawException;
import org.araymond.joal.core.ttorrent.client.announcer.request.AnnounceDataAccessor;
import org.araymond.joal.core.ttorrent.client.announcer.request.SuccessAnnounceResponse;
import org.araymond.joal.core.ttorrent.client.announcer.tracker.NewTrackerClient;
import org.araymond.joal.core.ttorrent.client.announcer.tracker.TrackerClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -24,12 +24,12 @@ public class Announcer implements AnnouncerFacade {
private Integer lastKnownSeeders = null;
private LocalDateTime lastAnnouncedAt = null;
private final MockedTorrent torrent;
private final NewTrackerClient trackerClient;
private final TrackerClient trackerClient;
private final AnnounceDataAccessor announceDataAccessor;
public Announcer(final MockedTorrent torrent, final AnnounceDataAccessor announceDataAccessor) {
this.torrent = torrent;
this.trackerClient = new NewTrackerClient(torrent);
this.trackerClient = new TrackerClient(torrent);
this.announceDataAccessor = announceDataAccessor;
}
@ -104,6 +104,11 @@ public class Announcer implements AnnouncerFacade {
return this.torrent.getName();
}
@Override
public long getTorrentSize() {
return this.torrent.getSize();
}
@Override
public InfoHash getTorrentInfoHash() {
return this.getTorrent().getTorrentInfoHash();

View file

@ -12,5 +12,6 @@ public interface AnnouncerFacade {
Optional<Integer> getLastKnownSeeders();
Optional<LocalDateTime> getLastAnnouncedAt();
String getTorrentName();
long getTorrentSize();
InfoHash getTorrentInfoHash();
}

View file

@ -25,12 +25,12 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class NewTrackerClient {
private static final Logger logger = LoggerFactory.getLogger(NewTrackerClient.class);
public class TrackerClient {
private static final Logger logger = LoggerFactory.getLogger(TrackerClient.class);
private final TrackerClientUriProvider trackerClientUriProvider;
public NewTrackerClient(final MockedTorrent torrent) {
public TrackerClient(final MockedTorrent torrent) {
final List<URI> trackerURIs = torrent.getAnnounceList().stream() // Use a list to keep it ordered
.sequential()
.flatMap(Collection::stream)
@ -55,7 +55,7 @@ public class NewTrackerClient {
if (responseMessage instanceof ErrorMessage) {
final ErrorMessage error = (ErrorMessage) responseMessage;
throw new AnnounceException(error.getReason());
throw new AnnounceException(baseUri + ": " + error.getReason());
}
} catch (final AnnounceException e) {
// If the request has failed we need to move to the next tracker.

View file

@ -9,6 +9,7 @@ import java.time.LocalDateTime;
public abstract class AnnouncePayload implements MessagePayload {
private final InfoHash infoHash;
private final String torrentName;
private final long torrentSize;
private final int lastKnownInterval;
private final int consecutiveFails;
private final LocalDateTime lastAnnouncedAt;
@ -18,6 +19,7 @@ public abstract class AnnouncePayload implements MessagePayload {
protected AnnouncePayload(final AnnouncerFacade announcerFacade) {
this.infoHash = announcerFacade.getTorrentInfoHash();
this.torrentName = announcerFacade.getTorrentName();
this.torrentSize = announcerFacade.getTorrentSize();
this.lastKnownInterval = announcerFacade.getLastKnownInterval();
this.consecutiveFails = announcerFacade.getConsecutiveFails();
this.lastAnnouncedAt = announcerFacade.getLastAnnouncedAt().orElse(null);
@ -31,6 +33,9 @@ public abstract class AnnouncePayload implements MessagePayload {
public String getTorrentName() {
return torrentName;
}
public long getTorrentSize() {
return torrentSize;
}
public int getLastKnownInterval() {
return lastKnownInterval;
}

View file

@ -12,7 +12,7 @@ public class SeedingSpeedHasChangedPayload implements MessagePayload {
public SeedingSpeedHasChangedPayload(final SeedingSpeedsHasChangedEvent event) {
this.speeds = event.getSpeeds().entrySet().stream()
.map(entry -> new SpeedPayload(entry.getKey(), String.valueOf(entry.getValue().getBytesPerSeconds())))
.map(entry -> new SpeedPayload(entry.getKey(), Long.valueOf(entry.getValue().getBytesPerSeconds())))
.collect(Collectors.toList());
}
@ -22,9 +22,9 @@ public class SeedingSpeedHasChangedPayload implements MessagePayload {
public static final class SpeedPayload {
private final InfoHash infoHash;
private final String bytesPerSeconds;
private final Long bytesPerSeconds;
public SpeedPayload(final InfoHash infoHash, final String bytesPerSeconds) {
public SpeedPayload(final InfoHash infoHash, final Long bytesPerSeconds) {
this.infoHash = infoHash;
this.bytesPerSeconds = bytesPerSeconds;
}
@ -33,7 +33,7 @@ public class SeedingSpeedHasChangedPayload implements MessagePayload {
return infoHash;
}
public String getBytesPerSeconds() {
public Long getBytesPerSeconds() {
return bytesPerSeconds;
}
}

View file

@ -3,12 +3,14 @@ package org.araymond.joal.web.resources;
import com.turn.ttorrent.common.protocol.TrackerMessage.AnnounceRequestMessage.RequestEvent;
import org.apache.commons.codec.binary.Base64;
import org.araymond.joal.core.SeedManager;
import org.araymond.joal.core.bandwith.Speed;
import org.araymond.joal.core.config.AppConfigurationIntegrityException;
import org.araymond.joal.core.events.announce.SuccessfullyAnnounceEvent;
import org.araymond.joal.core.events.config.ConfigHasBeenLoadedEvent;
import org.araymond.joal.core.events.config.ListOfClientFilesEvent;
import org.araymond.joal.core.events.speed.SeedingSpeedsHasChangedEvent;
import org.araymond.joal.core.events.torrent.files.TorrentFileAddedEvent;
import org.araymond.joal.core.torrent.torrent.InfoHash;
import org.araymond.joal.core.torrent.torrent.MockedTorrent;
import org.araymond.joal.core.ttorrent.client.announcer.AnnouncerFacade;
import org.araymond.joal.web.annotations.ConditionalOnWebUi;
@ -34,6 +36,7 @@ import javax.inject.Inject;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* Created by raymo on 28/07/2017.
@ -126,7 +129,10 @@ public class WebSocketController {
}
// speeds
events.addFirst(StompMessage.wrap(new SeedingSpeedHasChangedPayload(new SeedingSpeedsHasChangedEvent(this.seedManager.getSpeedMap()))));
final Map<InfoHash, Speed> speedMap = this.seedManager.getSpeedMap();
if (!speedMap.isEmpty()) {
events.addFirst(StompMessage.wrap(new SeedingSpeedHasChangedPayload(new SeedingSpeedsHasChangedEvent(speedMap))));
}
// Announcers are the most likely to change due to a concurrent access, so we gather them as late as possible, and we put them at the top of the list.
for (final AnnouncerFacade announcerFacade : this.seedManager.getCurrentlySeedingAnnouncer()) {