Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
57bd56160e
  1. 24
      basilisk/basilisk.c
  2. 17
      basilisk/basilisk_CMD.c
  3. 2
      gecko/gecko_blocks.c
  4. 2
      gecko/gecko_miner.c
  5. 18
      iguana/main.c
  6. 1
      iguana/tests/myip2
  7. 1
      iguana/tests/myip4
  8. 2
      includes/iguana_funcs.h
  9. 3
      includes/iguana_structs.h

24
basilisk/basilisk.c

@ -116,14 +116,28 @@ uint8_t *basilisk_jsondata(int32_t extraoffset,uint8_t **ptrp,uint8_t *space,int
char *basilisk_finish(struct basilisk_item *ptr,int32_t besti,char *errstr)
{
char *retstr = 0; struct basilisk_item *parent;
char *str,*retstr = 0; int32_t i; struct basilisk_item *parent; cJSON *retarray,*item;
if ( ptr->retstr != 0 )
return(ptr->retstr);
if ( besti >= 0 && besti < ptr->numresults )
/*if ( besti >= 0 && besti < ptr->numresults )
{
retstr = ptr->results[besti];
ptr->results[besti] = 0;
} else printf("besti.%d vs numresults.%d retstr.%p\n",besti,ptr->numresults,retstr);
*/
if ( ptr->numresults > 0 )
{
retarray = cJSON_CreateArray();
for (i=0; i<ptr->numresults; i++)
if ( (str= ptr->results[i]) != 0 )
{
ptr->results[i] = 0;
if ( (item= cJSON_Parse(str)) != 0 )
jaddi(retarray,item);
free(str);
}
retstr = jprint(retarray,1);
} else retstr = ptr->results[0], ptr->results[0] = 0;
if ( retstr == 0 )
retstr = clonestr(errstr);
ptr->retstr = retstr;
@ -322,7 +336,7 @@ char *basilisk_waitresponse(struct supernet_info *myinfo,char *CMD,char *symbol,
usleep(50000);
}
if ( retstr == 0 )
retstr = basilisk_finish(ptr,-1,"{\"error\":\"basilisk timeout\"}");
retstr = basilisk_finish(ptr,-1,"[{\"error\":\"basilisk timeout\"}]");
}
basilisk_sendback(myinfo,CMD,symbol,remoteaddr,ptr->basilisktag,retstr);
return(retstr);
@ -503,8 +517,8 @@ char *basilisk_iscomplete(struct basilisk_item *ptr)
return(0);
}
if ( ptr->uniqueflag == 0 && ptr->numexact != ptr->numresults && ptr->numexact < (ptr->numresults >> 1) )
besti = -1, errstr = "{\"error\":\"basilisk non-consensus results\"}";
else besti = basilisk_besti(ptr), errstr = "{\"error\":\"basilisk no valid results\"}";
besti = -1, errstr = "[{\"error\":\"basilisk non-consensus results\"}]";
else besti = basilisk_besti(ptr), errstr = "[{\"error\":\"basilisk no valid results\"}]";
//printf("%u complete besti.%d\n",ptr->basilisktag,besti);
retstr = basilisk_finish(ptr,besti,errstr);
//printf("%u besti.%d numexact.%d numresults.%d -> (%s)\n",ptr->basilisktag,besti,ptr->numexact,ptr->numresults,retstr);

17
basilisk/basilisk_CMD.c

@ -15,15 +15,23 @@
// included from basilisk.c
struct iguana_peer *basilisk_ensurerelay(struct iguana_info *btcd,uint32_t ipbits)
struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *btcd,uint32_t ipbits)
{
struct iguana_peer *addr;
struct iguana_peer *addr; int32_t i;
if ( (addr= iguana_peerfindipbits(btcd,ipbits,0)) == 0 )
{
if ( (addr= iguana_peerslot(btcd,ipbits,0)) != 0 )
{
printf("launch peer for relay\n");
addr->isrelay = 1;
myinfo->RELAYID = -1;
for (i=0; i<myinfo->numrelays; i++)
if ( myinfo->relaybits[i] == myinfo->myaddr.myipbits )
{
myinfo->RELAYID = i;
break;
}
iguana_launch(btcd,"addrelay",iguana_startconnection,addr,IGUANA_CONNTHREAD);
} else printf("error getting peerslot\n");
} else addr->isrelay = 1;
@ -54,7 +62,7 @@ char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint
printf("add relay[%d] <- %x\n",i,ipbits);
rp = &myinfo->relays[i];
rp->ipbits = ipbits;
rp->addr = basilisk_ensurerelay(btcd,rp->ipbits);
rp->addr = basilisk_ensurerelay(myinfo,btcd,rp->ipbits);
if ( myinfo->numrelays < sizeof(myinfo->relays)/sizeof(*myinfo->relays) )
myinfo->numrelays++;
for (i=0; i<myinfo->numrelays; i++)
@ -105,7 +113,8 @@ char *basilisk_respond_relays(struct supernet_info *myinfo,char *CMD,void *_addr
int32_t basilisk_relays_send(struct supernet_info *myinfo,struct iguana_peer *addr)
{
int32_t i,siglen,len = 0; char strbuf[512]; bits256 txhash2; uint8_t sig[128],serialized[sizeof(myinfo->relaybits)]; cJSON *vals; bits256 hash; char *retstr,hexstr[sizeof(myinfo->relaybits)*2 + 1];
if ( myinfo != 0 )
printf("skip sending relays\n");
if ( 0 && myinfo != 0 )
{
vals = cJSON_CreateObject();
hash = myinfo->myaddr.persistent;

2
gecko/gecko_blocks.c

@ -288,11 +288,13 @@ int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *bt
if ( jobj(retjson,"error") == 0 )
{
valsobj = cJSON_CreateObject();
jaddnum(valsobj,"minresults",myinfo->numrelays - 1);
jaddnum(valsobj,"timeout",1000);
jaddnum(valsobj,"fanout",-1);
jaddstr(valsobj,"symbol",virt->symbol);
if ( (str2= basilisk_standardservice("BLK",myinfo,hash2,valsobj,blockstr,1)) != 0 )
{
printf("got responses.(%s)\n",str2);
free(str2);
}
free_json(valsobj);

2
gecko/gecko_miner.c

@ -327,7 +327,7 @@ void gecko_blocksubmit(struct supernet_info *myinfo,struct iguana_info *btcd,str
void gecko_miner(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis,uint8_t *minerpubkey33)
{
struct iguana_zblock newblock; uint32_t prevtimestamp,nBits; int64_t reward = 0; int32_t txn_count; char *blockstr,*space[256]; struct gecko_memtx **txptrs; void *ptr; //struct iguana_bundle *bp;
if ( virt->virtualchain == 0 )
if ( virt->virtualchain == 0 || myinfo->RELAYID < 0 || myinfo->numrelays < 1 || (virt->blocks.hwmchain.height % myinfo->numrelays) != myinfo->RELAYID )
return;
memset(&newblock,0,sizeof(newblock));
newblock.height = virt->blocks.hwmchain.height + 1;

18
iguana/main.c

@ -87,6 +87,7 @@ struct supernet_info *SuperNET_MYINFO(char *passphrase)
OS_randombytes(MYINFO.privkey.bytes,sizeof(MYINFO.privkey));
MYINFO.myaddr.pubkey = curve25519(MYINFO.privkey,curve25519_basepoint9());
printf("SuperNET_MYINFO: generate session keypair\n");
MYINFO.RELAYID = -1;
}
if ( passphrase == 0 || passphrase[0] == 0 )
return(&MYINFO);
@ -2077,13 +2078,28 @@ STRING_ARG(SuperNET,priv2wif,priv)
STRING_ARG(SuperNET,myipaddr,ipaddr)
{
cJSON *retjson = cJSON_CreateObject();
int32_t i; cJSON *retjson = cJSON_CreateObject();
myinfo->RELAYID = -1;
if ( myinfo->ipaddr[0] == 0 )
{
if ( is_ipaddr(ipaddr) != 0 )
{
strcpy(myinfo->ipaddr,ipaddr);
myinfo->myaddr.myipbits = (uint32_t)calc_ipbits(ipaddr);
for (i=0; i<myinfo->numrelays; i++)
if ( myinfo->relaybits[i] == myinfo->myaddr.myipbits )
{
myinfo->RELAYID = i;
break;
}
}
}
jaddstr(retjson,"result",myinfo->ipaddr);
if ( myinfo->RELAYID >= 0 )
{
jaddnum(retjson,"relayid",myinfo->RELAYID);
jaddnum(retjson,"numrelays",myinfo->numrelays);
}
return(jprint(retjson,1));
}

1
iguana/tests/myip2

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"SuperNET\",\"method\":\"activehandle\",\"ipaddr\":\"5.9.102.210"}"

1
iguana/tests/myip4

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"SuperNET\",\"method\":\"activehandle\",\"ipaddr\":\"78.47.196.146\"}"

2
includes/iguana_funcs.h

@ -521,7 +521,7 @@ int32_t basilisk_relays_send(struct supernet_info *myinfo,struct iguana_peer *ad
int32_t basilisk_hashes_send(struct supernet_info *myinfo,struct iguana_info *virt,struct iguana_peer *addr,char *CMD,bits256 *txids,int32_t num);
int32_t iguana_opreturn(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int64_t crypto777_payment,int32_t height,uint64_t hdrsi_unspentind,int64_t payment,uint32_t fileid,uint64_t scriptpos,uint32_t scriptlen);
int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen);
struct iguana_peer *basilisk_ensurerelay(struct iguana_info *btcd,uint32_t ipbits);
struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *btcd,uint32_t ipbits);
#include "../includes/iguana_api.h"

3
includes/iguana_structs.h

@ -467,7 +467,8 @@ struct supernet_info
portable_mutex_t allcoins_mutex,gecko_mutex,basilisk_mutex;
void *ctx;
struct delayedPoW_info dPOW;
uint32_t relaybits[IGUANA_MAXRELAYS]; struct basilisk_relay relays[IGUANA_MAXRELAYS]; int32_t numrelays;
uint32_t relaybits[IGUANA_MAXRELAYS]; struct basilisk_relay relays[IGUANA_MAXRELAYS];
int32_t numrelays,RELAYID;
// compatibility
bits256 pangea_category,instantdex_category;
};

Loading…
Cancel
Save