Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
e040ef2d77
  1. 15
      basilisk/basilisk.c
  2. 13
      basilisk/basilisk_CMD.c
  3. 11
      gecko/gecko.c
  4. 2
      gecko/gecko.h
  5. 7
      gecko/gecko_mempool.c
  6. 2
      iguana/iguana_payments.c
  7. 2
      iguana/main.c

15
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; i<datalen-len; i++)
printf("%02x",data[len+i]);
printf(" ->received.%d basilisk_p2p.(%s) from %s tag.%d\n",datalen,type,senderip!=0?senderip:"?",basilisktag);
//int32_t i; for (i=0; i<datalen-len; i++)
// printf("%02x",data[len+i]);
//printf(" ->received.%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<datalen; i++)
printf("%02x",data[i]);
printf(" <-> got datalen.%d\n",datalen);
//if ( *data++ != 0 )
// data += sizeof(hash), datalen -= sizeof(hash);
//for (i=0; i<datalen; i++)
// printf("%02x",data[i]);
//printf(" <-> 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");

13
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; i<myinfo->numrelays; 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; i<myinfo->numrelays; 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; i<myinfo->numrelays; 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; i<n; i++)
{
len += iguana_rwnum(0,(void *)&data[len],sizeof(uint32_t),&ipbits);
printf("(%d %x) ",i,ipbits);
//printf("(%d %x) ",i,ipbits);
if ( (retstr= basilisk_addrelay_info(myinfo,0,ipbits,GENESIS_PUBKEY)) != 0 )
free(retstr);
}
@ -116,7 +111,7 @@ int32_t basilisk_relays_send(struct supernet_info *myinfo,struct iguana_peer *ad
for (i=0; i<myinfo->numrelays; 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 )
{

11
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);

2
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);

7
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 (; i<myinfo->numrelays; 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 )
{

2
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);
}

2
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 )

Loading…
Cancel
Save