From 1b6167cbce471b5bb37dd1301721365df9efa22c Mon Sep 17 00:00:00 2001 From: "Maxim.Zaytsev" Date: Wed, 16 Jan 2019 16:12:59 +0300 Subject: [PATCH] fix bug that seeder doesn't seed files after disconnecting all peers one time --- .../turn/ttorrent/client/CommunicationManager.java | 4 ++-- .../java/com/turn/ttorrent/client/SharedTorrent.java | 11 +++++++++++ .../com/turn/ttorrent/client/TorrentsStorage.java | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java b/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java index 1f5ee3ac4..192c99482 100644 --- a/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java +++ b/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java @@ -270,7 +270,7 @@ public void removeTorrent(String torrentHash) { SharedTorrent torrent = torrents.first(); if (torrent != null) { torrent.setClientState(ClientState.DONE); - torrent.close(); + torrent.closeFully(); } List peers = getPeersForTorrent(torrentHash); for (SharingPeer peer : peers) { @@ -474,7 +474,7 @@ void stop(int timeout, TimeUnit timeUnit) { for (SharedTorrent torrent : this.torrentsStorage.activeTorrents()) { logger.trace("try close torrent {}", torrent); - torrent.close(); + torrent.closeFully(); if (torrent.isFinished()) { torrent.setClientState(ClientState.DONE); } else { diff --git a/ttorrent-client/src/main/java/com/turn/ttorrent/client/SharedTorrent.java b/ttorrent-client/src/main/java/com/turn/ttorrent/client/SharedTorrent.java index 3f6309850..db85ca2dd 100644 --- a/ttorrent-client/src/main/java/com/turn/ttorrent/client/SharedTorrent.java +++ b/ttorrent-client/src/main/java/com/turn/ttorrent/client/SharedTorrent.java @@ -268,6 +268,17 @@ private void hashSingleThread() { } public synchronized void close() { + logger.trace("Closing torrent", myTorrentMetadata.getDirectoryName()); + try { + this.pieceStorage.close(); + isFileChannelOpen = false; + } catch (IOException ioe) { + logger.error("Error closing torrent byte storage: {}", + ioe.getMessage()); + } + } + + public synchronized void closeFully() { logger.trace("Closing torrent", myTorrentMetadata.getDirectoryName()); try { this.pieceStorage.closeFully(); diff --git a/ttorrent-client/src/main/java/com/turn/ttorrent/client/TorrentsStorage.java b/ttorrent-client/src/main/java/com/turn/ttorrent/client/TorrentsStorage.java index 73a50b2ae..27b49cef7 100644 --- a/ttorrent-client/src/main/java/com/turn/ttorrent/client/TorrentsStorage.java +++ b/ttorrent-client/src/main/java/com/turn/ttorrent/client/TorrentsStorage.java @@ -105,7 +105,7 @@ public Pair remove(String hash) { } } if (result.first() != null) { - result.first().close(); + result.first().closeFully(); } return result; } @@ -156,7 +156,7 @@ public void clear() { readWriteLock.writeLock().unlock(); } for (SharedTorrent sharedTorrent : sharedTorrents) { - sharedTorrent.close(); + sharedTorrent.closeFully(); } for (LoadedTorrent loadedTorrent : loadedTorrents) { try {