@Override public Parcel getParcel(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException { try { // URL url = new URL("http://localhost:8080/contracts/" + itemId.toBase64String()); URL url = new URL(nodeInfo.publicUrlString() + "/parcels/" + itemId.toBase64String()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", "Universa JAVA API Client"); connection.setRequestProperty("Connection", "close"); connection.setRequestMethod("GET"); if (200 != connection.getResponseCode()) return null; byte[] data = Do.read(connection.getInputStream()); Parcel parcel = Parcel.unpack(data); // tp.trace(); // Contract c = Contract.fromPackedTransaction(data); return parcel; } catch (Exception e) { report(getLabel(), "download failure. from: " + nodeInfo.getNumber() + " by: " + myInfo.getNumber() +" reason: " + e); return null; } }
@Override public NImmutableEnvironment getEnvironment(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException { try { System.out.println("getEnvironment " + itemId.toBase64String()); // URL url = new URL("http://localhost:8080/contracts/" + itemId.toBase64String()); URL url = new URL(nodeInfo.publicUrlString() + "/environments/" + itemId.toBase64String()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", "Universa JAVA API Client"); connection.setRequestProperty("Connection", "close"); connection.setRequestMethod("GET"); if (200 != connection.getResponseCode()) return null; byte[] data = Do.read(connection.getInputStream()); return Boss.load(data); } catch (Exception e) { report(getLabel(), "download failure. from: " + nodeInfo.getNumber() + " by: " + myInfo.getNumber() +" reason: " + e, DatagramAdapter.VerboseLevel.BASE); e.printStackTrace(); return null; } }
@Override public Approvable getItem(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException { try { // URL url = new URL("http://localhost:8080/contracts/" + itemId.toBase64String()); URL url = new URL(nodeInfo.publicUrlString() + "/contracts/" + itemId.toBase64String()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", "Universa JAVA API Client"); connection.setRequestProperty("Connection", "close"); connection.setRequestMethod("GET"); if (200 != connection.getResponseCode()) return null; byte[] data = Do.read(connection.getInputStream()); TransactionPack tp = TransactionPack.unpack(data, true); // tp.trace(); // Contract c = Contract.fromPackedTransaction(data); return tp.getContract(); } catch (Exception e) { report(getLabel(), "download failure. from: " + nodeInfo.getNumber() + " by: " + myInfo.getNumber() +" reason: " + e, DatagramAdapter.VerboseLevel.BASE); e.printStackTrace(); return null; } }
/** * 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); }
private TestSpace prepareTestSpace(PrivateKey key) throws Exception { TestSpace testSpace = new TestSpace(); testSpace.nodes = new ArrayList<>(); for (int i = 0; i < 4; i++) testSpace.nodes.add(createMain("node" + (i + 1), false)); testSpace.node = testSpace.nodes.get(0); assertEquals("http://localhost:8080", testSpace.node.myInfo.internalUrlString()); assertEquals("http://localhost:8080", testSpace.node.myInfo.publicUrlString()); testSpace.myKey = key; testSpace.client = new Client(testSpace.myKey, testSpace.node.myInfo, null); testSpace.clients = new ArrayList(); for (int i = 0; i < 4; i++) testSpace.clients.add(new Client(testSpace.myKey, testSpace.nodes.get(i).myInfo, null)); return testSpace; }
private TestSpace prepareTestSpace(PrivateKey key) throws Exception { TestSpace testSpace = new TestSpace(); testSpace.nodes = new ArrayList<>(); for (int i = 0; i < 4; i++) testSpace.nodes.add(createMain("node" + (i + 1), "", false)); testSpace.node = testSpace.nodes.get(0); assertEquals("http://localhost:8080", testSpace.node.myInfo.internalUrlString()); assertEquals("http://localhost:8080", testSpace.node.myInfo.publicUrlString()); testSpace.myKey = key; testSpace.client = new Client(testSpace.myKey, testSpace.node.myInfo, null); testSpace.clients = new ArrayList(); for (int i = 0; i < 4; i++) testSpace.clients.add(new Client(testSpace.myKey, testSpace.nodes.get(i).myInfo, null)); for (Main m : testSpace.nodes) { while (m.node.isSanitating()) Thread.sleep(100); } return testSpace; }
public static void createLocalNetwork() throws Exception { for (int i = 0; i < 3; i++) localNodes.add(createMain("node" + (i + 1), false)); Main main = localNodes.get(0); assertEquals("http://localhost:8080", main.myInfo.internalUrlString()); assertEquals("http://localhost:8080", main.myInfo.publicUrlString()); assertEquals(main.cache, main.node.getCache()); }
Main main = mm.get(0); assertEquals("http://localhost:8080", main.myInfo.internalUrlString()); assertEquals("http://localhost:8080", main.myInfo.publicUrlString()); PrivateKey myKey = new PrivateKey(Do.read("./src/test_contracts/keys/u_key.private.unikey"));
Main main = mm.get(0); assertEquals("http://localhost:8080", main.myInfo.internalUrlString()); assertEquals("http://localhost:8080", main.myInfo.publicUrlString()); PrivateKey myKey = new PrivateKey(Do.read("./src/test_contracts/keys/u_key.private.unikey"));
private void loadNodeConfig() throws IOException, SQLException { Yaml yaml = new Yaml(); configRoot = (String) options.valueOf("config"); nodeKey = null; Binder settings = Binder.of(yaml.load(new FileInputStream(configRoot + "/config/config.yaml"))); log("node settings: " + settings); String nodeKeyFileName = configRoot + "/tmp/" + settings.getStringOrThrow("node_name") + ".private.unikey"; log(nodeKeyFileName); nodeKey = new PrivateKey(Do.read(nodeKeyFileName)); myInfo = new NodeInfo(nodeKey.getPublicKey(), settings.getIntOrThrow("node_number"), settings.getStringOrThrow("node_name"), (String) settings.getListOrThrow("ip").get(0), settings.getStringOrThrow("public_host"), settings.getIntOrThrow("udp_server_port"), settings.getIntOrThrow("http_client_port"), settings.getIntOrThrow("http_server_port") ); config.setIsFreeRegistrationsAllowedFromYaml(settings.getBoolean("allow_free_registrations", false)); config.setPermanetMode(settings.getBoolean("permanet_mode", false)); ledger = new PostgresLedger(settings.getStringOrThrow("database")); log("ledger constructed"); log("key loaded: " + nodeKey.info()); log("node local URL: " + myInfo.publicUrlString()); log("node info: " + myInfo.toBinder()); }
log("node local URL: " + myInfo.publicUrlString()); log("node info: " + myInfo.toBinder());
netConfig.forEachNode(node -> { nodes.add(Binder.of( "url", node.publicUrlString(), "key", node.getPublicKey().pack(), "number", node.getNumber()