jl777 8 years ago
parent
commit
c7c6e871aa
  1. 34
      basilisk/basilisk_MSG.c

34
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; i<width; i++)
{
if ( allflag != 0 )
break;
keylen = basilisk_messagekey(key,channel,msgid,srchash,desthash);
if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);//, printf("gotmsg0.(%s)\n",jprint(item,0));
@ -151,9 +149,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
}
msgid--;
}
fprintf(stderr,"]");*/
portable_mutex_unlock(&myinfo->messagemutex);
fprintf(stderr,"}");
if ( cJSON_GetArraySize(array) > 0 )
{
retjson = cJSON_CreateObject();

Loading…
Cancel
Save