IFileConfiguration fileConfig = FileConfiguration.createDefault(); IH2HNode peerNode = H2HNode.createNode(fileConfig); boolean success = peerNode.connect(netConfig);
IFileConfiguration fileConfig = FileConfiguration.createDefault(); IH2HNode peerNode = H2HNode.createNode(fileConfig); boolean success = peerNode.connect(netConfig);
public static void main(String[] args) throws UnknownHostException { IFileConfiguration fileConfiguration = FileConfiguration.createDefault();
public static void main(String[] args) throws Exception { IFileConfiguration fileConfiguration = FileConfiguration.createDefault();
public static void main(String[] args) throws NoPeerConnectionException, InvalidProcessStateException, ProcessExecutionException { // Create a node and open a new overlay network IH2HNode node = H2HNode.createNode(FileConfiguration.createDefault()); node.connect(NetworkConfiguration.createInitial()); // The register functionality is in the user manager API IUserManager userManager = node.getUserManager(); // Create user credentials to register a new user 'Alice' UserCredentials alice = new UserCredentials("Alice", "very-secret-password", "secret-pin"); // Create a new register process and start it (blocking) IProcessComponent<Void> registerAlice = userManager.createRegisterProcess(alice); registerAlice.execute(); // Check if Alice is now registered boolean aliceRegistered = userManager.isRegistered("Alice"); System.out.println("Alice is registered: " + aliceRegistered); // Let's login to Alice's user account (blocking) IProcessComponent<Void> loginAlice = userManager.createLoginProcess(alice, new ExampleFileAgent()); loginAlice.execute(); // Check if Alice is now logged in System.out.println("Alice is logged in: " + userManager.isLoggedIn()); } }
public static void main(String[] args) throws Exception { IFileConfiguration fileConfiguration = FileConfiguration.createDefault();
@Test public void getPeer() { // a unconnected node does not provide a peer IFileConfiguration fileConfig = FileConfiguration.createDefault(); IH2HNode node = H2HNode.createNode(fileConfig); Assert.assertNull(node.getPeer()); // connected nodes return a peer for (IH2HNode connectedNode : network) { Assert.assertNotNull(connectedNode.getPeer()); } } }
public static void main(String[] args) throws Exception { IFileConfiguration fileConfiguration = FileConfiguration.createDefault(); // Create two nodes and open a new overlay network IH2HNode node1 = H2HNode.createNode(fileConfiguration); IH2HNode node2 = H2HNode.createNode(fileConfiguration); node1.connect(NetworkConfiguration.createInitial()); node2.connect(NetworkConfiguration.create(InetAddress.getLocalHost())); // These two file agents are used to configure the root directory of the logged in user ExampleFileAgent node1FileAgent = new ExampleFileAgent(); ExampleFileAgent node2FileAgent = new ExampleFileAgent(); // Register user 'Alice' and login her at node 1 and 2 UserCredentials alice = new UserCredentials("Alice", "password", "pin"); node1.getUserManager().createRegisterProcess(alice).execute(); node1.getUserManager().createLoginProcess(alice, node1FileAgent).execute(); node2.getUserManager().createLoginProcess(alice, node2FileAgent).execute(); // In this example, a file event listener is registered at node 2. Therefore, we will listen to events // that happen by actions taken by node 1. node2.getFileManager().subscribeFileEvents(new ExampleEventListener(node2.getFileManager())); // To demonstrate the 'add' event, we will add a new file with node 1 // Let's create a file and upload it at node 1 File fileAtNode1 = new File(node1FileAgent.getRoot(), "test-file-event.txt"); FileUtils.write(fileAtNode1, "Hello"); // add some content node1.getFileManager().createAddProcess(fileAtNode1).execute(); // Let's trigger a deletion event fileAtNode1.delete(); node1.getFileManager().createDeleteProcess(fileAtNode1).execute(); }