Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
59b066159e
  1. 43
      basilisk/basilisk.c
  2. 1
      basilisk/basilisk.h
  3. 25
      basilisk/basilisk_CMD.c
  4. 2
      iguana/iguana_instantdex.c
  5. 2
      iguana/tests/request
  6. 3
      includes/iguana_structs.h

43
basilisk/basilisk.c

@ -600,7 +600,7 @@ int32_t basilisk_relay_unping(struct supernet_info *myinfo,uint8_t *data,int32_t
int32_t basilisk_relays_ping(struct supernet_info *myinfo,uint8_t *data,int32_t maxlen) int32_t basilisk_relays_ping(struct supernet_info *myinfo,uint8_t *data,int32_t maxlen)
{ {
struct iguana_info *virt,*tmpcoin; int32_t i,iter,datalen = 0; uint32_t n; struct iguana_info *virt,*tmpcoin; struct queueitem *item,*tmp; uint8_t clen; int32_t i,iter,offset,datalen = 0; uint32_t n; uint16_t sn; uint32_t timestamp,now;
data[datalen++] = myinfo->numrelays; data[datalen++] = myinfo->numrelays;
for (iter=n=0; iter<2; iter++) for (iter=n=0; iter<2; iter++)
{ {
@ -622,6 +622,29 @@ int32_t basilisk_relays_ping(struct supernet_info *myinfo,uint8_t *data,int32_t
} }
for (i=0; i<myinfo->numrelays; i++) for (i=0; i<myinfo->numrelays; i++)
datalen += basilisk_relay_ping(myinfo,&data[datalen],maxlen - datalen,&myinfo->relays[i]); datalen += basilisk_relay_ping(myinfo,&data[datalen],maxlen - datalen,&myinfo->relays[i]);
offset = datalen, datalen += sizeof(uint16_t);
i = 0;
now = (uint32_t)time(NULL);
portable_mutex_lock(&myinfo->DEX_mutex);
DL_FOREACH_SAFE(myinfo->DEX_quotes,item,tmp)
{
memcpy(&clen,&item[1],sizeof(clen));
if ( datalen+clen < maxlen )
{
memcpy(&data[datalen],&item[1],clen+1), datalen += (clen + 1);
i++;
}
iguana_rwnum(0,(void *)((long)&item[1] + 1),sizeof(timestamp),&timestamp);
if ( now > timestamp + BASILISK_DEXDURATION )
{
DL_DELETE(myinfo->DEX_quotes,item);
free(item);
}
}
sn = i;
datalen += iguana_rwnum(1,&data[datalen],sizeof(sn),&sn);
portable_mutex_unlock(&myinfo->DEX_mutex);
//for (i=0; i<datalen; i++) //for (i=0; i<datalen; i++)
// printf("%02x",data[i]); // printf("%02x",data[i]);
//printf(" <- output ping\n"); //printf(" <- output ping\n");
@ -664,7 +687,7 @@ int32_t basilisk_blocksend(struct supernet_info *myinfo,struct iguana_info *btcd
void basilisk_respond_ping(struct supernet_info *myinfo,struct iguana_peer *addr,uint32_t senderipbits,uint8_t *data,int32_t datalen) void basilisk_respond_ping(struct supernet_info *myinfo,struct iguana_peer *addr,uint32_t senderipbits,uint8_t *data,int32_t datalen)
{ {
int32_t diff,i,j,n,len = 0; struct iguana_info *btcd,*virt; char ipbuf[64],symbol[7]; struct basilisk_relay *rp; uint8_t numrelays; uint32_t numvirts,height,now = (uint32_t)time(NULL); int32_t diff,i,j,n,len = 0; struct iguana_info *btcd,*virt; char ipbuf[64],symbol[7]; struct basilisk_relay *rp; uint8_t numrelays,clen,serialized[256]; uint16_t sn; uint32_t numvirts,height,now = (uint32_t)time(NULL);
expand_ipbits(ipbuf,senderipbits); expand_ipbits(ipbuf,senderipbits);
btcd = iguana_coinfind("BTCD"); btcd = iguana_coinfind("BTCD");
for (i=0; i<myinfo->numrelays; i++) for (i=0; i<myinfo->numrelays; i++)
@ -718,7 +741,18 @@ void basilisk_respond_ping(struct supernet_info *myinfo,struct iguana_peer *addr
break; break;
len += n; len += n;
} }
//printf("PING got %d, processed.%d from (%s)\n",datalen,len,ipbuf); len += iguana_rwnum(1,&data[len],sizeof(sn),&sn);
char src[16],dest[16],message[128]; bits256 hash; uint64_t amount; uint32_t timestamp;
for (i=0; i<n; i++)
{
clen = data[len++];
memcpy(serialized,&data[len],clen), len += clen;
len += basilisk_rwDEXquote(0,serialized,&hash,src,&amount,dest,&timestamp,message);
printf("(%s (%s %.8f) -> %s) ",message,src,dstr(amount),dest);
}
if ( len != datalen )
printf("PING got %d, processed.%d from (%s)\n",datalen,len,ipbuf);
else printf("\n");
} }
void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t senderipbits,char *type,uint32_t basilisktag,uint8_t *data,int32_t datalen) void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t senderipbits,char *type,uint32_t basilisktag,uint8_t *data,int32_t datalen)
@ -925,7 +959,7 @@ void basilisks_loop(void *arg)
//portable_mutex_unlock(&myinfo->allcoins_mutex); //portable_mutex_unlock(&myinfo->allcoins_mutex);
if ( (rand() % 10) == 0 && myinfo->RELAYID >= 0 ) if ( (rand() % 10) == 0 && myinfo->RELAYID >= 0 )
{ {
struct iguana_peer *addr; struct basilisk_relay *rp; int32_t i,datalen=0; uint8_t data[32768]; struct iguana_peer *addr; struct basilisk_relay *rp; int32_t i,datalen=0; uint8_t data[32768]; // need bigger buffer
datalen = basilisk_relays_ping(myinfo,&data[sizeof(struct iguana_msghdr)],sizeof(data)-sizeof(struct iguana_msghdr)); datalen = basilisk_relays_ping(myinfo,&data[sizeof(struct iguana_msghdr)],sizeof(data)-sizeof(struct iguana_msghdr));
for (i=0; i<myinfo->numrelays; i++) for (i=0; i<myinfo->numrelays; i++)
{ {
@ -956,6 +990,7 @@ void basilisks_init(struct supernet_info *myinfo)
//iguana_initQ(&myinfo->basilisks.resultsQ,"resultsQ"); //iguana_initQ(&myinfo->basilisks.resultsQ,"resultsQ");
portable_mutex_init(&myinfo->allcoins_mutex); portable_mutex_init(&myinfo->allcoins_mutex);
portable_mutex_init(&myinfo->basilisk_mutex); portable_mutex_init(&myinfo->basilisk_mutex);
portable_mutex_init(&myinfo->DEX_mutex);
portable_mutex_init(&myinfo->gecko_mutex); portable_mutex_init(&myinfo->gecko_mutex);
myinfo->basilisks.launched = iguana_launch(iguana_coinfind("BTCD"),"basilisks_loop",basilisks_loop,myinfo,IGUANA_PERMTHREAD); myinfo->basilisks.launched = iguana_launch(iguana_coinfind("BTCD"),"basilisks_loop",basilisks_loop,myinfo,IGUANA_PERMTHREAD);
} }

1
basilisk/basilisk.h

@ -23,6 +23,7 @@
#define BASILISK_MAXFANOUT 64 #define BASILISK_MAXFANOUT 64
#define BASILISK_DEFAULTDIFF 0x1effffff #define BASILISK_DEFAULTDIFF 0x1effffff
#define BASILISK_MAXRELAYS 64 #define BASILISK_MAXRELAYS 64
#define BASILISK_DEXDURATION 60
#define BASILISK_MAXFUTUREBLOCK 60 #define BASILISK_MAXFUTUREBLOCK 60
//#define BASILISK_MAXBLOCKLAG 600 //#define BASILISK_MAXBLOCKLAG 600

25
basilisk/basilisk_CMD.c

@ -124,13 +124,34 @@ void basilisk_request_goodbye(struct supernet_info *myinfo)
free_json(valsobj); free_json(valsobj);
} }
int32_t basilisk_rwDEXquote(int32_t rwflag,uint8_t *serialized,bits256 *hashp,char *src,uint64_t *amountp,char *dest,uint32_t *timestampp,char *message)
{
int32_t len = 0;
len += iguana_rwnum(rwflag,&serialized[len],sizeof(*timestampp),timestampp);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(*hashp),hashp->bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(*amountp),amountp);
len += iguana_rwvarstr(rwflag,&serialized[len],8,src);
len += iguana_rwvarstr(rwflag,&serialized[len],8,dest);
if ( message == 0 )
message = "";
len += iguana_rwvarstr(rwflag,&serialized[len],128,message);
return(len);
}
char *basilisk_respond_instantdex(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) char *basilisk_respond_instantdex(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)
{ {
char *dest,*src,*retstr=0; uint64_t satoshis; char *dest,*src,*retstr=0; int32_t len; uint32_t timestamp; uint64_t satoshis; uint8_t serialized[64]; struct queueitem *item;
if ( (dest= jstr(valsobj,"dest")) != 0 && (src= jstr(valsobj,"src")) != 0 && (satoshis= j64bits(valsobj,"satoshis")) != 0 ) if ( (dest= jstr(valsobj,"dest")) != 0 && (src= jstr(valsobj,"src")) != 0 && (satoshis= j64bits(valsobj,"satoshis")) != 0 )
{ {
char str[65]; printf("DEX.(%s %.8f) -> %s %s\n",src,dstr(satoshis),dest,bits256_str(str,hash)); char str[65]; printf("DEX.(%s %.8f) -> %s %s\n",src,dstr(satoshis),dest,bits256_str(str,hash));
timestamp = (uint32_t)time(NULL);
len = basilisk_rwDEXquote(1,serialized+1,&hash,src,&satoshis,dest,&timestamp,jstr(valsobj,"msg"));
serialized[0] = len;
item = calloc(1,sizeof(*item) + len + 1);
memcpy(&item[1],serialized,len + 1);
portable_mutex_lock(&myinfo->DEX_mutex);
DL_APPEND(myinfo->DEX_quotes,item);
portable_mutex_unlock(&myinfo->DEX_mutex);
retstr = clonestr("{\"result\":\"DEX quote added\"}"); retstr = clonestr("{\"result\":\"DEX quote added\"}");
} }
//instantdex_quotep2p(myinfo,0,addr,data,datalen); //instantdex_quotep2p(myinfo,0,addr,data,datalen);

2
iguana/iguana_instantdex.c

@ -1738,6 +1738,8 @@ THREE_STRINGS_AND_DOUBLE(InstantDEX,request,message,dest,source,amount)
char *retstr; cJSON *vals = cJSON_CreateObject(); char *retstr; cJSON *vals = cJSON_CreateObject();
jaddstr(vals,"dest",dest); jaddstr(vals,"dest",dest);
jaddstr(vals,"src",source); jaddstr(vals,"src",source);
if ( strlen(message) < 128 )
jaddstr(vals,"msg",message);
jadd64bits(vals,"satoshis",amount * SATOSHIDEN); jadd64bits(vals,"satoshis",amount * SATOSHIDEN);
retstr = basilisk_standardservice("DEX",myinfo,0,myinfo->myaddr.persistent,vals,"",1); retstr = basilisk_standardservice("DEX",myinfo,0,myinfo->myaddr.persistent,vals,"",1);
free_json(vals); free_json(vals);

2
iguana/tests/request

@ -0,0 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"message\":\"message\",\"dest\":\"BTC\",\"source\":\"BTCD\",\"amount\":0.01}"

3
includes/iguana_structs.h

@ -463,11 +463,12 @@ struct supernet_info
struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges; struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges;
struct iguana_waccount *wallet; struct iguana_waccount *wallet;
struct iguana_info *allcoins; int32_t allcoins_being_added,allcoins_numvirts; struct iguana_info *allcoins; int32_t allcoins_being_added,allcoins_numvirts;
portable_mutex_t allcoins_mutex,gecko_mutex,basilisk_mutex; portable_mutex_t allcoins_mutex,gecko_mutex,basilisk_mutex,DEX_mutex;
void *ctx; void *ctx;
struct delayedPoW_info dPoW; struct delayedPoW_info dPoW;
struct basilisk_relay relays[BASILISK_MAXRELAYS]; struct basilisk_relay relays[BASILISK_MAXRELAYS];
int32_t numrelays,RELAYID; int32_t numrelays,RELAYID;
struct queueitem *DEX_quotes;
// compatibility // compatibility
bits256 pangea_category,instantdex_category; bits256 pangea_category,instantdex_category;
}; };

Loading…
Cancel
Save