-
Notifications
You must be signed in to change notification settings - Fork 5
Starting Peers as Bootstrap Nodes
Raphael Matile edited this page Mar 17, 2016
·
1 revision
To start peers as bootstrap nodes, i.e. as an initial peer to which other nodes may connect to join the network,
the BootstrapLocation should be set to null. When using the ApplicationConfigFactory, an appropriate method
is provided:
import org.rmatil.sync.core.Sync;
import org.rmatil.sync.core.init.ApplicationConfigFactory;
import org.rmatil.sync.core.model.ApplicationConfig;
import org.rmatil.sync.network.core.model.NodeLocation;
import org.rmatil.sync.persistence.core.tree.ITreeStorageAdapter;
import org.rmatil.sync.persistence.core.tree.local.LocalStorageAdapter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
// ...
Path rootDir = Paths.get("path/to/synchronised/folder");
ITreeStorageAdapter storageAdapter = new LocalStorageAdapter(rootDir);
// initialise the synchronised folder:
// - create folder for ObjectStore (usually .sync)
// - create folders for shared files:
// - sharedWithOthers (read-write)
// - sharedWithOthers (read-only)
Sync.init(storageAdapter);
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
KeyPair keyPair = keyGen.genKeyPair();
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
ApplicationConfig appConfig = ApplicationConfigFactory.createBootstrapApplicationConfig(
"Piff Jenkins",
"ThisIsSafeUseIt",
"SaltAndPepperMakesTheMealBetter",
publicKey,
privateKey,
ApplicationConfigFactory.getDefaultIgnorePatterns()
);
// create a new Sync instance pointing to the root of the
// specified storage adapter, i.e. path/to/synchronised/folder
Sync sync = new Sync(storageAdapter);
// start the node as bootstrap peer (depending on the specified configuration),
// reconcile state of the synchronised folder with the ObjectStore,
// reconcile local state with other connected clients of the same user
NodeLocation nodeLocation = sync.connect(appConfig);- Commons
- Persistence Layer
- Versioning Layer
- Event Aggregation Layer
- Network Layer
- Core (this repository)
- End-User Client