From 065ff583112961ded604e27f96960899787e3a15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 19:10:00 +0200 Subject: [PATCH 01/20] Test --- iguana/exchanges/LP_network.c | 64 ++++++++++++++++++++++------------ iguana/exchanges/LP_remember.c | 10 +++--- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index aaa0b377e..dcf66efbd 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -472,6 +472,24 @@ void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats portable_mutex_unlock(&LP_commandQmutex); } +void mynn_close(int32_t sock) +{ + struct nn_pollfd pfd; int32_t n; void *buf; + if ( sock >= 0 ) + { + while ( (n= nn_recv(sock,&buf,NN_MSG,0)) > 0 ) + printf("got n.%d bytes from nn_close(%d)\n",n,sock); + pfd.fd = sock; + pfd.events = POLLOUT; + while ( nn_poll(&pfd,1,100) > 0 ) + { + printf("cant send to nn_close(%d)\n",sock); + sleep(1); + } + nn_close(sock); + } +} + void LP_psockloop(void *_ptr) { static struct nn_pollfd *pfds; @@ -505,7 +523,7 @@ void LP_psockloop(void *_ptr) pfds = calloc(MAX_PSOCK_PORT,sizeof(*pfds)); portable_mutex_lock(&LP_psockmutex); memset(pfds,0,sizeof(*pfds) * ((Numpsocks*2 <= MAX_PSOCK_PORT) ? Numpsocks*2 : MAX_PSOCK_PORT)); - for (iter=0; iter<2; iter++) + for (iter=j=0; iter<2; iter++) { for (j=n=0; j= 0 ) - printf("sendsock.%d Numpsocks.%d\n",sendsock,Numpsocks); if ( sendsock < 0 ) { + usleep(30000); for (i=nonz=0; i ptr->lasttime+PSOCK_KEEPALIVE ) + if ( now > ptr->lasttime+PSOCK_KEEPALIVE/10 ) { - //printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime); + printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime); if ( ptr->sendsock != ptr->publicsock && ptr->sendsock >= 0 ) - nn_close(ptr->sendsock); + mynn_close(ptr->sendsock), ptr->sendsock = -1; if ( ptr->publicsock >= 0 ) - nn_close(ptr->publicsock); + mynn_close(ptr->publicsock), ptr->publicsock = -1; + nonz++; //portable_mutex_lock(&LP_psockmutex); if ( Numpsocks > 1 ) { @@ -619,25 +637,25 @@ void LP_psockloop(void *_ptr) memset(&PSOCKS[Numpsocks],0,sizeof(*ptr)); } else Numpsocks = 0; //portable_mutex_unlock(&LP_psockmutex); - break; } - else if ( now > ptr->lastping+PSOCK_KEEPALIVE/2 && ptr->errors < 3 ) + } + } + if ( nonz > 0 ) + { + n = Numpsocks; + for (i=0; isendsock < 0 && ptr->publicsock < 0 ) { - ptr->lastping = now; - if ( 0 ) - { - sendsock = ptr->sendsock; - sprintf(keepalive,"{\"method\":\"keepalive\",\"endpoint\":\"%s\"}",ptr->sendaddr); - size = (int32_t)strlen(keepalive) + 1; - buf = keepalive; - printf("send keepalive.(%s)\n",keepalive); - } - break; + for (j=i; jpairsock >= 0 ) { printf("%s already has pairsock.%d\n",bits256_str(str,pubkey),pubp->pairsock); + portable_mutex_lock(&LP_psockmutex); for (i=0; ipairsock ) { @@ -710,9 +729,10 @@ char *_LP_psock_create(int32_t *pullsockp,int32_t *pubsockp,char *ipaddr,uint16_ //printf("cmd.%d publicaddr.(%s) for subaddr.(%s), pullsock.%d pubsock.%d\n",cmdchannel,pushaddr,subaddr,pullsock,pubsock); *pullsockp = pullsock; *pubsockp = pubsock; + portable_mutex_unlock(&LP_psockmutex); return(jprint(retjson,1)); } - LP_psockadd(ispaired,pullsock,publicport,pubsock,subport,subaddr,pushaddr,cmdchannel); + portable_mutex_unlock(&LP_psockmutex); } //printf("pairsock for %s <- %d\n",bits256_str(str,pubkey),pullsock); //pubp->pairsock = pullsock; diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index e4b78c913..2aad1afb5 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -794,7 +794,7 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap,int32_t forceflag) { if ( (sentobj= LP_gettx(symbol,txid,1)) == 0 ) { - char str2[65]; printf("%s %s ready to broadcast\n",symbol,bits256_str(str2,txid)); + char str2[65]; printf("%s %s ready to broadcast %s r%u q%u\n",symbol,bits256_str(str2,txid),txnames[i],rswap->requestid,rswap->quoteid); } else { @@ -1132,10 +1132,10 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen); if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,claimtime,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) { - int32_t z; - for (z=0; z<20; z++) - printf("%02x",rswap.secretAm[z]); - printf(" secretAm, myprivs[1].(%s) bobreclaim.(%s)\n",bits256_str(str,rswap.myprivs[1]),rswap.txbytes[BASILISK_BOBRECLAIM]); + //int32_t z; + //for (z=0; z<20; z++) + // printf("%02x",rswap.secretAm[z]); + //printf(" secretAm, myprivs[1].(%s) bobreclaim.(%s)\n",bits256_str(str,rswap.myprivs[1]),rswap.txbytes[BASILISK_BOBRECLAIM]); } } LP_txbytes_update("bobreclaim",rswap.bobcoin,rswap.txbytes[BASILISK_BOBRECLAIM],&rswap.txids[BASILISK_BOBRECLAIM],&rswap.paymentspent,&rswap.sentflags[BASILISK_BOBRECLAIM]); From 96b8149fca6814fe5cdf128308a4e299115637ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 19:10:32 +0200 Subject: [PATCH 02/20] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index dcf66efbd..210bb97d4 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -622,7 +622,7 @@ void LP_psockloop(void *_ptr) if ( i < Numpsocks ) { ptr = &PSOCKS[i]; - if ( now > ptr->lasttime+PSOCK_KEEPALIVE/10 ) + if ( now > ptr->lasttime+PSOCK_KEEPALIVE ) { printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime); if ( ptr->sendsock != ptr->publicsock && ptr->sendsock >= 0 ) From f41a2e7991f2c062ef91ccfce6303db0aeb64af9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 19:11:20 +0200 Subject: [PATCH 03/20] Test --- iguana/exchanges/LP_network.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 210bb97d4..e33ae0c03 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -622,7 +622,7 @@ void LP_psockloop(void *_ptr) if ( i < Numpsocks ) { ptr = &PSOCKS[i]; - if ( now > ptr->lasttime+PSOCK_KEEPALIVE ) + if ( now > ptr->lasttime+PSOCK_KEEPALIVE/10 ) { printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime); if ( ptr->sendsock != ptr->publicsock && ptr->sendsock >= 0 ) @@ -630,13 +630,6 @@ void LP_psockloop(void *_ptr) if ( ptr->publicsock >= 0 ) mynn_close(ptr->publicsock), ptr->publicsock = -1; nonz++; - //portable_mutex_lock(&LP_psockmutex); - if ( Numpsocks > 1 ) - { - PSOCKS[i] = PSOCKS[--Numpsocks]; - memset(&PSOCKS[Numpsocks],0,sizeof(*ptr)); - } else Numpsocks = 0; - //portable_mutex_unlock(&LP_psockmutex); } } } From 923361d22f8a1c108efa0a40c8043de775833cd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 19:11:50 +0200 Subject: [PATCH 04/20] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index e33ae0c03..c55ead670 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -622,7 +622,7 @@ void LP_psockloop(void *_ptr) if ( i < Numpsocks ) { ptr = &PSOCKS[i]; - if ( now > ptr->lasttime+PSOCK_KEEPALIVE/10 ) + if ( now > ptr->lasttime+PSOCK_KEEPALIVE ) { printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime); if ( ptr->sendsock != ptr->publicsock && ptr->sendsock >= 0 ) From 3b34b928b3393745f0bfb3712b28c6a1d676917f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 19:24:01 +0200 Subject: [PATCH 05/20] Test --- iguana/exchanges/LP_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index c55ead670..9c7f21a8b 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -486,7 +486,7 @@ void mynn_close(int32_t sock) printf("cant send to nn_close(%d)\n",sock); sleep(1); } - nn_close(sock); + //nn_close(sock); // dont know why but it crashes... } } @@ -622,7 +622,7 @@ void LP_psockloop(void *_ptr) if ( i < Numpsocks ) { ptr = &PSOCKS[i]; - if ( now > ptr->lasttime+PSOCK_KEEPALIVE ) + if ( now > ptr->lasttime+PSOCK_KEEPALIVE/10 ) { printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime); if ( ptr->sendsock != ptr->publicsock && ptr->sendsock >= 0 ) From 651a7fff3959d684c300970e22043b545dcdc19e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 19:24:45 +0200 Subject: [PATCH 06/20] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 9c7f21a8b..6723df3ce 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -622,7 +622,7 @@ void LP_psockloop(void *_ptr) if ( i < Numpsocks ) { ptr = &PSOCKS[i]; - if ( now > ptr->lasttime+PSOCK_KEEPALIVE/10 ) + if ( now > ptr->lasttime+PSOCK_KEEPALIVE ) { printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime); if ( ptr->sendsock != ptr->publicsock && ptr->sendsock >= 0 ) From f9746843b05b91bdb05d16cc36e64321ce1825ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 19:33:48 +0200 Subject: [PATCH 07/20] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 6723df3ce..eb257aed7 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -622,7 +622,7 @@ void LP_psockloop(void *_ptr) if ( i < Numpsocks ) { ptr = &PSOCKS[i]; - if ( now > ptr->lasttime+PSOCK_KEEPALIVE ) + if ( ptr->cmdchannel == 0 && now > ptr->lasttime+PSOCK_KEEPALIVE ) { printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime); if ( ptr->sendsock != ptr->publicsock && ptr->sendsock >= 0 ) From a2c0b77289eea3bd826182b4c708b0a231821d42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 19:34:34 +0200 Subject: [PATCH 08/20] Test --- iguana/exchanges/LP_network.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index eb257aed7..b632e470d 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -486,7 +486,8 @@ void mynn_close(int32_t sock) printf("cant send to nn_close(%d)\n",sock); sleep(1); } - //nn_close(sock); // dont know why but it crashes... + if ( IAMLP != 0 ) + nn_close(sock); } } From d6c22e581d73c8fcd2d3fe5dbd4f8d3b26579e99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 19:51:51 +0200 Subject: [PATCH 09/20] LP_DONT_CMDCHANNEL --- iguana/exchanges/LP_include.h | 2 ++ iguana/exchanges/LP_peers.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index d456d9c66..e0f794da8 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -25,6 +25,8 @@ #define LP_TECHSUPPORT 0 #endif +#define LP_DONT_CMDCHANNEL + #ifdef FROMGUI #define printf dontprintf diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 00762efd0..ced058f37 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -60,6 +60,9 @@ void LP_cmdchannel(struct LP_peerinfo *peer) { char *hellostr = "{\"method\":\"hello\"}"; char connectaddr[128],publicaddr[128],*retstr; int32_t pairsock=-1,pubsock,sentbytes=-2; uint16_t cmdport; +#ifdef LP_DONT_CMDCHANNEL + return; +#endif if ( bits256_nonz(G.LP_mypub25519) == 0 || strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 ) return; if ( (cmdport= LP_psock_get(connectaddr,publicaddr,1,1,peer->ipaddr)) != 0 ) From 9c7afed512cbe3120b0220dcf7bdc890eb36644a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 20:56:38 +0200 Subject: [PATCH 10/20] Test --- iguana/exchanges/LP_ordermatch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 680a36ceb..f858c7e3b 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -230,7 +230,7 @@ int32_t LP_nanobind(void *ctx,char *pairstr) printf("error creating utxo->pair\n"); else { - for (i=0; i<1000; i++) + for (i=0; i<10000; i++) { r = (10000 + (LP_rand() % 50000)) & 0xffff; if ( LP_fixed_pairport != 0 ) @@ -248,6 +248,9 @@ int32_t LP_nanobind(void *ctx,char *pairstr) if ( LP_fixed_pairport != 0 ) break; } + printf("%d ports all used\n",i); + nn_close(pairsock); + pairsock = -1; } } else pairsock = LP_initpublicaddr(ctx,&mypullport,pairstr,"127.0.0.1",0,1); return(pairsock); From b7cd2b27bbc6d076a2ffff7ca94702da389e8973 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 22:25:34 +0200 Subject: [PATCH 11/20] Test --- iguana/exchanges/LP_transaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 68568345b..9be0e469c 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -444,7 +444,7 @@ int32_t bitcoin_verifyvins(void *ctx,char *symbol,uint8_t taddr,uint8_t pubtype, if ( sig == 0 || siglen == 0 ) { memset(vp->signers[j].pubkey,0,sizeof(vp->signers[j].pubkey)); - printf("no sig.%p or siglen.%d zero\n",sig,siglen); + char str[65]; printf("no sig.%p or siglen.%d zero priv.(%s)\n",sig,siglen,bits256_str(str,vp->signers[j].privkey)); continue; } if ( bitcoin_verify(ctx,sig,siglen-1,sigtxid,vp->signers[j].pubkey,bitcoin_pubkeylen(vp->signers[j].pubkey)) < 0 ) From 50215d62526953b690d3224698b5f834c58daa5c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 22:30:44 +0200 Subject: [PATCH 12/20] Test --- iguana/exchanges/LP_transaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 9be0e469c..327cb4cdf 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -425,7 +425,7 @@ int32_t bitcoin_verifyvins(void *ctx,char *symbol,uint8_t taddr,uint8_t pubtype, { sig = vp->signers[j].sig; siglen = vp->signers[j].siglen; - if ( signtx != 0 && bits256_nonz(vp->signers[j].privkey) != 0 ) + if ( signtx != 0 )//&& bits256_nonz(vp->signers[j].privkey) != 0 ) { siglen = bitcoin_sign(ctx,symbol,sig,sigtxid,vp->signers[j].privkey,0); //if ( (plen= bitcoin_pubkeylen(vp->signers[j].pubkey)) <= 0 ) From 42005e39e2dd228850fa8f93c215fe14930d7e1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 22:33:33 +0200 Subject: [PATCH 13/20] Test --- iguana/exchanges/LP_secp.c | 2 +- iguana/exchanges/LP_transaction.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_secp.c b/iguana/exchanges/LP_secp.c index 516e2be75..fe8e2e937 100644 --- a/iguana/exchanges/LP_secp.c +++ b/iguana/exchanges/LP_secp.c @@ -94,7 +94,7 @@ int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256 funcp = secp256k1_nonce_function_rfc6979; if ( secp256k1_ec_seckey_verify(ctx,privkey.bytes) == 0 ) { - //printf("bitcoin_sign illegal privkey\n"); + printf("bitcoin_sign illegal privkey\n"); return(-1); } if ( strcmp(symbol,"BCH") == 0 || strcmp(symbol,"BTG") == 0 ) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 327cb4cdf..731bde1ae 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -432,16 +432,16 @@ int32_t bitcoin_verifyvins(void *ctx,char *symbol,uint8_t taddr,uint8_t pubtype, bitcoin_pubkey33(ctx,vp->signers[j].pubkey,vp->signers[j].privkey); sig[siglen++] = sighash; vp->signers[j].siglen = siglen; - /*char str[65]; printf("SIGTXID.(%s) ",bits256_str(str,sigtxid)); + char str[65]; printf("SIGTXID.(%s) ",bits256_str(str,sigtxid)); int32_t i; for (i=0; isigners[j].pubkey[i]); // s2 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1; - printf(" SIGNEDTX.[%02x] siglen.%d priv.%s\n",sig[siglen-1],siglen,bits256_str(str,vp->signers[j].privkey));*/ + printf(" SIGNEDTX.[%02x] siglen.%d priv.%s\n",sig[siglen-1],siglen,bits256_str(str,vp->signers[j].privkey)); } - if ( sig == 0 || siglen == 0 ) + if ( sig == 0 || siglen <= 0 ) { memset(vp->signers[j].pubkey,0,sizeof(vp->signers[j].pubkey)); char str[65]; printf("no sig.%p or siglen.%d zero priv.(%s)\n",sig,siglen,bits256_str(str,vp->signers[j].privkey)); From 64262933c9cbd37858b4a458cc213388c003b324 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 22:35:17 +0200 Subject: [PATCH 14/20] Test --- iguana/exchanges/LP_secp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_secp.c b/iguana/exchanges/LP_secp.c index fe8e2e937..1fd987b2d 100644 --- a/iguana/exchanges/LP_secp.c +++ b/iguana/exchanges/LP_secp.c @@ -95,7 +95,7 @@ int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256 if ( secp256k1_ec_seckey_verify(ctx,privkey.bytes) == 0 ) { printf("bitcoin_sign illegal privkey\n"); - return(-1); + //return(-1); } if ( strcmp(symbol,"BCH") == 0 || strcmp(symbol,"BTG") == 0 ) { From 40c4af7bfde772bf42213c6c73efe64f2bec27c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 22:57:36 +0200 Subject: [PATCH 15/20] Make sure valid privkey --- iguana/exchanges/LP_privkey.c | 8 +++++++- iguana/exchanges/LP_secp.c | 2 +- iguana/exchanges/LP_transaction.c | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index a2b9494a5..d382138f8 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -254,7 +254,7 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr) bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr) { //static uint32_t counter; - bits256 privkey,userpub,zero,userpass,checkkey,tmpkey; char tmpstr[128]; cJSON *retjson; uint8_t tmptype; int32_t notarized; uint64_t nxtaddr; + bits256 privkey,userpub,zero,userpass,checkkey,tmpkey; char tmpstr[128]; cJSON *retjson; uint8_t tmptype,sig[128]; int32_t notarized; uint64_t nxtaddr; if ( (wifstr == 0 || wifstr[0] == 0) && LP_wifstr_valid(coin->symbol,passphrase) > 0 ) { wifstr = passphrase; @@ -293,6 +293,12 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan nxtaddr = conv_NXTpassword(tmpkey.bytes,pubkeyp->bytes,0,0); RS_encode(G.LP_NXTaddr,nxtaddr); } + OS_randombytes(tmpkey.bytes,sizeof(tmpkey)); + if ( bits256_nonz(privkey) == 0 || bitcoin_sign(ctx,coin->symbol,sig,tmpkey,privkey,0) <= 0 ) + { + char str[65]; printf("illegal privkey %s\n",bits256_str(str,privkey)); + exit(0); + } bitcoin_priv2pub(ctx,coin->symbol,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype); if ( coin->counter == 0 ) { diff --git a/iguana/exchanges/LP_secp.c b/iguana/exchanges/LP_secp.c index 1fd987b2d..fe8e2e937 100644 --- a/iguana/exchanges/LP_secp.c +++ b/iguana/exchanges/LP_secp.c @@ -95,7 +95,7 @@ int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256 if ( secp256k1_ec_seckey_verify(ctx,privkey.bytes) == 0 ) { printf("bitcoin_sign illegal privkey\n"); - //return(-1); + return(-1); } if ( strcmp(symbol,"BCH") == 0 || strcmp(symbol,"BTG") == 0 ) { diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 731bde1ae..9be0e469c 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -425,23 +425,23 @@ int32_t bitcoin_verifyvins(void *ctx,char *symbol,uint8_t taddr,uint8_t pubtype, { sig = vp->signers[j].sig; siglen = vp->signers[j].siglen; - if ( signtx != 0 )//&& bits256_nonz(vp->signers[j].privkey) != 0 ) + if ( signtx != 0 && bits256_nonz(vp->signers[j].privkey) != 0 ) { siglen = bitcoin_sign(ctx,symbol,sig,sigtxid,vp->signers[j].privkey,0); //if ( (plen= bitcoin_pubkeylen(vp->signers[j].pubkey)) <= 0 ) bitcoin_pubkey33(ctx,vp->signers[j].pubkey,vp->signers[j].privkey); sig[siglen++] = sighash; vp->signers[j].siglen = siglen; - char str[65]; printf("SIGTXID.(%s) ",bits256_str(str,sigtxid)); + /*char str[65]; printf("SIGTXID.(%s) ",bits256_str(str,sigtxid)); int32_t i; for (i=0; isigners[j].pubkey[i]); // s2 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1; - printf(" SIGNEDTX.[%02x] siglen.%d priv.%s\n",sig[siglen-1],siglen,bits256_str(str,vp->signers[j].privkey)); + printf(" SIGNEDTX.[%02x] siglen.%d priv.%s\n",sig[siglen-1],siglen,bits256_str(str,vp->signers[j].privkey));*/ } - if ( sig == 0 || siglen <= 0 ) + if ( sig == 0 || siglen == 0 ) { memset(vp->signers[j].pubkey,0,sizeof(vp->signers[j].pubkey)); char str[65]; printf("no sig.%p or siglen.%d zero priv.(%s)\n",sig,siglen,bits256_str(str,vp->signers[j].privkey)); From 105e114445315cc5995c2d9238a64be346042464 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 23:03:21 +0200 Subject: [PATCH 16/20] Test --- iguana/exchanges/LP_privkey.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index d382138f8..10c12ac2f 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -254,7 +254,7 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr) bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr) { //static uint32_t counter; - bits256 privkey,userpub,zero,userpass,checkkey,tmpkey; char tmpstr[128]; cJSON *retjson; uint8_t tmptype,sig[128]; int32_t notarized; uint64_t nxtaddr; + bits256 privkey,userpub,zero,userpass,checkkey,tmpkey; char str[65],str2[65],tmpstr[128]; cJSON *retjson; uint8_t tmptype,sig[128]; int32_t notarized,siglen; uint64_t nxtaddr; if ( (wifstr == 0 || wifstr[0] == 0) && LP_wifstr_valid(coin->symbol,passphrase) > 0 ) { wifstr = passphrase; @@ -294,9 +294,14 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan RS_encode(G.LP_NXTaddr,nxtaddr); } OS_randombytes(tmpkey.bytes,sizeof(tmpkey)); - if ( bits256_nonz(privkey) == 0 || bitcoin_sign(ctx,coin->symbol,sig,tmpkey,privkey,0) <= 0 ) + if ( bits256_nonz(privkey) == 0 || (siglen= bitcoin_sign(ctx,coin->symbol,sig,tmpkey,privkey,0)) <= 0 ) { - char str[65]; printf("illegal privkey %s\n",bits256_str(str,privkey)); + printf("illegal privkey %s\n",bits256_str(str,privkey)); + exit(0); + } + if ( bitcoin_verify(ctx,sig,siglen-1,tmpkey,coin->pubkey33,33) != 0 ) + { + printf("signature for %s by %s didnt verify\n",bits256_str(str,tmpkey),bits256_str(str2,privkey)); exit(0); } bitcoin_priv2pub(ctx,coin->symbol,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype); From 37464dd0c139a246130d9362de7c007fbc805574 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 23:05:29 +0200 Subject: [PATCH 17/20] Test --- iguana/exchanges/LP_privkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 10c12ac2f..d84f11a66 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -293,6 +293,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan nxtaddr = conv_NXTpassword(tmpkey.bytes,pubkeyp->bytes,0,0); RS_encode(G.LP_NXTaddr,nxtaddr); } + bitcoin_priv2pub(ctx,coin->symbol,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype); OS_randombytes(tmpkey.bytes,sizeof(tmpkey)); if ( bits256_nonz(privkey) == 0 || (siglen= bitcoin_sign(ctx,coin->symbol,sig,tmpkey,privkey,0)) <= 0 ) { @@ -304,7 +305,6 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan printf("signature for %s by %s didnt verify\n",bits256_str(str,tmpkey),bits256_str(str2,privkey)); exit(0); } - bitcoin_priv2pub(ctx,coin->symbol,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype); if ( coin->counter == 0 ) { coin->counter++; From 42e23c6112c8ebc469d218015304800370fd7339 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 23:07:28 +0200 Subject: [PATCH 18/20] Test --- iguana/exchanges/LP_privkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index d84f11a66..9c3c3ae47 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -300,9 +300,9 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan printf("illegal privkey %s\n",bits256_str(str,privkey)); exit(0); } - if ( bitcoin_verify(ctx,sig,siglen-1,tmpkey,coin->pubkey33,33) != 0 ) + if ( bitcoin_verify(ctx,sig,siglen,tmpkey,coin->pubkey33,33) != 0 ) { - printf("signature for %s by %s didnt verify\n",bits256_str(str,tmpkey),bits256_str(str2,privkey)); + printf("signature.[%d] for %s by %s didnt verify\n",siglen,bits256_str(str,tmpkey),bits256_str(str2,privkey)); exit(0); } if ( coin->counter == 0 ) From f576c829d996928e03135ed15845309e6cf7dbea Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 23:27:18 +0200 Subject: [PATCH 19/20] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4ea68f074..277d1fc4d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -448,7 +448,7 @@ int32_t LP_nanomsg_recvs(void *ctx) int32_t n=0,nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp; if ( (origipaddr= LP_myipaddr) == 0 ) origipaddr = "127.0.0.1"; - //portable_mutex_lock(&LP_nanorecvsmutex); + portable_mutex_lock(&LP_nanorecvsmutex); HASH_ITER(hh,LP_peerinfos,peer,tmp) { if ( n++ > 0 && peer->errors >= LP_MAXPEER_ERRORS ) @@ -474,7 +474,7 @@ int32_t LP_nanomsg_recvs(void *ctx) { nonz += LP_sock_check("PULL",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); } - //portable_mutex_unlock(&LP_nanorecvsmutex); + portable_mutex_unlock(&LP_nanorecvsmutex); return(nonz); } From 6cf019b61d3684dc4311d6d6167e6353c3dc36d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Feb 2018 23:30:38 +0200 Subject: [PATCH 20/20] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 277d1fc4d..a0076c183 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -250,7 +250,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( duplicate != 0 ) dup++; else uniq++; - //portable_mutex_lock(&LP_commandmutex); + portable_mutex_lock(&LP_commandmutex); if ( (LP_rand() % 100000) == 0 ) printf("%s dup.%d (%u / %u) %.1f%% encrypted.%d recv.%u [%02x %02x] vs %02x %02x\n",typestr,duplicate,dup,dup+uniq,(double)100*dup/(dup+uniq),encrypted,crc32,ptr[0],ptr[1],crc32&0xff,(crc32>>8)&0xff); if ( duplicate == 0 ) @@ -341,7 +341,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, free_json(argjson); } } //else printf("DUPLICATE.(%s)\n",(char *)ptr); - //portable_mutex_unlock(&LP_commandmutex); + portable_mutex_unlock(&LP_commandmutex); if ( jsonstr != 0 && (void *)jsonstr != (void *)ptr && encrypted == 0 ) free(jsonstr); return(retstr);