forked from Qortal/qortal
Select a random host when importing a bootstrap, and started adding support for multiple bootstrap types.
This commit is contained in:
parent
47b1b6daba
commit
51bb776e56
@ -18,6 +18,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.*;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@ -256,7 +257,7 @@ public class Bootstrap {
|
||||
);
|
||||
|
||||
LOGGER.info("Compressing...");
|
||||
String compressedOutputPath = String.format("%s%s", Settings.getInstance().getBootstrapFilenamePrefix(), "bootstrap.7z");
|
||||
String compressedOutputPath = String.format("%s%s", Settings.getInstance().getBootstrapFilenamePrefix(), this.getFilename());
|
||||
try {
|
||||
Files.delete(Paths.get(compressedOutputPath));
|
||||
} catch (NoSuchFileException e) {
|
||||
@ -305,7 +306,8 @@ public class Bootstrap {
|
||||
Path path = null;
|
||||
try {
|
||||
Path tempDir = Files.createTempDirectory("qortal-bootstrap");
|
||||
path = Paths.get(tempDir.toString(), "bootstrap.7z");
|
||||
String filename = String.format("%s%s", Settings.getInstance().getBootstrapFilenamePrefix(), this.getFilename());
|
||||
path = Paths.get(tempDir.toString(), filename);
|
||||
|
||||
this.downloadToPath(path);
|
||||
this.importFromPath(path);
|
||||
@ -325,11 +327,31 @@ public class Bootstrap {
|
||||
}
|
||||
}
|
||||
|
||||
private String getFilename() {
|
||||
boolean pruningEnabled = Settings.getInstance().isPruningEnabled();
|
||||
boolean archiveEnabled = Settings.getInstance().isArchiveEnabled();
|
||||
|
||||
if (pruningEnabled) {
|
||||
return "bootstrap-toponly.7z";
|
||||
}
|
||||
else if (archiveEnabled) {
|
||||
return "bootstrap-archive.7z";
|
||||
}
|
||||
else {
|
||||
return "bootstrap-full.7z";
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadToPath(Path path) throws DataException {
|
||||
String bootstrapUrl = "http://bootstrap.qortal.org/bootstrap.7z";
|
||||
// Select a random host from bootstrapHosts
|
||||
String[] hosts = Settings.getInstance().getBootstrapHosts();
|
||||
int index = new SecureRandom().nextInt(hosts.length);
|
||||
String bootstrapHost = hosts[index];
|
||||
String bootstrapFilename = this.getFilename();
|
||||
|
||||
try {
|
||||
LOGGER.info("Downloading bootstrap...");
|
||||
String bootstrapUrl = String.format("%s/%s", bootstrapHost, bootstrapFilename);
|
||||
InputStream in = new URL(bootstrapUrl).openStream();
|
||||
Files.copy(in, path, REPLACE_EXISTING);
|
||||
|
||||
|
@ -194,6 +194,11 @@ public class Settings {
|
||||
// Bootstrap
|
||||
private String bootstrapFilenamePrefix = "";
|
||||
|
||||
// Bootstrap sources
|
||||
private String[] bootstrapHosts = new String[] {
|
||||
"http://bootstrap.qortal.org"
|
||||
};
|
||||
|
||||
// Auto-update sources
|
||||
private String[] autoUpdateRepos = new String[] {
|
||||
"https://github.com/Qortal/qortal/raw/%s/qortal.update",
|
||||
@ -528,6 +533,10 @@ public class Settings {
|
||||
return this.autoUpdateRepos;
|
||||
}
|
||||
|
||||
public String[] getBootstrapHosts() {
|
||||
return this.bootstrapHosts;
|
||||
}
|
||||
|
||||
public String getListsPath() {
|
||||
return this.listsPath;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public class BootstrapTests extends Common {
|
||||
@Test
|
||||
public void testCreateAndImportBootstrap() throws DataException, InterruptedException, TransformationException, IOException {
|
||||
|
||||
Path bootstrapPath = Paths.get(String.format("%s%s", Settings.getInstance().getBootstrapFilenamePrefix(), "bootstrap.7z"));
|
||||
Path bootstrapPath = Paths.get(String.format("%s%s", Settings.getInstance().getBootstrapFilenamePrefix(), "bootstrap-archive.7z"));
|
||||
Path archivePath = Paths.get(Settings.getInstance().getRepositoryPath(), "archive", "2-900.dat");
|
||||
BlockData block1000;
|
||||
byte[] originalArchiveContents;
|
||||
@ -183,7 +183,23 @@ public class BootstrapTests extends Common {
|
||||
|
||||
private void deleteBootstraps() throws IOException {
|
||||
try {
|
||||
Path path = Paths.get(String.format("%s%s", Settings.getInstance().getBootstrapFilenamePrefix(), "bootstrap.7z"));
|
||||
Path path = Paths.get(String.format("%s%s", Settings.getInstance().getBootstrapFilenamePrefix(), "bootstrap-archive.7z"));
|
||||
Files.delete(path);
|
||||
|
||||
} catch (NoSuchFileException e) {
|
||||
// Nothing to delete
|
||||
}
|
||||
|
||||
try {
|
||||
Path path = Paths.get(String.format("%s%s", Settings.getInstance().getBootstrapFilenamePrefix(), "bootstrap-toponly.7z"));
|
||||
Files.delete(path);
|
||||
|
||||
} catch (NoSuchFileException e) {
|
||||
// Nothing to delete
|
||||
}
|
||||
|
||||
try {
|
||||
Path path = Paths.get(String.format("%s%s", Settings.getInstance().getBootstrapFilenamePrefix(), "bootstrap-full.7z"));
|
||||
Files.delete(path);
|
||||
|
||||
} catch (NoSuchFileException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user