From 03c4b2bb228ba13159207cad7634bf4ac44cef7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 21 Sep 2016 18:06:14 -0300 Subject: [PATCH] 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