Browse Source

RPC

release/v0.1
jl777 9 years ago
parent
commit
495ca4336e
  1. 7
      crypto777/iguana_serdes.c
  2. 4
      iguana/SuperNET.c
  3. 2
      iguana/SuperNET.h
  4. 34
      iguana/iguana777.c
  5. 2
      iguana/iguana777.h
  6. 34
      iguana/iguana_bundles.c
  7. 4
      iguana/iguana_init.c
  8. 5
      iguana/iguana_json.c
  9. 6
      iguana/iguana_peers.c
  10. 2
      iguana/iguana_ramchain.c
  11. 33
      iguana/iguana_recv.c
  12. 18
      iguana/iguana_rpc.c
  13. 6
      iguana/iguana_unspents.c
  14. 18
      iguana/main.c

7
crypto777/iguana_serdes.c

@ -92,15 +92,16 @@ int32_t iguana_sethdr(struct iguana_msghdr *H,const uint8_t netmagic[4],char *co
memset(H,0,sizeof(*H));
memcpy(H->netmagic,netmagic,4);
strncpy(H->command,command,12);
if ( datalen < 0 || datalen > IGUANA_MAXPACKETSIZE )
return(-1);
iguana_rwnum(1,H->serdatalen,sizeof(int32_t),&datalen);
if ( data != 0 && datalen != 0 )
if ( data != 0 )
{
hash2 = bits256_doublesha256(0,data,datalen);
iguana_rwbignum(1,tmp.bytes,sizeof(tmp),hash2.bytes);
for (i=0; i<4; i++)
H->hash[i] = tmp.bytes[i];
}
else H->hash[0] = 0x5d, H->hash[1] = 0xf6, H->hash[2] = 0xe0, H->hash[3] = 0xe2;
} else H->hash[0] = 0x5d, H->hash[1] = 0xf6, H->hash[2] = 0xe0, H->hash[3] = 0xe2;
return(datalen + sizeof(*H));
}

4
iguana/SuperNET.c

@ -707,9 +707,9 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr,ui
if ( (retstr= SuperNET_processJSON(myinfo,json,remoteaddr,port)) != 0 )
{
//printf("retstr.(%s)\n",retstr);
if ( remoteaddr != 0 && (retjson= cJSON_Parse(retstr)) != 0 )
if ( retstr[strlen(retstr)-1] != '\n' && (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( jobj(retjson,"result") != 0 || jobj(retjson,"error") != 0 || jobj(retjson,"method") == 0 )
if ( jobj(retjson,"result") == 0 || jobj(retjson,"error") != 0 || jobj(retjson,"method") != 0 )
{
//printf("it is a result, dont return\n");
free(retstr);

2
iguana/SuperNET.h

@ -82,7 +82,7 @@ struct supernet_info
uint8_t *recvbuf[6];
struct supernet_address myaddr;
int32_t LBsock,PUBsock,reqsock,subsock,networktimeout,maxdelay;
uint16_t LBport,PUBport,reqport,subport,rpcport,publicRPC;
uint16_t LBport,PUBport,reqport,subport,rpcport,publicRPC,argport;
//struct nn_pollfd pfd[SUPERNET_MAXAGENTS]; //struct relay_info active;
struct supernet_agent agents[SUPERNET_MAXAGENTS]; queue_t acceptQ;
int32_t numagents,numexchanges;

34
iguana/iguana777.c

@ -431,19 +431,13 @@ int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convert
if ( coin->origbalanceswritten <= 1 )
hdrsi = 0;
else hdrsi = coin->origbalanceswritten;
/*while ( (n= iguana_validated(coin)) < max )
{
sleep(3);
printf("validated.%d of %d\n",n,max);
}*/
for (; hdrsi<max; hdrsi++,coin->balanceswritten++)
{
iguana_ramchain_prefetch(coin,&coin->bundles[hdrsi]->ramchain,0);
if ( iguana_balancegen(coin,0,coin->bundles[hdrsi],0,coin->chain->bundlesize-1,0) == 0 )
bp->balancefinish = (uint32_t)time(NULL);
}
if ( iguana_balanceflush(coin,max) > 0 )
printf("balanceswritten.%d flushed bp->hdrsi %d vs %d coin->longestchain/coin->chain->bundlesize\n",coin->balanceswritten,bp->hdrsi,coin->longestchain/coin->chain->bundlesize);
coin->balanceflush = max;
} else printf("error saving spendvectors\n");
}
for (hdrsi=helperid; hdrsi<max; hdrsi+=incr)
@ -680,7 +674,6 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
mapflags = IGUANA_MAPRECVDATA | maphash*IGUANA_MAPTXIDITEMS | maphash*IGUANA_MAPPKITEMS | maphash*IGUANA_MAPBLOCKITEMS | maphash*IGUANA_MAPPEERITEMS;
printf("setcoin.%s\n",symbol);
coin = iguana_coinadd(symbol,json);
coin->launched = launched;
if ( (coin->MAXPEERS= maxpeers) <= 0 )
coin->MAXPEERS = (strcmp(symbol,"BTC") == 0) ? 128 : 64;
if ( (coin->MAXRECVCACHE= maxrecvcache) == 0 )
@ -754,6 +747,8 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
if ( coin->chain == 0 && (coin->chain= iguana_createchain(json)) == 0 )
{
printf("cant initialize chain.(%s)\n",jstr(json,0));
strcpy(coin->name,"illegalcoin");
coin->symbol[0] = 0;
return(0);
} else iguana_chainparms(coin->chain,json);
if ( jobj(json,"RELAY") != 0 )
@ -799,12 +794,13 @@ int32_t iguana_launchcoin(char *symbol,cJSON *json)
coins[0] = (void *)((long)1);
coins[1] = coin;
printf("launch coinloop for.%s services.%llx\n",coin->symbol,(long long)services);
iguana_launch(coin,"iguana_coinloop",iguana_coinloop,coins,IGUANA_PERMTHREAD);
coin->launched = iguana_launch(coin,"iguana_coinloop",iguana_coinloop,coins,IGUANA_PERMTHREAD);
coin->active = 1;
return(1);
}
else
{
printf("launchcoin: couldnt initialize.(%s)\n",symbol);
myfree(coins,sizeof(*coins) * 2);
return(-1);
}
@ -825,10 +821,17 @@ void iguana_coins(void *arg)
if ( (symbol= jstr(json,"coin")) != 0 && strncmp(symbol,"BTC",3) == 0 )
{
coins = mycalloc('A',1+1,sizeof(*coins));
coins[1] = iguana_setcoin(symbol,coins,0,0,0,0,0,0,0,0,json);
_iguana_calcrmd160(coins[1],&V);
coins[0] = (void *)((long)1);
iguana_coinloop(coins);
if ( (coins[1]= iguana_setcoin(symbol,coins,0,0,0,0,0,0,0,0,json)) != 0 )
{
_iguana_calcrmd160(coins[1],&V);
coins[0] = (void *)((long)1);
iguana_coinloop(coins);
}
else
{
printf("iguana_coins: couldnt initialize.(%s)\n",symbol);
return;
}
} else printf("no coins[] array in JSON.(%s) only BTCD and BTC can be quicklaunched\n",jsonstr);
free_json(json);
return;
@ -847,6 +850,11 @@ void iguana_coins(void *arg)
}
iguana_coinargs(symbol,&maxrecvcache,&minconfirms,&maxpeers,&initialheight,&services,&maxrequests,&maxbundles,item);
coins[1 + i] = coin = iguana_setcoin(symbol,coins,maxpeers,maxrecvcache,services,initialheight,maphash,minconfirms,maxrequests,maxbundles,item);
if ( coin == 0 )
{
printf("iguana_coins: couldnt initialize.(%s)\n",symbol);
return;
}
}
coins[0] = (void *)((long)n);
iguana_coinloop(coins);

2
iguana/iguana777.h

@ -494,7 +494,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,RTstarti,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime,RThdrstime;
double bandwidth,maxbandwidth,backstopmillis; bits256 backstophash2; int64_t spaceused;
int32_t initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids,allhashes; bits256 reqtxids[64];
int32_t initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids,allhashes,balanceflush; bits256 reqtxids[64];
void *launched,*started,*rpcloop;
uint64_t bloomsearches,bloomhits,bloomfalse,collisions;
uint8_t blockspace[IGUANA_MAXPACKETSIZE + 8192]; struct OS_memspace blockMEM;

34
iguana/iguana_bundles.c

@ -1038,24 +1038,26 @@ static int32_t revsortds(double *buf,uint32_t num,int32_t size)
int32_t iguana_cacheprocess(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei)
{
int32_t recvlen; struct iguana_msghdr H; uint8_t *data; struct iguana_block *block;
if ( (data= bp->speculativecache[bundlei]) != 0 && bp->speculative != 0 && (block= iguana_blockfind("cacheprocess",coin,bp->speculative[bundlei])) != 0 )
if ( (data= bp->speculativecache[bundlei]) != 0 && bp->speculative != 0 && (block= iguana_blockfind("cacheprocess",coin,bp->speculative[bundlei])) != 0 && block->processed == 0 )
{
iguana_bundlehash2add(coin,0,bp,bundlei,bp->speculative[bundlei]);
block->processed = 1;
bp->speculativecache[bundlei] = 0;
iguana_bundlehash2add(coin,0,bp,bundlei,block->RO.hash2);
recvlen = *(int32_t *)data;
memset(&H,0,sizeof(H));
iguana_sethdr(&H,coin->chain->netmagic,"block",&data[sizeof(recvlen)],recvlen);
if ( coin->internaladdr.RAWMEM.ptr == 0 )
iguana_meminit(&coin->internaladdr.RAWMEM,"cache",0,IGUANA_MAXPACKETSIZE + 65536*3,0);
if ( coin->TXMEM.ptr == 0 )
iguana_meminit(&coin->internaladdr.TXDATA,"txdata",0,IGUANA_MAXPACKETSIZE*1.5,0);
if ( coin->internaladdr.HASHMEM.ptr == 0 )
iguana_meminit(&coin->internaladdr.HASHMEM,"HASHPTRS",0,256,0);
if ( iguana_msgparser(coin,&coin->internaladdr,&coin->internaladdr.RAWMEM,&coin->internaladdr.TXDATA,&coin->internaladdr.HASHMEM,&H,&data[sizeof(recvlen)],recvlen) < 0 )
printf("error parsing speculativecache.[%d:%d]\n",bp->hdrsi,bundlei);
else block->processed = 1;
//char str[65]; printf("iguana_cacheprocess [%d:%d] %s fp.%x len.%d:%d\n",bp->hdrsi,bundlei,bits256_str(str,bp->hashes[bundlei]),block->fpipbits,block->RO.recvlen,recvlen);
//myfree(data,recvlen + sizeof(recvlen));
//bp->speculativecache[bundlei] = 0;
memset(&H,0,sizeof(H));
if ( iguana_sethdr(&H,coin->chain->netmagic,"block",&data[sizeof(recvlen)],recvlen) > 0 )
{
if ( coin->internaladdr.RAWMEM.ptr == 0 )
iguana_meminit(&coin->internaladdr.RAWMEM,"cache",0,IGUANA_MAXPACKETSIZE + 65536*3,0);
if ( coin->TXMEM.ptr == 0 )
iguana_meminit(&coin->internaladdr.TXDATA,"txdata",0,IGUANA_MAXPACKETSIZE*1.5,0);
if ( coin->internaladdr.HASHMEM.ptr == 0 )
iguana_meminit(&coin->internaladdr.HASHMEM,"HASHPTRS",0,256,0);
if ( iguana_msgparser(coin,&coin->internaladdr,&coin->internaladdr.RAWMEM,&coin->internaladdr.TXDATA,&coin->internaladdr.HASHMEM,&H,&data[sizeof(recvlen)],recvlen) < 0 )
printf("error parsing speculativecache.[%d:%d]\n",bp->hdrsi,bundlei);
}
free(data);
return(recvlen);
}
return(-1);
@ -1170,8 +1172,6 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag)
{
for (j=0; j<bp->n; j++)
{
//if ( bp->blocks[j] == 0 && bp->speculative != 0 && bits256_nonz(bp->speculative[j]) != 0 )
// bp->blocks[j] = iguana_blockhashset("speculative3",coin,bp->bundleheight+j,bp->speculative[j],1);
if ( ((block= bp->blocks[j]) == 0 || bp == coin->current) && bp->speculativecache[j] != 0 )
{
if ( (block != 0 || (block= iguana_blockhashset("bundlestats3",coin,-1,bp->speculative[j],1)) != 0) && block->processed == 0 )

4
iguana/iguana_init.c

@ -363,7 +363,7 @@ void iguana_bundlepurge(struct iguana_info *coin,struct iguana_bundle *bp)
for (i=0; i<bp->n; i++)
if ( bp->speculativecache[i] != 0 )
{
myfree(bp->speculativecache[i],*(int32_t *)bp->speculativecache[i]);
free(bp->speculativecache[i]);
bp->speculativecache[i] = 0;
}
myfree(bp->speculative,sizeof(*bp->speculative) * bp->numspec);
@ -479,7 +479,7 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
}
if ( coin->rpcloop == 0 )
{
myinfo->rpcport = coin->chain->rpcport;
myinfo->argport = coin->chain->rpcport;
coin->rpcloop = malloc(sizeof(pthread_t));
if ( OS_thread_create(coin->rpcloop,NULL,(void *)iguana_rpcloop,(void *)myinfo) != 0 )
{

5
iguana/iguana_json.c

@ -832,8 +832,9 @@ STRING_ARG(SuperNET,bitcoinrpc,setcoin)
strcpy(myinfo->rpcsymbol,setcoin);
touppercase(myinfo->rpcsymbol);
printf("bitcoinrpc.%s\n",myinfo->rpcsymbol);
iguana_launchcoin(myinfo->rpcsymbol,json);
return(clonestr("{\"result\":\"set bitcoin RPC coin\"}"));
if ( iguana_launchcoin(myinfo->rpcsymbol,json) < 0 )
return(clonestr("{\"error\":\"error creating coin\"}"));
else return(clonestr("{\"result\":\"set bitcoin RPC coin\"}"));
} else return(clonestr("{\"error\":\"bitcoinrpc needs setcoin value\"}"));
}

6
iguana/iguana_peers.c

@ -446,7 +446,8 @@ int32_t iguana_queue_send(struct iguana_info *coin,struct iguana_peer *addr,int3
exit(-1);
return(-1);
}
datalen = iguana_sethdr((void *)serialized,coin->chain->netmagic,cmd,&serialized[sizeof(struct iguana_msghdr)],len);
if ( (datalen= iguana_sethdr((void *)serialized,coin->chain->netmagic,cmd,&serialized[sizeof(struct iguana_msghdr)],len)) < 0 )
return(-1);
if ( strcmp("getaddr",cmd) == 0 && time(NULL) < addr->lastgotaddr+300 )
return(0);
//if ( strcmp("version",cmd) == 0 )
@ -499,8 +500,7 @@ void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct ig
{
struct iguana_msghdr checkH;
memset(&checkH,0,sizeof(checkH));
iguana_sethdr(&checkH,coin->chain->netmagic,H->command,buf,len);
if ( memcmp(&checkH,H,sizeof(checkH)) == 0 )
if ( iguana_sethdr(&checkH,coin->chain->netmagic,H->command,buf,len) > 0 && memcmp(&checkH,H,sizeof(checkH)) == 0 )
{
if ( strcmp(H->command,"block") == 0 || strcmp(H->command,"tx") == 0 )
{

2
iguana/iguana_ramchain.c

@ -2021,7 +2021,7 @@ void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,stru
if ( (ptr= bp->speculativecache[i]) != 0 )
{
memcpy(&recvlen,ptr,sizeof(recvlen));
myfree(ptr,recvlen + sizeof(recvlen));
free(ptr);
bp->speculativecache[i] = 0;
}
}

33
iguana/iguana_recv.c

@ -207,18 +207,30 @@ struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundl
int32_t iguana_speculativefind(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_block *block,uint8_t *data,int32_t recvlen)
{
int32_t i,j,numcached; uint8_t *tmp; char str[65];
for (i=1; i<bp->n; i++)
int32_t i,j,numcached,cachelen; uint8_t *tmp; char str[65];
if ( recvlen < 0 || recvlen > IGUANA_MAXPACKETSIZE )
{
printf("iguana_speculativefind: illegal recvlen.%d\n",recvlen);
return(-1);
}
for (i=0; i<bp->n; i++)
{
if ( bits256_cmp(bp->speculative[i],block->RO.hash2) == 0 )
{
if ( (tmp= bp->speculativecache[i]) != 0 )
{
memcmp(&cachelen,tmp,sizeof(cachelen));
if ( cachelen < 0 || cachelen > IGUANA_MAXPACKETSIZE )
{
printf("illegal cachelen.%d %s [%d:%d] %p\n",cachelen,coin->symbol,bp->hdrsi,i,tmp);
bp->speculativecache[i] = 0;
continue;
}
if ( memcmp(&recvlen,tmp,sizeof(recvlen)) != 0 || memcmp(&tmp[sizeof(recvlen)],data,recvlen) != 0 )
printf("data ERROR [%d:%d] already has recvlen.%d for %s\n",bp->hdrsi,i,recvlen,bits256_str(str,block->RO.hash2));
return(0);
}
bp->speculativecache[i] = mycalloc('p',1,recvlen + sizeof(recvlen));
bp->speculativecache[i] = calloc(1,recvlen + sizeof(recvlen));
memcpy(bp->speculativecache[i],&recvlen,sizeof(recvlen));
memcpy(&bp->speculativecache[i][sizeof(recvlen)],data,recvlen);
for (j=numcached=0; j<bp->n; j++)
@ -279,6 +291,11 @@ void iguana_bundletime(struct iguana_info *coin,struct iguana_bundle *bp,int32_t
void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen)
{
struct iguana_bundlereq *req; struct iguana_txblock *txdata = 0; int32_t valid,speculative=0,i,j,bundlei,copyflag; struct iguana_block *block; struct iguana_bundle *bp; uint32_t now; char str[65];
if ( recvlen < 0 || recvlen > IGUANA_MAXPACKETSIZE )
{
printf("iguana_getblockM: illegal recvlen.%d\n",recvlen);
return;
}
if ( 0 )
{
for (i=0; i<txdata->space[0]; i++)
@ -738,7 +755,7 @@ void iguana_checklongestchain(struct iguana_info *coin,struct iguana_bundle *bp,
{
if ( coin->longestchain > bp->bundleheight+num+coin->chain->minconfirms )
{
//printf("strange.%d suspicious longestchain.%d vs [%d:%d] %d bp->n %d\n",coin->longestchain_strange,coin->longestchain,bp->hdrsi,num,bp->bundleheight+num,bp->n);
printf("strange.%d suspicious longestchain.%d vs [%d:%d] %d bp->n %d\n",coin->longestchain_strange,coin->longestchain,bp->hdrsi,num,bp->bundleheight+num,bp->n);
if ( coin->longestchain_strange++ > 10 )
{
coin->badlongestchain = coin->longestchain;
@ -1534,6 +1551,12 @@ int32_t iguana_processrecv(struct iguana_info *coin) // single threaded
char str[2000];
hwmheight = coin->blocks.hwmchain.height;
coin->RTramchain_busy = 1;
if ( coin->balanceflush != 0 )
{
if ( iguana_balanceflush(coin,coin->balanceflush) > 0 )
printf("balanceswritten.%d flushed coin->balanceflush %d vs %d coin->longestchain/coin->chain->bundlesize\n",coin->balanceswritten,coin->balanceflush,coin->longestchain/coin->chain->bundlesize);
coin->balanceflush = 0;
}
//printf("recvQ\n");
flag += iguana_processrecvQ(coin,&newhwm);
//printf("reqhdrs\n");
@ -1571,7 +1594,7 @@ int32_t iguana_processrecv(struct iguana_info *coin) // single threaded
{
for (i=0; i<coin->chain->bundlesize; i++)
{
if ( iguana_realtime_update(coin) <= 0 )
if ( coin->RTdatabad != 0 || iguana_realtime_update(coin) <= 0 )
break;
//printf("call iguana_realtime_update i.%d\n",i);
}

18
iguana/iguana_rpc.c

@ -46,10 +46,9 @@ char *sglue(GLUEARGS,char *agent,char *method)
len = (int32_t)strlen(rpcretstr);
if ( rpcretstr[0] == '"' && rpcretstr[len-1] == '"' )
{
for (i=1,j=0; i<len-1; i++,j++)
for (i=1,j=0; i<len-2; i++,j++)
rpcretstr[j] = rpcretstr[i];
rpcretstr[j] = '\n';
//free_json(json);
rpcretstr[j++] = '\n', rpcretstr[j] = 0;
free_json(retjson);
free(retstr);
return(rpcretstr);
@ -512,6 +511,7 @@ static char *getrawchangeaddress(RPCARGS)
#define false 0
struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,remoteflag; } RPCcalls[] =
{
{ "getblockhash", &getblockhash, false, true },
{ "walletpassphrase", &walletpassphrase, true, false },
{ "SuperNET", &SuperNET, false, true },
//{ "SuperNETb", &SuperNET, false, true },
@ -545,7 +545,6 @@ struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,remotefla
{ "sendmany", &sendmany, false, false },
{ "addmultisigaddress", &addmultisigaddress, false, false },
{ "getblock", &getblock, false, true },
{ "getblockhash", &getblockhash, false, true },
{ "gettransaction", &gettransaction, false, true },
{ "listtransactions", &listtransactions, false, false },
{ "listaddressgroupings", &listaddressgroupings, false, false },
@ -630,7 +629,7 @@ char *iguana_bitcoinrpc(struct supernet_info *myinfo,uint16_t port,struct iguana
char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr,uint16_t port)
{
cJSON *params[16],*array; struct iguana_info *coin = 0; char *symbol; int32_t i,c,n; char *retstr = 0;
cJSON *params[16],*array; struct iguana_info *coin = 0; char *symbol = "BTCD"; int32_t i,c,n; char *retstr = 0;
memset(params,0,sizeof(params));
if ( json != 0 )
{
@ -654,7 +653,7 @@ char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,ch
if ( i == IGUANA_MAXCOINS )
coin = 0;
}
//printf("method.(%s) (%s) remote.%s symbol.(%s)\n",method,jprint(json,0),remoteaddr,symbol);
//printf("method.(%s) (%s) remote.(%s) symbol.(%s)\n",method,jprint(json,0),remoteaddr,symbol);
if ( method != 0 && symbol != 0 && (coin != 0 || (coin= iguana_coinfind(symbol)) != 0) )
{
if ( (array= jarray(&n,json,"params")) == 0 )
@ -670,7 +669,7 @@ char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,ch
//printf("add params[%d] of %d <- (%s) %p.(%p %p)\n",i,n,jprint(params[i],0),params[i],params[i]->next,params[i]->prev);
}
}
retstr = iguana_bitcoinrpc(myinfo,port,coin,method,params,n,json,remoteaddr,array);
retstr = iguana_bitcoinrpc(myinfo,IGUANA_RPCPORT,coin,method,params,n,json,remoteaddr,array);
if ( n > 0 )
for (i=0; i<n; i++)
if ( params[i] != 0 )
@ -678,7 +677,7 @@ char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,ch
}
}
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"cant parse jsonstr\"}");
retstr = clonestr("{\"error\":\"null return from iguana_bitcoinRPC\"}");
return(retstr);
}
@ -999,7 +998,8 @@ void iguana_rpcloop(void *args)
int32_t recvlen,flag,bindsock,postflag,contentlen,sock,remains,numsent,jsonflag,hdrsize,len;
socklen_t clilen; char helpname[512],remoteaddr[64],*buf,*retstr,*space;//,*retbuf; ,n,i,m
struct sockaddr_in cli_addr; uint32_t ipbits,i,size = IGUANA_WIDTH*IGUANA_HEIGHT*16 + 512;
port = myinfo->rpcport;
if ( (port= myinfo->argport) == 0 )
port = myinfo->rpcport;
if ( jsonbuf == 0 )
jsonbuf = calloc(1,IGUANA_MAXPACKETSIZE);
while ( (bindsock= iguana_socket(1,"127.0.0.1",port)) < 0 )

6
iguana/iguana_unspents.c

@ -1577,7 +1577,7 @@ int32_t iguana_spendvectorsaves(struct iguana_info *coin)
}
}
}
else if ( bp->ramchain.Xspendinds == 0 && iguana_spendvectorsave(coin,bp,&bp->ramchain,bp->tmpspends,bp->numtmpspends,bp->ramchain.H.data->numspends) == 0 )
else if ( iguana_spendvectorsave(coin,bp,&bp->ramchain,bp->tmpspends,bp->numtmpspends,bp->ramchain.H.data->numspends) == 0 )
{
if ( bp->tmpspends != 0 && bp->numtmpspends > 0 && bp->tmpspends != bp->ramchain.Xspendinds )
myfree(bp->tmpspends,sizeof(*bp->tmpspends) * bp->numtmpspends);
@ -1907,11 +1907,11 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
if ( (block= iguana_bundleblock(coin,&hash2,bp,bundlei)) != 0 )
iguana_bundlehashadd(coin,bp,bundlei,block);
//printf("RT.%d vs hwm.%d starti.%d bp->n %d block.%p/%p ramchain.%p\n",coin->RTheight,coin->blocks.hwmchain.height,coin->RTstarti,bp->n,block,bp->blocks[bundlei],dest->H.data);
if ( block != 0 && bits256_nonz(block->RO.prev_block) != 0 )
if ( coin->RTdatabad == 0 && block != 0 && bits256_nonz(block->RO.prev_block) != 0 )
{
iguana_blocksetcounters(coin,block,dest);
startmillis0 = OS_milliseconds();
if ( iguana_ramchainfile(coin,dest,&blockR,bp,bundlei,block) == 0 )
if ( coin->RTdatabad == 0 && iguana_ramchainfile(coin,dest,&blockR,bp,bundlei,block) == 0 )
{
for (i=0; i<bp->n; i++)
if ( GETBIT(bp->haveblock,i) == 0 )

18
iguana/main.c

@ -199,7 +199,7 @@ char *iguana_JSON(char *jsonstr,uint16_t port)
free_json(json);
}
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"cant parse jsonstr from pnacl\"}");
retstr = clonestr("{\"error\":\"null return from iguana_JSON\"}");
return(retstr);
}
@ -228,16 +228,17 @@ int32_t iguana_jsonQ()
{
if ( ptr->expired != 0 )
{
*ptr->retjsonstrp = clonestr("{\"error\":\"request timeout\"}");
if ( ptr->retjsonstrp != 0 && *ptr->retjsonstrp != 0 )
free(*ptr->retjsonstrp); // *ptr->retjsonstrp = clonestr("{\"error\":\"request timeout\"}");
printf("garbage collection: expired.(%s)\n",ptr->jsonstr);
myfree(ptr,ptr->allocsize);
} else queue_enqueue("finishedQ",&finishedQ,&ptr->DL,0);
}
if ( (ptr= queue_dequeue(&jsonQ,0)) != 0 )
{
if ( *ptr->retjsonstrp != 0 && (*ptr->retjsonstrp= SuperNET_jsonstr(ptr->myinfo,ptr->jsonstr,ptr->remoteaddr,ptr->port)) == 0 )
if ( ptr->retjsonstrp != 0 && (*ptr->retjsonstrp= SuperNET_jsonstr(ptr->myinfo,ptr->jsonstr,ptr->remoteaddr,ptr->port)) == 0 )
*ptr->retjsonstrp = clonestr("{\"error\":\"null return from iguana_jsonstr\"}");
printf("finished.(%s) -> (%s)\n",ptr->jsonstr,*ptr->retjsonstrp!=0?*ptr->retjsonstrp:"null return");
//printf("finished.(%s) -> (%s) %.0f\n",ptr->jsonstr,*ptr->retjsonstrp!=0?*ptr->retjsonstrp:"null return",OS_milliseconds());
queue_enqueue("finishedQ",&finishedQ,&ptr->DL,0);
return(1);
}
@ -248,7 +249,7 @@ char *iguana_blockingjsonstr(struct supernet_info *myinfo,char *jsonstr,uint64_t
{
struct iguana_jsonitem *ptr; char *retjsonstr = 0; int32_t len,allocsize; double expiration;
expiration = OS_milliseconds() + maxmillis;
printf("blocking case.(%s)\n",jsonstr);
printf("blocking case.(%s) %.0f maxmillis.%d\n",jsonstr,OS_milliseconds(),maxmillis);
len = (int32_t)strlen(jsonstr);
allocsize = sizeof(*ptr) + len + 1;
ptr = mycalloc('J',1,allocsize);
@ -296,7 +297,7 @@ char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remote
}
jsonstr = jprint(json,0);
//printf("RPC? (%s)\n",jsonstr);
if ( (remoteaddr == 0 || jstr(json,"immediate") != 0) && port == IGUANA_RPCPORT )
if ( (remoteaddr == 0 || remoteaddr[0] == 0 || jstr(json,"immediate") != 0) && port == IGUANA_RPCPORT )
retjsonstr = SuperNET_jsonstr(myinfo,jsonstr,remoteaddr,port);
else retjsonstr = iguana_blockingjsonstr(myinfo,jsonstr,tag,timeout,remoteaddr,port);
if ( retjsonstr != 0 )
@ -305,7 +306,8 @@ char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remote
{
if ( j64bits(retjson,"tag") != tag )
{
jdelete(retjson,"tag");
if ( jobj(retjson,"tag") != 0 )
jdelete(retjson,"tag");
jadd64bits(retjson,"tag",tag);
}
retstr = jprint(retjson,1);
@ -434,7 +436,7 @@ void mainloop(struct supernet_info *myinfo)
if ( iguana_validated(coin) < n || iguana_utxofinished(coin) < n || iguana_balancefinished(coin) < n )
{
coin->spendvectorsaved = 1;
printf("start UTXOGEN\n");
printf("update volatile data\n");
}
else
{

Loading…
Cancel
Save