|
|
@ -17,7 +17,7 @@ |
|
|
|
|
|
|
|
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; |
|
|
|
struct basilisk_message *msg; int32_t i; bits256 desthash; |
|
|
|
HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); |
|
|
|
if ( msg == 0 && keylen == BASILISK_KEYSIZE ) |
|
|
|
{ |
|
|
@ -26,6 +26,11 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 |
|
|
|
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; |
|
|
|
if ( bits256_nonz(desthash) == 0 ) |
|
|
|
msg->broadcast = 1; |
|
|
|
msg->duration = duration; |
|
|
|
msg->expiration = (uint32_t)time(NULL) + duration; |
|
|
|
msg->keylen = keylen; |
|
|
@ -47,28 +52,33 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 |
|
|
|
} else return(0); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *basilisk_msgjson(struct basilisk_message *msg,uint8_t *key,int32_t keylen) |
|
|
|
{ |
|
|
|
cJSON *msgjson=0; char *ptr = 0,strbuf[32768],keystr[BASILISK_KEYSIZE*2+1]; |
|
|
|
msgjson = cJSON_CreateObject(); |
|
|
|
if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),msg->data,msg->datalen) != 0 ) |
|
|
|
{ |
|
|
|
init_hexbytes_noT(keystr,key,keylen); |
|
|
|
jaddstr(msgjson,"key",keystr); |
|
|
|
jaddnum(msgjson,"expiration",msg->expiration); |
|
|
|
jaddnum(msgjson,"duration",msg->duration); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
printf("basilisk_respond_getmessage: couldnt basilisk_addhexstr data.[%d]\n",msg->datalen); |
|
|
|
free_json(msgjson); |
|
|
|
msgjson = 0; |
|
|
|
} |
|
|
|
return(msgjson); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) |
|
|
|
{ |
|
|
|
cJSON *msgjson=0; struct basilisk_message *msg; char *ptr = 0,strbuf[32768],keystr[BASILISK_KEYSIZE*2+1]; |
|
|
|
cJSON *msgjson = 0; struct basilisk_message *msg; |
|
|
|
portable_mutex_lock(&myinfo->messagemutex); |
|
|
|
HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); |
|
|
|
if ( msg != 0 ) |
|
|
|
{ |
|
|
|
msgjson = cJSON_CreateObject(); |
|
|
|
if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),msg->data,msg->datalen) != 0 ) |
|
|
|
{ |
|
|
|
init_hexbytes_noT(keystr,key,keylen); |
|
|
|
jaddstr(msgjson,"key",keystr); |
|
|
|
jaddnum(msgjson,"expiration",msg->expiration); |
|
|
|
jaddnum(msgjson,"duration",msg->duration); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
printf("basilisk_respond_getmessage: couldnt basilisk_addhexstr data.[%d]\n",msg->datalen); |
|
|
|
free_json(msgjson); |
|
|
|
msgjson = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
msgjson = basilisk_msgjson(msg,key,keylen); |
|
|
|
portable_mutex_unlock(&myinfo->messagemutex); |
|
|
|
return(msgjson); |
|
|
|
} |
|
|
@ -87,27 +97,43 @@ 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; |
|
|
|
int32_t keylen,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 senderhash; char *retstr; |
|
|
|
senderhash = jbits256(valsobj,"sender"); |
|
|
|
duration = juint(valsobj,"duration"); |
|
|
|
keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,hash); |
|
|
|
if( bits256_nonz(senderhash) == 0 && bits256_nonz(hash) == 0 && duration > BASILISK_MSGDURATION ) |
|
|
|
duration = BASILISK_MSGDURATION; |
|
|
|
retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); |
|
|
|
if ( bits256_nonz(hash) == 0 ) |
|
|
|
{ |
|
|
|
if ( duration > BASILISK_MSGDURATION ) |
|
|
|
duration = BASILISK_MSGDURATION; |
|
|
|
} |
|
|
|
// 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(basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration)); |
|
|
|
return(retstr); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash) |
|
|
|
{ |
|
|
|
return(-1); |
|
|
|
} |
|
|
|
|
|
|
|
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 i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; |
|
|
|
struct basilisk_message *msg,*tmpmsg; uint8_t key[BASILISK_KEYSIZE]; int32_t i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; |
|
|
|
memset(zero.bytes,0,sizeof(zero)); |
|
|
|
array = cJSON_CreateArray(); |
|
|
|
portable_mutex_lock(&myinfo->messagemutex); |
|
|
|
portable_mutex_unlock(&myinfo->messagemutex); |
|
|
|
if ( (width= origwidth) > 3600 ) |
|
|
|
width = 3600; |
|
|
|
else if ( width < 1 ) |
|
|
|
width = 1; |
|
|
|
//printf("iterate_MSG width.%d channel.%d msgid.%d src.%llx -> %llx\n",origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid);
|
|
|
|
HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg) |
|
|
|
{ |
|
|
|
if ( msg->broadcast != 0 && basilisk_msgcmp(msg,width,channel,msgid,zero,zero) == 0 ) |
|
|
|
jaddi(array,basilisk_msgjson(msg,msg->key,msg->keylen)); |
|
|
|
} |
|
|
|
//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<width; i++) |
|
|
|
{ |
|
|
|
keylen = basilisk_messagekey(key,channel,msgid,srchash,desthash); |
|
|
@ -124,13 +150,10 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_ |
|
|
|
if ( bits256_nonz(desthash) != 0 ) |
|
|
|
{ |
|
|
|
keylen = basilisk_messagekey(key,channel,msgid,srchash,zero); |
|
|
|
//int32_t j; for (j=0; j<keylen; j++)
|
|
|
|
// printf("%02x",key[j]);
|
|
|
|
//printf(" <- key\n");
|
|
|
|
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 ) |
|
|
|
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 ) |
|
|
@ -187,7 +210,9 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) |
|
|
|
{ |
|
|
|
keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"sender"),hash); |
|
|
|
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")); |
|
|
|
} |
|
|
|
if ( ptr != 0 ) |
|
|
|
free(ptr); |
|
|
|
if ( retstr != 0 ) |
|
|
@ -292,7 +317,7 @@ int32_t basilisk_process_retarray(struct supernet_info *myinfo,void *ptr,int32_t |
|
|
|
expiration = juint(item,"expiration"); |
|
|
|
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 ) |
|
|
|
if ( (*process_func)(myinfo,ptr,internal_func,channel,msgid,data,datalen,expiration,duration) < 0 ) |
|
|
|
errs++; |
|
|
|
free(retstr); |
|
|
|
} // else printf("duplicate.%d skipped\n",datalen);
|
|
|
|