Browse Source

test

etomic
jl777 8 years ago
parent
commit
9b37711662
  1. 1
      basilisk/basilisk.h
  2. 20
      basilisk/basilisk_DEX.c
  3. 11
      basilisk/basilisk_swap.c
  4. 4
      iguana/dPoW.h
  5. 21
      iguana/dpow/dpow_network.c

1
basilisk/basilisk.h

@ -141,5 +141,6 @@ int32_t basilisk_rwDEXquote(int32_t rwflag,uint8_t *serialized,struct basilisk_r
cJSON *basilisk_requestjson(struct basilisk_request *rp);
int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t depositflag,int32_t genflag);
void basilisk_txlog(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,int32_t delay);
int32_t basilisk_messagekey(uint8_t *key,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash);
#endif

20
basilisk/basilisk_DEX.c

@ -269,7 +269,7 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,u
void basilisk_requests_poll(struct supernet_info *myinfo)
{
static uint32_t lastpoll;
char *retstr; uint8_t data[32768],buf[4096]; cJSON *outerarray,*retjson; uint32_t msgid,crcs[2],crc,channel; int32_t datalen,i,n,numiters; struct basilisk_request issueR; double hwm = 0.;
char *retstr; uint8_t data[32768]; cJSON *outerarray,*retjson; uint32_t msgid,channel; int32_t datalen,i,n; struct basilisk_request issueR; double hwm = 0.;
if ( time(NULL) < lastpoll+3 )
return;
lastpoll = (uint32_t)time(NULL);
@ -306,24 +306,27 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
free(retstr);*/
if ( bits256_cmp(myinfo->myaddr.persistent,issueR.srchash) == 0 ) // my request
{
if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 )
dex_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid)); // 60
if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 )
free(retstr);
/*if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 )
free(retstr);
printf("my req hwm %f -> %u\n",hwm,issueR.requestid);
basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60);
numiters = crc = 0;
/*while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),crcs)) == 0 )
while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),crcs)) == 0 )
{
printf("didnt get back what was sent\n");
sleep(3);
basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60);
numiters++;
}
if ( crc != 0 )*/
if ( crc != 0 )
{
printf("crc.%08x -> basilisk_starta\n",crc);
if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 )
free(retstr);
} // else printf("couldnt accept offer\n");
} // else printf("couldnt accept offer\n");*/
}
else //if ( issueR.quoteid == 0 )
{
@ -332,7 +335,10 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
issueR.desthash = myinfo->myaddr.persistent;
datalen = basilisk_rwDEXquote(1,data,&issueR);
msgid = (uint32_t)time(NULL);
crcs[0] = crcs[1] = 0;
dex_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen); //INSTANTDEX_LOCKTIME*2
if ( (retstr= basilisk_start(myinfo,&issueR,0,issueR.optionhours * 3600)) != 0 )
free(retstr);
/*crcs[0] = crcs[1] = 0;
numiters = 0;
basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2);
while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),issueR.desthash,issueR.srchash,channel,msgid,data,datalen,crcs)) == 0 )
@ -347,7 +353,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
printf("crc.%08x -> basilisk_start\n",crc);
if ( (retstr= basilisk_start(myinfo,&issueR,0,issueR.optionhours * 3600)) != 0 )
free(retstr);
}
}*/
} //else printf("basilisk_requests_poll unexpected hwm issueR\n");
}
}

11
basilisk/basilisk_swap.c

@ -867,10 +867,10 @@ int32_t basilisk_swapget(struct supernet_info *myinfo,struct basilisk_swap *swap
uint32_t basilisk_swapsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t nextbits,uint32_t crcs[2])
{
//if ( (rand() % 10) == 0 )
basilisk_channelsend(myinfo,swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2);
if ( basilisk_crcsend(myinfo,0,swap->verifybuf,sizeof(swap->verifybuf),swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen,crcs) != 0 )
return(nextbits);
basilisk_channelsend(myinfo,swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2);
// basilisk_channelsend(myinfo,swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2);
//if ( basilisk_crcsend(myinfo,0,swap->verifybuf,sizeof(swap->verifybuf),swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen,crcs) != 0 )
//return(nextbits);
dex_channelsend(myinfo,swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen); //INSTANTDEX_LOCKTIME*2
return(0);
}
@ -1711,7 +1711,8 @@ void basilisk_swaploop(void *_swap)
while ( (swap->I.statebits & (0x08|0x02)) != (0x08|0x02) && time(NULL) < expiration )
{
printf("A r%u/q%u swapstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits);
basilisk_channelsend(myinfo,swap->I.req.srchash,swap->I.req.desthash,channel,0x4000000,(void *)&swap->I.req.requestid,sizeof(swap->I.req.requestid),60);
//basilisk_channelsend(myinfo,swap->I.req.srchash,swap->I.req.desthash,channel,0x4000000,(void *)&swap->I.req.requestid,sizeof(swap->I.req.requestid),60);
dex_channelsend(myinfo,swap->I.req.srchash,swap->I.req.desthash,channel,0x4000000,(void *)&swap->I.req.requestid,sizeof(swap->I.req.requestid)); //,60);
basilisk_sendstate(myinfo,swap,data,maxlen);
basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys
if ( basilisk_checkdeck(myinfo,swap,data,maxlen) == 0) // check for other deck 0x02

4
iguana/dPoW.h

@ -45,7 +45,7 @@
#define DPOW_MAXRELAYS 64
#define DPOW_MAXSIGLEN 128
#define DEX_VERSION 0x0103
#define DEX_VERSION 0x0104
#define DPOW_SOCK 7775
#define DEX_SOCK 7774
#define PUB_SOCK 7773
@ -183,4 +183,6 @@ char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol);
int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height);
cJSON *dpow_checkaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address);
void dex_channelsend(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen);
#endif

21
iguana/dpow/dpow_network.c

@ -278,7 +278,7 @@ void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t
}
}
char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen)
char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen)
{
struct dex_nanomsghdr *dexp; cJSON *retjson; char ipaddr[64],str[128]; int32_t timeout,i,n,size,recvbytes,sentbytes = 0,reqsock,subsock; uint32_t *retptr,ipbits; void *freeptr; char *retstr = 0;
portable_mutex_lock(&myinfo->dexmutex);
@ -328,7 +328,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
portable_mutex_unlock(&myinfo->dexmutex);
if ( myinfo->reqsock >= 0 )
{
size = (int32_t)(sizeof(*dexp) + datalen);
size = (int32_t)(sizeof(*dexp) + keylen + datalen);
dexp = calloc(1,size); // endian dependent!
safecopy(dexp->handler,handler,sizeof(dexp->handler));
dexp->size = size;
@ -336,7 +336,12 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
dexp->timestamp = (uint32_t)time(NULL);
dexp->version0 = DEX_VERSION & 0xff;
dexp->version1 = (DEX_VERSION >> 8) & 0xff;
memcpy(dexp->packet,data,datalen);
if ( key != 0 && keylen != 0 )
{
memcpy(dexp->packet,key,keylen);
memcpy(&dexp->packet[keylen],data,datalen);
}
else memcpy(dexp->packet,data,datalen);
dexp->crc32 = calc_crc32(0,data,datalen);
for (i=0; i<100; i++)
{
@ -417,6 +422,14 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
return(retstr);
}
void dex_channelsend(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen)
{
int32_t keylen; uint8_t key[BASILISK_KEYSIZE]; char *retstr;
keylen = basilisk_messagekey(key,channel,msgid,srchash,desthash);
if ( (retstr= _dex_reqsend(myinfo,"DEX",key,keylen,data,datalen)) != 0 )
free(retstr);
}
void dpow_randipbits(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *retjson)
{
int32_t m; uint32_t ipbits; char *coinstr;
@ -593,7 +606,7 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32
memset(retstrs,0,sizeof(retstrs));
for (i=j=0; i<=max; i++)
{
if ( (retstrs[j]= _dex_reqsend(myinfo,handler,data,datalen)) != 0 )
if ( (retstrs[j]= _dex_reqsend(myinfo,handler,0,0,data,datalen)) != 0 )
{
//printf("j.%d of max.%d M.%d (%s)\n",j,max,M,retstrs[j]);
if ( strncmp(retstrs[j],"{\"error\":\"null return\"}",strlen("{\"error\":\"null return\"}")) != 0 && strncmp(retstrs[j],"[]",strlen("[]")) != 0 && strcmp("0",retstrs[j]) != 0 )

Loading…
Cancel
Save