Advertisement
MorisDove

stratum.cpp

Oct 12th, 2021
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.27 KB | None | 0 0
  1.  
  2. #include "stratum.h"
  3. #include <signal.h>
  4. #include <sys/resource.h>
  5.  
  6. CommonList g_list_coind;
  7. CommonList g_list_client;
  8. CommonList g_list_job;
  9. CommonList g_list_remote;
  10. CommonList g_list_renter;
  11. CommonList g_list_share;
  12. CommonList g_list_worker;
  13. CommonList g_list_block;
  14. CommonList g_list_submit;
  15. CommonList g_list_source;
  16.  
  17. int g_tcp_port;
  18.  
  19. char g_tcp_server[1024];
  20. char g_tcp_password[1024];
  21.  
  22. char g_sql_host[1024];
  23. char g_sql_database[1024];
  24. char g_sql_username[1024];
  25. char g_sql_password[1024];
  26. int g_sql_port = 3306;
  27.  
  28. char g_stratum_coin_include[256];
  29. char g_stratum_coin_exclude[256];
  30.  
  31. char g_stratum_algo[256];
  32. double g_stratum_difficulty;
  33. double g_stratum_min_diff;
  34. double g_stratum_max_diff;
  35.  
  36. double g_stratum_nicehash_difficulty;
  37. double g_stratum_nicehash_min_diff;
  38. double g_stratum_nicehash_max_diff;
  39.  
  40. int g_stratum_max_ttf;
  41. int g_stratum_max_cons = 5000;
  42. bool g_stratum_reconnect;
  43. bool g_stratum_renting;
  44. bool g_stratum_segwit = false;
  45.  
  46. int g_limit_txs_per_block = 0;
  47.  
  48. bool g_handle_haproxy_ips = false;
  49. int g_socket_recv_timeout = 600;
  50.  
  51. bool g_debuglog_client;
  52. bool g_debuglog_hash;
  53. bool g_debuglog_socket;
  54. bool g_debuglog_rpc;
  55. bool g_debuglog_list;
  56. bool g_debuglog_remote;
  57.  
  58. bool g_autoexchange = true;
  59.  
  60. uint64_t g_max_shares = 0;
  61. uint64_t g_shares_counter = 0;
  62. uint64_t g_shares_log = 0;
  63.  
  64. bool g_allow_rolltime = true;
  65. time_t g_last_broadcasted = 0;
  66. YAAMP_DB *g_db = NULL;
  67.  
  68. pthread_mutex_t g_db_mutex;
  69. pthread_mutex_t g_nonce1_mutex;
  70. pthread_mutex_t g_job_create_mutex;
  71.  
  72. struct ifaddrs *g_ifaddr;
  73.  
  74. volatile bool g_exiting = false;
  75.  
  76. void *stratum_thread(void *p);
  77. void *monitor_thread(void *p);
  78.  
  79. ////////////////////////////////////////////////////////////////////////////////////////
  80.  
  81. static void scrypt_hash(const char* input, char* output, uint32_t len)
  82. {
  83. scrypt_1024_1_1_256((unsigned char *)input, (unsigned char *)output);
  84. }
  85.  
  86. static void scryptn_hash(const char* input, char* output, uint32_t len)
  87. {
  88. time_t time_table[][2] =
  89. {
  90. {2048, 1389306217},
  91. {4096, 1456415081},
  92. {8192, 1506746729},
  93. {16384, 1557078377},
  94. {32768, 1657741673},
  95. {65536, 1859068265},
  96. {131072, 2060394857},
  97. {262144, 1722307603},
  98. {524288, 1769642992},
  99. {1048576, 3536789865},
  100. {0, 0},
  101. };
  102.  
  103. for(int i=0; time_table[i][0]; i++)
  104. if(time(NULL) < time_table[i+1][1])
  105. {
  106. scrypt_1048576_1_1_256(input, output, time_table[i][0], 1, len);
  107. return;
  108. }
  109. }
  110.  
  111. static void neoscrypt_hash(const char* input, char* output, uint32_t len)
  112. {
  113. neoscrypt((unsigned char *)input, (unsigned char *)output, 0x80000620);
  114. }
  115.  
  116. YAAMP_ALGO g_algos[] =
  117. {
  118. {"a5a", a5a_hash, 0x10000, 0, 0},
  119. {"aergo", aergo_hash, 1, 0, 0},
  120. {"allium", allium_hash, 0x100, 0, 0},
  121. {"anime", anime_hash, 1, 0, 0},
  122. {"argon2d250", argon2d_crds_hash, 0x10000, 0, 0 }, // Credits Argon2d Implementation
  123. {"argon2d500", argon2d_dyn_hash, 0x10000, 0, 0 }, // Dynamic Argon2d Implementation
  124. {"argon2d16000", argon2d16000_hash, 0x10000, 0, 0 }, // Argon2d16000 Implementation
  125. {"astralhash", astralhash_hash, 0x100, 0, 0},
  126. {"bastion", bastion_hash, 1, 0 },
  127. {"bcd", bcd_hash, 1, 0, 0},
  128. {"bitcore", timetravel10_hash, 0x100, 0, 0},
  129. {"blake", blake_hash, 1, 0 },
  130. {"blake2s", blake2s_hash, 1, 0 },
  131. {"blakecoin", blakecoin_hash, 1 /*0x100*/, 0, sha256_hash_hex },
  132. {"bmw", bmw_hash, 1, 0, 0},
  133. {"bmw512", bmw512_hash, 0x100, 0, 0},
  134. {"c11", c11_hash, 1, 0, 0},
  135. {"cosa", cosa_hash, 1, 0, 0}, //Cosanta (COSA)
  136. {"cpupower", cpupower_hash, 0x10000, 0, 0}, //CPUchain
  137. {"curvehash", curve_hash, 1, 0, 0},
  138. {"decred", decred_hash, 1, 0 },
  139. {"dedal", dedal_hash, 0x100, 0, 0},
  140. {"deep", deep_hash, 1, 0, 0},
  141. {"dmd-gr", groestl_hash, 0x100, 0, 0}, /* diamond (double groestl) */
  142. {"fresh", fresh_hash, 0x100, 0, 0},
  143. {"geek", geek_hash, 1, 0, 0},
  144. {"gr", gr_hash, 0x10000, 0, 0},
  145. {"groestl", groestl_hash, 0x100, 0, sha256_hash_hex }, /* groestlcoin */
  146. {"heavyhash", heavyhash_hash, 1, 0, 0}, /* OBTC */
  147. {"hex", hex_hash, 0x100, 0, sha256_hash_hex },
  148. {"hive", hive_hash, 0x10000, 0, 0},
  149. {"hmq1725", hmq17_hash, 0x10000, 0, 0},
  150. {"honeycomb", beenode_hash, 0x10000, 0, 0},
  151. {"hsr", hsr_hash, 1, 0, 0},
  152. {"jeonghash", jeonghash_hash, 0x100, 0, 0},
  153. {"jha", jha_hash, 0x10000, 0},
  154. {"keccak", keccak256_hash, 0x80, 0, sha256_hash_hex },
  155. {"keccakc", keccak256_hash, 0x100, 0, 0},
  156. {"lbk3", lbk3_hash, 0x100, 0, 0},
  157. {"lbry", lbry_hash, 0x100, 0, 0},
  158. {"luffa", luffa_hash, 1, 0, 0},
  159. {"lyra2", lyra2re_hash, 0x80, 0, 0},
  160. {"lyra2v2", lyra2v2_hash, 0x100, 0, 0},
  161. {"lyra2v3", lyra2v3_hash, 0x100, 0, 0},
  162. {"lyra2vc0ban", lyra2vc0ban_hash, 0x100, 0, 0},
  163. {"lyra2z", lyra2z_hash, 0x100, 0, 0},
  164. {"lyra2z330", lyra2z330_hash, 0x100, 0, 0},
  165. {"m7m", m7m_hash, 0x10000, 0, 0},
  166. {"megabtx", megabtx_hash, 0x100, 0, 0}, /* Bitcore New Algo*/
  167. {"megamec", megamec_hash, 0x100, 0, 0}, /* Megacoin New Algo*/
  168. {"minotaur", minotaur_hash, 1, 0, 0},
  169. {"minotaurx", minotaurx_hash, 1, 0, 0},
  170. {"myr-gr", groestlmyriad_hash, 1, 0, 0}, /* groestl + sha 64 */
  171. {"neoscrypt", neoscrypt_hash, 0x10000, 0, 0},
  172. {"nist5", nist5_hash, 1, 0, 0},
  173. {"pawelhash", pawelhash_hash, 0x100, 0, 0},
  174. {"penta", penta_hash, 1, 0, 0},
  175. {"phi", phi_hash, 1, 0, 0},
  176. {"phi2", phi2_hash, 0x100, 0, 0},
  177. {"phi5", phi5_hash, 1, 0, 0},
  178. {"pipe", pipe_hash, 1,0,0},
  179. {"polytimos", polytimos_hash, 1, 0, 0},
  180. {"power2b", power2b_hash, 0x10000, 0, 0 },
  181. {"quark", quark_hash, 1, 0, 0},
  182. {"qubit", qubit_hash, 1, 0, 0},
  183. {"rainforest", rainforest_hash, 0x100, 0, 0},
  184. {"renesis", renesis_hash, 1, 0, 0},
  185. {"scrypt", scrypt_hash, 0x10000, 0, 0},
  186. {"scryptn", scryptn_hash, 0x10000, 0, 0},
  187. {"sha256", sha256_hash, 1, 0, 0},
  188. {"sha256d", sha256_double_hash, 1, 0, 0},
  189. {"sha256csm", sha256csm_hash, 1, 0, 0},
  190. {"sha256t", sha256t_hash, 1, 0, 0}, // sha256 3x
  191. {"sib", sib_hash, 1, 0, 0},
  192. {"skein", skein_hash, 1, 0, 0},
  193. {"skein2", skein2_hash, 1, 0, 0},
  194. {"skunk", skunk_hash, 1, 0, 0},
  195. {"sonoa", sonoa_hash, 1, 0, 0},
  196. {"timetravel", timetravel_hash, 0x100, 0, 0},
  197. {"tribus", tribus_hash, 1, 0, 0},
  198. {"vanilla", blakecoin_hash, 1, 0 },
  199. {"veltor", veltor_hash, 1, 0, 0},
  200. {"velvet", velvet_hash, 0x10000, 0, 0},
  201. {"vitalium", vitalium_hash, 1, 0, 0},
  202. {"x11", x11_hash, 1, 0, 0},
  203. {"x11evo", x11evo_hash, 1, 0, 0},
  204. {"x11k", x11k_hash, 1, 0, 0},
  205. {"x11kvs", x11kvs_hash, 0x100, 0, 0,7},
  206. {"x12", x12_hash, 1, 0, 0},
  207. {"x13", x13_hash, 1, 0, 0},
  208. {"x14", x14_hash, 1, 0, 0},
  209. {"x15", x15_hash, 1, 0, 0},
  210. {"x16r", x16r_hash, 0x100, 0, 0},
  211. {"x16rv2", x16rv2_hash, 0x100, 0, 0},
  212. {"x16rt", x16rt_hash, 0x100, 0, 0},
  213. {"x16s", x16s_hash, 0x100, 0, 0},
  214. {"x17", x17_hash, 1, 0, 0},
  215. {"x17r", x17r_hash, 1, 0, 0}, //ufo-project
  216. {"x18", x18_hash, 1, 0, 0},
  217. {"x20r", x20r_hash, 0x100, 0, 0},
  218. {"x21s", x21s_hash, 0x100, 0, 0},
  219. {"x22", x22_hash, 1, 0, 0},
  220. {"x22i", x22i_hash, 1, 0, 0},
  221. {"x25x", x25x_hash, 1, 0, 0},
  222. {"xevan", xevan_hash, 0x100, 0, 0},
  223. {"yescrypt", yescrypt_hash, 0x10000, 0, 0},
  224. {"yescryptR8", yescryptR8_hash, 0x10000, 0, 0 },
  225. {"yescryptR16", yescryptR16_hash, 0x10000, 0, 0 },
  226. {"yescryptR32", yescryptR32_hash, 0x10000, 0, 0 },
  227. {"yespower", yespower_hash, 0x10000, 0, 0 },
  228. {"yespowerIC", yespowerIC_hash, 0x10000, 0, 0 }, //IsotopeC[IC]
  229. {"yespowerIOTS", yespowerIOTS_hash, 0x10000, 0, 0 }, //Iots [IOTS]
  230. {"yespowerLITB", yespowerLITB_hash, 0x10000, 0, 0 }, //LightBit[LITB]
  231. {"yespowerLTNCG", yespowerLTNCG_hash, 0x10000, 0, 0 }, //LightningCash Gold[LTNCG]
  232. {"yespowerR16", yespowerR16_hash, 0x10000, 0, 0 },
  233. {"yespowerRES", yespowerRES_hash, 0x10000, 0, 0 }, //Resistanse[RES]
  234. {"yespowerSUGAR", yespowerSUGAR_hash, 0x10000, 0, 0 }, //Sugarchain[SUGAR]
  235. {"yespowerTIDE", yespowerTIDE_hash, 0x10000, 0, 0 }, //Tidecoin[TDC]
  236. {"yespowerURX", yespowerURX_hash, 0x10000, 0, 0 }, //UraniumX[URX]
  237. {"yespowerMGPC", yespowerMGPC_hash, 0x10000, 0, 0 }, //Magpiecoin[MGPC]
  238. {"yespowerARWN", yespowerARWN_hash, 0x10000, 0, 0 }, //Arowanacoin[ARWN]
  239. {"whirlcoin", whirlpool_hash, 1, 0, sha256_hash_hex }, /* old sha merkleroot */
  240. {"whirlpool", whirlpool_hash, 1, 0 }, /* sha256d merkleroot */
  241. {"whirlpoolx", whirlpoolx_hash, 1, 0, 0},
  242. {"zr5", zr5_hash, 1, 0, 0},
  243. {"", NULL, 0, 0},
  244. };
  245.  
  246. YAAMP_ALGO *g_current_algo = NULL;
  247.  
  248. YAAMP_ALGO *stratum_find_algo(const char *name)
  249. {
  250. for(int i=0; g_algos[i].name[0]; i++)
  251. if(!strcmp(name, g_algos[i].name))
  252. return &g_algos[i];
  253.  
  254. return NULL;
  255. }
  256.  
  257. ////////////////////////////////////////////////////////////////////////////////////////
  258.  
  259. int main(int argc, char **argv)
  260. {
  261. if(argc < 2)
  262. {
  263. printf("usage: %s <algo>\n", argv[0]);
  264. return 1;
  265. }
  266.  
  267. srand(time(NULL));
  268. getifaddrs(&g_ifaddr);
  269.  
  270. initlog(argv[1]);
  271.  
  272. #ifdef NO_EXCHANGE
  273. // todo: init with a db setting or a yiimp shell command
  274. g_autoexchange = false;
  275. #endif
  276.  
  277. char configfile[1024];
  278. sprintf(configfile, "%s.conf", argv[1]);
  279.  
  280. dictionary *ini = iniparser_load(configfile);
  281. if(!ini)
  282. {
  283. debuglog("cant load config file %s\n", configfile);
  284. return 1;
  285. }
  286.  
  287. g_tcp_port = iniparser_getint(ini, "TCP:port", 3333);
  288. strcpy(g_tcp_server, iniparser_getstring(ini, "TCP:server", NULL));
  289. strcpy(g_tcp_password, iniparser_getstring(ini, "TCP:password", NULL));
  290.  
  291. strcpy(g_sql_host, iniparser_getstring(ini, "SQL:host", NULL));
  292. strcpy(g_sql_database, iniparser_getstring(ini, "SQL:database", NULL));
  293. strcpy(g_sql_username, iniparser_getstring(ini, "SQL:username", NULL));
  294. strcpy(g_sql_password, iniparser_getstring(ini, "SQL:password", NULL));
  295. g_sql_port = iniparser_getint(ini, "SQL:port", 3306);
  296.  
  297. // optional coin filters (to mine only one on a special port or a test instance)
  298. char *coin_filter = iniparser_getstring(ini, "WALLETS:include", NULL);
  299. strcpy(g_stratum_coin_include, coin_filter ? coin_filter : "");
  300. coin_filter = iniparser_getstring(ini, "WALLETS:exclude", NULL);
  301. strcpy(g_stratum_coin_exclude, coin_filter ? coin_filter : "");
  302.  
  303. strcpy(g_stratum_algo, iniparser_getstring(ini, "STRATUM:algo", NULL));
  304. g_stratum_difficulty = iniparser_getdouble(ini, "STRATUM:difficulty", 16);
  305. g_stratum_min_diff = iniparser_getdouble(ini, "STRATUM:diff_min", g_stratum_difficulty/2);
  306. g_stratum_max_diff = iniparser_getdouble(ini, "STRATUM:diff_max", g_stratum_difficulty*8192);
  307.  
  308. g_stratum_nicehash_difficulty = iniparser_getdouble(ini, "STRATUM:nicehash", 16);
  309. g_stratum_nicehash_min_diff = iniparser_getdouble(ini, "STRATUM:nicehash_diff_min", g_stratum_nicehash_difficulty/2);
  310. g_stratum_nicehash_max_diff = iniparser_getdouble(ini, "STRATUM:nicehash_diff_max", g_stratum_nicehash_difficulty*8192);
  311.  
  312. g_stratum_max_cons = iniparser_getint(ini, "STRATUM:max_cons", 5000);
  313. g_stratum_max_ttf = iniparser_getint(ini, "STRATUM:max_ttf", 0x70000000);
  314. g_stratum_reconnect = iniparser_getint(ini, "STRATUM:reconnect", true);
  315. g_stratum_renting = iniparser_getint(ini, "STRATUM:renting", true);
  316. g_handle_haproxy_ips = iniparser_getint(ini, "STRATUM:haproxy_ips", g_handle_haproxy_ips);
  317. g_socket_recv_timeout = iniparser_getint(ini, "STRATUM:recv_timeout", 600);
  318.  
  319. g_max_shares = iniparser_getint(ini, "STRATUM:max_shares", g_max_shares);
  320. g_limit_txs_per_block = iniparser_getint(ini, "STRATUM:max_txs_per_block", 0);
  321.  
  322. g_debuglog_client = iniparser_getint(ini, "DEBUGLOG:client", false);
  323. g_debuglog_hash = iniparser_getint(ini, "DEBUGLOG:hash", false);
  324. g_debuglog_socket = iniparser_getint(ini, "DEBUGLOG:socket", false);
  325. g_debuglog_rpc = iniparser_getint(ini, "DEBUGLOG:rpc", false);
  326. g_debuglog_list = iniparser_getint(ini, "DEBUGLOG:list", false);
  327. g_debuglog_remote = iniparser_getint(ini, "DEBUGLOG:remote", false);
  328.  
  329. iniparser_freedict(ini);
  330.  
  331. g_current_algo = stratum_find_algo(g_stratum_algo);
  332.  
  333. if(!g_current_algo) yaamp_error("invalid algo");
  334. if(!g_current_algo->hash_function) yaamp_error("no hash function");
  335.  
  336. // struct rlimit rlim_files = {0x10000, 0x10000};
  337. // setrlimit(RLIMIT_NOFILE, &rlim_files);
  338.  
  339. struct rlimit rlim_threads = {0x8000, 0x8000};
  340. setrlimit(RLIMIT_NPROC, &rlim_threads);
  341.  
  342. stratumlogdate("starting stratum for %s on %s:%d\n",
  343. g_current_algo->name, g_tcp_server, g_tcp_port);
  344.  
  345. // ntime should not be changed by miners for these algos
  346. g_allow_rolltime = strcmp(g_stratum_algo,"x11evo");
  347. g_allow_rolltime = g_allow_rolltime && strcmp(g_stratum_algo,"timetravel");
  348. g_allow_rolltime = g_allow_rolltime && strcmp(g_stratum_algo,"bitcore");
  349. g_allow_rolltime = g_allow_rolltime && strcmp(g_stratum_algo,"exosis");
  350. if (!g_allow_rolltime)
  351. stratumlog("note: time roll disallowed for %s algo\n", g_current_algo->name);
  352.  
  353. g_db = db_connect();
  354. if(!g_db) yaamp_error("Cant connect database");
  355.  
  356. // db_query(g_db, "update mining set stratumids='loading'");
  357.  
  358. yaamp_create_mutex(&g_db_mutex);
  359. yaamp_create_mutex(&g_nonce1_mutex);
  360. yaamp_create_mutex(&g_job_create_mutex);
  361.  
  362. YAAMP_DB *db = db_connect();
  363. if(!db) yaamp_error("Cant connect database");
  364.  
  365. db_register_stratum(db);
  366. db_update_algos(db);
  367. db_update_coinds(db);
  368.  
  369. sleep(2);
  370. job_init();
  371.  
  372. // job_signal();
  373.  
  374. ////////////////////////////////////////////////
  375.  
  376. pthread_t thread1;
  377. pthread_create(&thread1, NULL, monitor_thread, NULL);
  378.  
  379. pthread_t thread2;
  380. pthread_create(&thread2, NULL, stratum_thread, NULL);
  381.  
  382. sleep(20);
  383.  
  384. while(!g_exiting)
  385. {
  386. db_register_stratum(db);
  387. db_update_workers(db);
  388. db_update_algos(db);
  389. db_update_coinds(db);
  390.  
  391. if(g_stratum_renting)
  392. {
  393. db_update_renters(db);
  394. db_update_remotes(db);
  395. }
  396.  
  397. share_write(db);
  398. share_prune(db);
  399.  
  400. block_prune(db);
  401. submit_prune(db);
  402.  
  403. sleep(1);
  404. job_signal();
  405.  
  406. ////////////////////////////////////
  407.  
  408. // source_prune();
  409.  
  410. object_prune(&g_list_coind, coind_delete);
  411. object_prune(&g_list_remote, remote_delete);
  412. object_prune(&g_list_job, job_delete);
  413. object_prune(&g_list_client, client_delete);
  414. object_prune(&g_list_block, block_delete);
  415. object_prune(&g_list_worker, worker_delete);
  416. object_prune(&g_list_share, share_delete);
  417. object_prune(&g_list_submit, submit_delete);
  418.  
  419. if (!g_exiting) sleep(20);
  420. }
  421.  
  422. stratumlog("closing database...\n");
  423. db_close(db);
  424.  
  425. pthread_join(thread2, NULL);
  426. db_close(g_db); // client threads (called by stratum one)
  427.  
  428. closelogs();
  429.  
  430. return 0;
  431. }
  432.  
  433. ///////////////////////////////////////////////////////////////////////////////
  434.  
  435. void *monitor_thread(void *p)
  436. {
  437. while(!g_exiting)
  438. {
  439. sleep(120);
  440.  
  441. if(g_last_broadcasted + YAAMP_MAXJOBDELAY < time(NULL))
  442. {
  443. g_exiting = true;
  444. stratumlogdate("%s dead lock, exiting...\n", g_stratum_algo);
  445. exit(1);
  446. }
  447.  
  448. if(g_max_shares && g_shares_counter)
  449. {
  450.  
  451. if((g_shares_counter - g_shares_log) > 10000)
  452. {
  453. stratumlogdate("%s %luK shares...\n", g_stratum_algo, (g_shares_counter/1000u));
  454. g_shares_log = g_shares_counter;
  455. }
  456.  
  457. if(g_shares_counter > g_max_shares)
  458. {
  459. g_exiting = true;
  460. stratumlogdate("%s need a restart (%lu shares), exiting...\n", g_stratum_algo, (unsigned long) g_max_shares);
  461. exit(1);
  462. }
  463. }
  464. }
  465. }
  466.  
  467. ///////////////////////////////////////////////////////////////////////////////
  468.  
  469. void *stratum_thread(void *p)
  470. {
  471. int listen_sock = socket(AF_INET, SOCK_STREAM, 0);
  472. if(listen_sock <= 0) yaamp_error("socket");
  473.  
  474. int optval = 1;
  475. setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval);
  476.  
  477. struct sockaddr_in serv;
  478.  
  479. serv.sin_family = AF_INET;
  480. serv.sin_addr.s_addr = htonl(INADDR_ANY);
  481. serv.sin_port = htons(g_tcp_port);
  482.  
  483. int res = bind(listen_sock, (struct sockaddr*)&serv, sizeof(serv));
  484. if(res < 0) yaamp_error("bind");
  485.  
  486. res = listen(listen_sock, 4096);
  487. if(res < 0) yaamp_error("listen");
  488.  
  489. /////////////////////////////////////////////////////////////////////////
  490.  
  491. int failcount = 0;
  492. while(!g_exiting)
  493. {
  494. int sock = accept(listen_sock, NULL, NULL);
  495. if(sock <= 0)
  496. {
  497. int error = errno;
  498. stratumlog("%s socket accept() error %d\n", g_stratum_algo, error);
  499. failcount++;
  500. usleep(50000);
  501. if (error == 24 && failcount > 5) {
  502. g_exiting = true; // happen when max open files is reached (see ulimit)
  503. stratumlogdate("%s too much socket failure, exiting...\n", g_stratum_algo);
  504. exit(error);
  505. }
  506. continue;
  507. }
  508.  
  509. failcount = 0;
  510. pthread_t thread;
  511. int res = pthread_create(&thread, NULL, client_thread, (void *)(long)sock);
  512. if(res != 0)
  513. {
  514. int error = errno;
  515. close(sock);
  516. g_exiting = true;
  517. stratumlog("%s pthread_create error %d %d\n", g_stratum_algo, res, error);
  518. }
  519.  
  520. pthread_detach(thread);
  521. }
  522. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement