Remove unused directory command

This commit is contained in:
Moxie Marlinspike 2019-04-01 18:25:49 -07:00
parent e8f795763b
commit 944e1d9698
3 changed files with 0 additions and 242 deletions

View File

@ -107,7 +107,6 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
@Override
public void initialize(Bootstrap<WhisperServerConfiguration> bootstrap) {
bootstrap.addCommand(new DirectoryCommand());
bootstrap.addCommand(new VacuumCommand());
bootstrap.addCommand(new TrimMessagesCommand());
bootstrap.addCommand(new DeleteUserCommand());

View File

@ -1,88 +0,0 @@
/**
* Copyright (C) 2013 Open WhisperSystems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.whispersystems.textsecuregcm.workers;
import com.fasterxml.jackson.databind.DeserializationFeature;
import net.sourceforge.argparse4j.inf.Namespace;
import org.skife.jdbi.v2.DBI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.WhisperServerConfiguration;
import org.whispersystems.textsecuregcm.providers.RedisClientFactory;
import org.whispersystems.textsecuregcm.redis.ReplicatedJedisPool;
import org.whispersystems.textsecuregcm.storage.Accounts;
import org.whispersystems.textsecuregcm.storage.AccountsManager;
import org.whispersystems.textsecuregcm.storage.DirectoryManager;
import io.dropwizard.Application;
import io.dropwizard.cli.EnvironmentCommand;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.jdbi.ImmutableListContainerFactory;
import io.dropwizard.jdbi.ImmutableSetContainerFactory;
import io.dropwizard.jdbi.OptionalContainerFactory;
import io.dropwizard.jdbi.args.OptionalArgumentFactory;
import io.dropwizard.setup.Environment;
public class DirectoryCommand extends EnvironmentCommand<WhisperServerConfiguration> {
private final Logger logger = LoggerFactory.getLogger(DirectoryCommand.class);
public DirectoryCommand() {
super(new Application<WhisperServerConfiguration>() {
@Override
public void run(WhisperServerConfiguration configuration, Environment environment)
throws Exception
{
}
}, "directory", "Update directory from DB and peers.");
}
@Override
protected void run(Environment environment, Namespace namespace,
WhisperServerConfiguration configuration)
throws Exception
{
try {
environment.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
DataSourceFactory dbConfig = configuration.getReadDataSourceFactory();
DBI dbi = new DBI(dbConfig.getUrl(), dbConfig.getUser(), dbConfig.getPassword());
dbi.registerArgumentFactory(new OptionalArgumentFactory(dbConfig.getDriverClass()));
dbi.registerContainerFactory(new ImmutableListContainerFactory());
dbi.registerContainerFactory(new ImmutableSetContainerFactory());
dbi.registerContainerFactory(new OptionalContainerFactory());
Accounts accounts = dbi.onDemand(Accounts.class);
ReplicatedJedisPool cacheClient = new RedisClientFactory("main_cache_directory_command", configuration.getCacheConfiguration().getUrl(), configuration.getCacheConfiguration().getReplicaUrls(), configuration.getCacheConfiguration().getCircuitBreakerConfiguration()).getRedisClientPool();
ReplicatedJedisPool redisClient = new RedisClientFactory("directory_cache_directory_command", configuration.getDirectoryConfiguration().getRedisConfiguration().getUrl(), configuration.getDirectoryConfiguration().getRedisConfiguration().getReplicaUrls(), configuration.getDirectoryConfiguration().getRedisConfiguration().getCircuitBreakerConfiguration()).getRedisClientPool();
DirectoryManager directory = new DirectoryManager(redisClient);
AccountsManager accountsManager = new AccountsManager(accounts, directory, cacheClient);
DirectoryUpdater update = new DirectoryUpdater(accountsManager, directory);
update.updateFromLocalDatabase();
} catch (Exception ex) {
logger.warn("Directory Exception", ex);
throw new RuntimeException(ex);
} finally {
// Thread.sleep(3000);
// System.exit(0);
}
}
}

View File

@ -1,153 +0,0 @@
/*
* Copyright (C) 2013 Open WhisperSystems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.whispersystems.textsecuregcm.workers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.entities.ClientContact;
import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.AccountsManager;
import org.whispersystems.textsecuregcm.storage.DirectoryManager;
import org.whispersystems.textsecuregcm.storage.DirectoryManager.BatchOperationHandle;
import org.whispersystems.textsecuregcm.util.Util;
import java.util.List;
public class DirectoryUpdater {
private static final int CHUNK_SIZE = 10000;
private final Logger logger = LoggerFactory.getLogger(DirectoryUpdater.class);
private final AccountsManager accountsManager;
private final DirectoryManager directory;
public DirectoryUpdater(AccountsManager accountsManager, DirectoryManager directory)
{
this.accountsManager = accountsManager;
this.directory = directory;
}
public void updateFromLocalDatabase() {
int contactsAdded = 0;
int contactsRemoved = 0;
BatchOperationHandle batchOperation = directory.startBatchOperation();
try {
logger.info("Updating from local DB.");
int offset = 0;
for (;;) {
List<Account> accounts = accountsManager.getAll(offset, CHUNK_SIZE);
if (accounts == null || accounts.isEmpty()) break;
else offset += accounts.size();
for (Account account : accounts) {
if (account.isActive()) {
byte[] token = Util.getContactToken(account.getNumber());
ClientContact clientContact = new ClientContact(token, null, true, true);
directory.add(batchOperation, clientContact);
contactsAdded++;
} else {
directory.remove(batchOperation, account.getNumber());
contactsRemoved++;
}
}
logger.info("Processed " + CHUNK_SIZE + " local accounts...");
}
} finally {
directory.stopBatchOperation(batchOperation);
}
logger.info(String.format("Local directory is updated (%d added, %d removed).", contactsAdded, contactsRemoved));
}
// public void updateFromPeers() {
// logger.info("Updating peer directories.");
//
// int contactsAdded = 0;
// int contactsRemoved = 0;
// List<FederatedClient> clients = federatedClientManager.getClients();
//
// for (FederatedClient client : clients) {
// logger.info("Updating directory from peer: " + client.getPeerName());
//
// int userCount = client.getUserCount();
// int retrieved = 0;
//
// logger.info("Remote peer user count: " + userCount);
//
// while (retrieved < userCount) {
// logger.info("Retrieving remote tokens...");
// List<ClientContact> remoteContacts = client.getUserTokens(retrieved);
// List<PendingClientContact> localContacts = new LinkedList<>();
// BatchOperationHandle handle = directory.startBatchOperation();
//
// if (remoteContacts == null) {
// logger.info("Remote tokens empty, ending...");
// break;
// } else {
// logger.info("Retrieved " + remoteContacts.size() + " remote tokens...");
// }
//
// for (ClientContact remoteContact : remoteContacts) {
// localContacts.add(directory.get(handle, remoteContact.getToken()));
// }
//
// directory.stopBatchOperation(handle);
//
// handle = directory.startBatchOperation();
// Iterator<ClientContact> remoteContactIterator = remoteContacts.iterator();
// Iterator<PendingClientContact> localContactIterator = localContacts.iterator();
//
// while (remoteContactIterator.hasNext() && localContactIterator.hasNext()) {
// try {
// ClientContact remoteContact = remoteContactIterator.next();
// Optional<ClientContact> localContact = localContactIterator.next().get();
//
// remoteContact.setRelay(client.getPeerName());
//
// if (!remoteContact.isInactive() && (!localContact.isPresent() || client.getPeerName().equals(localContact.get().getRelay()))) {
// contactsAdded++;
// directory.add(handle, remoteContact);
// } else {
// if (localContact.isPresent() && client.getPeerName().equals(localContact.get().getRelay())) {
// contactsRemoved++;
// directory.remove(handle, remoteContact.getToken());
// }
// }
// } catch (IOException e) {
// logger.warn("JSON Serialization Failed: ", e);
// }
// }
//
// directory.stopBatchOperation(handle);
//
// retrieved += remoteContacts.size();
// logger.info("Processed: " + retrieved + " remote tokens.");
// }
//
// logger.info("Update from peer complete.");
// }
//
// logger.info("Update from peer directories complete.");
// logger.info(String.format("Added %d and removed %d remove contacts.", contactsAdded, contactsRemoved));
// }
}