Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
abd167dd58
  1. 15
      basilisk/basilisk.c
  2. 38
      basilisk/basilisk_DEX.c
  3. 27
      basilisk/basilisk_MSG.c
  4. 12
      basilisk/basilisk_tradebot.c

15
basilisk/basilisk.c

@ -559,8 +559,12 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi
if ( jobj(item,"myip") == 0 )
jaddstr(item,"myip",myinfo->ipaddr);
jaddi(pending->retarray,item);
} else printf("couldnt parse.(%s)\n",retstr);
if ( jobj(item,"error") == 0 )
{
printf("numresults.%d (%s)\n",pending->numresults,jprint(item,0));
pending->numresults++;
}
} else printf("couldnt parse.(%s)\n",retstr);
} //else printf("couldnt find issued.%u\n",basilisktag);
}
}
@ -628,12 +632,10 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
CMD[i] = toupper((int32_t)CMD[i]);
cmd[i] = tolower((int32_t)CMD[i]);
}
//origcmd[0] = 0;
if ( RELAYID >= 0 )
{
if ( basilisk_specialcmd(CMD) == 0 )
return;
//printf("MSGPROCESS %s.(%s) tag.%d\n",CMD,(char *)data,basilisktag);
}
symbol = "BTCD";
if ( senderipbits == 0 )
@ -641,9 +643,6 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
else expand_ipbits(remoteaddr,senderipbits);
if ( (valsobj= cJSON_Parse((char *)data)) != 0 )
{
//if ( origcmd[0] != 0 )
// jaddstr(valsobj,"origcmd",origcmd);
//printf("MSGVALS.(%s)\n",(char *)data);
if ( jobj(valsobj,"coin") != 0 )
coin = iguana_coinfind(jstr(valsobj,"coin"));
else if ( jobj(valsobj,"symbol") != 0 )
@ -766,7 +765,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
memset(&issueR,0,sizeof(issueR));
if ( (retstr= InstantDEX_incoming(myinfo,0,0,0,0)) != 0 )
{
//printf("poll.(%s)\n",retstr);
printf("poll.(%s)\n",retstr);
if ( (outerarray= cJSON_Parse(retstr)) != 0 )
{
if ( is_cJSON_Array(outerarray) != 0 )
@ -844,7 +843,7 @@ void basilisks_loop(void *arg)
coin->lastunspentsupdate = (uint32_t)time(NULL);
}
}
if ( RELAYID < 0 )
if ( RELAYID < 0 && myinfo->expiration != 0 )
basilisk_requests_poll(myinfo);
now = (uint32_t)time(NULL);
portable_mutex_lock(&myinfo->messagemutex);

38
basilisk/basilisk_DEX.c

@ -489,7 +489,6 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
else return(clonestr("{\"error\":\"DEX message couldnt be sent\"}"));
}
return(clonestr("{\"error\":\"DEX message not sent\"}"));
//return(basilisk_standardservice("DEX",myinfo,0,myinfo->myaddr.persistent,vals,"",1));
}
INT_ARG(InstantDEX,automatched,requestid)
@ -499,21 +498,36 @@ INT_ARG(InstantDEX,automatched,requestid)
return(clonestr("{\"result\":\"automatched not yet\"}"));
}
int32_t InstantDEX_incoming_func(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)
{
int32_t i;
for (i=0; i<datalen; i++)
printf("%02x",data[i]);
printf(" <- incoming\n");
return(0);
}
int32_t InstantDEX_process_channelget(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)
{
return((*internal_func)(myinfo,ptr,data,datalen));
}
INT_ARG(InstantDEX,incoming,requestid)
{
cJSON *vals; char *retstr;
cJSON *retjson,*retarray; uint32_t DEX_channel,msgid; int32_t retval; uint8_t data[8192];
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME;
//if ( myinfo->IAMLP != 0 )
// return(basilisk_respond_requests(myinfo,myinfo->myaddr.persistent,requestid,0));
//else
retjson = cJSON_CreateObject();
DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
msgid = (uint32_t)time(NULL) + 3;
if ( (retarray= basilisk_channelget(myinfo,myinfo->myaddr.persistent,DEX_channel,msgid,64)) != 0 )
{
vals = cJSON_CreateObject();
jaddnum(vals,"requestid",(uint32_t)requestid);
jaddbits256(vals,"hash",myinfo->myaddr.persistent);
retstr = basilisk_standardservice("RID",myinfo,0,myinfo->myaddr.persistent,vals,"",1);
free_json(vals);
return(retstr);
}
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");
} else jaddstr(retjson,"error","cant process InstantDEX retarray");
jadd(retjson,"responses",retarray);
} else jaddstr(retjson,"error","cant do InstantDEX channelget");
return(jprint(retjson,1));
}
/*TWO_INTS(InstantDEX,swapstatus,requestid,quoteid)

27
basilisk/basilisk_MSG.c

@ -54,22 +54,13 @@ cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int
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 )
{
//retjson = cJSON_CreateObject();
msgjson = cJSON_CreateObject();
jaddnum(msgjson,"expiration",msg->expiration);
jaddnum(msgjson,"duration",msg->duration);
//jadd(retjson,"message",msgjson);
printf("havemessage len.%d\n",msg->datalen);
}
else
{
//jaddstr(retjson,"error","couldnt add message");
printf("couldnt add message\n");
free_json(msgjson);
msgjson = 0;
}
} else printf("basilisk_respond_getmessage: couldnt basilisk_addhexstr\n");
}
portable_mutex_unlock(&myinfo->messagemutex);
return(msgjson);
@ -100,12 +91,12 @@ char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,cha
return(basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration));
}
char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t width)
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; cJSON *item,*retjson,*array; bits256 zero;
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();
if ( width > 3600 )
if ( (width= origwidth) > 3600 )
width = 3600;
else if ( width < 1 )
width = 1;
@ -114,7 +105,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
keylen = basilisk_messagekey(key,channel,msgid,srchash,desthash);
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);
if ( width > 0 )
if ( origwidth > 0 )
{
if ( bits256_nonz(srchash) != 0 )
{
@ -130,6 +121,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
}
if ( bits256_nonz(srchash) != 0 || bits256_nonz(desthash) != 0 )
{
printf("check broadcast %u %u\n",channel,msgid);
keylen = basilisk_messagekey(key,channel,msgid,zero,zero);
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);
@ -153,7 +145,7 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha
width = juint(valsobj,"width");
msgid = juint(valsobj,"msgid");
channel = juint(valsobj,"channel");
char str[65]; printf("%s channel.%u msgid.%x datalen.%d width.%d\n",bits256_str(str,hash),juint(valsobj,"channel"),msgid,datalen,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));
}
@ -248,7 +240,8 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t ch
msgid = (uint32_t)time(NULL);
jaddnum(valsobj,"msgid",msgid);
jaddnum(valsobj,"width",width);
jaddnum(valsobj,"fanout",1);
jaddnum(valsobj,"fanout",(int32_t)sqrt(NUMRELAYS)+1);
jaddnum(valsobj,"minresults",2);
if ( (retstr= basilisk_getmessage(myinfo,0,0,0,hash,valsobj,0)) != 0 )
{
printf("channel.%u msgid.%u gotmessage.(%s)\n",channel,msgid,retstr);

12
basilisk/basilisk_tradebot.c

@ -228,14 +228,15 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_request *issueR,cJSON *retjson,double hwm)
{
cJSON *array,*item; int32_t i,n,m; struct basilisk_request tmpR,R,refR,list[BASILISK_MAXRELAYS]; double metric=0.;
//printf("process_results.(%s)\n",jprint(retjson,0));
cJSON *array,*item; int32_t i,n,m,nonz; struct basilisk_request tmpR,R,refR,list[BASILISK_MAXRELAYS]; double metric=0.;
if ( (array= jarray(&n,retjson,"result")) != 0 )
{
for (i=m=0; i<n; i++)
for (i=nonz=m=0; i<n; i++)
{
item = jitem(array,i);
if ( i != 0 )
if ( jobj(item,"error") != 0 )
{
if ( nonz != 0 )
{
basilisk_parsejson(&R,item);
if ( refR.requestid == R.requestid )
@ -247,9 +248,12 @@ double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_req
m = 0;
}
}
nonz++;
if ( m < sizeof(list)/sizeof(*list) )
basilisk_parsejson(&list[m++],item);
}
}
printf("process_results n.%d m.%d nonz.%d\n",n,m,nonz);
if ( m > 0 && m < sizeof(list)/sizeof(*list) )
if ( (metric= basilisk_request_listprocess(myinfo,&tmpR,list,m)) > hwm )
*issueR = tmpR, hwm = metric;

Loading…
Cancel
Save