From e040ef2d77e74b4755653e04587da057caf70ddf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Jun 2016 17:03:36 -0300 Subject: [PATCH] test --- basilisk/basilisk.c | 15 ++++++--------- basilisk/basilisk_CMD.c | 13 ++++--------- gecko/gecko.c | 11 +++++------ gecko/gecko.h | 2 +- gecko/gecko_mempool.c | 7 +++++-- iguana/iguana_payments.c | 2 +- iguana/main.c | 2 +- 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index c7ede84c9..47b7e26a7 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -278,9 +278,9 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t ipbits = (uint32_t)calc_ipbits(senderip); else ipbits = 0; len += iguana_rwnum(0,data,sizeof(basilisktag),&basilisktag); - int32_t i; for (i=0; ireceived.%d basilisk_p2p.(%s) from %s tag.%d\n",datalen,type,senderip!=0?senderip:"?",basilisktag); + //int32_t i; for (i=0; ireceived.%d basilisk_p2p.(%s) from %s tag.%d\n",datalen,type,senderip!=0?senderip:"?",basilisktag); basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len); if ( ptr != 0 ) free(ptr); @@ -1079,11 +1079,9 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende if ( datalen > jsonlen ) { data += jsonlen, datalen -= jsonlen; - for (i=0; i got datalen.%d\n",datalen); - //if ( *data++ != 0 ) - // data += sizeof(hash), datalen -= sizeof(hash); + //for (i=0; i got datalen.%d\n",datalen); } else data = 0, datalen = 0; if ( coin == 0 ) coin = iguana_coinfind("BTCD"); @@ -1145,7 +1143,6 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende { if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 ) // iguana node { - printf("relay path\n"); if ( from_basilisk != 0 ) { printf("echo to other relays\n"); diff --git a/basilisk/basilisk_CMD.c b/basilisk/basilisk_CMD.c index 665b62f17..68b254a4a 100755 --- a/basilisk/basilisk_CMD.c +++ b/basilisk/basilisk_CMD.c @@ -33,7 +33,6 @@ struct iguana_peer *basilisk_ensurerelay(struct iguana_info *btcd,uint32_t ipbit char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint32_t ipbits,bits256 pubkey) { int32_t i; struct basilisk_relay *rp; struct iguana_info *btcd; - printf("addrelay.%x\n",ipbits); if ( (btcd= iguana_coinfind("BTCD")) == 0 || ipbits == 0 ) return(clonestr("{\"error\":\"add relay needs BTCD and ipbits\"}")); for (i=0; inumrelays; i++) @@ -45,7 +44,7 @@ char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint rp->pubkey = pubkey; if ( pubkey33 != 0 && pubkey33[0] != 0 ) memcpy(rp->pubkey33,pubkey33,33); - printf("updated relay[%d] %x\n",i,ipbits); + //printf("updated relay[%d] %x\n",i,ipbits); return(clonestr("{\"error\":\"relay already there\"}")); } } @@ -58,19 +57,15 @@ char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint if ( myinfo->numrelays < sizeof(myinfo->relays)/sizeof(*myinfo->relays) ) myinfo->numrelays++; for (i=0; inumrelays; i++) - { myinfo->relaybits[i] = myinfo->relays[i].ipbits; - printf("%x ",myinfo->relaybits[i]); - } revsort32(&myinfo->relaybits[0],myinfo->numrelays,sizeof(myinfo->relaybits[0])); - printf(" -> sorted "); for (i=0; inumrelays; i++) { char ipaddr[64]; expand_ipbits(ipaddr,myinfo->relaybits[i]); printf("%s ",ipaddr); } - printf("\n"); + printf("sorted\n"); return(clonestr("{\"result\":\"relay added\"}")); } @@ -96,7 +91,7 @@ char *basilisk_respond_relays(struct supernet_info *myinfo,char *CMD,void *_addr for (i=len=0; inumrelays; i++) len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),&myinfo->relaybits[i]); init_hexbytes_noT(hexstr,serialized,len); - printf("send relays.(%s)\n",hexstr); + //printf("send relays.(%s)\n",hexstr); vcalc_sha256(0,txhash2.bytes,serialized,len); if ( (siglen= bitcoin_sign(myinfo->ctx,"BTCD",sig,txhash2,myinfo->persistent_priv,1)) > 0 ) { diff --git a/gecko/gecko.c b/gecko/gecko.c index 499376a2f..22b7ec255 100755 --- a/gecko/gecko.c +++ b/gecko/gecko.c @@ -508,9 +508,10 @@ HASH_ARRAY_STRING(basilisk,newgeckochain,hash,vals,hexstr) return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new gecko chain\"}")); } -char *gecko_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *virt,uint8_t *data,int32_t datalen,bits256 txid,cJSON *vals,char *signedtx) +char *gecko_sendrawtransaction(struct supernet_info *myinfo,char *symbol,uint8_t *data,int32_t datalen,bits256 txid,cJSON *vals,char *signedtx) { - char *retstr = 0; struct iguana_info *btcd = iguana_coinfind("BTCD"); + char *retstr = 0; struct iguana_info *virt,*btcd = iguana_coinfind("BTCD"); + virt = iguana_coinfind(symbol); if ( btcd != 0 && (btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0) ) { basilisk_wait(myinfo,virt); @@ -523,15 +524,13 @@ char *gecko_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info * HASH_ARRAY_STRING(basilisk,geckotx,hash,vals,hexstr) { - struct iguana_info *btcd,*virt; char *retstr=0,*symbol; uint8_t *data,*allocptr,space[4096]; int32_t datalen; bits256 txid; + struct iguana_info *btcd; char *retstr=0,*symbol; uint8_t *data,*allocptr,space[4096]; int32_t datalen; bits256 txid; if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 ) { if ( (data= get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 ) { txid = bits256_doublesha256(0,data,datalen); - if ( (virt= iguana_coinfind(symbol)) != 0 ) - retstr = gecko_sendrawtransaction(myinfo,virt,data,datalen,txid,vals,hexstr); - else retstr = clonestr("{\"error\":\"virtualchain not found\"}"); + retstr = gecko_sendrawtransaction(myinfo,symbol,data,datalen,txid,vals,hexstr); } else retstr = clonestr("{\"error\":\"no tx submitted\"}"); if ( allocptr != 0 ) free(allocptr); diff --git a/gecko/gecko.h b/gecko/gecko.h index 1f905d188..48d0e4267 100755 --- a/gecko/gecko.h +++ b/gecko/gecko.h @@ -77,7 +77,7 @@ char *gecko_blockarrived(struct supernet_info *myinfo,struct iguana_info *virt,c char *gecko_txarrived(struct supernet_info *myinfo,struct iguana_info *virt,char *remoteaddr,uint8_t *data,int32_t datalen,bits256 hash2); char *gecko_mempoolarrived(struct supernet_info *myinfo,struct iguana_info *virt,char *remoteaddr,uint8_t *data,int32_t datalen,bits256 hash2); char *gecko_headersarrived(struct supernet_info *myinfo,struct iguana_info *virt,char *remoteaddr,uint8_t *data,int32_t datalen,bits256 hash2); -char *gecko_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *virt,uint8_t *data,int32_t datalen,bits256 txid,cJSON *vals,char *signedtx); +char *gecko_sendrawtransaction(struct supernet_info *myinfo,char *symbol,uint8_t *data,int32_t datalen,bits256 txid,cJSON *vals,char *signedtx); struct gecko_mempool *gecko_mempoolfind(struct supernet_info *myinfo,struct iguana_info *virt,int32_t *numotherp,uint32_t ipbits); void gecko_iteration(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis); diff --git a/gecko/gecko_mempool.c b/gecko/gecko_mempool.c index 8873b9920..9d1c7a9f3 100755 --- a/gecko/gecko_mempool.c +++ b/gecko/gecko_mempool.c @@ -43,15 +43,18 @@ struct gecko_mempool *gecko_mempoolfind(struct supernet_info *myinfo,struct igua void gecko_mempool_sync(struct supernet_info *myinfo,struct iguana_info *virt,bits256 *reftxids,int32_t numtx) { - int32_t i,j,k,n,num,numother; struct iguana_peer *addr; bits256 txid,*txids; struct gecko_mempool *pool,*otherpool; + int32_t i,j,k,n,num,numother; struct iguana_peer *addr; bits256 txid,*txids; struct gecko_mempool *pool,*otherpool; struct iguana_info *coin; if ( (pool= virt->mempool) == 0 ) return; n = sqrt(myinfo->numrelays) + 2; i = (myinfo->myaddr.myipbits % n); txids = calloc(pool->numtx,sizeof(bits256)); + if ( virt->peers == 0 ) + coin = iguana_coinfind("BTCD"); + else coin = virt; for (; inumrelays; i+=n) { - if ( (addr= iguana_peerfindipbits(virt,myinfo->relaybits[i],1)) != 0 ) + if ( (addr= iguana_peerfindipbits(coin,myinfo->relaybits[i],1)) != 0 ) { if ( (otherpool= gecko_mempoolfind(myinfo,virt,&numother,myinfo->relaybits[i])) != 0 ) { diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index 76209dd21..1bb86fb1b 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -317,7 +317,7 @@ bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_inf { vals = cJSON_CreateObject(); jaddstr(vals,"symbol",coin->symbol); - if ( (str= gecko_sendrawtransaction(myinfo,coin,serialized,len,txid,vals,signedtx)) != 0 ) + if ( (str= gecko_sendrawtransaction(myinfo,coin->symbol,serialized,len,txid,vals,signedtx)) != 0 ) free(str); free_json(vals); } diff --git a/iguana/main.c b/iguana/main.c index 5ddc63b5f..ad1ada25f 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -1150,7 +1150,7 @@ void iguana_appletests(struct supernet_info *myinfo) bitcoin_sharedsecret(myinfo->ctx,hash2,pubkey,33); printf("secp256k1 elapsed %.3f for %d iterations\n",OS_milliseconds() - startmillis,i); getchar();**/ - if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"protover\":70002,\"RELAY\":1,\"VALIDATE\":0,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":128,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":4,\"poll\":1}"),0,myinfo->rpcport)) != 0 ) + if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"protover\":70002,\"RELAY\":0,\"VALIDATE\":0,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":128,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":4,\"poll\":1}"),0,myinfo->rpcport)) != 0 ) { free(str); if ( 0 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"portp2p\":8333,\"RELAY\":0,\"VALIDATE\":0,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":64,\"newcoin\":\"BTC\",\"active\":0,\"numhelpers\":4,\"poll\":100}"),0,myinfo->rpcport)) != 0 )