/** * Start http client (used with constructor passing delayedStart = true) * @param session set to null or to the reconstructed instance * @throws IOException */ public void start(BasicHttpClientSession session) throws IOException { httpClient.start(clientPrivateKey, nodePublicKey, session); }
/** * Start new client protocol session. It doesn't load network configuration. Only creates client protocol session with given node * @param rootUrlString node url * @param clientPrivateKey client private key * @param nodePublicKey node key * @param session set to null or to the reconstructed instance * @throws IOException */ public Client(String rootUrlString, PrivateKey clientPrivateKey, PublicKey nodePublicKey, BasicHttpClientSession session) throws IOException { httpClient = new BasicHttpClient(rootUrlString); this.clientPrivateKey = clientPrivateKey; this.nodePublicKey = nodePublicKey; httpClient.start(clientPrivateKey, nodePublicKey, session); }
public void restart() throws IOException { synchronized (this) { System.err.println("Restarting connection to $"+this.nodeNumber+": "+this.getUrl()); PrivateKey privateKey = session.getPrivateKey(); PublicKey nodePublicKey = session.getNodePublicKey(); session = null; start(privateKey, nodePublicKey, null); } }
/** * Create new client protocol session. It loads network configuration and creates client protocol session with random node. Allows delayed start of http client * @param someNodeUrl url on some node in network * @param clientPrivateKey client private key * @param session set to null or to the reconstructed instance * @param delayedStart indicates if start of http client should be delayed * @throws IOException */ public Client(String someNodeUrl, PrivateKey clientPrivateKey, BasicHttpClientSession session, boolean delayedStart) throws IOException { this.clientPrivateKey = clientPrivateKey; loadNetworkFrom(someNodeUrl); clients = new ArrayList<>(size()); for (int i = 0; i < size(); i++) { clients.add(null); } NodeRecord r = Do.sample(nodes); httpClient = new BasicHttpClient(r.url); this.nodePublicKey = r.key; if(!delayedStart) httpClient.start(clientPrivateKey, r.key, session); }
/** * Start new client protocol session. It doesn't load network configuration. Only creates client protocol session with given node * @param myPrivateKey client private key * @param nodeInfo node info specifying node public key and url * @param session set to null or to the reconstructed instance * @throws IOException */ public Client(PrivateKey myPrivateKey, NodeInfo nodeInfo, BasicHttpClientSession session) throws IOException { httpClient = new BasicHttpClient(nodeInfo.publicUrlString()); this.clientPrivateKey = myPrivateKey; this.nodePublicKey = nodeInfo.getPublicKey(); httpClient.start(myPrivateKey, nodeInfo.getPublicKey(), session); }
@Test public void testError() throws Exception { PrivateKey nodeKey = TestKeys.privateKey(1); PrivateKey clientKey = TestKeys.privateKey(2); BasicHttpServer s = new BasicHttpServer(nodeKey, 15600, 32, log); BasicHttpClient c = new BasicHttpClient("http://localhost:15600"); c.start(clientKey, nodeKey.getPublicKey(), null); assertThrows(CommandFailedException.class, ()->c.command("test_error")); }
@Test public void handshakeAndSecureCommand() throws Exception { PrivateKey nodeKey = TestKeys.privateKey(1); PrivateKey clientKey = TestKeys.privateKey(2); BasicHttpServer s = new BasicHttpServer(nodeKey, 15600, 32, log); BasicHttpClient c = new BasicHttpClient("http://localhost:15600"); c.start(clientKey, nodeKey.getPublicKey(), null); Binder res = c.command("sping"); assertEquals("spong", res.getStringOrThrow("sping")); s.addSecureEndpoint("getSessionInfo", (params,session)-> { // System.out.println("in sec, "+session); // System.out.println("\t "+session.getPublicKey()); return Binder.of("publicKey", session.getPublicKey().info().toString()); }); res = c.command("getSessionInfo"); s.shutdown(); }