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