Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
29c1ea07f2
  1. 2
      basilisk/basilisk.c
  2. 23
      basilisk/basilisk_DEX.c
  3. 62
      basilisk/basilisk_MSG.c
  4. 2
      iguana/iguana777.h

2
basilisk/basilisk.c

@ -561,7 +561,7 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi
jaddi(pending->retarray,item); jaddi(pending->retarray,item);
if ( jobj(item,"error") == 0 ) if ( jobj(item,"error") == 0 )
{ {
printf("numresults.%d (%s)\n",pending->numresults,jprint(item,0)); //printf("numresults.%d (%s)\n",pending->numresults,jprint(item,0));
pending->numresults++; pending->numresults++;
} }
} else printf("couldnt parse.(%s)\n",retstr); } else printf("couldnt parse.(%s)\n",retstr);

23
basilisk/basilisk_DEX.c

@ -514,19 +514,32 @@ int32_t InstantDEX_process_channelget(struct supernet_info *myinfo,void *ptr,int
INT_ARG(InstantDEX,incoming,requestid) INT_ARG(InstantDEX,incoming,requestid)
{ {
cJSON *retjson,*retarray; uint32_t DEX_channel,msgid; int32_t retval; uint8_t data[8192]; cJSON *retjson,*retarray; uint32_t DEX_channel,msgid,now; int32_t retval,width,drift=3; uint8_t data[8192];
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; now = (uint32_t)time(NULL);
width = (now - myinfo->DEXpoll);
//if ( width < (drift+1) )
// width = 2*drift+1;
//else if ( width > 64 )
width = 64;
myinfo->DEXpoll = now;
myinfo->DEXactive = now + INSTANTDEX_LOCKTIME;
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();
DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
msgid = (uint32_t)time(NULL) + 3; msgid = (uint32_t)time(NULL) + drift;
if ( (retarray= basilisk_channelget(myinfo,myinfo->myaddr.persistent,DEX_channel,msgid,64)) != 0 ) if ( (retarray= basilisk_channelget(myinfo,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 ) if ( (retval= basilisk_process_retarray(myinfo,0,InstantDEX_process_channelget,data,sizeof(data),DEX_channel,msgid,retarray,InstantDEX_incoming_func)) > 0 )
{ {
jaddstr(retjson,"result","success"); jaddstr(retjson,"result","success");
} else jaddstr(retjson,"error","cant process InstantDEX retarray"); } else jaddstr(retjson,"error","cant process InstantDEX retarray");
jadd(retjson,"responses",retarray); jadd(retjson,"responses",retarray);
} else jaddstr(retjson,"error","cant do InstantDEX channelget"); }
else
{
jaddstr(retjson,"error","cant do InstantDEX channelget");
printf("error channelget\n");
}
return(jprint(retjson,1)); return(jprint(retjson,1));
} }

62
basilisk/basilisk_MSG.c

@ -57,14 +57,21 @@ cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int
msgjson = cJSON_CreateObject(); msgjson = cJSON_CreateObject();
if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),msg->data,msg->datalen) != 0 ) if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),msg->data,msg->datalen) != 0 )
{ {
jaddnum(msgjson,"expiration",msg->expiration); if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),key,keylen) != 0 )
jaddnum(msgjson,"duration",msg->duration); {
{int32_t i; for (i=0; i<keylen; i++) printf("%02x",key[i]); jaddnum(msgjson,"expiration",msg->expiration);
printf(" havemessage len.%d (%s)\n",msg->datalen,strbuf); } jaddnum(msgjson,"duration",msg->duration);
}
else
{
printf("basilisk_respond_getmessage: couldnt basilisk_addhexstr key\n");
free_json(msgjson);
msgjson = 0;
}
} }
else else
{ {
printf("basilisk_respond_getmessage: couldnt basilisk_addhexstr\n"); printf("basilisk_respond_getmessage: couldnt basilisk_addhexstr data.[%d]\n",msg->datalen);
free_json(msgjson); free_json(msgjson);
msgjson = 0; msgjson = 0;
} }
@ -150,7 +157,7 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha
width = juint(valsobj,"width"); width = juint(valsobj,"width");
msgid = juint(valsobj,"msgid"); msgid = juint(valsobj,"msgid");
channel = juint(valsobj,"channel"); 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); //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,"sender"),hash,width)); return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"sender"),hash,width));
} }
@ -218,22 +225,27 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t
return(retval); return(retval);
} }
int32_t basilisk_message_returned(uint8_t *data,int32_t maxlen,cJSON *item) int32_t basilisk_message_returned(uint8_t *key,uint8_t *data,int32_t maxlen,cJSON *json)
{ {
char *hexstr=0; cJSON *msgobj; int32_t datalen=0,retval = -1; char *keystr=0,*hexstr=0; int32_t i,n,datalen=0,retval = -1; cJSON *item,*msgobj;
if ( (msgobj= jobj(item,"message")) != 0 ) if ( (msgobj= jarray(&n,json,"messages")) != 0 )
{ {
if ( (hexstr= jstr(msgobj,"data")) != 0 && (datalen= is_hexstr(hexstr,0)) > 0 ) for (i=0; i<n; i++)
{ {
datalen >>= 1; item = jitem(msgobj,i);
if ( datalen < maxlen ) if ( (keystr= jstr(item,"key")) != 0 && is_hexstr(keystr,0) == BASILISK_KEYSIZE && (hexstr= jstr(item,"data")) != 0 && (datalen= is_hexstr(hexstr,0)) > 0 )
{ {
decode_hex(data,datalen,hexstr); decode_hex(key,BASILISK_KEYSIZE,keystr);
//printf("decoded hexstr.[%d]\n",datalen); datalen >>= 1;
retval = datalen; if ( datalen < maxlen )
} else printf("datalen.%d < maxlen.%d\n",datalen,maxlen); {
} else printf("no hexstr.%p or datalen.%d\n",hexstr,datalen); decode_hex(data,datalen,hexstr);
} //else printf("no msgobj\n"); //printf("decoded hexstr.[%d]\n",datalen);
retval = datalen;
} else printf("datalen.%d < maxlen.%d\n",datalen,maxlen);
}
}
}else printf("no hexstr.%p or datalen.%d (%s)\n",hexstr,datalen,jprint(json,0));
return(retval); return(retval);
} }
@ -269,20 +281,26 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t ch
int32_t basilisk_process_retarray(struct supernet_info *myinfo,void *ptr,int32_t (*process_func)(struct supernet_info *myinfo,void *ptr,int32_t (*internal_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen),uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t expiration,uint32_t duration),uint8_t *data,int32_t maxlen,uint32_t channel,uint32_t msgid,cJSON *retarray,int32_t (*internal_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)) int32_t basilisk_process_retarray(struct supernet_info *myinfo,void *ptr,int32_t (*process_func)(struct supernet_info *myinfo,void *ptr,int32_t (*internal_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen),uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t expiration,uint32_t duration),uint8_t *data,int32_t maxlen,uint32_t channel,uint32_t msgid,cJSON *retarray,int32_t (*internal_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen))
{ {
cJSON *item; uint32_t duration,expiration; int32_t i,n,datalen,errs = 0; cJSON *item; uint32_t duration,expiration; char *retstr; uint8_t key[BASILISK_KEYSIZE]; int32_t i,n,datalen,errs = 0;
if ( (n= cJSON_GetArraySize(retarray)) > 0 ) if ( (n= cJSON_GetArraySize(retarray)) > 0 )
{ {
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
item = jitem(retarray,i); item = jitem(retarray,i);
if ( (datalen= basilisk_message_returned(data,maxlen,item)) > 0 ) //printf("(%s).%d ",jprint(item,0),i);
if ( (datalen= basilisk_message_returned(key,data,maxlen,item)) > 0 )
{ {
duration = juint(item,"duration"); duration = juint(item,"duration");
expiration = juint(item,"expiration"); expiration = juint(item,"expiration");
if ( (*process_func)(myinfo,ptr,internal_func,channel,msgid,data,datalen,expiration,duration) < 0 ) if ( (retstr= basilisk_respond_addmessage(myinfo,key,BASILISK_KEYSIZE,data,datalen,0,duration)) != 0 )
errs++; {
if ( (*process_func)(myinfo,ptr,internal_func,channel,msgid,data,datalen,expiration,duration) < 0 )
errs++;
free(retstr);
}
} }
} }
//printf("n.%d maxlen.%d\n",n,maxlen);
} }
if ( errs > 0 ) if ( errs > 0 )
return(-errs); return(-errs);

2
iguana/iguana777.h

@ -65,7 +65,7 @@ struct supernet_info
char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024]; char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024];
char *decryptstr; char *decryptstr;
int32_t maxdelay,IAMRELAY,IAMLP,publicRPC,basilisk_busy,genesisresults; int32_t maxdelay,IAMRELAY,IAMLP,publicRPC,basilisk_busy,genesisresults;
uint32_t expiration,dirty,DEXactive; uint32_t expiration,dirty,DEXactive,DEXpoll;
uint16_t argport,rpcport; uint16_t argport,rpcport;
struct basilisk_info basilisks; struct basilisk_info basilisks;
struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges; struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges;

Loading…
Cancel
Save