mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Skip fetching RSS feeds if Tor is not active.
This commit is contained in:
@@ -25,6 +25,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.plugin.TorConstants;
|
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
||||||
|
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
@@ -97,6 +98,8 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
private final Dns noDnsLookups;
|
private final Dns noDnsLookups;
|
||||||
private final AtomicBoolean fetcherStarted = new AtomicBoolean(false);
|
private final AtomicBoolean fetcherStarted = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
private volatile boolean torActive = false;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedManagerImpl(@Scheduler ScheduledExecutorService scheduler,
|
FeedManagerImpl(@Scheduler ScheduledExecutorService scheduler,
|
||||||
@IoExecutor Executor ioExecutor, DatabaseComponent db,
|
@IoExecutor Executor ioExecutor, DatabaseComponent db,
|
||||||
@@ -123,11 +126,20 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
if (e instanceof TransportActiveEvent) {
|
if (e instanceof TransportActiveEvent) {
|
||||||
TransportId t = ((TransportActiveEvent) e).getTransportId();
|
TransportId t = ((TransportActiveEvent) e).getTransportId();
|
||||||
if (t.equals(TorConstants.ID)) {
|
if (t.equals(TorConstants.ID)) {
|
||||||
|
setTorActive(true);
|
||||||
startFeedExecutor();
|
startFeedExecutor();
|
||||||
}
|
}
|
||||||
|
} else if (e instanceof TransportInactiveEvent) {
|
||||||
|
TransportId t = ((TransportInactiveEvent) e).getTransportId();
|
||||||
|
if (t.equals(TorConstants.ID)) setTorActive(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Package access for testing
|
||||||
|
void setTorActive(boolean active) {
|
||||||
|
torActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
private void startFeedExecutor() {
|
private void startFeedExecutor() {
|
||||||
if (fetcherStarted.getAndSet(true)) return;
|
if (fetcherStarted.getAndSet(true)) return;
|
||||||
LOG.info("Tor started, scheduling RSS feed fetcher");
|
LOG.info("Tor started, scheduling RSS feed fetcher");
|
||||||
@@ -279,6 +291,7 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
* and we can not block the database that long.
|
* and we can not block the database that long.
|
||||||
*/
|
*/
|
||||||
void fetchFeeds() {
|
void fetchFeeds() {
|
||||||
|
if (!torActive) return;
|
||||||
LOG.info("Updating RSS feeds...");
|
LOG.info("Updating RSS feeds...");
|
||||||
|
|
||||||
// Get current feeds
|
// Get current feeds
|
||||||
|
|||||||
@@ -76,15 +76,22 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
|||||||
SocketFactory.getDefault(), clock, noDnsLookups);
|
SocketFactory.getDefault(), clock, noDnsLookups);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyFetchFeed() throws Exception {
|
public void testFetchFeedsReturnsEarlyIfTorIsNotActive() {
|
||||||
BdfList feedList = new BdfList();
|
feedManager.setTorActive(false);
|
||||||
expectGetFeeds(feedList);
|
|
||||||
expectStoreFeed(feedList);
|
|
||||||
feedManager.fetchFeeds();
|
feedManager.fetchFeeds();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFetchFeedIoException() throws Exception {
|
public void testEmptyFetchFeeds() throws Exception {
|
||||||
|
BdfList feedList = new BdfList();
|
||||||
|
expectGetFeeds(feedList);
|
||||||
|
expectStoreFeed(feedList);
|
||||||
|
feedManager.setTorActive(true);
|
||||||
|
feedManager.fetchFeeds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFetchFeedsIoException() throws Exception {
|
||||||
BdfDictionary feedDict= new BdfDictionary();
|
BdfDictionary feedDict= new BdfDictionary();
|
||||||
BdfList feedList = BdfList.of(feedDict);
|
BdfList feedList = BdfList.of(feedDict);
|
||||||
|
|
||||||
@@ -95,6 +102,7 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
|||||||
}});
|
}});
|
||||||
expectStoreFeed(feedList);
|
expectStoreFeed(feedList);
|
||||||
|
|
||||||
|
feedManager.setTorActive(true);
|
||||||
feedManager.fetchFeeds();
|
feedManager.fetchFeeds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user