1616import java .math .BigInteger ;
1717import java .security .MessageDigest ;
1818import java .security .NoSuchAlgorithmException ;
19+ import org .json .JSONObject ;
1920
2021class WatcherThread extends Thread {
2122 MainActivity mactivity ;
@@ -38,10 +39,14 @@ public void run(){
3839
3940
4041
42+
4143class MiningThread extends Thread {
4244 MainActivity mactivity ;
4345 String username ;
4446 int thread_id ;
47+ String ip = "51.15.127.80" ;
48+ Integer port = 2813 ;
49+
4550 MiningThread (MainActivity act , String username , int thread_id ){
4651 this .mactivity = act ;
4752 this .username = username ;
@@ -64,16 +69,49 @@ public static byte[] hexStringToByteArray(String s) {
6469 }
6570 return data ;
6671 }
72+ public void get_pool (){
73+ URL url ;
74+ HttpURLConnection con ;
75+ String inputLine ;
76+ StringBuffer content = new StringBuffer ();
77+ try {
78+ url = new URL ("https://server.duinocoin.com/getPool" );
79+ con = (HttpURLConnection ) url .openConnection ();
80+ con .setRequestMethod ("GET" );
81+
82+ BufferedReader in = new BufferedReader (
83+ new InputStreamReader (con .getInputStream ()));
84+ while ((inputLine = in .readLine ()) != null ) {
85+ content .append (inputLine );
86+ }
87+ in .close ();
88+ }catch (Exception e ) {
89+ return ;
90+ }
91+ String content_string = content .toString ();
92+ JSONObject json_response ;
93+ try {
94+ json_response = new JSONObject (content_string );
95+ }catch (Exception e ){
96+ return ;
97+ }
98+ try {
99+ ip = (String )json_response .get ("ip" );
100+ port = Integer .parseInt ((String )json_response .get ("port" ));
101+ }catch (Exception e ){
102+ return ;
103+ }
67104
105+ }
68106 public void run (){
69107 boolean connected = false ;
70108 OutputStream output ;
71109 PrintWriter writer ;
72110 InputStream input ;
73111 Socket client_socket ;
74- String ip = "51.15.127.80" ;
75112
76- int port = 2813 ;
113+ get_pool ();
114+
77115 SocketAddress address = new InetSocketAddress (ip ,port );
78116 TextView to_add ;
79117
@@ -93,9 +131,9 @@ public void run(){
93131 client_socket .connect (address ,15 *1000 );
94132 }catch (Exception e ){
95133 //mactivity.add_string_to_console(e.toString());
96- //mactivity.add_string_to_console("Connection Failed");
97134 continue ;
98135 }
136+
99137 //mactivity.add_string_to_console("Connected to server");
100138
101139 connected = true ;
@@ -119,6 +157,7 @@ public void run(){
119157
120158 while (connected ){
121159 received_data = new byte [1024 ];
160+
122161 try {
123162 output .write (job_query .getBytes ("UTF-8" ));
124163 }catch (Exception e ){
@@ -139,7 +178,15 @@ public void run(){
139178
140179 Job = new String (received_data );
141180 try {
142- Job = Job .substring (0 , this .get_position (Job , '\n' ));
181+ Integer end_pos = this .get_position (Job , '\n' );
182+ if (end_pos !=-1 ) {
183+ Job = Job .substring (0 , end_pos );
184+ }else {
185+ end_pos = this .get_position (Job , '\0' );
186+ if (end_pos !=-1 ) {
187+ Job = Job .substring (0 , end_pos );
188+ }
189+ }
143190 }catch (Exception e ){
144191 connected = false ;
145192 break ;
0 commit comments