Browse Source

Merge branch 'master' into release/v0.1

release/v0.1
jl777 8 years ago
parent
commit
f69649af98
  1. 4
      basilisk/basilisk.c
  2. 4
      basilisk/basilisk.h
  3. 107
      basilisk/basilisk_MSG.c
  4. 6
      basilisk/basilisk_ping.c
  5. 7
      iguana/iguana777.c
  6. 2
      iguana/iguana777.h
  7. 3
      iguana/iguana_bundles.c
  8. 2
      iguana/iguana_init.c
  9. 19
      iguana/iguana_recv.c
  10. 17
      iguana/iguana_rpc.c
  11. 26
      iguana/main.c
  12. 1
      iguana/tests/amlp
  13. 2
      includes/iguana_structs.h

4
basilisk/basilisk.c

@ -244,7 +244,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
break;
if ( s == myinfo->NOTARY.NUMRELAYS )
{
printf("skip non-relay.(%s)\n",addr->ipaddr);
//printf("skip non-relay.(%s)\n",addr->ipaddr);
continue;
}
valid = 1;
@ -806,7 +806,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 ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (outerarray= jarray(&n,retjson,"responses")) != 0 )

4
basilisk/basilisk.h

@ -85,8 +85,8 @@ struct basilisk_item
struct basilisk_message
{
struct queueitem DL; UT_hash_handle hh;
uint32_t datalen,expiration,duration;
uint8_t key[BASILISK_KEYSIZE],keylen;
uint32_t expiration,duration,datalen;
uint8_t keylen,broadcast,key[BASILISK_KEYSIZE];
uint8_t data[];
};

107
basilisk/basilisk_MSG.c

@ -17,7 +17,7 @@
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;
struct basilisk_message *msg; int32_t i; bits256 desthash;
HASH_FIND(hh,myinfo->messagetable,key,keylen,msg);
if ( msg == 0 && keylen == BASILISK_KEYSIZE )
{
@ -26,6 +26,11 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3
duration = BASILISK_MSGDURATION;
else if ( duration > INSTANTDEX_LOCKTIME*2 )
duration = INSTANTDEX_LOCKTIME*2;
memcpy(desthash.bytes,&key[BASILISK_KEYSIZE - sizeof(desthash)],sizeof(desthash));
if ( bits256_nonz(desthash) == 0 )
msg->broadcast = 1;
if ( bits256_nonz(desthash) == 0 )
msg->broadcast = 1;
msg->duration = duration;
msg->expiration = (uint32_t)time(NULL) + duration;
msg->keylen = keylen;
@ -47,34 +52,49 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3
} else return(0);
}
cJSON *basilisk_msgjson(struct basilisk_message *msg,uint8_t *key,int32_t keylen)
{
cJSON *msgjson=0; char *ptr = 0,strbuf[32768],keystr[BASILISK_KEYSIZE*2+1];
msgjson = cJSON_CreateObject();
if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),msg->data,msg->datalen) != 0 )
{
init_hexbytes_noT(keystr,key,keylen);
jaddstr(msgjson,"key",keystr);
jaddnum(msgjson,"expiration",msg->expiration);
jaddnum(msgjson,"duration",msg->duration);
}
else
{
printf("basilisk_respond_getmessage: couldnt basilisk_addhexstr data.[%d]\n",msg->datalen);
free_json(msgjson);
msgjson = 0;
}
return(msgjson);
}
cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen)
{
cJSON *msgjson=0; struct basilisk_message *msg; char *ptr = 0,strbuf[32768],keystr[BASILISK_KEYSIZE*2+1];
cJSON *msgjson = 0; struct basilisk_message *msg;
portable_mutex_lock(&myinfo->messagemutex);
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 )
{
init_hexbytes_noT(keystr,key,keylen);
jaddstr(msgjson,"key",keystr);
jaddnum(msgjson,"expiration",msg->expiration);
jaddnum(msgjson,"duration",msg->duration);
}
else
{
printf("basilisk_respond_getmessage: couldnt basilisk_addhexstr data.[%d]\n",msg->datalen);
free_json(msgjson);
msgjson = 0;
}
}
if ( msg != 0 && msg->broadcast == 0 )
msgjson = basilisk_msgjson(msg,key,keylen);
portable_mutex_unlock(&myinfo->messagemutex);
return(msgjson);
}
// respond to incoming OUT, MSG
int32_t basilisk_messagekeyread(uint8_t *key,uint32_t *channelp,uint32_t *msgidp,bits256 *srchashp,bits256 *desthashp)
{
int32_t keylen = 0;
keylen += iguana_rwnum(0,&key[keylen],sizeof(uint32_t),channelp);
keylen += iguana_rwnum(0,&key[keylen],sizeof(uint32_t),msgidp);
keylen += iguana_rwbignum(0,&key[keylen],sizeof(*srchashp),srchashp->bytes);
keylen += iguana_rwbignum(0,&key[keylen],sizeof(*desthashp),desthashp->bytes);
return(keylen);
}
int32_t basilisk_messagekey(uint8_t *key,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash)
{
int32_t keylen = 0;
@ -87,26 +107,56 @@ int32_t basilisk_messagekey(uint8_t *key,uint32_t channel,uint32_t msgid,bits256
char *basilisk_respond_OUT(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)
{
int32_t keylen,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 senderhash;
int32_t keylen,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 senderhash; char *retstr;
senderhash = jbits256(valsobj,"sender");
duration = juint(valsobj,"duration");
keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,hash);
if( bits256_nonz(senderhash) == 0 && bits256_nonz(hash) == 0 && duration > BASILISK_MSGDURATION )
duration = BASILISK_MSGDURATION;
retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration);
if ( bits256_nonz(hash) == 0 )
{
if ( duration > BASILISK_MSGDURATION )
duration = BASILISK_MSGDURATION;
}
// 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(basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration));
return(retstr);
}
int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash)
{
uint32_t keychannel,keymsgid; bits256 keysrc,keydest;
basilisk_messagekeyread(msg->key,&keychannel,&keymsgid,&keysrc,&keydest);
if ( bits256_nonz(srchash) == 0 || bits256_cmp(srchash,keysrc) == 0 )
{
if ( bits256_nonz(desthash) == 0 || bits256_cmp(desthash,keydest) == 0 )
{
while ( width >= 0 )
{
if ( msgid == keymsgid && keychannel == channel )
return(0);
msgid--;
}
return(-1);
} else return(-2);
} else return(-3);
}
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,width; cJSON *item,*retjson,*array; bits256 zero;
struct basilisk_message *msg,*tmpmsg; 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= origwidth) > 3600 )
width = 3600;
else if ( width < 1 )
width = 1;
portable_mutex_lock(&myinfo->messagemutex);
HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg)
{
if ( msg->broadcast != 0 && basilisk_msgcmp(msg,origwidth,channel,msgid,zero,zero) == 0 )
jaddi(array,basilisk_msgjson(msg,msg->key,msg->keylen));
}
portable_mutex_unlock(&myinfo->messagemutex);
//printf("iterate_MSG width.%d channel.%d msgid.%d src.%llx -> %llx\n",origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid);
for (i=0; i<width; i++)
{
@ -124,13 +174,10 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
if ( bits256_nonz(desthash) != 0 )
{
keylen = basilisk_messagekey(key,channel,msgid,srchash,zero);
//int32_t j; for (j=0; j<keylen; j++)
// printf("%02x",key[j]);
//printf(" <- key\n");
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 )
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 )
@ -187,7 +234,9 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
{
keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"sender"),hash);
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"));
}
if ( ptr != 0 )
free(ptr);
if ( retstr != 0 )
@ -292,7 +341,7 @@ int32_t basilisk_process_retarray(struct supernet_info *myinfo,void *ptr,int32_t
expiration = juint(item,"expiration");
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 )
if ( (*process_func)(myinfo,ptr,internal_func,channel,msgid,data,datalen,expiration,duration) < 0 )
errs++;
free(retstr);
} // else printf("duplicate.%d skipped\n",datalen);

6
basilisk/basilisk_ping.c

@ -107,7 +107,7 @@ int32_t basilisk_ping_genvirts(struct supernet_info *myinfo,uint8_t *data,int32_
int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipbits,uint8_t *data,int32_t datalen)
{
int32_t i,msglen,len=0; uint8_t num,keylen,*msg,*key; uint32_t duration;
int32_t i,msglen,len=0; uint8_t num,keylen,*message,*key; uint32_t duration;
if ( (num= data[len++]) > 0 )
{
//printf("processMSG num.%d datalen.%d\n",num,datalen);
@ -127,14 +127,14 @@ int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipb
}
len += iguana_rwnum(0,&data[len],sizeof(msglen),&msglen);
len += iguana_rwnum(0,&data[len],sizeof(duration),&duration);
msg = &data[len], len += msglen;
message = &data[len], len += msglen;
if ( msglen <= 0 || len > datalen )
{
printf("illegal msglen.%d or len.%d > %d\n",msglen,len,datalen);
return(0);
}
//printf("i.%d: keylen.%d msglen.%d\n",i,keylen,msglen);
basilisk_respond_addmessage(myinfo,key,keylen,msg,msglen,0,duration);
basilisk_respond_addmessage(myinfo,key,keylen,message,msglen,0,duration);
}
}
return(len);

7
iguana/iguana777.c

@ -933,18 +933,21 @@ void iguana_coinloop(void *arg)
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 || coin->MAXPEERS == 1 )
{
portable_mutex_lock(&coin->allcoins_mutex);
coin->busy_processing = 1;
flag += iguana_processrecv(myinfo,coin);
coin->busy_processing = 0;
portable_mutex_unlock(&coin->allcoins_mutex);
if ( strcmp(coin->symbol,"BTCD") == 0 && coin->RTheight > 0 && coin->RTheight > coin->chain->bundlesize )
/*if ( strcmp(coin->symbol,"BTCD") == 0 && coin->RTheight > 0 && coin->RTheight > coin->chain->bundlesize )
{
int32_t hdrsi,nonz,errs; struct iguana_pkhash *refP; struct iguana_bundle *bp;
hdrsi = (coin->RTheight / coin->chain->bundlesize) - 1;
if ( 0 && (bp= coin->bundles[hdrsi]) != 0 && bp->weights == 0 )
bp->weights = iguana_PoS_weights(myinfo,coin,&refP,&bp->supply,&bp->numweights,&nonz,&errs,bp->bundleheight);
}
}*/
}
}
coin->idletime = (uint32_t)time(NULL);
iguana_jsonQ(myinfo,coin);
}
}
//iguana_jsonQ();

2
iguana/iguana777.h

@ -76,7 +76,7 @@ struct supernet_info
uint8_t persistent_pubkey33[33];
char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024];
char *decryptstr;
int32_t maxdelay,IAMRELAY,IAMNOTARY,IAMLP,publicRPC,basilisk_busy,genesisresults;
int32_t maxdelay,IAMRELAY,IAMNOTARY,IAMLP,publicRPC,basilisk_busy,genesisresults,remoteorigin;
uint32_t expiration,dirty,DEXactive,DEXpoll;
uint16_t argport,rpcport;
struct basilisk_info basilisks;

3
iguana/iguana_bundles.c

@ -882,7 +882,7 @@ int32_t iguana_bundlehdr(struct supernet_info *myinfo,struct iguana_info *coin,s
bp->hdrtime = (uint32_t)time(NULL);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
}
if ( strcmp("BTC",coin->symbol) != 0 && (bp == coin->current || bp->hdrsi == coin->bundlescount-1) && bits256_nonz(bp->nextbundlehash2) == 0 )
if ( time(NULL) > bp->hdrtime+dist && strcmp("BTC",coin->symbol) != 0 && (bp == coin->current || bp->hdrsi == coin->bundlescount-1) && bits256_nonz(bp->nextbundlehash2) == 0 )
{
if ( bp->numhashes < bp->n && bp->numcached < bp->n )
{
@ -890,6 +890,7 @@ int32_t iguana_bundlehdr(struct supernet_info *myinfo,struct iguana_info *coin,s
for (i=0; i<bp->n; i++)
if ( GETBIT(bp->haveblock,i) == 0 )
bp->issued[i] = 0;
bp->hdrtime = (uint32_t)time(NULL);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
}
iguana_bundleissuemissing(myinfo,coin,bp,3,3.);

2
iguana/iguana_init.c

@ -378,7 +378,7 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3
{
if ( iguana_bundleinitmap(myinfo,coin,bp,height,hash2,hash1) == 0 )
lastbundle = hash2, lastheight = height;
else if ( missing++ > coin->MAXBUNDLES && strcmp("BTCD",coin->symbol) != 0 )
else if ( 0 && missing++ > coin->MAXBUNDLES && strcmp("BTCD",coin->symbol) != 0 )
{
printf("missing.%d\n",missing);
break;

19
iguana/iguana_recv.c

@ -1056,10 +1056,11 @@ void iguana_bundlespeculate(struct iguana_info *coin,struct iguana_bundle *bp,in
{
if ( bp == 0 )
return;
if ( strcmp("BTC",coin->symbol) != 0 && bp->numhashes < bp->n && bundlei == 0 && bp->speculative == 0 && bp->bundleheight < coin->longestchain-coin->chain->bundlesize )
if ( time(NULL) > bp->hdrtime+3 && strcmp("BTC",coin->symbol) != 0 && bp->numhashes < bp->n && bundlei == 0 && bp->speculative == 0 && bp->bundleheight < coin->longestchain-coin->chain->bundlesize )
{
char str[65]; bits256_str(str,bp->hashes[0]);
//fprintf(stderr,"Afound block -> %d %d hdr.%s\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,str);
bp->hdrtime = (uint32_t)time(NULL);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
}
}
@ -1447,8 +1448,11 @@ void iguana_autoextend(struct supernet_info *myinfo,struct iguana_info *coin,str
newbp = iguana_bundlecreate(coin,&bundlei,bp->bundleheight+coin->chain->bundlesize,bp->nextbundlehash2,zero,1);
if ( newbp != 0 )
{
if ( newbp->speculative == 0 )
if ( time(NULL) > bp->hdrtime+3 && newbp->speculative == 0 )
{
bp->hdrtime = (uint32_t)time(NULL);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1);
}
//char str[65],str2[65]; printf("EXTEND last bundle %s/%s ht.%d\n",bits256_str(str,newbp->hashes[0]),bits256_str(str2,bp->nextbundlehash2),newbp->bundleheight);
if ( newbp->queued == 0 )
iguana_bundleQ(myinfo,coin,newbp,1000);
@ -1711,9 +1715,10 @@ struct iguana_bundlereq *iguana_recvblock(struct supernet_info *myinfo,struct ig
}
} // else printf("RECV MAINCHAIN.%d\n",coin->blocks.hwmchain.height);
}
if ( 0 && bundlei == 1 && bp != 0 && bp->numhashes < bp->n && strcmp("BTC",coin->symbol) != 0 && bp->speculative == 0 && bp == coin->current )
if ( 0 && time(NULL) > bp->hdrtime+3 && bundlei == 1 && bp != 0 && bp->numhashes < bp->n && strcmp("BTC",coin->symbol) != 0 && bp->speculative == 0 && bp == coin->current )
{
printf("reissue hdrs request for [%d]\n",bp->hdrsi);
bp->hdrtime = (uint32_t)time(NULL);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
}
if ( (block= iguana_blockhashset("recvblock",coin,-1,origblock->RO.hash2,1)) != 0 )
@ -1977,7 +1982,7 @@ int32_t iguana_needhdrs(struct iguana_info *coin)
int32_t iguana_reqhdrs(struct iguana_info *coin)
{
int32_t i,lag,n = 0; struct iguana_bundle *bp; char hashstr[65];
int32_t i,lag,n = 0; struct iguana_bundle *bp; char hashstr[65]; uint32_t now = (uint32_t)time(NULL);
//if ( queue_size(&coin->hdrsQ) == 0 )
{
if ( coin->active != 0 )
@ -1991,10 +1996,11 @@ int32_t iguana_reqhdrs(struct iguana_info *coin)
else if ( coin->current == 0 || bp->hdrsi > coin->current->hdrsi+coin->MAXBUNDLES )
continue;
else lag = 30;
if ( time(NULL) > bp->issuetime+lag )
if ( now > bp->issuetime+lag && now > bp->hdrtime+3 )
{
bp->hdrtime = now;
if ( 0 && bp == coin->current )
printf("LAG.%d hdrsi.%d numhashes.%d:%d needhdrs.%d qsize.%d zcount.%d\n",(uint32_t)(time(NULL)-bp->hdrtime),i,bp->numhashes,bp->n,iguana_needhdrs(coin),queue_size(&coin->hdrsQ),coin->zcount);
printf("LAG.%d hdrsi.%d numhashes.%d:%d needhdrs.%d qsize.%d zcount.%d\n",(uint32_t)(now-bp->hdrtime),i,bp->numhashes,bp->n,iguana_needhdrs(coin),queue_size(&coin->hdrsQ),coin->zcount);
if ( bp->issuetime == 0 )
coin->numpendings++;
init_hexbytes_noT(hashstr,bp->hashes[0].bytes,sizeof(bits256));
@ -2274,7 +2280,6 @@ int32_t iguana_processrecv(struct supernet_info *myinfo,struct iguana_info *coin
flag += iguana_processrecvQ(myinfo,coin,&newhwm);
if ( coin->RTheight == 0 || (rand() % 7) == 0 )
flag += iguana_reqblocks(myinfo,coin);
iguana_jsonQ(myinfo,coin);
if ( time(NULL) > coin->laststats+3 )
{
flag += iguana_reqhdrs(coin);

17
iguana/iguana_rpc.c

@ -836,8 +836,23 @@ cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr)
char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port)
{
cJSON *tokens,*argjson,*origargjson,*json = 0; long filesize; struct iguana_info *coin = 0;
char symbol[64],buf[4096],urlmethod[16],*data,url[1024],furl[1024],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0;
char symbol[64],buf[4096],*originstr,urlmethod[16],*data,url[8192],furl[8192],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0;
//printf("rpcparse.(%s)\n",urlstr);
if ( myinfo->remoteorigin == 0 )
{
n = (int32_t)(strlen(urlstr) - strlen("Origin: "));
for (i=0; i<n; i++)
if ( strncmp("Origin: ",&urlstr[i],strlen("Origin: ")) == 0 )
{
originstr = &urlstr[i + strlen("Origin: ")];
if ( strncmp("null",originstr,strlen("null")) != 0 && strncmp("http://localhost:",originstr,strlen("http://localhost:")) != 0 && strncmp("http://127.0.0.1:",originstr,strlen("http://127.0.0.1:")) != 0 && strncmp("http://easydex.supernet.org:",originstr,strlen("http://easydex.supernet.org:")) != 0 )
{
printf("remote Origin REJECT.(%s)\n",urlstr);
return(clonestr("{\"error\":\"remote origin not enabled\"}"));
} //else printf("allow file://\n");
break;
}
}
for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++)
urlmethod[i] = urlstr[i];
urlmethod[i++] = 0;

26
iguana/main.c

@ -253,7 +253,7 @@ char *iguana_blockingjsonstr(struct supernet_info *myinfo,struct iguana_info *co
char *SuperNET_processJSON(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,uint16_t port)
{
cJSON *retjson; uint64_t tag; uint32_t timeout; char *jsonstr,*retjsonstr,*retstr = 0; //*hexmsg,*method,
cJSON *retjson; double endmillis; uint64_t tag; uint32_t timeout,immedmillis; char *jsonstr,*retjsonstr,*retstr = 0; //*hexmsg,*method,
//char str[65]; printf("processJSON %p %s\n",&myinfo->privkey,bits256_str(str,myinfo->privkey));
if ( json != 0 )
{
@ -272,9 +272,26 @@ char *SuperNET_processJSON(struct supernet_info *myinfo,struct iguana_info *coin
}*/
jsonstr = jprint(json,0);
//printf("RPC? (%s)\n",jsonstr);
if ( jstr(json,"immediate") != 0 || ((remoteaddr == 0 || remoteaddr[0] == 0) && port == IGUANA_RPCPORT) )
retjsonstr = SuperNET_jsonstr(myinfo,jsonstr,remoteaddr,port);
else retjsonstr = iguana_blockingjsonstr(myinfo,coin,jsonstr,tag,timeout,remoteaddr,port);
if ( (immedmillis= juint(json,"immediate")) != 0 || ((remoteaddr == 0 || remoteaddr[0] == 0) && port == IGUANA_RPCPORT) )
{
if ( coin != 0 )
{
if ( immedmillis > 60000 )
immedmillis = 60000;
endmillis = OS_milliseconds() + immedmillis;
while ( 1 )
{
if ( coin->busy_processing == 0 )
break;
usleep(100);
if ( OS_milliseconds() > endmillis )
break;
}
if ( coin->busy_processing == 0 )
retjsonstr = SuperNET_jsonstr(myinfo,jsonstr,remoteaddr,port);
else retjsonstr = clonestr("{\"error\":\"coin is busy processing\"}");
} else retjsonstr = SuperNET_jsonstr(myinfo,jsonstr,remoteaddr,port);
} else retjsonstr = iguana_blockingjsonstr(myinfo,coin,jsonstr,tag,timeout,remoteaddr,port);
if ( retjsonstr != 0 )
{
if ( (retjsonstr[0] == '{' || retjsonstr[0] == '[') && (retjson= cJSON_Parse(retjsonstr)) != 0 )
@ -593,6 +610,7 @@ int32_t iguana_commandline(struct supernet_info *myinfo,char *arg)
else
{
IGUANA_NUMHELPERS = juint(argjson,"numhelpers");
myinfo->remoteorigin = juint(argjson,"remoteorigin");
free_json(argjson);
printf("Will run (%s) after initialized with %d threads\n",COMMANDLINE_ARGFILE,IGUANA_NUMHELPERS);
}

1
iguana/tests/amlp

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"tradebot\",\"method\":\"amlp\"}"

2
includes/iguana_structs.h

@ -485,7 +485,7 @@ struct iguana_info
int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle,numsaved,pendbalances,numverified,blockdepth;
uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,firstRTgenesis,RTstarti,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime,RThdrstime,nextchecked,lastcheckpoint,sigserrs,sigsvalidated;
double bandwidth,maxbandwidth,backstopmillis; bits256 backstophash2; int64_t spaceused;
int32_t disableUTXO,initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,firstRTheight,polltimeout,numreqtxids,allhashes,balanceflush,basilisk_busy,almostRT; bits256 reqtxids[64];
int32_t disableUTXO,initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,firstRTheight,polltimeout,numreqtxids,allhashes,balanceflush,basilisk_busy,almostRT,busy_processing; bits256 reqtxids[64];
void *launched,*started,*rpcloop;
uint64_t bloomsearches,bloomhits,bloomfalse,collisions,txfee_perkb,txfee;
uint8_t *blockspace; int32_t blockspacesize; struct OS_memspace blockMEM,RTHASHMEM;

Loading…
Cancel
Save