Browse Source

Merge branch 'dev' of https://github.com/jl777/SuperNET into dev-decker-dev

patch-3
DeckerSU 7 years ago
parent
commit
204ba07b95
  1. 2
      iguana/exchanges/LP_include.h
  2. 8
      iguana/exchanges/LP_nativeDEX.c
  3. 72
      iguana/exchanges/LP_network.c
  4. 5
      iguana/exchanges/LP_ordermatch.c
  5. 3
      iguana/exchanges/LP_peers.c
  6. 13
      iguana/exchanges/LP_privkey.c
  7. 10
      iguana/exchanges/LP_remember.c
  8. 2
      iguana/exchanges/LP_secp.c
  9. 2
      iguana/exchanges/LP_transaction.c

2
iguana/exchanges/LP_include.h

@ -25,6 +25,8 @@
#define LP_TECHSUPPORT 0
#endif
#define LP_DONT_CMDCHANNEL
#ifdef FROMGUI
#define printf dontprintf

8
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);
@ -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);
}

72
iguana/exchanges/LP_network.c

@ -472,6 +472,25 @@ 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);
}
if ( IAMLP != 0 )
nn_close(sock);
}
}
void LP_psockloop(void *_ptr)
{
static struct nn_pollfd *pfds;
@ -505,7 +524,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<Numpsocks; j++)
{
@ -596,48 +615,41 @@ void LP_psockloop(void *_ptr)
} // else printf("num pfds.%d retval.%d\n",n,retval);
}
}
if ( 0 && sendsock >= 0 )
printf("sendsock.%d Numpsocks.%d\n",sendsock,Numpsocks);
if ( sendsock < 0 )
{
usleep(30000);
for (i=nonz=0; i<Numpsocks; i++)
{
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);
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);
//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);
break;
mynn_close(ptr->publicsock), ptr->publicsock = -1;
nonz++;
}
else if ( now > ptr->lastping+PSOCK_KEEPALIVE/2 && ptr->errors < 3 )
}
}
if ( nonz > 0 )
{
n = Numpsocks;
for (i=0; i<n; i++)
{
ptr = &PSOCKS[i];
if ( ptr->sendsock < 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; j<n-1; j++)
PSOCKS[j] = PSOCKS[j+1];
n--;
}
}
printf("PSOCKS purge nonz.%d n.%d vs Numpsocks.%d\n",nonz,n,Numpsocks);
Numpsocks = n;
}
if ( nonz == 0 && i == Numpsocks )
usleep(100000);
}
portable_mutex_unlock(&LP_psockmutex);
} else usleep(100000);
@ -694,6 +706,7 @@ char *_LP_psock_create(int32_t *pullsockp,int32_t *pubsockp,char *ipaddr,uint16_
if ( pubp->pairsock >= 0 )
{
printf("%s already has pairsock.%d\n",bits256_str(str,pubkey),pubp->pairsock);
portable_mutex_lock(&LP_psockmutex);
for (i=0; i<Numpsocks; i++)
if ( PSOCKS[i].publicsock == pubp->pairsock )
{
@ -710,9 +723,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;

5
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);

3
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 )

13
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 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,6 +294,17 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan
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 )
{
printf("illegal privkey %s\n",bits256_str(str,privkey));
exit(0);
}
if ( bitcoin_verify(ctx,sig,siglen,tmpkey,coin->pubkey33,33) != 0 )
{
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 )
{
coin->counter++;

10
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]);

2
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 )

2
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 )

Loading…
Cancel
Save