Beispiel #1
0
  public String set_old_key(String keyx) {

    System.out.println("Build old keys");

    while (network.database_in_use == 1) {

      int test_db = 0;
      System.out.println("Database in use... import key");
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
      test_db++;
    } // *********************************

    mining.mining3 = false;

    krypton_database_import_keys import_kx = new krypton_database_import_keys(keyx);

    krypton_database_load_network xxn = new krypton_database_load_network();
    krypton_database_load xxs = new krypton_database_load();

    mining.mining3 = true;

    return network.settingsx[5];
  } // **********************
Beispiel #2
0
  public String set_new_node(String nodex) {

    System.out.println("Add new node");

    while (network.database_in_use == 1) {

      int test_db = 0;
      System.out.println("Database in use... import node");
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
      test_db++;
    } // *********************************

    mining.mining3 = false;

    krypton_database_nodes add_node = new krypton_database_nodes(nodex);

    krypton_database_load_network nodesx = new krypton_database_load_network();

    krypton_database_load loadx = new krypton_database_load();

    mining.mining3 = true;

    return Integer.toString(network.network_list.size());
  } // **********************
Beispiel #3
0
  public String delete_all_nodes() {

    System.out.println("Delete all nodes");

    while (network.database_in_use == 1) {

      int test_db = 0;
      System.out.println("Database in use... delete all nodes");
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
      test_db++;
    } // *********************************

    mining.mining3 = false;

    krypton_database_delete_network pxd = new krypton_database_delete_network();

    krypton_database_load_network nodesx = new krypton_database_load_network();

    krypton_database_load loadx = new krypton_database_load();

    mining.mining3 = true;

    return "deleted";
  } // **********************
Beispiel #4
0
  public String set_new_block(String array) {

    String jsontext = new String("");

    String update_token[] = new String[network.listing_size];

    try {

      JSONParser parserx = new JSONParser();
      Object objx = parserx.parse(array);
      JSONObject jsonObjectx = (JSONObject) objx;

      for (int loop = 0; loop < network.listing_size; loop++) { // ************

        update_token[loop] = (String) jsonObjectx.get(Integer.toString(loop));
        System.out.println("import " + update_token[loop]);
      } // *******************************************************************

    } catch (Exception e) {
      e.printStackTrace();
    }

    String testerx = new String("error");

    for (int loop = 0; loop < network.listing_size; loop++) { // ************
      try {
        if (update_token[loop].equals("0")) {}
      } catch (Exception e) {
        statex = "0";
        testerx = "1";
        jsontext = "e09 NullException";
      }
    } // *******************************************************************

    while (!testerx.equals("1")) {

      System.out.println("Mining send new block update >>>>");

      // String testg = krypton_net_client.send_new_block_update(update_token);
      // System.out.println("testg " + testg);

      // if(testg.equals("1") || testg.equals("0")){System.out.println("BREAK"); break;}

      try {
        Thread.sleep(10000);
      } catch (InterruptedException e) {
      }
    } // while

    return jsontext;
  } // ***************************************
Beispiel #5
0
  public String build_keysx() {

    System.out.println("Build new keys");

    while (network.database_in_use == 1) {

      int test_db = 0;
      System.out.println("Database in use...keys");
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
      test_db++;
    } // *********************************

    krypton_rebuild_keys keysx = new krypton_rebuild_keys();
    krypton_database_load loadxs = new krypton_database_load();

    return network.settingsx[5];
  } // **********************
Beispiel #6
0
    public void
        run() { // ************************************************************************************

      String jsonText2 = new String("");

      JSONObject obj_out = new JSONObject();

      ServerSocket welcomeSocket;

      while (true) {

        try { // *********************************************************

          welcomeSocket = new ServerSocket(network.api_port, 0, InetAddress.getByName("localhost"));
          Socket connectionSocket = welcomeSocket.accept();
          BufferedReader inFromClient =
              new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
          DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
          clientSentence = inFromClient.readLine();

          JSONParser parser = new JSONParser();

          try { // *********************************************************

            statex = "0";
            responsex = "e00";
            jsonText = "";

            if (!clientSentence.contains("")) {
              throw new EmptyStackException();
            }
            Object obj = parser.parse(clientSentence);

            jsonObject = (JSONObject) obj;

            String request = (String) jsonObject.get("request");

            String item_id = new String("");
            String item_array = new String("");
            String old_key = new String("");
            String node = new String("");
            try {
              item_id = (String) jsonObject.get("item_id").toString();
            } catch (Exception e) {
              System.out.println("extra info no item_id...");
            }
            try {
              item_array = (String) jsonObject.get("item_array").toString();
            } catch (Exception e) {
              System.out.println("extra info no item_array...");
            }
            try {
              old_key = (String) jsonObject.get("key").toString();
            } catch (Exception e) {
              System.out.println("extra info no key...");
            }
            try {
              node = (String) jsonObject.get("node").toString();
            } catch (Exception e) {
              System.out.println("extra info no node...");
            }

            while (network.database_in_use == 1 && !request.equals("status")) {

              System.out.println("Database in use...");
              try {
                Thread.sleep(1000);
              } catch (InterruptedException e) {
              }
            } // **************************************************************

            if (request.equals("status")) {
              statex = "1";
              responsex = get_status();
            } // ***************************
            else if (request.equals("get_version")) {
              statex = "1";
              responsex = network.versionx;
            } //
            else if (request.equals("get_tor_active")) {
              statex = "1";
              responsex = Integer.toString(network.tor_active);
            } //
            else if (request.equals("get_last_block")) {
              statex = "1";
              responsex = network.last_block_id;
            } //
            else if (request.equals("get_last_block_timestamp")) {
              statex = "1";
              responsex = network.last_block_timestamp;
            } //
            else if (request.equals("get_last_block_hash")) {
              statex = "1";
              responsex = network.last_block_idx;
            } //
            else if (request.equals("get_difficulty")) {
              statex = "1";
              responsex = Long.toString(network.difficultyx);
            } //
            else if (request.equals("get_last_mining_id")) {
              statex = "1";
              responsex = network.last_block_mining_idx;
            } //
            else if (request.equals("get_prev_mining_id")) {
              statex = "1";
              responsex = network.prev_block_mining_idx;
            } //
            else if (request.equals("get_last_unconfirmed_id")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_my_token_total")) {
              statex = "1";
              responsex = Integer.toString(network.database_listings_owner);
            } //
            else if (request.equals("get_my_id_list")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_my_ids_limit")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_token")) {
              statex = "1";
              responsex = get_item_array(item_id);
            } //
            else if (request.equals("get_settings")) {
              statex = "1";
              responsex = get_settings_array();
            } //
            else if (request.equals("get_mining_info")) {
              statex = "1";
              responsex = get_item_array(item_id);
            } //
            else if (request.equals("get_new_keys")) {
              statex = "1";
              responsex = build_keysx();
            } //
            else if (request.equals("delete_node")) {
              statex = "1";
              responsex = delete_node(node);
            } //
            else if (request.equals("delete_all_nodes")) {
              statex = "1";
              responsex = delete_all_nodes();
            } //
            else if (request.equals("set_new_node")) {
              statex = "1";
              responsex = set_new_node(node);
            } //
            else if (request.equals("set_old_key")) {
              statex = "1";
              responsex = set_old_key(old_key);
            } //
            else if (request.equals("set_new_block")) {
              statex = "1";
              responsex = set_new_block(item_array);
            } //
            else if (request.equals("set_edit_block")) {
              statex = "1";
              update_state = "set_edit_block";
              responsex = update_token(item_array);
            } //
            else if (request.equals("set_transfer_block")) {
              statex = "1";
              update_state = "set_transfer_block";
              responsex = update_token(item_array);
            } //
            else if (request.equals("system_restart")) {
              statex = "1";
              responsex = "restarting";
              toolkit = Toolkit.getDefaultToolkit();
              xtimerx = new Timer();
              xtimerx.schedule(new RemindTask_restart(), 0);
            } //
            else if (request.equals("system_exit")) {
              statex = "1";
              System.exit(0);
            } //
            else {
              statex = "0";
              responsex = "e01 UnknownRequestException";
            }

          } // try
          catch (ParseException e) {
            e.printStackTrace();
            statex = "0";
            responsex = "e02 ParseException";
          } catch (Exception e) {
            e.printStackTrace();
            statex = "0";
            responsex = "e03 Exception";
          }

          JSONObject obj = new JSONObject();
          obj.put("response", statex);
          try {
            obj.put("message", responsex);
          } catch (Exception e) {
            e.printStackTrace();
          }

          StringWriter outs = new StringWriter();
          obj.writeJSONString(outs);
          jsonText = outs.toString();
          System.out.println("SEND RESPONSE " + responsex);

          outToClient.writeBytes(jsonText + '\n');
          welcomeSocket.close();

        } catch (Exception e) {
          e.printStackTrace();
          System.out.println("Server ERROR x3");
        }
      } // **********while
    } // runx***************************************************************************************************