mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +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.TransportId;
|
||||
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.GroupId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
@@ -97,6 +98,8 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
||||
private final Dns noDnsLookups;
|
||||
private final AtomicBoolean fetcherStarted = new AtomicBoolean(false);
|
||||
|
||||
private volatile boolean torActive = false;
|
||||
|
||||
@Inject
|
||||
FeedManagerImpl(@Scheduler ScheduledExecutorService scheduler,
|
||||
@IoExecutor Executor ioExecutor, DatabaseComponent db,
|
||||
@@ -123,11 +126,20 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
||||
if (e instanceof TransportActiveEvent) {
|
||||
TransportId t = ((TransportActiveEvent) e).getTransportId();
|
||||
if (t.equals(TorConstants.ID)) {
|
||||
setTorActive(true);
|
||||
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() {
|
||||
if (fetcherStarted.getAndSet(true)) return;
|
||||
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.
|
||||
*/
|
||||
void fetchFeeds() {
|
||||
if (!torActive) return;
|
||||
LOG.info("Updating RSS feeds...");
|
||||
|
||||
// Get current feeds
|
||||
|
||||
@@ -76,15 +76,22 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
SocketFactory.getDefault(), clock, noDnsLookups);
|
||||
|
||||
@Test
|
||||
public void testEmptyFetchFeed() throws Exception {
|
||||
BdfList feedList = new BdfList();
|
||||
expectGetFeeds(feedList);
|
||||
expectStoreFeed(feedList);
|
||||
public void testFetchFeedsReturnsEarlyIfTorIsNotActive() {
|
||||
feedManager.setTorActive(false);
|
||||
feedManager.fetchFeeds();
|
||||
}
|
||||
|
||||
@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();
|
||||
BdfList feedList = BdfList.of(feedDict);
|
||||
|
||||
@@ -95,6 +102,7 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
expectStoreFeed(feedList);
|
||||
|
||||
feedManager.setTorActive(true);
|
||||
feedManager.fetchFeeds();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user