From ea1ae41c34695c5a5fb07de39b5fdfb03900c250 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 15:11:06 -0300 Subject: [PATCH 01/56] test --- basilisk/basilisk_DEX.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 6bdf8dc44..9b702abcb 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -420,6 +420,7 @@ STRING_ARG(InstantDEX,available,source) { if ( (unspents= iguana_listunspents(myinfo,coin,0,0,0,remoteaddr)) != 0 ) { + printf("available.(%s)\n",jprint(unspents,0)); if ( (n= cJSON_GetArraySize(unspents)) > 0 ) { for (i=0; i %.8f\n",jprint(item,0),dstr(total)); + printf("(%s) -> %.8f\n",jprint(item,0),dstr(total)); } } free_json(unspents); From 074c39f70797409b81e978dc48553f6aff991363 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 15:15:43 -0300 Subject: [PATCH 02/56] test --- iguana/iguana_payments.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index 032ce2e87..87032e972 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -1288,24 +1288,29 @@ ARRAY_OBJ_INT(bitcoinrpc,createrawtransaction,vins,vouts,locktime) cJSON *iguana_listunspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,char *remoteaddr) { + cJSON *retjson; int32_t flag = 0; + if ( array == 0 ) + { + array = iguana_getaddressesbyaccount(myinfo,coin,"*"); + flag = 1; + } if ( minconf == 0 ) minconf = 1; if ( maxconf == 0 ) maxconf = (1 << 30); - return(iguana_RTlistunspent(myinfo,coin,array,minconf,maxconf,remoteaddr,0)); + retjson = iguana_RTlistunspent(myinfo,coin,array,minconf,maxconf,remoteaddr,0); + if ( array != 0 && flag != 0 ) + free_json(array); + return(retjson); } TWOINTS_AND_ARRAY(bitcoinrpc,listunspent,minconf,maxconf,array) { //int32_t numrmds,numunspents=0; uint8_t *rmdarray; cJSON *retjson = cJSON_CreateArray(); - cJSON *argarray,*retjson; + cJSON *retjson; if ( remoteaddr != 0 ) return(clonestr("{\"error\":\"no remote\"}")); - if ( (argarray= array) == 0 || cJSON_GetArraySize(array) == 0 ) - argarray = iguana_getaddressesbyaccount(myinfo,coin,"*"); - retjson = iguana_listunspents(myinfo,coin,argarray,minconf,maxconf,remoteaddr); - if ( argarray != array ) - free_json(argarray); + retjson = iguana_listunspents(myinfo,coin,0,minconf,maxconf,remoteaddr); return(jprint(retjson,1)); } From 7029e3b589f2c5575b036b71a00c3eea902fcf2e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 15:25:15 -0300 Subject: [PATCH 03/56] test --- basilisk/basilisk_DEX.c | 4 ++-- basilisk/basilisk_MSG.c | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 9b702abcb..53da4c9fc 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -420,7 +420,7 @@ STRING_ARG(InstantDEX,available,source) { if ( (unspents= iguana_listunspents(myinfo,coin,0,0,0,remoteaddr)) != 0 ) { - printf("available.(%s)\n",jprint(unspents,0)); + //printf("available.(%s)\n",jprint(unspents,0)); if ( (n= cJSON_GetArraySize(unspents)) > 0 ) { for (i=0; i %.8f\n",jprint(item,0),dstr(total)); + //printf("(%s) -> %.8f\n",jprint(item,0),dstr(total)); } } free_json(unspents); diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 3e3907c26..0211f9509 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -159,6 +159,9 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ for (i=0; i 0 ) @@ -168,12 +171,18 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ keylen = basilisk_messagekey(key,channel,msgid,zero,desthash); if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0)); + keylen = basilisk_messagekey(key,channel,msgid,desthash,zero); + if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0)); } if ( bits256_nonz(desthash) != 0 ) { keylen = basilisk_messagekey(key,channel,msgid,srchash,zero); if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); + keylen = basilisk_messagekey(key,channel,msgid,zero,srchash); + if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); } if ( bits256_nonz(srchash) != 0 && bits256_nonz(desthash) != 0 ) { From 7c8c765550aa59e455703bc4d286a1faae0cce43 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 15:46:54 -0300 Subject: [PATCH 04/56] test --- basilisk/basilisk_MSG.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 0211f9509..07b9b551c 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -251,7 +251,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) free(retstr); } if ( vals != 0 && juint(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2)); + jaddnum(vals,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2)); return(basilisk_standardservice("OUT",myinfo,0,hash,vals,hexstr,0)); } #include "../includes/iguana_apiundefs.h" @@ -265,7 +265,7 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 srchash,bits25 jaddnum(valsobj,"channel",channel); if ( msgid == 0 ) msgid = (uint32_t)time(NULL); - jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2)); + jaddnum(valsobj,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2)); jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"duration",duration); jaddbits256(valsobj,"srchash",srchash); @@ -314,14 +314,14 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256 msgid = (uint32_t)time(NULL); jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"width",width); - jaddnum(valsobj,"timeout",2500); - jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); + jaddnum(valsobj,"timeout",3000); + jaddnum(valsobj,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); jaddnum(valsobj,"numrequired",1); jaddbits256(valsobj,"srchash",srchash); jaddbits256(valsobj,"desthash",desthash); if ( (retstr= basilisk_getmessage(myinfo,0,0,0,desthash,valsobj,0)) != 0 ) { - printf("channel.%u msgid.%u gotmessage.(%d)\n",channel,msgid,(int32_t)strlen(retstr)); + //printf("channel.%u msgid.%u gotmessage.(%d)\n",channel,msgid,(int32_t)strlen(retstr)); if ( (retarray= cJSON_Parse(retstr)) != 0 ) { if ( is_cJSON_Array(retarray) == 0 ) From 071418e3d6fe56f949f850a5f4447f6fea4b44bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 15:53:35 -0300 Subject: [PATCH 05/56] test --- basilisk/basilisk_MSG.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 07b9b551c..302ff14b1 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -141,23 +141,26 @@ int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t chan char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) { - struct basilisk_message *msg,*tmpmsg; uint8_t key[BASILISK_KEYSIZE]; int32_t i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; + struct basilisk_message *msg,*tmpmsg; uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; memset(zero.bytes,0,sizeof(zero)); array = cJSON_CreateArray(); if ( (width= origwidth) > 3600 ) width = 3600; else if ( width < 1 ) width = 1; + allflag = (bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); portable_mutex_lock(&myinfo->messagemutex); HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { - if ( msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0 ) + if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) jaddi(array,basilisk_msgjson(msg,msg->key,msg->keylen)); } portable_mutex_unlock(&myinfo->messagemutex); //printf("iterate_MSG width.%d channel.%d msgid.%d src.%llx -> %llx\n",origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); for (i=0; i Date: Wed, 21 Sep 2016 16:24:02 -0300 Subject: [PATCH 06/56] test --- basilisk/basilisk_DEX.c | 2 +- basilisk/basilisk_MSG.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 53da4c9fc..d5258a8b7 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -521,7 +521,7 @@ INT_ARG(InstantDEX,incoming,requestid) retjson = cJSON_CreateObject(); DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); msgid = (uint32_t)time(NULL) + drift; - if ( (retarray= basilisk_channelget(myinfo,zero,myinfo->myaddr.persistent,DEX_channel,msgid,width)) != 0 ) + if ( (retarray= basilisk_channelget(myinfo,zero,zero,DEX_channel,msgid,width)) != 0 ) // myinfo->myaddr.persistent { //printf("GOT.(%s)\n",jprint(retarray,0)); if ( (retval= basilisk_process_retarray(myinfo,0,InstantDEX_process_channelget,data,sizeof(data),DEX_channel,msgid,retarray,InstantDEX_incoming_func)) > 0 ) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 302ff14b1..5720fc8b2 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -105,10 +105,11 @@ int32_t basilisk_messagekey(uint8_t *key,uint32_t channel,uint32_t msgid,bits256 char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) { - int32_t keylen,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 senderhash; char *retstr; + int32_t keylen,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 desthash,senderhash; char *retstr; senderhash = jbits256(valsobj,"srchash"); + desthash = jbits256(valsobj,"desthash"); duration = juint(valsobj,"duration"); - keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,hash); + keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,desthash); retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); if ( bits256_nonz(hash) == 0 ) { @@ -213,7 +214,7 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha msgid = juint(valsobj,"msgid"); channel = juint(valsobj,"channel"); //char str[65],str2[65]; printf("%s -> %s channel.%u msgid.%x width.%d\n",bits256_str(str,jbits256(valsobj,"sender")),bits256_str(str2,hash),juint(valsobj,"channel"),msgid,width); - return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"srchash"),hash,width)); + return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"srchash"),jbits256(valsobj,"desthash"),width)); } #include "../includes/iguana_apidefs.h" @@ -222,8 +223,10 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) { uint32_t msgid,width,channel; - jaddbits256(vals,"srchash",hash); - jaddbits256(vals,"desthash",myinfo->myaddr.persistent); + if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"srchash")) == 0 ) + jaddbits256(vals,"srchash",hash); + if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"desthash")) == 0 ) + jaddbits256(vals,"desthash",myinfo->myaddr.persistent); if ( (msgid= juint(vals,"msgid")) == 0 ) { msgid = (uint32_t)time(NULL); @@ -234,8 +237,8 @@ HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) { channel = juint(vals,"channel"); width = juint(vals,"width"); - return(basilisk_iterate_MSG(myinfo,channel,msgid,myinfo->myaddr.persistent,myinfo->myaddr.persistent,width)); - } else return(basilisk_standardservice("MSG",myinfo,0,myinfo->myaddr.persistent,vals,hexstr,1)); + return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(vals,"srchash"),jbits256(vals,"desthash"),width)); + } else return(basilisk_standardservice("MSG",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,1)); } HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) @@ -322,7 +325,7 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256 jaddnum(valsobj,"numrequired",1); jaddbits256(valsobj,"srchash",srchash); jaddbits256(valsobj,"desthash",desthash); - if ( (retstr= basilisk_getmessage(myinfo,0,0,0,desthash,valsobj,0)) != 0 ) + if ( (retstr= basilisk_getmessage(myinfo,0,0,0,srchash,valsobj,0)) != 0 ) { //printf("channel.%u msgid.%u gotmessage.(%d)\n",channel,msgid,(int32_t)strlen(retstr)); if ( (retarray= cJSON_Parse(retstr)) != 0 ) From b047cff61294bd926dcd3cd121e2a0116fd8328c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 16:35:43 -0300 Subject: [PATCH 07/56] test --- basilisk/basilisk_MSG.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 5720fc8b2..23726d73b 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -157,7 +157,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ jaddi(array,basilisk_msgjson(msg,msg->key,msg->keylen)); } portable_mutex_unlock(&myinfo->messagemutex); - //printf("iterate_MSG width.%d channel.%d msgid.%d src.%llx -> %llx\n",origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); + printf("iterate_MSG width.%d channel.%d msgid.%d src.%llx -> %llx\n",origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); for (i=0; i Date: Wed, 21 Sep 2016 16:58:30 -0300 Subject: [PATCH 08/56] test --- basilisk/basilisk.c | 2 +- basilisk/basilisk_MSG.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index fe63fb3c0..17a2a2eaa 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -750,7 +750,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende { if ( (retstr= (*basilisk_services[i][1])(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,hash,from_basilisk)) != 0 ) { - //printf("from_basilisk.%d ret.(%s)\n",from_basilisk,retstr); + printf("%s from_basilisk.%d ret.(%s)\n",addr->ipaddr,from_basilisk,retstr); //if ( from_basilisk != 0 || strcmp(CMD,"GET") == 0 ) basilisk_sendback(myinfo,CMD,symbol,remoteaddr,basilisktag,retstr); if ( retstr != 0 ) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 23726d73b..cdf2ec5b0 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -246,7 +246,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) int32_t keylen,datalen; uint8_t key[BASILISK_KEYSIZE],space[16384],*data,*ptr = 0; char *retstr=0; if ( myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 ) { - keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"srchash"),hash); + keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"srchash"),jbits256(vals,"desthash")); if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 ) { retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration")); @@ -258,7 +258,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) } if ( vals != 0 && juint(vals,"fanout") == 0 ) jaddnum(vals,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2)); - return(basilisk_standardservice("OUT",myinfo,0,hash,vals,hexstr,0)); + return(basilisk_standardservice("OUT",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,0)); } #include "../includes/iguana_apiundefs.h" From e4c9ad222b3793a1769bc2e23779847f73d73cc4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 17:16:02 -0300 Subject: [PATCH 09/56] test --- iguana/iguana_peers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index 249aa40ad..9e417ba8d 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -528,7 +528,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s } } addr->totalsent += len; - if ( 0 && addr->basilisk != 0 ) + //if ( 0 && addr->basilisk != 0 ) printf("verack.%d (%s) sent.%d bytes to %s\n",addr->msgcounts.verack,cmdstr,len,addr->ipaddr); return(len); } @@ -584,7 +584,7 @@ int32_t iguana_recv(char *ipaddr,int32_t usock,uint8_t *recvbuf,int32_t len) remains -= recvlen; //int32_t i; for (i=0; i Date: Wed, 21 Sep 2016 17:32:23 -0300 Subject: [PATCH 10/56] test --- basilisk/basilisk.c | 2 +- iguana/iguana_peers.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 17a2a2eaa..66313f2c1 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -795,7 +795,7 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t len += iguana_rwnum(0,data,sizeof(basilisktag),&basilisktag); //int32_t i; for (i=0; iNOTARY.RELAYID >= 0 ) + //if ( 0 && myinfo->NOTARY.RELAYID >= 0 ) printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,datalen,type,senderip!=0?senderip:"?",basilisktag); basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len); } diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index 9e417ba8d..dadbe176c 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -413,6 +413,9 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port) closesocket(sock); return(-1); } + timeout.tv_sec = 10000000; + timeout.tv_usec = 0; + setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(void *)&timeout,sizeof(timeout)); } else { @@ -448,9 +451,9 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port) } } #ifdef __APPLE__ - timeout.tv_sec = 0; - timeout.tv_usec = 30000; - setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(void *)&timeout,sizeof(timeout)); + //timeout.tv_sec = 0; + //timeout.tv_usec = 30000; + //setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(void *)&timeout,sizeof(timeout)); timeout.tv_sec = 0; timeout.tv_usec = 10000; setsockopt(sock,SOL_SOCKET,SO_SNDTIMEO,(void *)&timeout,sizeof(timeout)); @@ -502,7 +505,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s #ifdef _WIN32 if ( (numsent= (int32_t)send(usock,serialized,remains,0)) < 0 ) #else - if ( (numsent= (int32_t)send(usock,serialized,remains,MSG_NOSIGNAL)) < 0 ) + if ( (numsent= (int32_t)send(usock,serialized,remains,MSG_NOSIGNAL)) < 0 ) #endif { if ( errno == EAGAIN || errno == EWOULDBLOCK ) From 03c4b2bb228ba13159207cad7634bf4ac44cef7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 18:06:14 -0300 Subject: [PATCH 11/56] test --- basilisk/basilisk.c | 1 + basilisk/basilisk_MSG.c | 75 ++++++++++++++++++++++++----------------- iguana/iguana_peers.c | 4 +-- 3 files changed, 47 insertions(+), 33 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 66313f2c1..15e12839f 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -798,6 +798,7 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t //if ( 0 && myinfo->NOTARY.RELAYID >= 0 ) printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,datalen,type,senderip!=0?senderip:"?",basilisktag); basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len); + printf("processed.%s from %s\n",type,senderip!=0?senderip:"?"); } if ( ptr != 0 ) free(ptr); diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index cdf2ec5b0..1a85b5154 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -18,36 +18,47 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration) { struct basilisk_message *msg; int32_t i; bits256 desthash; + if ( keylen != BASILISK_KEYSIZE ) + return(0); + portable_mutex_lock(&myinfo->messagemutex); HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); - if ( msg == 0 && keylen == BASILISK_KEYSIZE ) + if ( msg == 0 || msg->datalen != datalen ) { + if ( msg != 0 ) + { + printf("overwrite delete of msg.[%d]\n",msg->datalen); + HASH_DELETE(hh,myinfo->messagetable,msg); + QUEUEITEMS--; + free(msg); + } msg = calloc(1,sizeof(*msg) + datalen); - if ( duration == 0 ) - duration = BASILISK_MSGDURATION; - else if ( duration > INSTANTDEX_LOCKTIME*2 ) - duration = INSTANTDEX_LOCKTIME*2; - memcpy(desthash.bytes,&key[BASILISK_KEYSIZE - sizeof(desthash)],sizeof(desthash)); - if ( bits256_nonz(desthash) == 0 ) - msg->broadcast = 1; - msg->duration = duration; - msg->expiration = (uint32_t)time(NULL) + duration; - msg->keylen = keylen; - memcpy(msg->key,key,keylen); - msg->datalen = datalen; - memcpy(msg->data,data,datalen); - portable_mutex_lock(&myinfo->messagemutex); - HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg); - for (i=0; iexpiration); - QUEUEITEMS++; + } + if ( duration == 0 ) + duration = BASILISK_MSGDURATION; + else if ( duration > INSTANTDEX_LOCKTIME*2 ) + duration = INSTANTDEX_LOCKTIME*2; + memcpy(desthash.bytes,&key[BASILISK_KEYSIZE - sizeof(desthash)],sizeof(desthash)); + if ( bits256_nonz(desthash) == 0 ) + msg->broadcast = 1; + msg->duration = duration; + msg->expiration = (uint32_t)time(NULL) + duration; + msg->keylen = keylen; + memcpy(msg->key,key,keylen); + msg->datalen = datalen; + memcpy(msg->data,data,datalen); + HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg); + for (i=0; iexpiration); + QUEUEITEMS++; + if ( sendping != 0 ) + { + queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0); portable_mutex_unlock(&myinfo->messagemutex); - if ( sendping != 0 ) - { - queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0); - return(clonestr("{\"result\":\"message added to hashtable\"}")); - } else return(0); - } else return(0); + return(clonestr("{\"result\":\"message added to hashtable\"}")); + } + portable_mutex_unlock(&myinfo->messagemutex); + return(0); } cJSON *basilisk_msgjson(struct basilisk_message *msg,uint8_t *key,int32_t keylen) @@ -144,12 +155,12 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ { struct basilisk_message *msg,*tmpmsg; uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; memset(zero.bytes,0,sizeof(zero)); - array = cJSON_CreateArray(); if ( (width= origwidth) > 3600 ) width = 3600; else if ( width < 1 ) width = 1; allflag = (bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); + array = cJSON_CreateArray(); portable_mutex_lock(&myinfo->messagemutex); HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { @@ -157,7 +168,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ jaddi(array,basilisk_msgjson(msg,msg->key,msg->keylen)); } portable_mutex_unlock(&myinfo->messagemutex); - printf("iterate_MSG width.%d channel.%d msgid.%d src.%llx -> %llx\n",origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); + printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); for (i=0; i %s channel.%u msgid.%x width.%d\n",bits256_str(str,jbits256(valsobj,"sender")),bits256_str(str2,hash),juint(valsobj,"channel"),msgid,width); - return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"srchash"),jbits256(valsobj,"desthash"),width)); + char str[65],str2[65]; printf("%s -> %s channel.%u msgid.%x width.%d\n",bits256_str(str,jbits256(valsobj,"sender")),bits256_str(str2,jbits256(valsobj,"desthash")),juint(valsobj,"channel"),msgid,width); + retstr = basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"srchash"),jbits256(valsobj,"desthash"),width); + printf("iterate_MSG.(%s)\n",retstr); + return(retstr); } #include "../includes/iguana_apidefs.h" diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index dadbe176c..01d82f41e 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -531,7 +531,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s } } addr->totalsent += len; - //if ( 0 && addr->basilisk != 0 ) + if ( 0 && addr->basilisk != 0 ) printf("verack.%d (%s) sent.%d bytes to %s\n",addr->msgcounts.verack,cmdstr,len,addr->ipaddr); return(len); } @@ -587,7 +587,7 @@ int32_t iguana_recv(char *ipaddr,int32_t usock,uint8_t *recvbuf,int32_t len) remains -= recvlen; //int32_t i; for (i=0; i Date: Wed, 21 Sep 2016 18:38:24 -0300 Subject: [PATCH 12/56] test --- basilisk/basilisk_MSG.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 1a85b5154..823100898 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -52,13 +52,9 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 printf(" <- ADDMSG.[%d] exp %u\n",QUEUEITEMS,msg->expiration); QUEUEITEMS++; if ( sendping != 0 ) - { queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0); - portable_mutex_unlock(&myinfo->messagemutex); - return(clonestr("{\"result\":\"message added to hashtable\"}")); - } portable_mutex_unlock(&myinfo->messagemutex); - return(0); + return(clonestr("{\"result\":\"message added to hashtable\"}")); } cJSON *basilisk_msgjson(struct basilisk_message *msg,uint8_t *key,int32_t keylen) @@ -121,12 +117,12 @@ char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,cha desthash = jbits256(valsobj,"desthash"); duration = juint(valsobj,"duration"); keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,desthash); - retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); if ( bits256_nonz(hash) == 0 ) { if ( duration > BASILISK_MSGDURATION ) duration = BASILISK_MSGDURATION; } + retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); // printf("OUT keylen.%d datalen.%d\n",keylen,datalen); char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); return(retstr); @@ -161,13 +157,13 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ width = 1; allflag = (bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); array = cJSON_CreateArray(); - portable_mutex_lock(&myinfo->messagemutex); + /*portable_mutex_lock(&myinfo->messagemutex); HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) jaddi(array,basilisk_msgjson(msg,msg->key,msg->keylen)); } - portable_mutex_unlock(&myinfo->messagemutex); + portable_mutex_unlock(&myinfo->messagemutex);*/ printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); for (i=0; i Date: Wed, 21 Sep 2016 18:54:19 -0300 Subject: [PATCH 13/56] test --- basilisk/basilisk.c | 5 +++-- basilisk/basilisk_MSG.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 15e12839f..a842d0932 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -795,10 +795,11 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t len += iguana_rwnum(0,data,sizeof(basilisktag),&basilisktag); //int32_t i; for (i=0; iNOTARY.RELAYID >= 0 ) + if ( myinfo->IAMLP == 0 ) printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,datalen,type,senderip!=0?senderip:"?",basilisktag); basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len); - printf("processed.%s from %s\n",type,senderip!=0?senderip:"?"); + if ( myinfo->IAMLP == 0 ) + printf("processed.%s from %s\n",type,senderip!=0?senderip:"?"); } if ( ptr != 0 ) free(ptr); diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 823100898..4d54c8648 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -149,7 +149,7 @@ int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t chan char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) { - struct basilisk_message *msg,*tmpmsg; uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; + uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; //struct basilisk_message *msg,*tmpmsg; memset(zero.bytes,0,sizeof(zero)); if ( (width= origwidth) > 3600 ) width = 3600; From 5fa9b71eea61fb189d432d18faaca7d8f7527955 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 19:14:51 -0300 Subject: [PATCH 14/56] test --- basilisk/basilisk.c | 8 ++++++-- basilisk/basilisk_MSG.c | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index a842d0932..92ce5ab39 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -169,7 +169,9 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ { printf("return after locally basilisk_msgprocess\n"); hash = GENESIS_PUBKEY; + portable_mutex_lock(&myinfo->messagemutex); basilisk_msgprocess(myinfo,0,0,type,*basilisktagp,data,datalen); + portable_mutex_unlock(&myinfo->messagemutex); return(0); } } @@ -795,10 +797,12 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t len += iguana_rwnum(0,data,sizeof(basilisktag),&basilisktag); //int32_t i; for (i=0; iIAMLP == 0 ) + if ( 0 && myinfo->IAMLP == 0 ) printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,datalen,type,senderip!=0?senderip:"?",basilisktag); + portable_mutex_lock(&myinfo->messagemutex); basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len); - if ( myinfo->IAMLP == 0 ) + portable_mutex_unlock(&myinfo->messagemutex); + if ( 0 && myinfo->IAMLP == 0 ) printf("processed.%s from %s\n",type,senderip!=0?senderip:"?"); } if ( ptr != 0 ) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 4d54c8648..886d23744 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -20,7 +20,7 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 struct basilisk_message *msg; int32_t i; bits256 desthash; if ( keylen != BASILISK_KEYSIZE ) return(0); - portable_mutex_lock(&myinfo->messagemutex); + //portable_mutex_lock(&myinfo->messagemutex); HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); if ( msg == 0 || msg->datalen != datalen ) { @@ -53,7 +53,7 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 QUEUEITEMS++; if ( sendping != 0 ) queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0); - portable_mutex_unlock(&myinfo->messagemutex); + //portable_mutex_unlock(&myinfo->messagemutex); return(clonestr("{\"result\":\"message added to hashtable\"}")); } @@ -80,11 +80,11 @@ cJSON *basilisk_msgjson(struct basilisk_message *msg,uint8_t *key,int32_t keylen cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) { cJSON *msgjson = 0; struct basilisk_message *msg; - portable_mutex_lock(&myinfo->messagemutex); + // portable_mutex_lock(&myinfo->messagemutex); HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); if ( msg != 0 && msg->broadcast == 0 ) msgjson = basilisk_msgjson(msg,key,keylen); - portable_mutex_unlock(&myinfo->messagemutex); + //portable_mutex_unlock(&myinfo->messagemutex); return(msgjson); } @@ -149,7 +149,7 @@ int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t chan char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) { - uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; //struct basilisk_message *msg,*tmpmsg; + uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg; memset(zero.bytes,0,sizeof(zero)); if ( (width= origwidth) > 3600 ) width = 3600; @@ -157,14 +157,14 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ width = 1; allflag = (bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); array = cJSON_CreateArray(); - /*portable_mutex_lock(&myinfo->messagemutex); + //portable_mutex_lock(&myinfo->messagemutex); HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) jaddi(array,basilisk_msgjson(msg,msg->key,msg->keylen)); } - portable_mutex_unlock(&myinfo->messagemutex);*/ - printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); + //portable_mutex_unlock(&myinfo->messagemutex); + //printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); for (i=0; i %s channel.%u msgid.%x width.%d\n",bits256_str(str,jbits256(valsobj,"sender")),bits256_str(str2,jbits256(valsobj,"desthash")),juint(valsobj,"channel"),msgid,width); + //char str[65],str2[65]; printf("%s -> %s channel.%u msgid.%x width.%d\n",bits256_str(str,jbits256(valsobj,"sender")),bits256_str(str2,jbits256(valsobj,"desthash")),juint(valsobj,"channel"),msgid,width); retstr = basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"srchash"),jbits256(valsobj,"desthash"),width); - printf("iterate_MSG.(%s)\n",retstr); + //printf("iterate_MSG.(%s)\n",retstr); return(retstr); } @@ -285,7 +285,7 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 srchash,bits25 jaddnum(valsobj,"duration",duration); jaddbits256(valsobj,"srchash",srchash); jaddbits256(valsobj,"desthash",desthash); - char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d:%d\n",datalen,channel,msgid,bits256_str(str,desthash),myinfo->NOTARY.NUMRELAYS,juint(valsobj,"fanout")); + //char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d:%d\n",datalen,channel,msgid,bits256_str(str,desthash),myinfo->NOTARY.NUMRELAYS,juint(valsobj,"fanout")); if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,desthash,valsobj,hexstr)) != 0 ) free(retstr); free_json(valsobj); From 6db01da396647aa09134d14d33f6cf9aad404e44 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 19:26:35 -0300 Subject: [PATCH 15/56] test --- iguana/iguana_peers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index 01d82f41e..732f82ccf 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -531,7 +531,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s } } addr->totalsent += len; - if ( 0 && addr->basilisk != 0 ) + //if ( 0 && addr->basilisk != 0 ) printf("verack.%d (%s) sent.%d bytes to %s\n",addr->msgcounts.verack,cmdstr,len,addr->ipaddr); return(len); } @@ -587,7 +587,7 @@ int32_t iguana_recv(char *ipaddr,int32_t usock,uint8_t *recvbuf,int32_t len) remains -= recvlen; //int32_t i; for (i=0; i Date: Wed, 21 Sep 2016 19:36:28 -0300 Subject: [PATCH 16/56] test --- basilisk/basilisk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 92ce5ab39..9e5649200 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -789,7 +789,9 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t { if ( strcmp(type,"PIN") == 0 && myinfo->NOTARY.RELAYID >= 0 ) { + portable_mutex_lock(&myinfo->messagemutex); basilisk_ping_process(myinfo,_addr,ipbits,data,datalen); + portable_mutex_unlock(&myinfo->messagemutex); } } else @@ -885,7 +887,9 @@ void basilisks_loop(void *arg) } } //portable_mutex_unlock(&myinfo->allcoins_mutex); + portable_mutex_lock(&myinfo->messagemutex); basilisk_ping_send(myinfo,notary); + portable_mutex_unlock(&myinfo->messagemutex); } } // else printf("not notary %p %d\n",notary,myinfo->NOTARY.RELAYID); else if ( myinfo->expiration != 0 ) From 2dd262f68bef0ffb354ae6b077f5ac928b605ef3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 19:46:21 -0300 Subject: [PATCH 17/56] test --- basilisk/basilisk.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 9e5649200..8590a113d 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -801,9 +801,12 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t // printf("%02x",data[len+i]); if ( 0 && myinfo->IAMLP == 0 ) printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,datalen,type,senderip!=0?senderip:"?",basilisktag); - portable_mutex_lock(&myinfo->messagemutex); - basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len); - portable_mutex_unlock(&myinfo->messagemutex); + if ( strcmp(type,"MSG") != 0 && strcmp(type,"OUT") != 0 ) + { + portable_mutex_lock(&myinfo->messagemutex); + basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len); + portable_mutex_unlock(&myinfo->messagemutex); + } if ( 0 && myinfo->IAMLP == 0 ) printf("processed.%s from %s\n",type,senderip!=0?senderip:"?"); } From ab12c86e72eeba857acb919d7b3707b2c1872055 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 19:53:25 -0300 Subject: [PATCH 18/56] test --- basilisk/basilisk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 8590a113d..6febf4eb7 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -801,7 +801,7 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t // printf("%02x",data[len+i]); if ( 0 && myinfo->IAMLP == 0 ) printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,datalen,type,senderip!=0?senderip:"?",basilisktag); - if ( strcmp(type,"MSG") != 0 && strcmp(type,"OUT") != 0 ) + if ( strcmp(type,"MSG") != 0 )//&& strcmp(type,"OUT") != 0 ) { portable_mutex_lock(&myinfo->messagemutex); basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len); From bc8d8fbf005cb2c27b1e59b2e9543fa767b6cfb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 19:55:09 -0300 Subject: [PATCH 19/56] test --- iguana/iguana_peers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index 732f82ccf..01d82f41e 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -531,7 +531,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s } } addr->totalsent += len; - //if ( 0 && addr->basilisk != 0 ) + if ( 0 && addr->basilisk != 0 ) printf("verack.%d (%s) sent.%d bytes to %s\n",addr->msgcounts.verack,cmdstr,len,addr->ipaddr); return(len); } @@ -587,7 +587,7 @@ int32_t iguana_recv(char *ipaddr,int32_t usock,uint8_t *recvbuf,int32_t len) remains -= recvlen; //int32_t i; for (i=0; i Date: Thu, 22 Sep 2016 04:44:43 -0300 Subject: [PATCH 20/56] serialize OUT/MSG --- basilisk/basilisk.c | 195 +++++++++++++++++++++----------------- basilisk/basilisk.h | 2 +- basilisk/basilisk_MSG.c | 43 +++++---- basilisk/basilisk_ping.c | 8 +- iguana/iguana777.h | 2 +- iguana/iguana_msg.c | 2 +- includes/iguana_structs.h | 8 ++ 7 files changed, 150 insertions(+), 110 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 6febf4eb7..3383a81e9 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -769,9 +769,48 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende myinfo->basilisk_busy = 0; } -void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t datalen,char *type,int32_t encrypted) +int32_t basilisk_p2pQ_process(struct supernet_info *myinfo,int32_t maxiters) { - uint32_t ipbits,basilisktag; int32_t msglen,len=0; void *ptr = 0; uint8_t space[4096]; bits256 senderpub; struct supernet_info *myinfo = _myinfo; + struct basilisk_p2pitem *ptr; char senderip[64]; uint32_t n=0,basilisktag,len = 0; + while ( n < maxiters && (ptr= queue_dequeue(&myinfo->p2pQ,0)) != 0 ) + { + expand_ipbits(senderip,ptr->ipbits); + if ( ptr->type[0] == 'P' && ptr->type[1] == 'I' && ptr->type[2] == 'N' ) + { + if ( strcmp(ptr->type,"PIN") == 0 && myinfo->NOTARY.RELAYID >= 0 ) + basilisk_ping_process(myinfo,ptr->addr,ptr->ipbits,ptr->data,ptr->datalen); + } + else + { + len += iguana_rwnum(0,ptr->data,sizeof(basilisktag),&basilisktag); + if ( 0 && myinfo->IAMLP == 0 ) + printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,ptr->datalen,ptr->type,senderip!=0?senderip:"?",basilisktag); + basilisk_msgprocess(myinfo,ptr->addr,ptr->ipbits,ptr->type,basilisktag,&ptr->data[len],ptr->datalen - len); + if ( 0 && myinfo->IAMLP == 0 ) + printf("processed.%s from %s\n",ptr->type,senderip!=0?senderip:"?"); + } + free(ptr); + n++; + } + return(n); +} + +struct basilisk_p2pitem *basilisk_p2pitem_create(void *_coin,void *_addr,char *type,uint32_t ipbits,uint8_t *data,int32_t datalen) +{ + struct basilisk_p2pitem *ptr; + ptr = calloc(1,sizeof(*ptr) + datalen); + ptr->coin = _coin; + ptr->addr = _addr; + ptr->ipbits = ipbits; + safecopy(ptr->type,type,sizeof(ptr->type)); + memcpy(ptr->data,data,datalen); + return(ptr); +} + +void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *senderip,uint8_t *data,int32_t datalen,char *type,int32_t encrypted) +{ + uint32_t ipbits; int32_t msglen; void *ptr = 0; uint8_t space[4096]; bits256 senderpub; + ipbits = (uint32_t)calc_ipbits(senderip); if ( encrypted != 0 ) { printf("encrypted p2p\n"); @@ -781,37 +820,14 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t printf("basilisk_p2p decrytion error\n"); return; } else datalen = msglen; + if ( ptr != 0 ) + free(ptr); } if ( senderip != 0 && senderip[0] != 0 && strcmp(senderip,"127.0.0.1") != 0 ) ipbits = (uint32_t)calc_ipbits(senderip); else ipbits = myinfo->myaddr.myipbits; - if ( type[0] == 'P' && type[1] == 'I' && type[2] == 'N' ) - { - if ( strcmp(type,"PIN") == 0 && myinfo->NOTARY.RELAYID >= 0 ) - { - portable_mutex_lock(&myinfo->messagemutex); - basilisk_ping_process(myinfo,_addr,ipbits,data,datalen); - portable_mutex_unlock(&myinfo->messagemutex); - } - } - else - { - len += iguana_rwnum(0,data,sizeof(basilisktag),&basilisktag); - //int32_t i; for (i=0; iIAMLP == 0 ) - printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,datalen,type,senderip!=0?senderip:"?",basilisktag); - if ( strcmp(type,"MSG") != 0 )//&& strcmp(type,"OUT") != 0 ) - { - portable_mutex_lock(&myinfo->messagemutex); - basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len); - portable_mutex_unlock(&myinfo->messagemutex); - } - if ( 0 && myinfo->IAMLP == 0 ) - printf("processed.%s from %s\n",type,senderip!=0?senderip:"?"); - } - if ( ptr != 0 ) - free(ptr); + ptr = basilisk_p2pitem_create(coin,addr,type,ipbits,data,datalen); + queue_enqueue("p2pQ",&myinfo->p2pQ,ptr,0); } void basilisk_requests_poll(struct supernet_info *myinfo) @@ -856,75 +872,78 @@ void basilisk_requests_poll(struct supernet_info *myinfo) } } -void basilisks_loop(void *arg) +int32_t basilisk_issued_purge(struct supernet_info *myinfo,int32_t timepad) { - struct iguana_info *virt,*tmpcoin,*notary; struct basilisk_message *msg,*tmpmsg; struct basilisk_item *tmp,*pending; uint32_t now; int32_t iter,maxmillis,flag=0; struct supernet_info *myinfo = arg; - iter = 0; - while ( 1 ) + struct basilisk_item *tmp,*pending; int32_t n = 0; double startmilli = OS_milliseconds(); + portable_mutex_lock(&myinfo->basilisk_mutex); + HASH_ITER(hh,myinfo->basilisks.issued,pending,tmp) { - portable_mutex_lock(&myinfo->basilisk_mutex); - HASH_ITER(hh,myinfo->basilisks.issued,pending,tmp) + if ( pending != 0 && (pending->finished != 0 || startmilli > pending->expiration+timepad) ) { - if ( pending != 0 && (pending->finished != 0 || OS_milliseconds() > pending->expiration+600000) ) - { - //printf("enable free for HASH_DELETE.(%p)\n",pending); - HASH_DELETE(hh,myinfo->basilisks.issued,pending); - memset(pending,0,sizeof(*pending)); - free(pending); - } + HASH_DELETE(hh,myinfo->basilisks.issued,pending); + memset(pending,0,sizeof(*pending)); + free(pending); + n++; } - notary = iguana_coinfind("NOTARY"); - now = (uint32_t)time(NULL); - portable_mutex_unlock(&myinfo->basilisk_mutex); - if ( myinfo->NOTARY.RELAYID >= 0 ) - { - if ( notary != 0 ) - { - maxmillis = (1000 / (myinfo->allcoins_numvirts + 1)) + 1; - //portable_mutex_lock(&myinfo->allcoins_mutex); - HASH_ITER(hh,myinfo->allcoins,virt,tmpcoin) - { - if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 ) - { - gecko_iteration(myinfo,notary,virt,maxmillis), flag++; - } - } - //portable_mutex_unlock(&myinfo->allcoins_mutex); - portable_mutex_lock(&myinfo->messagemutex); - basilisk_ping_send(myinfo,notary); - portable_mutex_unlock(&myinfo->messagemutex); - } - } // else printf("not notary %p %d\n",notary,myinfo->NOTARY.RELAYID); - else if ( myinfo->expiration != 0 ) + } + portable_mutex_unlock(&myinfo->basilisk_mutex); + return(n); +} + +void basilisk_iteration(struct supernet_info *myinfo) +{ + struct iguana_info *virt,*tmpcoin,*notary; struct basilisk_message *msg,*tmpmsg; uint32_t now; int32_t maxmillis,flag=0; + now = (uint32_t)time(NULL); + notary = iguana_coinfind("NOTARY"); + portable_mutex_lock(&myinfo->messagemutex); + HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) + { + if ( now > msg->expiration ) { - /*HASH_ITER(hh,myinfo->allcoins,coin,tmpcoin) - { - if ( strcmp(coin->symbol,"NOTARY") != 0 && (myinfo->Cunspents == 0 || time(NULL) > coin->lastunspentsupdate+60) ) - { - //printf(">>>>>>>>>>>>> update %s\n",coin->symbol); - basilisk_unspents_update(myinfo,coin); - coin->lastunspentsupdate = now; - //printf(">>>>>>>>>>>>> update %s finished\n",coin->symbol); - } - }*/ - if ( myinfo->IAMLP != 0 || myinfo->DEXactive > now ) - basilisk_requests_poll(myinfo); + printf("delete expired message.%p QUEUEITEMS.%d\n",msg,QUEUEITEMS); + HASH_DELETE(hh,myinfo->messagetable,msg); + QUEUEITEMS--; + free(msg); } - portable_mutex_lock(&myinfo->messagemutex); - HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) + if ( myinfo->NOTARY.RELAYID >= 0 ) + basilisk_ping_send(myinfo,notary); + } + portable_mutex_unlock(&myinfo->messagemutex); + if ( myinfo->NOTARY.RELAYID >= 0 ) + { + if ( notary != 0 ) { - if ( now > msg->expiration ) + maxmillis = (1000 / (myinfo->allcoins_numvirts + 1)) + 1; + HASH_ITER(hh,myinfo->allcoins,virt,tmpcoin) { - printf("delete expired message.%p QUEUEITEMS.%d\n",msg,QUEUEITEMS); - HASH_DELETE(hh,myinfo->messagetable,msg); - QUEUEITEMS--; - free(msg); - } //else printf("remains.%d\n",msg->expiration - now); + if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 ) + gecko_iteration(myinfo,notary,virt,maxmillis), flag++; + } } - portable_mutex_unlock(&myinfo->messagemutex); + } + else if ( myinfo->expiration != 0 ) + { + if ( myinfo->IAMLP != 0 || myinfo->DEXactive > now ) + basilisk_requests_poll(myinfo); + } +} + +void basilisks_loop(void *arg) +{ + struct supernet_info *myinfo = arg; int32_t iter; double startmilli,endmilli; + iter = 0; + while ( 1 ) + { + startmilli = OS_milliseconds(); + basilisk_issued_purge(myinfo,600000); + basilisk_iteration(myinfo); + basilisk_p2pQ_process(myinfo,777); if ( myinfo->NOTARY.RELAYID >= 0 ) - usleep(500000); - else usleep(3000000); + endmilli = startmilli + 500; + else endmilli = startmilli + 2500; + while ( OS_milliseconds() < endmilli ) + usleep(10000); + iter++; } } diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index 2f3183160..aba91c9fb 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -102,7 +102,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *type,uint32_t *basilisktagp,int32_t encryptflag,int32_t delaymillis,uint8_t *data,int32_t datalen,int32_t fanout,uint32_t nBits); // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag) void basilisks_init(struct supernet_info *myinfo); -void basilisk_p2p(void *myinfo,void *_addr,char *ipaddr,uint8_t *data,int32_t datalen,char *type,int32_t encrypted); +void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *senderip,uint8_t *data,int32_t datalen,char *type,int32_t encrypted); uint8_t *basilisk_jsondata(int32_t extraoffset,uint8_t **ptrp,uint8_t *space,int32_t spacesize,int32_t *datalenp,char *symbol,cJSON *sendjson,uint32_t basilisktag); uint8_t *SuperNET_ciphercalc(void **ptrp,int32_t *cipherlenp,bits256 *privkeyp,bits256 *destpubkeyp,uint8_t *data,int32_t datalen,uint8_t *space2,int32_t space2size); diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 886d23744..07b6b37a5 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -15,7 +15,7 @@ // included from basilisk.c -char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration) +char *_basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration) { struct basilisk_message *msg; int32_t i; bits256 desthash; if ( keylen != BASILISK_KEYSIZE ) @@ -77,7 +77,7 @@ cJSON *basilisk_msgjson(struct basilisk_message *msg,uint8_t *key,int32_t keylen return(msgjson); } -cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) +cJSON *_basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) { cJSON *msgjson = 0; struct basilisk_message *msg; // portable_mutex_lock(&myinfo->messagemutex); @@ -122,7 +122,9 @@ char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,cha if ( duration > BASILISK_MSGDURATION ) duration = BASILISK_MSGDURATION; } - retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); + portable_mutex_lock(&myinfo->messagemutex); + retstr = _basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); + portable_mutex_unlock(&myinfo->messagemutex); // printf("OUT keylen.%d datalen.%d\n",keylen,datalen); char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); return(retstr); @@ -147,7 +149,7 @@ int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t chan } else return(-3); } -char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) +char *_basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) { uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg; memset(zero.bytes,0,sizeof(zero)); @@ -170,35 +172,35 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ if ( allflag != 0 ) break; keylen = basilisk_messagekey(key,channel,msgid,srchash,desthash); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg0.(%s)\n",jprint(item,0)); keylen = basilisk_messagekey(key,channel,msgid,desthash,srchash); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg0.(%s)\n",jprint(item,0)); if ( origwidth > 0 ) { if ( bits256_nonz(srchash) != 0 ) { keylen = basilisk_messagekey(key,channel,msgid,zero,desthash); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0)); keylen = basilisk_messagekey(key,channel,msgid,desthash,zero); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0)); } if ( bits256_nonz(desthash) != 0 ) { keylen = basilisk_messagekey(key,channel,msgid,srchash,zero); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); keylen = basilisk_messagekey(key,channel,msgid,zero,srchash); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); } if ( bits256_nonz(srchash) != 0 && bits256_nonz(desthash) != 0 ) { keylen = basilisk_messagekey(key,channel,msgid,zero,zero); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg3.(%s)\n",jprint(item,0)); } } @@ -221,7 +223,9 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha msgid = juint(valsobj,"msgid"); channel = juint(valsobj,"channel"); //char str[65],str2[65]; printf("%s -> %s channel.%u msgid.%x width.%d\n",bits256_str(str,jbits256(valsobj,"sender")),bits256_str(str2,jbits256(valsobj,"desthash")),juint(valsobj,"channel"),msgid,width); - retstr = basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"srchash"),jbits256(valsobj,"desthash"),width); + portable_mutex_lock(&myinfo->messagemutex); + retstr = _basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"srchash"),jbits256(valsobj,"desthash"),width); + portable_mutex_unlock(&myinfo->messagemutex); //printf("iterate_MSG.(%s)\n",retstr); return(retstr); } @@ -231,7 +235,7 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) { - uint32_t msgid,width,channel; + uint32_t msgid,width,channel; char *retstr; if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"srchash")) == 0 ) jaddbits256(vals,"srchash",hash); if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"desthash")) == 0 ) @@ -246,7 +250,10 @@ HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) { channel = juint(vals,"channel"); width = juint(vals,"width"); - return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(vals,"srchash"),jbits256(vals,"desthash"),width)); + portable_mutex_lock(&myinfo->messagemutex); + retstr = _basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(vals,"srchash"),jbits256(vals,"desthash"),width); + portable_mutex_unlock(&myinfo->messagemutex); + return(retstr); } else return(basilisk_standardservice("MSG",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,1)); } @@ -258,7 +265,9 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"srchash"),jbits256(vals,"desthash")); if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 ) { - retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration")); + portable_mutex_lock(&myinfo->messagemutex); + retstr = _basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration")); + portable_mutex_unlock(&myinfo->messagemutex); } if ( ptr != 0 ) free(ptr); @@ -365,12 +374,14 @@ int32_t basilisk_process_retarray(struct supernet_info *myinfo,void *ptr,int32_t { duration = juint(item,"duration"); expiration = juint(item,"expiration"); - if ( (retstr= basilisk_respond_addmessage(myinfo,key,BASILISK_KEYSIZE,data,datalen,0,duration)) != 0 ) + portable_mutex_lock(&myinfo->messagemutex); + if ( (retstr= _basilisk_respond_addmessage(myinfo,key,BASILISK_KEYSIZE,data,datalen,0,duration)) != 0 ) { if ( (*process_func)(myinfo,ptr,internal_func,channel,msgid,data,datalen,expiration,duration) < 0 ) errs++; free(retstr); } // else printf("duplicate.%d skipped\n",datalen); + portable_mutex_unlock(&myinfo->messagemutex); } } //printf("n.%d maxlen.%d\n",n,maxlen); diff --git a/basilisk/basilisk_ping.c b/basilisk/basilisk_ping.c index 191cf36fe..f10c5165e 100755 --- a/basilisk/basilisk_ping.c +++ b/basilisk/basilisk_ping.c @@ -105,7 +105,7 @@ int32_t basilisk_ping_genvirts(struct supernet_info *myinfo,uint8_t *data,int32_ } #endif -int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipbits,uint8_t *data,int32_t datalen) +int32_t _basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipbits,uint8_t *data,int32_t datalen) { int32_t i,msglen,len=0; uint8_t num,keylen,*message,*key; uint32_t duration; if ( (num= data[len++]) > 0 ) @@ -134,7 +134,7 @@ int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipb return(0); } //printf("i.%d: keylen.%d msglen.%d\n",i,keylen,msglen); - basilisk_respond_addmessage(myinfo,key,keylen,message,msglen,0,duration); + _basilisk_respond_addmessage(myinfo,key,keylen,message,msglen,0,duration); } } return(len); @@ -243,7 +243,9 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr if ( len <= datalen-sizeof(sn) ) { //len += basilisk_ping_processDEX(myinfo,senderipbits,&data[len],datalen-len); - len += basilisk_ping_processMSG(myinfo,senderipbits,&data[len],datalen-len); + portable_mutex_lock(&myinfo->messagemutex); + len += _basilisk_ping_processMSG(myinfo,senderipbits,&data[len],datalen-len); + portable_mutex_unlock(&myinfo->messagemutex); } //printf("PING got %d, processed.%d from (%s)\n",datalen,len,ipbuf); //else printf("\n"); diff --git a/iguana/iguana777.h b/iguana/iguana777.h index ee45bc7d1..dd8d3bd95 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -86,7 +86,7 @@ struct supernet_info portable_mutex_t bu_mutex,allcoins_mutex,gecko_mutex,basilisk_mutex,DEX_mutex,DEX_reqmutex,DEX_swapmutex; struct queueitem *DEX_quotes; cJSON *Cunspents,*Cspends; struct basilisk_swap *swaps[256]; int32_t numswaps; - struct basilisk_message *messagetable; portable_mutex_t messagemutex; queue_t msgQ; + struct basilisk_message *messagetable; portable_mutex_t messagemutex; queue_t msgQ,p2pQ; void *ctx; uint8_t *pingbuf; struct delayedPoW_info dPoW; diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index 81be7eb1c..536343946 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -940,7 +940,7 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s } else ipaddr = 0; len = recvlen; //printf("GOT.(%s) len.%d from %s\n",H->command,recvlen,addr->ipaddr); - basilisk_p2p(myinfo,addr,ipaddr,data,recvlen,&H->command[strlen("SuperNET")],H->command[6] == 'e' && H->command[7] == 't'); + basilisk_p2p(myinfo,coin,addr,ipaddr,data,recvlen,&H->command[strlen("SuperNET")],H->command[6] == 'e' && H->command[7] == 't'); return(0); } if ( addr != 0 ) diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index f1550d962..39d5016ad 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -545,6 +545,14 @@ struct _gfshare_ctx uint8_t sharenrs[255],buffer[]; }; +struct basilisk_p2pitem +{ + struct queueitem DL; + struct iguana_info *coin; struct iguana_peer *addr; + uint32_t ipbits,datalen; char type[4]; + uint8_t data[]; +}; + struct basilisk_request { uint32_t requestid,timestamp,quoteid,quotetime; // 0 to 15 From 5ce4a7c683a12156882a398fe2c93d0824842c0d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 04:55:16 -0300 Subject: [PATCH 21/56] test --- basilisk/basilisk.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 3383a81e9..2dd7bc7d5 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -771,9 +771,10 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende int32_t basilisk_p2pQ_process(struct supernet_info *myinfo,int32_t maxiters) { - struct basilisk_p2pitem *ptr; char senderip[64]; uint32_t n=0,basilisktag,len = 0; + struct basilisk_p2pitem *ptr; char senderip[64]; uint32_t n=0,basilisktag,len; while ( n < maxiters && (ptr= queue_dequeue(&myinfo->p2pQ,0)) != 0 ) { + len = 0; expand_ipbits(senderip,ptr->ipbits); if ( ptr->type[0] == 'P' && ptr->type[1] == 'I' && ptr->type[2] == 'N' ) { @@ -795,12 +796,12 @@ int32_t basilisk_p2pQ_process(struct supernet_info *myinfo,int32_t maxiters) return(n); } -struct basilisk_p2pitem *basilisk_p2pitem_create(void *_coin,void *_addr,char *type,uint32_t ipbits,uint8_t *data,int32_t datalen) +struct basilisk_p2pitem *basilisk_p2pitem_create(struct iguana_info *coin,struct iguana_peer *addr,char *type,uint32_t ipbits,uint8_t *data,int32_t datalen) { struct basilisk_p2pitem *ptr; ptr = calloc(1,sizeof(*ptr) + datalen); - ptr->coin = _coin; - ptr->addr = _addr; + ptr->coin = coin; + ptr->addr = addr; ptr->ipbits = ipbits; safecopy(ptr->type,type,sizeof(ptr->type)); memcpy(ptr->data,data,datalen); From 754b550db45ad591880dde0824fb73d9087cd013 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 05:17:42 -0300 Subject: [PATCH 22/56] test --- basilisk/basilisk.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 2dd7bc7d5..096b72022 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -778,15 +778,21 @@ int32_t basilisk_p2pQ_process(struct supernet_info *myinfo,int32_t maxiters) expand_ipbits(senderip,ptr->ipbits); if ( ptr->type[0] == 'P' && ptr->type[1] == 'I' && ptr->type[2] == 'N' ) { - if ( strcmp(ptr->type,"PIN") == 0 && myinfo->NOTARY.RELAYID >= 0 ) + if ( myinfo->NOTARY.RELAYID >= 0 ) + { + fprintf(stderr,"P"); basilisk_ping_process(myinfo,ptr->addr,ptr->ipbits,ptr->data,ptr->datalen); + fprintf(stderr,"p"); + } } else { len += iguana_rwnum(0,ptr->data,sizeof(basilisktag),&basilisktag); if ( 0 && myinfo->IAMLP == 0 ) printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,ptr->datalen,ptr->type,senderip!=0?senderip:"?",basilisktag); + fprintf(stderr,"%s ",ptr->type); basilisk_msgprocess(myinfo,ptr->addr,ptr->ipbits,ptr->type,basilisktag,&ptr->data[len],ptr->datalen - len); + fprintf(stderr,"%s n.%d\n",ptr->type,n); if ( 0 && myinfo->IAMLP == 0 ) printf("processed.%s from %s\n",ptr->type,senderip!=0?senderip:"?"); } @@ -811,6 +817,7 @@ struct basilisk_p2pitem *basilisk_p2pitem_create(struct iguana_info *coin,struct void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *senderip,uint8_t *data,int32_t datalen,char *type,int32_t encrypted) { uint32_t ipbits; int32_t msglen; void *ptr = 0; uint8_t space[4096]; bits256 senderpub; + fprintf(stderr,"P2P "); ipbits = (uint32_t)calc_ipbits(senderip); if ( encrypted != 0 ) { @@ -829,6 +836,7 @@ void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct i else ipbits = myinfo->myaddr.myipbits; ptr = basilisk_p2pitem_create(coin,addr,type,ipbits,data,datalen); queue_enqueue("p2pQ",&myinfo->p2pQ,ptr,0); + fprintf(stderr,"p2p\n"); } void basilisk_requests_poll(struct supernet_info *myinfo) @@ -936,9 +944,13 @@ void basilisks_loop(void *arg) while ( 1 ) { startmilli = OS_milliseconds(); + fprintf(stderr,"G"); basilisk_issued_purge(myinfo,600000); + fprintf(stderr,"I"); basilisk_iteration(myinfo); + fprintf(stderr,"2"); basilisk_p2pQ_process(myinfo,777); + fprintf(stderr,"\n"); if ( myinfo->NOTARY.RELAYID >= 0 ) endmilli = startmilli + 500; else endmilli = startmilli + 2500; From 7ccc254a2c19f537ea57fec59946532bea034352 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 05:29:42 -0300 Subject: [PATCH 23/56] test --- basilisk/basilisk.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 096b72022..5887fb1ea 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -169,9 +169,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ { printf("return after locally basilisk_msgprocess\n"); hash = GENESIS_PUBKEY; - portable_mutex_lock(&myinfo->messagemutex); basilisk_msgprocess(myinfo,0,0,type,*basilisktagp,data,datalen); - portable_mutex_unlock(&myinfo->messagemutex); return(0); } } From 7fcbb827429f27b25cd1b13caa8e089ea118a201 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 05:48:03 -0300 Subject: [PATCH 24/56] test --- basilisk/basilisk_MSG.c | 57 +++++++++++++++++----------------------- basilisk/basilisk_ping.c | 8 +++--- 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 07b6b37a5..c09a2431e 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -15,12 +15,12 @@ // included from basilisk.c -char *_basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration) +char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration) { struct basilisk_message *msg; int32_t i; bits256 desthash; if ( keylen != BASILISK_KEYSIZE ) return(0); - //portable_mutex_lock(&myinfo->messagemutex); + portable_mutex_lock(&myinfo->messagemutex); HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); if ( msg == 0 || msg->datalen != datalen ) { @@ -53,7 +53,7 @@ char *_basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int QUEUEITEMS++; if ( sendping != 0 ) queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0); - //portable_mutex_unlock(&myinfo->messagemutex); + portable_mutex_unlock(&myinfo->messagemutex); return(clonestr("{\"result\":\"message added to hashtable\"}")); } @@ -77,14 +77,14 @@ cJSON *basilisk_msgjson(struct basilisk_message *msg,uint8_t *key,int32_t keylen return(msgjson); } -cJSON *_basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) +cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) { cJSON *msgjson = 0; struct basilisk_message *msg; - // portable_mutex_lock(&myinfo->messagemutex); + portable_mutex_lock(&myinfo->messagemutex); HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); if ( msg != 0 && msg->broadcast == 0 ) msgjson = basilisk_msgjson(msg,key,keylen); - //portable_mutex_unlock(&myinfo->messagemutex); + portable_mutex_unlock(&myinfo->messagemutex); return(msgjson); } @@ -122,9 +122,7 @@ char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,cha if ( duration > BASILISK_MSGDURATION ) duration = BASILISK_MSGDURATION; } - portable_mutex_lock(&myinfo->messagemutex); - retstr = _basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); - portable_mutex_unlock(&myinfo->messagemutex); + retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); // printf("OUT keylen.%d datalen.%d\n",keylen,datalen); char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); return(retstr); @@ -149,9 +147,9 @@ int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t chan } else return(-3); } -char *_basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) +char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) { - uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg; + uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *msgjson,*item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg; memset(zero.bytes,0,sizeof(zero)); if ( (width= origwidth) > 3600 ) width = 3600; @@ -159,48 +157,49 @@ char *_basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32 width = 1; allflag = (bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); array = cJSON_CreateArray(); - //portable_mutex_lock(&myinfo->messagemutex); + portable_mutex_lock(&myinfo->messagemutex); HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) - jaddi(array,basilisk_msgjson(msg,msg->key,msg->keylen)); + if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) + jaddi(array,msgjson); } - //portable_mutex_unlock(&myinfo->messagemutex); + portable_mutex_unlock(&myinfo->messagemutex); //printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); for (i=0; i 0 ) { if ( bits256_nonz(srchash) != 0 ) { keylen = basilisk_messagekey(key,channel,msgid,zero,desthash); - if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0)); keylen = basilisk_messagekey(key,channel,msgid,desthash,zero); - if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0)); } if ( bits256_nonz(desthash) != 0 ) { keylen = basilisk_messagekey(key,channel,msgid,srchash,zero); - if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); keylen = basilisk_messagekey(key,channel,msgid,zero,srchash); - if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); } if ( bits256_nonz(srchash) != 0 && bits256_nonz(desthash) != 0 ) { keylen = basilisk_messagekey(key,channel,msgid,zero,zero); - if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg3.(%s)\n",jprint(item,0)); } } @@ -223,9 +222,7 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha msgid = juint(valsobj,"msgid"); channel = juint(valsobj,"channel"); //char str[65],str2[65]; printf("%s -> %s channel.%u msgid.%x width.%d\n",bits256_str(str,jbits256(valsobj,"sender")),bits256_str(str2,jbits256(valsobj,"desthash")),juint(valsobj,"channel"),msgid,width); - portable_mutex_lock(&myinfo->messagemutex); - retstr = _basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"srchash"),jbits256(valsobj,"desthash"),width); - portable_mutex_unlock(&myinfo->messagemutex); + retstr = basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"srchash"),jbits256(valsobj,"desthash"),width); //printf("iterate_MSG.(%s)\n",retstr); return(retstr); } @@ -250,9 +247,7 @@ HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) { channel = juint(vals,"channel"); width = juint(vals,"width"); - portable_mutex_lock(&myinfo->messagemutex); - retstr = _basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(vals,"srchash"),jbits256(vals,"desthash"),width); - portable_mutex_unlock(&myinfo->messagemutex); + retstr = basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(vals,"srchash"),jbits256(vals,"desthash"),width); return(retstr); } else return(basilisk_standardservice("MSG",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,1)); } @@ -265,9 +260,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"srchash"),jbits256(vals,"desthash")); if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 ) { - portable_mutex_lock(&myinfo->messagemutex); - retstr = _basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration")); - portable_mutex_unlock(&myinfo->messagemutex); + retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration")); } if ( ptr != 0 ) free(ptr); @@ -374,14 +367,12 @@ int32_t basilisk_process_retarray(struct supernet_info *myinfo,void *ptr,int32_t { duration = juint(item,"duration"); expiration = juint(item,"expiration"); - portable_mutex_lock(&myinfo->messagemutex); - if ( (retstr= _basilisk_respond_addmessage(myinfo,key,BASILISK_KEYSIZE,data,datalen,0,duration)) != 0 ) + if ( (retstr= basilisk_respond_addmessage(myinfo,key,BASILISK_KEYSIZE,data,datalen,0,duration)) != 0 ) { if ( (*process_func)(myinfo,ptr,internal_func,channel,msgid,data,datalen,expiration,duration) < 0 ) errs++; free(retstr); } // else printf("duplicate.%d skipped\n",datalen); - portable_mutex_unlock(&myinfo->messagemutex); } } //printf("n.%d maxlen.%d\n",n,maxlen); diff --git a/basilisk/basilisk_ping.c b/basilisk/basilisk_ping.c index f10c5165e..191cf36fe 100755 --- a/basilisk/basilisk_ping.c +++ b/basilisk/basilisk_ping.c @@ -105,7 +105,7 @@ int32_t basilisk_ping_genvirts(struct supernet_info *myinfo,uint8_t *data,int32_ } #endif -int32_t _basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipbits,uint8_t *data,int32_t datalen) +int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipbits,uint8_t *data,int32_t datalen) { int32_t i,msglen,len=0; uint8_t num,keylen,*message,*key; uint32_t duration; if ( (num= data[len++]) > 0 ) @@ -134,7 +134,7 @@ int32_t _basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderip return(0); } //printf("i.%d: keylen.%d msglen.%d\n",i,keylen,msglen); - _basilisk_respond_addmessage(myinfo,key,keylen,message,msglen,0,duration); + basilisk_respond_addmessage(myinfo,key,keylen,message,msglen,0,duration); } } return(len); @@ -243,9 +243,7 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr if ( len <= datalen-sizeof(sn) ) { //len += basilisk_ping_processDEX(myinfo,senderipbits,&data[len],datalen-len); - portable_mutex_lock(&myinfo->messagemutex); - len += _basilisk_ping_processMSG(myinfo,senderipbits,&data[len],datalen-len); - portable_mutex_unlock(&myinfo->messagemutex); + len += basilisk_ping_processMSG(myinfo,senderipbits,&data[len],datalen-len); } //printf("PING got %d, processed.%d from (%s)\n",datalen,len,ipbuf); //else printf("\n"); From 34c8b3060faefad52b76665fe95ea59ecef599b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 05:57:58 -0300 Subject: [PATCH 25/56] test --- basilisk/basilisk.c | 6 ++---- basilisk/basilisk_ping.c | 14 +++++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 5887fb1ea..085318fdf 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -815,7 +815,6 @@ struct basilisk_p2pitem *basilisk_p2pitem_create(struct iguana_info *coin,struct void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *senderip,uint8_t *data,int32_t datalen,char *type,int32_t encrypted) { uint32_t ipbits; int32_t msglen; void *ptr = 0; uint8_t space[4096]; bits256 senderpub; - fprintf(stderr,"P2P "); ipbits = (uint32_t)calc_ipbits(senderip); if ( encrypted != 0 ) { @@ -834,7 +833,6 @@ void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct i else ipbits = myinfo->myaddr.myipbits; ptr = basilisk_p2pitem_create(coin,addr,type,ipbits,data,datalen); queue_enqueue("p2pQ",&myinfo->p2pQ,ptr,0); - fprintf(stderr,"p2p\n"); } void basilisk_requests_poll(struct supernet_info *myinfo) @@ -950,8 +948,8 @@ void basilisks_loop(void *arg) basilisk_p2pQ_process(myinfo,777); fprintf(stderr,"\n"); if ( myinfo->NOTARY.RELAYID >= 0 ) - endmilli = startmilli + 500; - else endmilli = startmilli + 2500; + endmilli = startmilli + 2500; + else endmilli = startmilli + 5000; while ( OS_milliseconds() < endmilli ) usleep(10000); iter++; diff --git a/basilisk/basilisk_ping.c b/basilisk/basilisk_ping.c index 191cf36fe..6057526e4 100755 --- a/basilisk/basilisk_ping.c +++ b/basilisk/basilisk_ping.c @@ -152,7 +152,7 @@ int32_t basilisk_ping_genMSG(struct supernet_info *myinfo,uint8_t *data,int32_t datalen += iguana_rwnum(1,&data[datalen],sizeof(msg->duration),&msg->duration); if ( maxlen > datalen+msg->datalen ) { - //printf("SEND keylen.%d msglen.%d\n",msg->keylen,msg->datalen); + printf("SEND keylen.%d msglen.%d\n",msg->keylen,msg->datalen); memcpy(&data[datalen],msg->data,msg->datalen), datalen += msg->datalen; } else @@ -247,9 +247,9 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr } //printf("PING got %d, processed.%d from (%s)\n",datalen,len,ipbuf); //else printf("\n"); - //for (i=0; iNOTARY.RELAYID,QUEUEITEMS); + for (i=0; iNOTARY.RELAYID,QUEUEITEMS); } int32_t basilisk_ping_gen(struct supernet_info *myinfo,uint8_t *data,int32_t maxlen) @@ -261,9 +261,9 @@ int32_t basilisk_ping_gen(struct supernet_info *myinfo,uint8_t *data,int32_t max datalen += basilisk_ping_genrelay(myinfo,&data[datalen],maxlen - datalen,&myinfo->NOTARY.RELAYS[i]); //datalen += basilisk_ping_genDEX(myinfo,&data[datalen],maxlen - datalen); datalen += basilisk_ping_genMSG(myinfo,&data[datalen],maxlen - datalen); - //for (i=0; i>>>>>>>>> Q.%d\n",datalen,myinfo->RELAYID,QUEUEITEMS); + for (i=0; i>>>>>>>>> Q.%d\n",datalen,myinfo->NOTARY.RELAYID,QUEUEITEMS); return(datalen); } From 1f96dbc2398aeafae508b81a97ac94d4e8424576 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 06:06:21 -0300 Subject: [PATCH 26/56] test --- basilisk/basilisk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 085318fdf..fed6c29ac 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -778,7 +778,7 @@ int32_t basilisk_p2pQ_process(struct supernet_info *myinfo,int32_t maxiters) { if ( myinfo->NOTARY.RELAYID >= 0 ) { - fprintf(stderr,"P"); + fprintf(stderr,"P.%d ",ptr->datalen); basilisk_ping_process(myinfo,ptr->addr,ptr->ipbits,ptr->data,ptr->datalen); fprintf(stderr,"p"); } @@ -807,6 +807,7 @@ struct basilisk_p2pitem *basilisk_p2pitem_create(struct iguana_info *coin,struct ptr->coin = coin; ptr->addr = addr; ptr->ipbits = ipbits; + ptr->datalen = datalen; safecopy(ptr->type,type,sizeof(ptr->type)); memcpy(ptr->data,data,datalen); return(ptr); @@ -831,6 +832,7 @@ void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct i if ( senderip != 0 && senderip[0] != 0 && strcmp(senderip,"127.0.0.1") != 0 ) ipbits = (uint32_t)calc_ipbits(senderip); else ipbits = myinfo->myaddr.myipbits; + fprintf(stderr,"p2pQ.%d ",datalen); ptr = basilisk_p2pitem_create(coin,addr,type,ipbits,data,datalen); queue_enqueue("p2pQ",&myinfo->p2pQ,ptr,0); } From 4ab9ae90a2ee5056e7b756a470dd4c83d8a2e5be Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 06:18:21 -0300 Subject: [PATCH 27/56] test --- basilisk/basilisk.c | 5 ++--- basilisk/basilisk_ping.c | 12 ++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index fed6c29ac..29056d6d9 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -912,12 +912,11 @@ void basilisk_iteration(struct supernet_info *myinfo) QUEUEITEMS--; free(msg); } - if ( myinfo->NOTARY.RELAYID >= 0 ) - basilisk_ping_send(myinfo,notary); } portable_mutex_unlock(&myinfo->messagemutex); if ( myinfo->NOTARY.RELAYID >= 0 ) { + basilisk_ping_send(myinfo,notary); if ( notary != 0 ) { maxmillis = (1000 / (myinfo->allcoins_numvirts + 1)) + 1; @@ -946,7 +945,7 @@ void basilisks_loop(void *arg) basilisk_issued_purge(myinfo,600000); fprintf(stderr,"I"); basilisk_iteration(myinfo); - fprintf(stderr,"2"); + fprintf(stderr," backI\n"); basilisk_p2pQ_process(myinfo,777); fprintf(stderr,"\n"); if ( myinfo->NOTARY.RELAYID >= 0 ) diff --git a/basilisk/basilisk_ping.c b/basilisk/basilisk_ping.c index 6057526e4..de8cbec95 100755 --- a/basilisk/basilisk_ping.c +++ b/basilisk/basilisk_ping.c @@ -247,9 +247,9 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr } //printf("PING got %d, processed.%d from (%s)\n",datalen,len,ipbuf); //else printf("\n"); - for (i=0; iNOTARY.RELAYID,QUEUEITEMS); + //for (i=0; iNOTARY.RELAYID,QUEUEITEMS); } int32_t basilisk_ping_gen(struct supernet_info *myinfo,uint8_t *data,int32_t maxlen) @@ -261,9 +261,9 @@ int32_t basilisk_ping_gen(struct supernet_info *myinfo,uint8_t *data,int32_t max datalen += basilisk_ping_genrelay(myinfo,&data[datalen],maxlen - datalen,&myinfo->NOTARY.RELAYS[i]); //datalen += basilisk_ping_genDEX(myinfo,&data[datalen],maxlen - datalen); datalen += basilisk_ping_genMSG(myinfo,&data[datalen],maxlen - datalen); - for (i=0; i>>>>>>>>> Q.%d\n",datalen,myinfo->NOTARY.RELAYID,QUEUEITEMS); + //for (i=0; i>>>>>>>>> Q.%d\n",datalen,myinfo->NOTARY.RELAYID,QUEUEITEMS); return(datalen); } From 41883285727299152aa2f120d5ecc3527a048077 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 06:28:20 -0300 Subject: [PATCH 28/56] test --- basilisk/basilisk.c | 19 ++++--------------- basilisk/basilisk_MSG.c | 9 ++++++++- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 29056d6d9..56902fcf3 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -899,33 +899,22 @@ int32_t basilisk_issued_purge(struct supernet_info *myinfo,int32_t timepad) void basilisk_iteration(struct supernet_info *myinfo) { - struct iguana_info *virt,*tmpcoin,*notary; struct basilisk_message *msg,*tmpmsg; uint32_t now; int32_t maxmillis,flag=0; + struct iguana_info *notary; uint32_t now; now = (uint32_t)time(NULL); notary = iguana_coinfind("NOTARY"); - portable_mutex_lock(&myinfo->messagemutex); - HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) - { - if ( now > msg->expiration ) - { - printf("delete expired message.%p QUEUEITEMS.%d\n",msg,QUEUEITEMS); - HASH_DELETE(hh,myinfo->messagetable,msg); - QUEUEITEMS--; - free(msg); - } - } - portable_mutex_unlock(&myinfo->messagemutex); if ( myinfo->NOTARY.RELAYID >= 0 ) { basilisk_ping_send(myinfo,notary); - if ( notary != 0 ) + /*if ( notary != 0 ) { + struct iguana_info *virt,*tmpcoin; int32_t maxmillis; maxmillis = (1000 / (myinfo->allcoins_numvirts + 1)) + 1; HASH_ITER(hh,myinfo->allcoins,virt,tmpcoin) { if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 ) gecko_iteration(myinfo,notary,virt,maxmillis), flag++; } - } + }*/ } else if ( myinfo->expiration != 0 ) { diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index c09a2431e..aaad4291c 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -149,7 +149,7 @@ int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t chan char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) { - uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *msgjson,*item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg; + uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *msgjson,*item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg; uint32_t now = (uint32_t)time(NULL); memset(zero.bytes,0,sizeof(zero)); if ( (width= origwidth) > 3600 ) width = 3600; @@ -160,6 +160,13 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ portable_mutex_lock(&myinfo->messagemutex); HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { + if ( now > msg->expiration ) + { + printf("delete expired message.%p QUEUEITEMS.%d\n",msg,QUEUEITEMS); + HASH_DELETE(hh,myinfo->messagetable,msg); + QUEUEITEMS--; + free(msg); + } if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) jaddi(array,msgjson); From 7f599df546fbbd65dcd1acdaecbf8d19da1d06d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 06:47:50 -0300 Subject: [PATCH 29/56] test --- basilisk/basilisk.c | 2 +- basilisk/basilisk_MSG.c | 186 ++++++++++++++++++++-------------------- 2 files changed, 94 insertions(+), 94 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 56902fcf3..0a0790780 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -635,7 +635,6 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende { (void *)"VOT", &basilisk_respond_VOT }, // VOTE handler for something //{ (void *)"PIN", &basilisk_respond_PIN }, - // encrypted data for jumblr { (void *)"HOP", &basilisk_respond_forward }, // message forwarding { (void *)"BOX", &basilisk_respond_mailbox }, // create/send/check mailbox pubkey @@ -748,6 +747,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende { if ( (coin != 0 && coin->FULLNODE != 0) || myinfo->NOTARY.RELAYID >= 0 ) // iguana node { + printf("\n call %s from_basilisk.%d (%s)\n",addr->ipaddr,from_basilisk,type); if ( (retstr= (*basilisk_services[i][1])(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,hash,from_basilisk)) != 0 ) { printf("%s from_basilisk.%d ret.(%s)\n",addr->ipaddr,from_basilisk,retstr); diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index aaad4291c..8d6246bca 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -15,46 +15,24 @@ // included from basilisk.c -char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration) +int32_t basilisk_messagekeyread(uint8_t *key,uint32_t *channelp,uint32_t *msgidp,bits256 *srchashp,bits256 *desthashp) { - struct basilisk_message *msg; int32_t i; bits256 desthash; - if ( keylen != BASILISK_KEYSIZE ) - return(0); - portable_mutex_lock(&myinfo->messagemutex); - HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); - if ( msg == 0 || msg->datalen != datalen ) - { - if ( msg != 0 ) - { - printf("overwrite delete of msg.[%d]\n",msg->datalen); - HASH_DELETE(hh,myinfo->messagetable,msg); - QUEUEITEMS--; - free(msg); - } - msg = calloc(1,sizeof(*msg) + datalen); - } - if ( duration == 0 ) - duration = BASILISK_MSGDURATION; - else if ( duration > INSTANTDEX_LOCKTIME*2 ) - duration = INSTANTDEX_LOCKTIME*2; - memcpy(desthash.bytes,&key[BASILISK_KEYSIZE - sizeof(desthash)],sizeof(desthash)); - if ( bits256_nonz(desthash) == 0 ) - msg->broadcast = 1; - msg->duration = duration; - msg->expiration = (uint32_t)time(NULL) + duration; - msg->keylen = keylen; - memcpy(msg->key,key,keylen); - msg->datalen = datalen; - memcpy(msg->data,data,datalen); - HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg); - for (i=0; iexpiration); - QUEUEITEMS++; - if ( sendping != 0 ) - queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0); - portable_mutex_unlock(&myinfo->messagemutex); - return(clonestr("{\"result\":\"message added to hashtable\"}")); + int32_t keylen = 0; + keylen += iguana_rwnum(0,&key[keylen],sizeof(uint32_t),channelp); + keylen += iguana_rwnum(0,&key[keylen],sizeof(uint32_t),msgidp); + keylen += iguana_rwbignum(0,&key[keylen],sizeof(*srchashp),srchashp->bytes); + keylen += iguana_rwbignum(0,&key[keylen],sizeof(*desthashp),desthashp->bytes); + return(keylen); +} + +int32_t basilisk_messagekey(uint8_t *key,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash) +{ + int32_t keylen = 0; + keylen += iguana_rwnum(1,&key[keylen],sizeof(uint32_t),&channel); + keylen += iguana_rwnum(1,&key[keylen],sizeof(uint32_t),&msgid); + keylen += iguana_rwbignum(1,&key[keylen],sizeof(srchash),srchash.bytes); + keylen += iguana_rwbignum(1,&key[keylen],sizeof(desthash),desthash.bytes); + return(keylen); } cJSON *basilisk_msgjson(struct basilisk_message *msg,uint8_t *key,int32_t keylen) @@ -77,57 +55,15 @@ cJSON *basilisk_msgjson(struct basilisk_message *msg,uint8_t *key,int32_t keylen return(msgjson); } -cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) +cJSON *_basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) { cJSON *msgjson = 0; struct basilisk_message *msg; - portable_mutex_lock(&myinfo->messagemutex); HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); if ( msg != 0 && msg->broadcast == 0 ) msgjson = basilisk_msgjson(msg,key,keylen); - portable_mutex_unlock(&myinfo->messagemutex); return(msgjson); } -// respond to incoming OUT, MSG - -int32_t basilisk_messagekeyread(uint8_t *key,uint32_t *channelp,uint32_t *msgidp,bits256 *srchashp,bits256 *desthashp) -{ - int32_t keylen = 0; - keylen += iguana_rwnum(0,&key[keylen],sizeof(uint32_t),channelp); - keylen += iguana_rwnum(0,&key[keylen],sizeof(uint32_t),msgidp); - keylen += iguana_rwbignum(0,&key[keylen],sizeof(*srchashp),srchashp->bytes); - keylen += iguana_rwbignum(0,&key[keylen],sizeof(*desthashp),desthashp->bytes); - return(keylen); -} - -int32_t basilisk_messagekey(uint8_t *key,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash) -{ - int32_t keylen = 0; - keylen += iguana_rwnum(1,&key[keylen],sizeof(uint32_t),&channel); - keylen += iguana_rwnum(1,&key[keylen],sizeof(uint32_t),&msgid); - keylen += iguana_rwbignum(1,&key[keylen],sizeof(srchash),srchash.bytes); - keylen += iguana_rwbignum(1,&key[keylen],sizeof(desthash),desthash.bytes); - return(keylen); -} - -char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) -{ - int32_t keylen,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 desthash,senderhash; char *retstr; - senderhash = jbits256(valsobj,"srchash"); - desthash = jbits256(valsobj,"desthash"); - duration = juint(valsobj,"duration"); - keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,desthash); - if ( bits256_nonz(hash) == 0 ) - { - if ( duration > BASILISK_MSGDURATION ) - duration = BASILISK_MSGDURATION; - } - retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); - // printf("OUT keylen.%d datalen.%d\n",keylen,datalen); - char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); - return(retstr); -} - int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash) { uint32_t keychannel,keymsgid; bits256 keysrc,keydest; @@ -157,9 +93,13 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ width = 1; allflag = (bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); array = cJSON_CreateArray(); + fprintf(stderr,"["); portable_mutex_lock(&myinfo->messagemutex); HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { + if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) + if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) + jaddi(array,msgjson); if ( now > msg->expiration ) { printf("delete expired message.%p QUEUEITEMS.%d\n",msg,QUEUEITEMS); @@ -167,51 +107,49 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ QUEUEITEMS--; free(msg); } - if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) - if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) - jaddi(array,msgjson); } - portable_mutex_unlock(&myinfo->messagemutex); //printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); for (i=0; i 0 ) { if ( bits256_nonz(srchash) != 0 ) { keylen = basilisk_messagekey(key,channel,msgid,zero,desthash); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0)); keylen = basilisk_messagekey(key,channel,msgid,desthash,zero); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0)); } if ( bits256_nonz(desthash) != 0 ) { keylen = basilisk_messagekey(key,channel,msgid,srchash,zero); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); keylen = basilisk_messagekey(key,channel,msgid,zero,srchash); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); } if ( bits256_nonz(srchash) != 0 && bits256_nonz(desthash) != 0 ) { keylen = basilisk_messagekey(key,channel,msgid,zero,zero); - if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg3.(%s)\n",jprint(item,0)); } } msgid--; } + portable_mutex_unlock(&myinfo->messagemutex); + fprintf(stderr,"]"); if ( cJSON_GetArraySize(array) > 0 ) { retjson = cJSON_CreateObject(); @@ -222,6 +160,68 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ } else return(clonestr("{\"error\":\"no messages\"}")); } +char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration) +{ + struct basilisk_message *msg; int32_t i; bits256 desthash; + if ( keylen != BASILISK_KEYSIZE ) + return(0); + portable_mutex_lock(&myinfo->messagemutex); + HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); + if ( msg == 0 || msg->datalen != datalen ) + { + if ( msg != 0 ) + { + printf("overwrite delete of msg.[%d]\n",msg->datalen); + HASH_DELETE(hh,myinfo->messagetable,msg); + QUEUEITEMS--; + free(msg); + } + msg = calloc(1,sizeof(*msg) + datalen); + } + if ( duration == 0 ) + duration = BASILISK_MSGDURATION; + else if ( duration > INSTANTDEX_LOCKTIME*2 ) + duration = INSTANTDEX_LOCKTIME*2; + memcpy(desthash.bytes,&key[BASILISK_KEYSIZE - sizeof(desthash)],sizeof(desthash)); + if ( bits256_nonz(desthash) == 0 ) + msg->broadcast = 1; + msg->duration = duration; + msg->expiration = (uint32_t)time(NULL) + duration; + msg->keylen = keylen; + memcpy(msg->key,key,keylen); + msg->datalen = datalen; + memcpy(msg->data,data,datalen); + HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg); + for (i=0; iexpiration); + QUEUEITEMS++; + if ( sendping != 0 ) + queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0); + portable_mutex_unlock(&myinfo->messagemutex); + return(clonestr("{\"result\":\"message added to hashtable\"}")); +} + +// respond to incoming OUT, MSG + +char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) +{ + int32_t keylen,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 desthash,senderhash; char *retstr; + senderhash = jbits256(valsobj,"srchash"); + desthash = jbits256(valsobj,"desthash"); + duration = juint(valsobj,"duration"); + keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,desthash); + if ( bits256_nonz(hash) == 0 ) + { + if ( duration > BASILISK_MSGDURATION ) + duration = BASILISK_MSGDURATION; + } + retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); + // printf("OUT keylen.%d datalen.%d\n",keylen,datalen); + char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); + return(retstr); +} + char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) { int32_t width; uint32_t msgid,channel; char *retstr; From 9a3ff83dbce96511c511be8e5faad50420c74b69 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 07:03:49 -0300 Subject: [PATCH 30/56] test --- basilisk/basilisk_MSG.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 8d6246bca..901a60147 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -98,8 +98,12 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) + { + fprintf(stderr,"."); if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) jaddi(array,msgjson); + } + fprintf(stderr,","); if ( now > msg->expiration ) { printf("delete expired message.%p QUEUEITEMS.%d\n",msg,QUEUEITEMS); @@ -108,6 +112,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ free(msg); } } + /* //printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); for (i=0; imessagemutex); fprintf(stderr,"]"); if ( cJSON_GetArraySize(array) > 0 ) From de5bcfde40e10e99645021900e74a997896afd22 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 07:23:40 -0300 Subject: [PATCH 31/56] test --- basilisk/basilisk_MSG.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 901a60147..c37a442fe 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -103,7 +103,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) jaddi(array,msgjson); } - fprintf(stderr,","); + fprintf(stderr,"(%p).%d\n",msg,msg->datalen); if ( now > msg->expiration ) { printf("delete expired message.%p QUEUEITEMS.%d\n",msg,QUEUEITEMS); @@ -201,9 +201,9 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 printf("%02x",key[i]); printf(" <- ADDMSG.[%d] exp %u\n",QUEUEITEMS,msg->expiration); QUEUEITEMS++; + portable_mutex_unlock(&myinfo->messagemutex); if ( sendping != 0 ) queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0); - portable_mutex_unlock(&myinfo->messagemutex); return(clonestr("{\"result\":\"message added to hashtable\"}")); } From 3d2d8c0b780b7cfbb7160dcb2792095830a6dc4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 07:41:37 -0300 Subject: [PATCH 32/56] test --- basilisk/basilisk_MSG.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index c37a442fe..5537e7a4e 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -199,7 +199,7 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg); for (i=0; iexpiration); + printf(" <- ADDMSG.[%d] exp %u %p (%p %p)\n",QUEUEITEMS,msg->expiration,msg,msg->hh.next,msg->hh.prev); QUEUEITEMS++; portable_mutex_unlock(&myinfo->messagemutex); if ( sendping != 0 ) From b2f7fb351c4d7bb2758ad7e43b1026399e3df1d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 07:58:22 -0300 Subject: [PATCH 33/56] test --- basilisk/basilisk_MSG.c | 44 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 5537e7a4e..f25f867bf 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -85,7 +85,7 @@ int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t chan char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) { - uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *msgjson,*item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg; uint32_t now = (uint32_t)time(NULL); + uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *msgjson,*item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg,*firstmsg = 0; uint32_t now = (uint32_t)time(NULL); memset(zero.bytes,0,sizeof(zero)); if ( (width= origwidth) > 3600 ) width = 3600; @@ -97,13 +97,20 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ portable_mutex_lock(&myinfo->messagemutex); HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { + if ( firstmsg == 0 ) + firstmsg = msg; + else if ( firstmsg == msg ) + { + printf("got 1stmsg.%p again?\n",firstmsg); + break; + } if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) { fprintf(stderr,"."); if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) jaddi(array,msgjson); } - fprintf(stderr,"(%p).%d\n",msg,msg->datalen); + fprintf(stderr,"(%p).%d 1st.%p\n",msg,msg->datalen,firstmsg); if ( now > msg->expiration ) { printf("delete expired message.%p QUEUEITEMS.%d\n",msg,QUEUEITEMS); @@ -112,7 +119,6 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ free(msg); } } - /* //printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); for (i=0; imessagemutex); fprintf(stderr,"]"); if ( cJSON_GetArraySize(array) > 0 ) @@ -170,6 +176,10 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 struct basilisk_message *msg; int32_t i; bits256 desthash; if ( keylen != BASILISK_KEYSIZE ) return(0); + if ( duration == 0 ) + duration = BASILISK_MSGDURATION; + else if ( duration > INSTANTDEX_LOCKTIME*2 ) + duration = INSTANTDEX_LOCKTIME*2; portable_mutex_lock(&myinfo->messagemutex); HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); if ( msg == 0 || msg->datalen != datalen ) @@ -182,21 +192,17 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 free(msg); } msg = calloc(1,sizeof(*msg) + datalen); - } - if ( duration == 0 ) - duration = BASILISK_MSGDURATION; - else if ( duration > INSTANTDEX_LOCKTIME*2 ) - duration = INSTANTDEX_LOCKTIME*2; - memcpy(desthash.bytes,&key[BASILISK_KEYSIZE - sizeof(desthash)],sizeof(desthash)); - if ( bits256_nonz(desthash) == 0 ) - msg->broadcast = 1; - msg->duration = duration; - msg->expiration = (uint32_t)time(NULL) + duration; - msg->keylen = keylen; - memcpy(msg->key,key,keylen); - msg->datalen = datalen; - memcpy(msg->data,data,datalen); - HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg); + msg->keylen = keylen; + memcpy(msg->key,key,keylen); + msg->datalen = datalen; + memcpy(msg->data,data,datalen); + memcpy(desthash.bytes,&key[BASILISK_KEYSIZE - sizeof(desthash)],sizeof(desthash)); + if ( bits256_nonz(desthash) == 0 ) + msg->broadcast = 1; + msg->duration = duration; + msg->expiration = (uint32_t)time(NULL) + duration; + HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg); + } else memcpy(msg->data,data,datalen); for (i=0; iexpiration,msg,msg->hh.next,msg->hh.prev); From e05ea137ec09952e73d747b245e18f095a4a7760 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 08:09:45 -0300 Subject: [PATCH 34/56] test --- basilisk/basilisk.c | 10 ---------- basilisk/basilisk_MSG.c | 15 ++------------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 0a0790780..f76f831e6 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -778,9 +778,7 @@ int32_t basilisk_p2pQ_process(struct supernet_info *myinfo,int32_t maxiters) { if ( myinfo->NOTARY.RELAYID >= 0 ) { - fprintf(stderr,"P.%d ",ptr->datalen); basilisk_ping_process(myinfo,ptr->addr,ptr->ipbits,ptr->data,ptr->datalen); - fprintf(stderr,"p"); } } else @@ -788,9 +786,7 @@ int32_t basilisk_p2pQ_process(struct supernet_info *myinfo,int32_t maxiters) len += iguana_rwnum(0,ptr->data,sizeof(basilisktag),&basilisktag); if ( 0 && myinfo->IAMLP == 0 ) printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,ptr->datalen,ptr->type,senderip!=0?senderip:"?",basilisktag); - fprintf(stderr,"%s ",ptr->type); basilisk_msgprocess(myinfo,ptr->addr,ptr->ipbits,ptr->type,basilisktag,&ptr->data[len],ptr->datalen - len); - fprintf(stderr,"%s n.%d\n",ptr->type,n); if ( 0 && myinfo->IAMLP == 0 ) printf("processed.%s from %s\n",ptr->type,senderip!=0?senderip:"?"); } @@ -832,9 +828,7 @@ void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct i if ( senderip != 0 && senderip[0] != 0 && strcmp(senderip,"127.0.0.1") != 0 ) ipbits = (uint32_t)calc_ipbits(senderip); else ipbits = myinfo->myaddr.myipbits; - fprintf(stderr,"p2pQ.%d ",datalen); ptr = basilisk_p2pitem_create(coin,addr,type,ipbits,data,datalen); - queue_enqueue("p2pQ",&myinfo->p2pQ,ptr,0); } void basilisk_requests_poll(struct supernet_info *myinfo) @@ -930,13 +924,9 @@ void basilisks_loop(void *arg) while ( 1 ) { startmilli = OS_milliseconds(); - fprintf(stderr,"G"); basilisk_issued_purge(myinfo,600000); - fprintf(stderr,"I"); basilisk_iteration(myinfo); - fprintf(stderr," backI\n"); basilisk_p2pQ_process(myinfo,777); - fprintf(stderr,"\n"); if ( myinfo->NOTARY.RELAYID >= 0 ) endmilli = startmilli + 2500; else endmilli = startmilli + 5000; diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index f25f867bf..df6d973db 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -85,7 +85,7 @@ int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t chan char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) { - uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *msgjson,*item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg,*firstmsg = 0; uint32_t now = (uint32_t)time(NULL); + uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *msgjson,*item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg; uint32_t now = (uint32_t)time(NULL); memset(zero.bytes,0,sizeof(zero)); if ( (width= origwidth) > 3600 ) width = 3600; @@ -93,24 +93,14 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ width = 1; allflag = (bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); array = cJSON_CreateArray(); - fprintf(stderr,"["); portable_mutex_lock(&myinfo->messagemutex); HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { - if ( firstmsg == 0 ) - firstmsg = msg; - else if ( firstmsg == msg ) - { - printf("got 1stmsg.%p again?\n",firstmsg); - break; - } if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) { - fprintf(stderr,"."); if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) jaddi(array,msgjson); } - fprintf(stderr,"(%p).%d 1st.%p\n",msg,msg->datalen,firstmsg); if ( now > msg->expiration ) { printf("delete expired message.%p QUEUEITEMS.%d\n",msg,QUEUEITEMS); @@ -160,7 +150,6 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ msgid--; } portable_mutex_unlock(&myinfo->messagemutex); - fprintf(stderr,"]"); if ( cJSON_GetArraySize(array) > 0 ) { retjson = cJSON_CreateObject(); @@ -229,7 +218,7 @@ char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,cha } retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); // printf("OUT keylen.%d datalen.%d\n",keylen,datalen); - char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); + //char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); return(retstr); } From 6bf88c3764352b85ccc90fa224a8bc1021e0fb92 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 08:28:53 -0300 Subject: [PATCH 35/56] test --- basilisk/basilisk.c | 1 + basilisk/basilisk_MSG.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index f76f831e6..7c6222fe6 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -829,6 +829,7 @@ void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct i ipbits = (uint32_t)calc_ipbits(senderip); else ipbits = myinfo->myaddr.myipbits; ptr = basilisk_p2pitem_create(coin,addr,type,ipbits,data,datalen); + queue_enqueue("p2pQ",&myinfo->p2pQ,ptr,0); } void basilisk_requests_poll(struct supernet_info *myinfo) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index df6d973db..ffca388ba 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -164,7 +164,10 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 { struct basilisk_message *msg; int32_t i; bits256 desthash; if ( keylen != BASILISK_KEYSIZE ) + { + printf("basilisk_respond_addmessage keylen.%d != %d\n",keylen,BASILISK_KEYSIZE); return(0); + } if ( duration == 0 ) duration = BASILISK_MSGDURATION; else if ( duration > INSTANTDEX_LOCKTIME*2 ) @@ -191,12 +194,12 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 msg->duration = duration; msg->expiration = (uint32_t)time(NULL) + duration; HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg); + QUEUEITEMS++; } else memcpy(msg->data,data,datalen); + portable_mutex_unlock(&myinfo->messagemutex); for (i=0; iexpiration,msg,msg->hh.next,msg->hh.prev); - QUEUEITEMS++; - portable_mutex_unlock(&myinfo->messagemutex); if ( sendping != 0 ) queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0); return(clonestr("{\"result\":\"message added to hashtable\"}")); @@ -216,9 +219,9 @@ char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,cha if ( duration > BASILISK_MSGDURATION ) duration = BASILISK_MSGDURATION; } + //char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); // printf("OUT keylen.%d datalen.%d\n",keylen,datalen); - //char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); return(retstr); } From 8cee3f44dd5bd552ab6ee2ec82419246b84dc38d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 09:23:55 -0300 Subject: [PATCH 36/56] test --- basilisk/basilisk.c | 2 +- iguana/iguana777.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 7c6222fe6..f7abeb04d 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -454,7 +454,7 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_add } ptr->finished = (uint32_t)time(NULL); } - if ( 0 && strcmp("RID",CMD) != 0 && strcmp("BAL",CMD) != 0 && strcmp("MSG",CMD) != 0 ) + if ( strcmp("MSG",CMD) == 0 ) printf("%s.(%s) -> (%s)\n",CMD,jprint(valsobj,0),retstr!=0?retstr:""); return(retstr); } diff --git a/iguana/iguana777.c b/iguana/iguana777.c index db10b4bc6..84ec009e0 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -742,6 +742,7 @@ void iguana_helper(void *arg) for (i=0; ibundles[i] == 0 || coin->bundles[i]->utxofinish <= 1 ) break; + retval = 1; if ( bp->utxofinish == 0 || (retval= iguana_spendvectors(myinfo,coin,bp,&bp->ramchain,0,bp->n,1,0)) >= 0 ) { if ( retval > 0 ) From bf84f287cc12c09d2406b277596aa966840d778a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 09:32:04 -0300 Subject: [PATCH 37/56] test --- basilisk/basilisk.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index f7abeb04d..598a255b8 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -375,7 +375,7 @@ struct basilisk_item *basilisk_issueremote(struct supernet_info *myinfo,struct i if ( (retarray= pending->retarray) != 0 ) { pending->retstr = jprint(retarray,0); - //printf("num.%d:%d required.%d RETSTR.(%s)\n",pending->numresults,cJSON_GetArraySize(pending->retarray),pending->numrequired,pending->retstr); + printf("num.%d:%d required.%d RETSTR.(%s)\n",pending->numresults,cJSON_GetArraySize(pending->retarray),pending->numrequired,pending->retstr); pending->retarray = 0; free_json(retarray); } @@ -401,8 +401,8 @@ struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,struc if ( (timeoutmillis= jint(valsobj,"timeout")) == 0 ) timeoutmillis = BASILISK_TIMEOUT; minfanout = sqrt(myinfo->NOTARY.NUMRELAYS)+1; - if ( minfanout < 5 ) - minfanout = 5; + if ( minfanout < 8 ) + minfanout = 8; if ( jobj(valsobj,"fanout") == 0 ) fanout = minfanout; else fanout = jint(valsobj,"fanout"); @@ -447,15 +447,15 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_add if ( ptr->numsent > 0 ) { //queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0); - jaddstr(retjson,"result","success"); + jaddstr(retjson,"result","error"); jaddnum(retjson,"numsent",ptr->numsent); } else jaddstr(retjson,"error","didnt find any nodes to send to"); retstr = jprint(retjson,1); } ptr->finished = (uint32_t)time(NULL); } - if ( strcmp("MSG",CMD) == 0 ) - printf("%s.(%s) -> (%s)\n",CMD,jprint(valsobj,0),retstr!=0?retstr:""); + //if ( strcmp("MSG",CMD) == 0 ) + // printf("%s.(%s) -> (%s)\n",CMD,jprint(valsobj,0),retstr!=0?retstr:""); return(retstr); } @@ -600,7 +600,7 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi jaddi(pending->retarray,item); if ( jobj(item,"error") == 0 ) { - //printf("numresults.%d:%d\n",pending->numresults,cJSON_GetArraySize(pending->retarray)); + printf("numresults.%d:%d\n",pending->numresults,cJSON_GetArraySize(pending->retarray)); pending->numresults++; } } else printf("couldnt parse.(%s)\n",retstr); From 4e615cdf9b88f5d812e1ec848ca08a9646e7e4ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 09:35:38 -0300 Subject: [PATCH 38/56] test --- basilisk/basilisk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 598a255b8..b4dea6019 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -600,7 +600,7 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi jaddi(pending->retarray,item); if ( jobj(item,"error") == 0 ) { - printf("numresults.%d:%d\n",pending->numresults,cJSON_GetArraySize(pending->retarray)); + printf("numresults.%d:%d (%s)\n",pending->numresults,cJSON_GetArraySize(pending->retarray),jprint(item,0)); pending->numresults++; } } else printf("couldnt parse.(%s)\n",retstr); From 79acf87a8f81e9d8207c8d30931637a0e855d48f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 12:33:27 -0300 Subject: [PATCH 39/56] test --- basilisk/basilisk.c | 108 ++++++++++++++++++-------------- basilisk/basilisk.h | 6 +- basilisk/basilisk_CMD.c | 8 +-- basilisk/basilisk_MSG.c | 2 +- basilisk/basilisk_bitcoin.c | 4 +- basilisk/basilisk_tradebot.c | 2 +- iguana/iguana777.c | 5 ++ iguana/iguana_unspents.c | 4 +- iguana/iguana_wallet.c | 4 +- iguana/pnacl/Release/iguana.nmf | 12 ++++ includes/iguana_funcs.h | 1 + 11 files changed, 93 insertions(+), 63 deletions(-) create mode 100644 iguana/pnacl/Release/iguana.nmf diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index b4dea6019..e8d00750b 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -141,7 +141,9 @@ struct basilisk_item *basilisk_itemcreate(struct supernet_info *myinfo,char *CMD ptr->numrequired = 1; strcpy(ptr->CMD,CMD); safecopy(ptr->symbol,symbol,sizeof(ptr->symbol)); + ptr->duration = timeoutmillis; ptr->expiration = OS_milliseconds() + timeoutmillis; + //printf("itemcreate.%p %s %f timeout.%d\n",ptr,CMD,OS_milliseconds(),timeoutmillis); return(ptr); } @@ -335,7 +337,7 @@ void basilisk_sendback(struct supernet_info *myinfo,char *origCMD,char *symbol,c struct basilisk_item *basilisk_issueremote(struct supernet_info *myinfo,struct iguana_peer *addr,int32_t *numsentp,char *CMD,char *symbol,int32_t blockflag,cJSON *valsobj,int32_t fanout,int32_t numrequired,uint32_t basilisktag,int32_t timeoutmillis,void *deprecated_dontuse,char *retstr,int32_t encryptflag,int32_t delaymillis,uint32_t nBits) { - struct basilisk_item *pending; uint8_t *allocptr,*data,space[4096]; int32_t datalen; cJSON *retarray; + struct basilisk_item *pending; uint8_t *allocptr,*data,space[4096]; int32_t datalen; pending = basilisk_itemcreate(myinfo,CMD,symbol,basilisktag,numrequired,valsobj,timeoutmillis,0); pending->nBits = nBits; *numsentp = 0; @@ -356,31 +358,23 @@ struct basilisk_item *basilisk_issueremote(struct supernet_info *myinfo,struct i HASH_ADD(hh,myinfo->basilisks.issued,basilisktag,sizeof(basilisktag),pending); portable_mutex_unlock(&myinfo->basilisk_mutex); if ( pending->expiration <= OS_milliseconds() ) - pending->expiration = OS_milliseconds() + BASILISK_TIMEOUT; - strcpy(pending->symbol,"BTCD"); + pending->expiration = OS_milliseconds() + pending->duration; + strcpy(pending->symbol,"NOTARY"); strcpy(pending->CMD,CMD); + //printf("block for %f\n",pending->expiration - OS_milliseconds()); while ( OS_milliseconds() < pending->expiration ) { portable_mutex_lock(&myinfo->basilisk_mutex); - if ( pending->numresults >= pending->numrequired )//|| (retstr= pending->retstr) != 0 ) + if ( pending->numresults >= pending->numrequired ) { portable_mutex_unlock(&myinfo->basilisk_mutex); - //printf("<<<<<<<<<<<<< numresults.%d vs numrequired.%d\n",pending->numresults,pending->numrequired); + //printf("%p <<<<<<<<<<<<< numresults.%d vs numrequired.%d\n",pending,pending->numresults,pending->numrequired); break; } portable_mutex_unlock(&myinfo->basilisk_mutex); usleep(10000); } - portable_mutex_lock(&myinfo->basilisk_mutex); - if ( (retarray= pending->retarray) != 0 ) - { - pending->retstr = jprint(retarray,0); - printf("num.%d:%d required.%d RETSTR.(%s)\n",pending->numresults,cJSON_GetArraySize(pending->retarray),pending->numrequired,pending->retstr); - pending->retarray = 0; - free_json(retarray); - } - portable_mutex_unlock(&myinfo->basilisk_mutex); - } else free(pending), pending = 0; //ptr->finished = (uint32_t)time(NULL); + } if ( allocptr != 0 ) free(allocptr); } @@ -409,7 +403,7 @@ struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,struc if ( fanout < minfanout ) fanout = minfanout; if ( (numrequired= jint(valsobj,"numrequired")) <= 0 ) - numrequired = MIN(fanout,sqrt(myinfo->NOTARY.NUMRELAYS)+1); + numrequired = MIN(fanout/2,sqrt(myinfo->NOTARY.NUMRELAYS)+1); if ( (symbol= jstr(valsobj,"coin")) != 0 || (symbol= jstr(valsobj,"symbol")) != 0 ) { if ( (virt= iguana_coinfind(symbol)) != 0 ) @@ -420,7 +414,7 @@ struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,struc } } if ( symbol == 0 ) - symbol = "BTCD"; + symbol = "NOTARY"; encryptflag = jint(valsobj,"encrypt"); delaymillis = jint(valsobj,"delay"); ptr = basilisk_issueremote(myinfo,addr,&numsent,CMD,symbol,blockflag,valsobj,fanout,numrequired,0,timeoutmillis,0,0,encryptflag,delaymillis,nBits); @@ -429,7 +423,7 @@ struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,struc char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_addr,bits256 hash,cJSON *valsobj,char *hexstr,int32_t blockflag) // client side { - uint32_t nBits = 0; uint8_t space[4096],*allocptr=0,*data = 0; struct basilisk_item *ptr; int32_t datalen = 0; cJSON *retjson; char *retstr=0; + uint32_t nBits = 0; uint8_t space[4096],*allocptr=0,*data = 0; struct basilisk_item *ptr; int32_t i,datalen = 0; cJSON *retjson; char *retstr=0; if ( myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 && (strcmp(CMD,"INF") != 0 && basilisk_notarycmd(CMD) == 0) ) return(clonestr("{\"error\":\"unsupported special relay command\"}")); data = get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr); @@ -439,23 +433,33 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_add free(allocptr); if ( ptr != 0 ) { - if ( ptr->retstr != 0 ) - retstr = ptr->retstr, ptr->retstr = 0; + if ( (retstr= ptr->retstr) != 0 ) + ptr->retstr = 0; else { - retjson = cJSON_CreateObject(); - if ( ptr->numsent > 0 ) + if ( ptr->numresults > 0 ) + { + retjson = cJSON_CreateArray(); + for (i=0; inumresults; i++) + jaddi(retjson,ptr->results[i]), ptr->results[i] = 0; + //printf("numresults.%d (%p)\n",ptr->numresults,ptr); + } + else { - //queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0); - jaddstr(retjson,"result","error"); - jaddnum(retjson,"numsent",ptr->numsent); - } else jaddstr(retjson,"error","didnt find any nodes to send to"); + retjson = cJSON_CreateObject(); + if ( ptr->numsent > 0 ) + { + //queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0); + jaddstr(retjson,"result","error"); + jaddnum(retjson,"numsent",ptr->numsent); + } else jaddstr(retjson,"error","didnt find any nodes to send to"); + } retstr = jprint(retjson,1); } - ptr->finished = (uint32_t)time(NULL); + ptr->finished = OS_milliseconds() + 10000; } - //if ( strcmp("MSG",CMD) == 0 ) - // printf("%s.(%s) -> (%s)\n",CMD,jprint(valsobj,0),retstr!=0?retstr:""); + if ( 0 && strcmp("MSG",CMD) == 0 ) + printf("%s.(%s) -> (%s)\n",CMD,jprint(valsobj,0),retstr!=0?retstr:""); return(retstr); } @@ -588,25 +592,22 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi { portable_mutex_lock(&myinfo->basilisk_mutex); HASH_FIND(hh,myinfo->basilisks.issued,&basilisktag,sizeof(basilisktag),pending); - //printf("HASH_FIND.%p\n",pending); + portable_mutex_unlock(&myinfo->basilisk_mutex); if ( pending != 0 && retstr != 0 ) { if ( (item= cJSON_Parse(retstr)) != 0 ) { - if ( pending->retarray == 0 ) - pending->retarray = cJSON_CreateArray(); if ( jobj(item,"myip") == 0 ) jaddstr(item,"myip",remoteaddr); - jaddi(pending->retarray,item); - if ( jobj(item,"error") == 0 ) + if ( pending->numresults < sizeof(pending->results)/sizeof(*pending->results) ) { - printf("numresults.%d:%d (%s)\n",pending->numresults,cJSON_GetArraySize(pending->retarray),jprint(item,0)); - pending->numresults++; + //printf("%p.(RESULT).%d\n",pending,pending->numresults); + pending->results[pending->numresults++] = item; } } else printf("couldnt parse.(%s)\n",retstr); } //else printf("couldnt find issued.%u\n",basilisktag); - portable_mutex_unlock(&myinfo->basilisk_mutex); } + free(retstr); } } @@ -785,10 +786,10 @@ int32_t basilisk_p2pQ_process(struct supernet_info *myinfo,int32_t maxiters) { len += iguana_rwnum(0,ptr->data,sizeof(basilisktag),&basilisktag); if ( 0 && myinfo->IAMLP == 0 ) - printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,ptr->datalen,ptr->type,senderip!=0?senderip:"?",basilisktag); + printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,ptr->datalen,ptr->type,senderip,basilisktag); basilisk_msgprocess(myinfo,ptr->addr,ptr->ipbits,ptr->type,basilisktag,&ptr->data[len],ptr->datalen - len); if ( 0 && myinfo->IAMLP == 0 ) - printf("processed.%s from %s\n",ptr->type,senderip!=0?senderip:"?"); + printf("processed.%s from %s\n",ptr->type,senderip); } free(ptr); n++; @@ -834,8 +835,13 @@ void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct i void basilisk_requests_poll(struct supernet_info *myinfo) { + static uint32_t lastpoll; char *retstr; uint8_t data[8192]; cJSON *outerarray,*retjson; int32_t datalen,i,n; struct basilisk_request issueR; double hwm = 0.; + if ( time(NULL) < lastpoll+3 ) + return; + lastpoll = (uint32_t)time(NULL); memset(&issueR,0,sizeof(issueR)); + //printf("Call incoming\n"); if ( (retstr= InstantDEX_incoming(myinfo,0,0,0,0)) != 0 ) { //printf("poll.(%s)\n",retstr); @@ -876,13 +882,19 @@ void basilisk_requests_poll(struct supernet_info *myinfo) int32_t basilisk_issued_purge(struct supernet_info *myinfo,int32_t timepad) { - struct basilisk_item *tmp,*pending; int32_t n = 0; double startmilli = OS_milliseconds(); + struct basilisk_item *tmp,*pending; cJSON *item; int32_t i,n = 0; double startmilli = OS_milliseconds(); portable_mutex_lock(&myinfo->basilisk_mutex); HASH_ITER(hh,myinfo->basilisks.issued,pending,tmp) { - if ( pending != 0 && (pending->finished != 0 || startmilli > pending->expiration+timepad) ) + if ( pending != 0 && ((pending->finished > 0 && startmilli > pending->finished) || startmilli > pending->expiration+timepad) ) { HASH_DELETE(hh,myinfo->basilisks.issued,pending); + //printf("%f > %f (%d) clear pending.%p numresults.%d %p\n",startmilli,pending->expiration+timepad,timepad,pending,pending->numresults,pending->retstr); + for (i=0; inumresults; i++) + if ( (item= pending->results[i]) != 0 ) + free_json(item); + if ( pending->retstr != 0 ) + free(pending->retstr); memset(pending,0,sizeof(*pending)); free(pending); n++; @@ -911,11 +923,11 @@ void basilisk_iteration(struct supernet_info *myinfo) } }*/ } - else if ( myinfo->expiration != 0 ) + /*else { - if ( myinfo->IAMLP != 0 || myinfo->DEXactive > now ) + if ( myinfo->expiration != 0 && (myinfo->IAMLP != 0 || myinfo->DEXactive > now) ) basilisk_requests_poll(myinfo); - } + }*/ } void basilisks_loop(void *arg) @@ -967,9 +979,9 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr) if ( jobj(vals,"history") == 0 ) jaddnum(vals,"history",3); if ( jobj(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); + jaddnum(vals,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); if ( jobj(vals,"numrequired") == 0 ) - jaddnum(vals,"numrequired",juint(vals,"fanout")); + jaddnum(vals,"numrequired",MIN(juint(vals,"fanout")/2,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS))); if ( jobj(vals,"addresses") == 0 ) { jadd(vals,"addresses",iguana_getaddressesbyaccount(myinfo,coin,"*")); @@ -978,7 +990,7 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr) if ( (basilisktag= juint(vals,"basilisktag")) == 0 ) basilisktag = rand(); if ( (timeoutmillis= juint(vals,"timeout")) <= 0 ) - timeoutmillis = 3000; + timeoutmillis = BASILISK_TIMEOUT; if ( coin != 0 ) { if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 ) @@ -986,7 +998,7 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr) if ( (ptr= basilisk_bitcoinbalances(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 ) { retstr = ptr->retstr, ptr->retstr = 0; - ptr->finished = (uint32_t)time(NULL); + ptr->finished = OS_milliseconds() + 10000; return(retstr); } return(clonestr("{\"error\":\"no result\"}")); diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index aba91c9fb..94524faf2 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -20,7 +20,7 @@ #include "../iguana/iguana777.h" -#define BASILISK_TIMEOUT 5000 +#define BASILISK_TIMEOUT 15000 #define BASILISK_MINFANOUT 8 #define BASILISK_MAXFANOUT 64 #define BASILISK_DEFAULTDIFF 0x1effffff @@ -76,8 +76,8 @@ struct basilisk_value { bits256 txid; int64_t value; int32_t height; int16_t vou struct basilisk_item { struct queueitem DL; UT_hash_handle hh; - double expiration; cJSON *retarray; - uint32_t submit,finished,basilisktag,numresults,numsent,numrequired,nBits; + double expiration,finished; cJSON *results[64]; + uint32_t submit,basilisktag,numresults,numsent,numrequired,nBits,duration; char symbol[32],CMD[4],remoteaddr[64],*retstr; }; diff --git a/basilisk/basilisk_CMD.c b/basilisk/basilisk_CMD.c index 5a25b9a4b..9f186c2e6 100755 --- a/basilisk/basilisk_CMD.c +++ b/basilisk/basilisk_CMD.c @@ -206,7 +206,7 @@ char *basilisk_respond_VPNmessage(struct supernet_info *myinfo,char *CMD,void *a if ( coin != 0 && (ptr= basilisk_bitcoinrawtx(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,valsobj)) != 0 ) { retstr = ptr->retstr; - ptr->finished = (uint32_t)time(NULL); + ptr->finished = OS_milliseconds() + 10000; } else retstr = clonestr("{\"error\":\"no coin specified or error bitcoinrawtx\"}"); return(retstr); }*/ @@ -220,7 +220,7 @@ char *basilisk_respond_value(struct supernet_info *myinfo,char *CMD,void *addr,c if ( coin != 0 && (ptr= basilisk_bitcoinvalue(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,valsobj)) != 0 ) { retstr = ptr->retstr; - ptr->finished = (uint32_t)time(NULL); + ptr->finished = OS_milliseconds() + 10000; } else retstr = clonestr("{\"error\":\"no coin specified or error bitcoin value\"}"); return(retstr); } @@ -234,7 +234,7 @@ char *basilisk_respond_balances(struct supernet_info *myinfo,char *CMD,void *add if ( coin != 0 && (ptr= basilisk_bitcoinbalances(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,valsobj)) != 0 ) { retstr = ptr->retstr; - ptr->finished = (uint32_t)time(NULL); + ptr->finished = OS_milliseconds() + 10000; } else retstr = clonestr("{\"error\":\"no coin specified or error bitcoin balances\"}"); return(retstr); } @@ -249,7 +249,7 @@ char *basilisk_respond_getinfo(struct supernet_info *myinfo,char *CMD,void *addr if ( coin != 0 && (ptr= basilisk_getinfo(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,valsobj)) != 0 ) { retstr = ptr->retstr; - ptr->finished = (uint32_t)time(NULL); + ptr->finished = OS_milliseconds() + 10000; } else retstr = clonestr("{\"error\":\"no coin specified or error bitcoin getinfo\"}"); return(retstr); } diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index ffca388ba..9d9483133 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -341,7 +341,7 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256 msgid = (uint32_t)time(NULL); jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"width",width); - jaddnum(valsobj,"timeout",3000); + jaddnum(valsobj,"timeout",BASILISK_TIMEOUT); jaddnum(valsobj,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); jaddnum(valsobj,"numrequired",1); jaddbits256(valsobj,"srchash",srchash); diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index dea04fc92..acf5e5c0a 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -842,7 +842,7 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) if ( coin->FULLNODE != 0 && (ptr= basilisk_bitcoinvalue(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 ) { retstr = ptr->retstr, ptr->retstr = 0; - ptr->finished = (uint32_t)time(NULL); + ptr->finished = OS_milliseconds() + 10000; return(retstr); } } @@ -862,7 +862,7 @@ HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr) if ( jobj(vals,"numrequired") == 0 ) jaddnum(vals,"numrequired",MIN(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); if ( jobj(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",MIN(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); + jaddnum(vals,"fanout",MAX(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); if ( coin != 0 ) { //if ( juint(vals,"burn") == 0 ) diff --git a/basilisk/basilisk_tradebot.c b/basilisk/basilisk_tradebot.c index bc62e5858..091eaa090 100755 --- a/basilisk/basilisk_tradebot.c +++ b/basilisk/basilisk_tradebot.c @@ -251,7 +251,7 @@ double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_req if ( (hexdata= get_dataptr(0,&allocptr,&hexlen,hexspace,sizeof(hexspace),hexstr)) != 0 ) { basilisk_rwDEXquote(0,hexdata,&R); - printf("[%d].(%s)\n",i,jprint(basilisk_requestjson(&R),1)); + //printf("[%d].(%s)\n",i,jprint(basilisk_requestjson(&R),1)); } } else basilisk_parsejson(&R,item); if ( nonz != 0 ) diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 84ec009e0..626c8774e 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -854,6 +854,11 @@ void iguana_coinloop(void *arg) { if ( (coin= coins[i]) != 0 ) { + if ( strcmp(coin->symbol,"NOTARY") == 0 ) + { + if ( myinfo->expiration != 0 && (myinfo->IAMLP != 0 || myinfo->DEXactive > now) ) + basilisk_requests_poll(myinfo); + } if ( n > 1 && coin->RTheight > 0 && (rand() % 10) != 0 ) continue; if ( coin->peers == 0 ) diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index a32a44a22..51f1d4de1 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -1039,8 +1039,8 @@ cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coi jaddstr(vals,"coin",coin->symbol); jaddnum(vals,"history",1); jaddnum(vals,"firstheight",0); - jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); - jaddnum(vals,"numrequired",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); + jaddnum(vals,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); + jaddnum(vals,"numrequired",MIN(4,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); jadd(vals,"addresses",jduplicate(argarray)); if ( (retstr= basilisk_standardservice("BAL",myinfo,0,hash,vals,"",1)) != 0 ) { diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index 18884b54f..4d4461070 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -1196,12 +1196,12 @@ ZERO_ARGS(bitcoinrpc,getinfo) } else { - free(ptr->retstr); + ptr->finished = OS_milliseconds(); return(jprint(array,1)); } free_json(array); } - free(ptr->retstr); + ptr->finished = OS_milliseconds(); if ( getinfoobj != 0 ) return(jprint(getinfoobj,1)); } diff --git a/iguana/pnacl/Release/iguana.nmf b/iguana/pnacl/Release/iguana.nmf new file mode 100644 index 000000000..9d37ed227 --- /dev/null +++ b/iguana/pnacl/Release/iguana.nmf @@ -0,0 +1,12 @@ +{ + "program": { + "portable": { + "pnacl-translate": { + "url": "iguana.pexe" + }, + "pnacl-debug": { + "url": "iguana_unstripped.bc" + } + } + } +} diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 1369ea1d6..b3d76e79f 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -565,6 +565,7 @@ int32_t iguana_opreturn(struct supernet_info *myinfo,int32_t ordered,struct igua int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen); struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *notaries,uint32_t ipbits); int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]); +void basilisk_requests_poll(struct supernet_info *myinfo); void iguana_RTreset(struct iguana_info *coin); void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight); From eda6b099b863e7aee70579cb7cdc584dd758a076 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 12:37:04 -0300 Subject: [PATCH 40/56] test --- basilisk/basilisk.c | 4 ++-- basilisk/basilisk.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index e8d00750b..4cf1683fc 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -941,8 +941,8 @@ void basilisks_loop(void *arg) basilisk_iteration(myinfo); basilisk_p2pQ_process(myinfo,777); if ( myinfo->NOTARY.RELAYID >= 0 ) - endmilli = startmilli + 2500; - else endmilli = startmilli + 5000; + endmilli = startmilli + 500; + else endmilli = startmilli + 2000; while ( OS_milliseconds() < endmilli ) usleep(10000); iter++; diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index 94524faf2..54a2a4dcc 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -20,7 +20,7 @@ #include "../iguana/iguana777.h" -#define BASILISK_TIMEOUT 15000 +#define BASILISK_TIMEOUT 3000 #define BASILISK_MINFANOUT 8 #define BASILISK_MAXFANOUT 64 #define BASILISK_DEFAULTDIFF 0x1effffff From 71c5b84f56cf8ca34f95347cad4acbe88d5894a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 12:37:26 -0300 Subject: [PATCH 41/56] test --- basilisk/basilisk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 4cf1683fc..fc1a85c10 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -748,10 +748,10 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende { if ( (coin != 0 && coin->FULLNODE != 0) || myinfo->NOTARY.RELAYID >= 0 ) // iguana node { - printf("\n call %s from_basilisk.%d (%s)\n",addr->ipaddr,from_basilisk,type); + //printf("\n call %s from_basilisk.%d (%s)\n",addr->ipaddr,from_basilisk,type); if ( (retstr= (*basilisk_services[i][1])(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,hash,from_basilisk)) != 0 ) { - printf("%s from_basilisk.%d ret.(%s)\n",addr->ipaddr,from_basilisk,retstr); + //printf("%s from_basilisk.%d ret.(%s)\n",addr->ipaddr,from_basilisk,retstr); //if ( from_basilisk != 0 || strcmp(CMD,"GET") == 0 ) basilisk_sendback(myinfo,CMD,symbol,remoteaddr,basilisktag,retstr); if ( retstr != 0 ) From 41278fa2c6e9fdef58f71b9391d239f9dae4736b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 12:56:25 -0300 Subject: [PATCH 42/56] test --- basilisk/basilisk_MSG.c | 2 +- basilisk/basilisk_tradebot.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 9d9483133..944058fd4 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -325,7 +325,7 @@ int32_t basilisk_message_returned(uint8_t *key,uint8_t *data,int32_t maxlen,cJSO decode_hex(data,datalen,hexstr); //printf("decoded hexstr.[%d]\n",datalen); retval = datalen; - } else printf("datalen.%d < maxlen.%d\n",datalen,maxlen); + } else printf("datalen.%d >= maxlen.%d\n",datalen,maxlen); } } } //else printf("no hexstr.%p or datalen.%d (%s)\n",hexstr,datalen,jprint(json,0)); diff --git a/basilisk/basilisk_tradebot.c b/basilisk/basilisk_tradebot.c index 091eaa090..e2a1ba707 100755 --- a/basilisk/basilisk_tradebot.c +++ b/basilisk/basilisk_tradebot.c @@ -236,7 +236,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_request *issueR,cJSON *retjson,double hwm) { - cJSON *array,*item; uint8_t *hexdata,*allocptr,hexspace[8192]; char *hexstr; int32_t i,hexlen,n,m,nonz; struct basilisk_request tmpR,R,refR,list[BASILISK_MAXRELAYS]; double metric=0.; + cJSON *array,*item; uint8_t *hexdata,*allocptr,hexspace[32768]; char *hexstr; int32_t i,hexlen,n,m,nonz; struct basilisk_request tmpR,R,refR,list[BASILISK_MAXRELAYS]; double metric=0.; memset(&refR,0,sizeof(refR)); //printf("process.(%s)\n",jprint(retjson,0)); if ( (array= jarray(&n,retjson,"messages")) != 0 ) From 443e8e4f1cfe0989448ab90857014ba8b5fa6547 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 13:26:30 -0300 Subject: [PATCH 43/56] test --- basilisk/basilisk.c | 2 +- basilisk/basilisk_DEX.c | 8 ++++---- basilisk/basilisk_MSG.c | 18 +++++++++++------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index fc1a85c10..cab863324 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -844,7 +844,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo) //printf("Call incoming\n"); if ( (retstr= InstantDEX_incoming(myinfo,0,0,0,0)) != 0 ) { - //printf("poll.(%s)\n",retstr); + printf("poll.(%s)\n",retstr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) { if ( (outerarray= jarray(&n,retjson,"responses")) != 0 ) diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index d5258a8b7..72b92bd37 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -495,10 +495,10 @@ INT_ARG(InstantDEX,automatched,requestid) int32_t InstantDEX_incoming_func(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen) { - int32_t i; - for (i=0; imessagemutex); HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { @@ -110,6 +111,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ } } //printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); + fprintf(stderr,"["); for (i=0; imessagemutex); + fprintf(stderr,"}"); if ( cJSON_GetArraySize(array) > 0 ) { retjson = cJSON_CreateObject(); @@ -174,7 +178,7 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 duration = INSTANTDEX_LOCKTIME*2; portable_mutex_lock(&myinfo->messagemutex); HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); - if ( msg == 0 || msg->datalen != datalen ) + if ( msg == 0 )//|| msg->datalen != datalen ) { if ( msg != 0 ) { @@ -195,13 +199,13 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 msg->expiration = (uint32_t)time(NULL) + duration; HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg); QUEUEITEMS++; - } else memcpy(msg->data,data,datalen); + for (i=0; iexpiration,msg,msg->hh.next,msg->hh.prev); + if ( sendping != 0 ) + queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0); + } //else memcpy(msg->data,data,datalen); portable_mutex_unlock(&myinfo->messagemutex); - for (i=0; iexpiration,msg,msg->hh.next,msg->hh.prev); - if ( sendping != 0 ) - queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0); return(clonestr("{\"result\":\"message added to hashtable\"}")); } From d54d1919740247a274c6fa9bb30f17b3ceb6e9ab Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 13:36:15 -0300 Subject: [PATCH 44/56] test --- basilisk/basilisk.c | 2 +- basilisk/basilisk_DEX.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index cab863324..831cc6d3b 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -836,7 +836,7 @@ void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct i void basilisk_requests_poll(struct supernet_info *myinfo) { static uint32_t lastpoll; - char *retstr; uint8_t data[8192]; cJSON *outerarray,*retjson; int32_t datalen,i,n; struct basilisk_request issueR; double hwm = 0.; + char *retstr; uint8_t data[32768]; cJSON *outerarray,*retjson; int32_t datalen,i,n; struct basilisk_request issueR; double hwm = 0.; if ( time(NULL) < lastpoll+3 ) return; lastpoll = (uint32_t)time(NULL); diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 72b92bd37..6e7b101d7 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -509,7 +509,7 @@ int32_t InstantDEX_process_channelget(struct supernet_info *myinfo,void *ptr,int INT_ARG(InstantDEX,incoming,requestid) { - cJSON *retjson,*retarray; bits256 zero; uint32_t DEX_channel,msgid,now; int32_t retval,width,drift=3; uint8_t data[8192]; + cJSON *retjson,*retarray; bits256 zero; uint32_t DEX_channel,msgid,now; int32_t retval,width,drift=3; uint8_t data[32768]; now = (uint32_t)time(NULL); memset(&zero,0,sizeof(zero)); width = (now - myinfo->DEXpoll) + 2*drift; From 975f81f2f900401c931a8d0fd9f7f9ec7a74b1fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 13:37:51 -0300 Subject: [PATCH 45/56] test --- basilisk/basilisk_MSG.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 15f9a7fd4..dd7f70ea3 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -91,11 +91,11 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ width = 3600; else if ( width < 1 ) width = 1; - allflag = (bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); + allflag = 0;//(bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); array = cJSON_CreateArray(); fprintf(stderr,"{"); portable_mutex_lock(&myinfo->messagemutex); - HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) + /*HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) { @@ -109,7 +109,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ QUEUEITEMS--; free(msg); } - } + }*/ //printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); fprintf(stderr,"["); for (i=0; i 0 ) { if ( bits256_nonz(srchash) != 0 ) @@ -129,18 +129,18 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ keylen = basilisk_messagekey(key,channel,msgid,zero,desthash); if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0)); - keylen = basilisk_messagekey(key,channel,msgid,desthash,zero); - if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) - jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0)); + //keylen = basilisk_messagekey(key,channel,msgid,desthash,zero); + //if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + // jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0)); } if ( bits256_nonz(desthash) != 0 ) { keylen = basilisk_messagekey(key,channel,msgid,srchash,zero); if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); - keylen = basilisk_messagekey(key,channel,msgid,zero,srchash); - if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) - jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); + //keylen = basilisk_messagekey(key,channel,msgid,zero,srchash); + //if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) + // jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); } if ( bits256_nonz(srchash) != 0 && bits256_nonz(desthash) != 0 ) { From b70982c85c893ddbcc9f4efe7283612a24eb2efa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 13:43:44 -0300 Subject: [PATCH 46/56] test --- basilisk/basilisk_MSG.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index dd7f70ea3..7f10e7e5c 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -91,13 +91,13 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ width = 3600; else if ( width < 1 ) width = 1; - allflag = 0;//(bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); + allflag = (bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); array = cJSON_CreateArray(); fprintf(stderr,"{"); portable_mutex_lock(&myinfo->messagemutex); - /*HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) + HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { - if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0) ) + if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,srchash,desthash) == 0) ) { if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) jaddi(array,msgjson); @@ -109,9 +109,9 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ QUEUEITEMS--; free(msg); } - }*/ + } //printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); - fprintf(stderr,"["); + /*fprintf(stderr,"["); for (i=0; imessagemutex); fprintf(stderr,"}"); if ( cJSON_GetArraySize(array) > 0 ) From 035da0b392d8ee6e7075fad646f3ed54280b19d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 13:55:04 -0300 Subject: [PATCH 47/56] test --- basilisk/basilisk_tradebot.c | 1 + 1 file changed, 1 insertion(+) diff --git a/basilisk/basilisk_tradebot.c b/basilisk/basilisk_tradebot.c index e2a1ba707..16e1499d1 100755 --- a/basilisk/basilisk_tradebot.c +++ b/basilisk/basilisk_tradebot.c @@ -250,6 +250,7 @@ double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_req { if ( (hexdata= get_dataptr(0,&allocptr,&hexlen,hexspace,sizeof(hexspace),hexstr)) != 0 ) { + memset(&R,0,sizeof(R)); basilisk_rwDEXquote(0,hexdata,&R); //printf("[%d].(%s)\n",i,jprint(basilisk_requestjson(&R),1)); } From c7c6e871aa95cd7a5b8db04846977d6293700b49 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 15:48:15 -0300 Subject: [PATCH 48/56] test --- basilisk/basilisk_MSG.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 7f10e7e5c..47c273aff 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -85,37 +85,35 @@ int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t chan char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) { - uint8_t key[BASILISK_KEYSIZE]; int32_t allflag,i,keylen,width; cJSON *msgjson,*item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg; uint32_t now = (uint32_t)time(NULL); + uint8_t key[BASILISK_KEYSIZE]; int32_t i,keylen,width; cJSON *msgjson,*item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg; uint32_t now = (uint32_t)time(NULL); memset(zero.bytes,0,sizeof(zero)); if ( (width= origwidth) > 3600 ) width = 3600; else if ( width < 1 ) width = 1; - allflag = (bits256_nonz(srchash) == 0 && bits256_nonz(desthash) == 0); array = cJSON_CreateArray(); - fprintf(stderr,"{"); portable_mutex_lock(&myinfo->messagemutex); - HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) + if ( bits256_nonz(srchash) == 0 ) { - if ( allflag != 0 || (msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,srchash,desthash) == 0) ) + HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { - if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) - jaddi(array,msgjson); - } - if ( now > msg->expiration ) - { - printf("delete expired message.%p QUEUEITEMS.%d\n",msg,QUEUEITEMS); - HASH_DELETE(hh,myinfo->messagetable,msg); - QUEUEITEMS--; - free(msg); + if ( msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,desthash) == 0 ) + { + if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) + jaddi(array,msgjson); + } + if ( now > msg->expiration ) + { + printf("delete expired message.%p QUEUEITEMS.%d\n",msg,QUEUEITEMS); + HASH_DELETE(hh,myinfo->messagetable,msg); + QUEUEITEMS--; + free(msg); + } } } //printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); - /*fprintf(stderr,"["); for (i=0; imessagemutex); - fprintf(stderr,"}"); if ( cJSON_GetArraySize(array) > 0 ) { retjson = cJSON_CreateObject(); From 9df1a8affd917fb827d57945eead3dac4849cbce Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 16:32:15 -0300 Subject: [PATCH 49/56] test --- basilisk/basilisk_MSG.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 47c273aff..19aff6f3e 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -97,7 +97,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ { HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { - if ( msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,desthash) == 0 ) + if ( basilisk_msgcmp(msg,origwidth,channel,msgid,zero,desthash) == 0 ) { if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) jaddi(array,msgjson); From 896e1cea74b5706dbf45be4dcf6fc7b9deef53e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 16:50:35 -0300 Subject: [PATCH 50/56] test --- basilisk/basilisk_DEX.c | 2 +- basilisk/basilisk_MSG.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 6e7b101d7..9b676ba51 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -521,7 +521,7 @@ INT_ARG(InstantDEX,incoming,requestid) retjson = cJSON_CreateObject(); DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); msgid = (uint32_t)time(NULL) + drift; - if ( (retarray= basilisk_channelget(myinfo,zero,zero,DEX_channel,msgid,width)) != 0 ) // myinfo->myaddr.persistent + if ( (retarray= basilisk_channelget(myinfo,zero,myinfo->myaddr.persistent,DEX_channel,msgid,width)) != 0 ) { //printf("GOT.(%s)\n",jprint(retarray,0)); if ( (retval= basilisk_process_retarray(myinfo,0,InstantDEX_process_channelget,data,sizeof(data),DEX_channel,msgid,retarray,InstantDEX_incoming_func)) > 0 ) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 19aff6f3e..670acaa99 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -346,7 +346,7 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256 jaddnum(valsobj,"numrequired",1); jaddbits256(valsobj,"srchash",srchash); jaddbits256(valsobj,"desthash",desthash); - if ( (retstr= basilisk_getmessage(myinfo,0,0,0,srchash,valsobj,0)) != 0 ) + if ( (retstr= basilisk_getmessage(myinfo,0,0,0,desthash,valsobj,0)) != 0 ) { //printf("channel.%u msgid.%u gotmessage.(%d)\n",channel,msgid,(int32_t)strlen(retstr)); if ( (retarray= cJSON_Parse(retstr)) != 0 ) From e973efd79d484ef8267ab679fb76467481c46b7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 17:27:43 -0300 Subject: [PATCH 51/56] test --- basilisk/basilisk.c | 2 +- basilisk/basilisk_MSG.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 831cc6d3b..07cf468ef 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -451,7 +451,7 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_add { //queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0); jaddstr(retjson,"result","error"); - jaddnum(retjson,"numsent",ptr->numsent); + jaddnum(retjson,"packetsize",ptr->numsent); } else jaddstr(retjson,"error","didnt find any nodes to send to"); } retstr = jprint(retjson,1); diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 670acaa99..b046f2f66 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -91,6 +91,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ width = 3600; else if ( width < 1 ) width = 1; + char str[65],str2[65]; printf("MSGiterate (%s) -> (%s)\n",bits256_str(str,srchash),bits256_str(str2,desthash)); array = cJSON_CreateArray(); portable_mutex_lock(&myinfo->messagemutex); if ( bits256_nonz(srchash) == 0 ) @@ -247,6 +248,7 @@ HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) jaddbits256(vals,"srchash",hash); if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"desthash")) == 0 ) jaddbits256(vals,"desthash",myinfo->myaddr.persistent); + char str[65]; printf("getmessage for (%s)\n",bits256_str(str,jbits256(vals,"desthash"))); if ( (msgid= juint(vals,"msgid")) == 0 ) { msgid = (uint32_t)time(NULL); From 45f6dd9f8dc6e94e3ca3d51bd7362d14daa1bfb2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 17:32:24 -0300 Subject: [PATCH 52/56] test --- basilisk/basilisk_MSG.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index b046f2f66..198c770a5 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -98,7 +98,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ { HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) { - if ( basilisk_msgcmp(msg,origwidth,channel,msgid,zero,desthash) == 0 ) + if ( basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0 ) { if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 ) jaddi(array,msgjson); From 7d3afba0ab1c1d5a47949a1b02c4140997740f21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 17:52:46 -0300 Subject: [PATCH 53/56] test --- basilisk/basilisk_CMD.c | 2 +- basilisk/basilisk_DEX.c | 2 +- basilisk/basilisk_MSG.c | 6 ++++-- iguana/iguana_wallet.c | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/basilisk/basilisk_CMD.c b/basilisk/basilisk_CMD.c index 9f186c2e6..97010ac4d 100755 --- a/basilisk/basilisk_CMD.c +++ b/basilisk/basilisk_CMD.c @@ -243,7 +243,7 @@ char *basilisk_respond_getinfo(struct supernet_info *myinfo,char *CMD,void *addr { char *symbol,*retstr=0; struct basilisk_item Lptr,*ptr; int32_t timeoutmillis; struct iguana_info *coin = 0; if ( (timeoutmillis= jint(valsobj,"timeout")) <= 0 ) - timeoutmillis = 1000; + timeoutmillis = 5000; if ( (symbol= jstr(valsobj,"coin")) != 0 || (symbol= jstr(valsobj,"symbol")) != 0 ) coin = iguana_coinfind(symbol); if ( coin != 0 && (ptr= basilisk_getinfo(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,valsobj)) != 0 ) diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 9b676ba51..47e2596bc 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -453,7 +453,7 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr) myinfo->DEXactive = (uint32_t)time(NULL) + 3*BASILISK_TIMEOUT; jadd64bits(vals,"minamount",jdouble(vals,"minprice") * jdouble(vals,"amount") * SATOSHIDEN); if ( jobj(vals,"srchash") == 0 ) - jaddbits256(vals,"srchash",myinfo->myaddr.pubkey); + jaddbits256(vals,"srchash",myinfo->myaddr.persistent); if ( jobj(vals,"desthash") == 0 ) jaddbits256(vals,"desthash",hash); jadd64bits(vals,"satoshis",jdouble(vals,"amount") * SATOSHIDEN); diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 198c770a5..a329387b1 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -156,9 +156,11 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); jadd(retjson,"messages",array); - //printf("MESSAGES.(%s)\n",jprint(array,0)); + printf("MESSAGES.(%s)\n",jprint(array,0)); return(jprint(retjson,1)); - } else return(clonestr("{\"error\":\"no messages\"}")); + } + printf("no matching messages\n"); + return(clonestr("{\"error\":\"no messages\"}")); } char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration) diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index 4d4461070..625b494cb 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -1146,7 +1146,7 @@ ZERO_ARGS(bitcoinrpc,getinfo) else { valsobj = cJSON_CreateObject(); - ptr = basilisk_getinfo(&Lptr,myinfo,coin,remoteaddr,0,3000,valsobj); + ptr = basilisk_getinfo(&Lptr,myinfo,coin,remoteaddr,0,5000,valsobj); free_json(valsobj); if ( ptr != 0 && ptr->retstr != 0 ) { From 10c58361488da30ab98885e5f83882b44bc0fa64 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 18:09:54 -0300 Subject: [PATCH 54/56] test --- basilisk/basilisk.c | 2 +- basilisk/basilisk_MSG.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 07cf468ef..010022402 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -844,7 +844,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo) //printf("Call incoming\n"); if ( (retstr= InstantDEX_incoming(myinfo,0,0,0,0)) != 0 ) { - printf("poll.(%s)\n",retstr); + //printf("poll.(%s)\n",retstr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) { if ( (outerarray= jarray(&n,retjson,"responses")) != 0 ) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index a329387b1..f6c448b25 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -250,7 +250,7 @@ HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) jaddbits256(vals,"srchash",hash); if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"desthash")) == 0 ) jaddbits256(vals,"desthash",myinfo->myaddr.persistent); - char str[65]; printf("getmessage for (%s)\n",bits256_str(str,jbits256(vals,"desthash"))); + //char str[65]; printf("getmessage for (%s)\n",bits256_str(str,jbits256(vals,"desthash"))); if ( (msgid= juint(vals,"msgid")) == 0 ) { msgid = (uint32_t)time(NULL); From 464823d1349212b886e90e676bc69753afd5b264 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 18:41:46 -0300 Subject: [PATCH 55/56] test --- iguana/iguana_spendvectors.c | 4 ++-- iguana/iguana_txidfind.c | 8 ++++---- iguana/iguana_unspents.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/iguana_spendvectors.c b/iguana/iguana_spendvectors.c index f0437cbda..660cb55b3 100755 --- a/iguana/iguana_spendvectors.c +++ b/iguana/iguana_spendvectors.c @@ -204,8 +204,8 @@ struct iguana_bundle *iguana_fastexternalspent(struct supernet_info *myinfo,stru X = RAMCHAIN_PTR(rdata,Xoffset); //X = (void *)(long)((long)rdata + rdata->Xoffset); *prevhashp = prev_hash = X[ind]; - if ( (unspentind= iguana_unspentindfind(myinfo,coin,&RTspent,0,0,0,0,&height,prev_hash,prev_vout,spent_hdrsi-1,0)) != 0 ) - //if ( (firstvout= iguana_txidfastfind(coin,&height,prev_hash,spent_hdrsi-1)) >= 0 ) + if ( (unspentind= iguana_unspentindfind(myinfo,coin,&RTspent,0,0,0,0,&height,prev_hash,prev_vout,spent_hdrsi-1,0)) > 0 ) + //if ( (firstvout= iguana_txidfastfind(coin,&height,prev_hash,spent_hdrsi-1)) > 0 ) { /*duration = (OS_milliseconds() - startmillis); if ( ((uint64_t)coin->txidfind_num % 100) == 1 ) diff --git a/iguana/iguana_txidfind.c b/iguana/iguana_txidfind.c index 5255dee9a..d8cec460f 100755 --- a/iguana/iguana_txidfind.c +++ b/iguana/iguana_txidfind.c @@ -362,13 +362,13 @@ int32_t iguana_txidfastfind(struct iguana_info *coin,int32_t *heightp,bits256 tx if ( val >= tablesize ) val = 0; if ( (i= hashtable[val]) == 0 ) - return(-1); + return(0); else { if ( i > num ) { printf("illegal val.%d vs num.%d tablesize.%d fastfind.%02x\n",i,num,tablesize,txid.bytes[31]); - return(-1); + return(0); } else { @@ -381,7 +381,7 @@ int32_t iguana_txidfastfind(struct iguana_info *coin,int32_t *heightp,bits256 tx if ( *heightp >= (lasthdrsi+1)*coin->chain->bundlesize ) { printf("txidfastfind: unexpected height.%d with lasthdrsi.%d\n",*heightp,lasthdrsi); - return(-1); + return(0); } return(firstvout); } @@ -403,7 +403,7 @@ int32_t iguana_txidfastfind(struct iguana_info *coin,int32_t *heightp,bits256 tx } } } - return(-1); + return(0); } int32_t iguana_fastfindadd(struct iguana_info *coin,bits256 txid,int32_t height,uint32_t firstvout) diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 51f1d4de1..f04c965d1 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -73,7 +73,7 @@ int32_t iguana_unspentindfind(struct supernet_info *myinfo,struct iguana_info *c *spentamountp = 0; if ( coinaddr != 0 ) coinaddr[0] = 0; - if ( coin->fastfind != 0 && (firstvout= iguana_txidfastfind(coin,heightp,txid,lasthdrsi)) >= 0 ) + if ( coin->fastfind != 0 && (firstvout= iguana_txidfastfind(coin,heightp,txid,lasthdrsi)) > 0 ) unspentind = (firstvout + vout); else if ( (tp= iguana_txidfind(coin,heightp,&TX,txid,lasthdrsi)) != 0 ) unspentind = (tp->firstvout + vout); From 4069b5ab47c774c030eb0657028aba57c2adf406 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Sep 2016 18:48:45 -0300 Subject: [PATCH 56/56] test --- iguana/iguana_payments.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index 87032e972..052c31d96 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -1310,7 +1310,7 @@ TWOINTS_AND_ARRAY(bitcoinrpc,listunspent,minconf,maxconf,array) cJSON *retjson; if ( remoteaddr != 0 ) return(clonestr("{\"error\":\"no remote\"}")); - retjson = iguana_listunspents(myinfo,coin,0,minconf,maxconf,remoteaddr); + retjson = iguana_listunspents(myinfo,coin,array,minconf,maxconf,remoteaddr); return(jprint(retjson,1)); }