diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 0f10adc50..fe22b2149 100755 --- a/basilisk/basilisk.c +++ b/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; inumresults; 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); diff --git a/basilisk/basilisk_CMD.c b/basilisk/basilisk_CMD.c index 0d2c0c49d..7b5921bff 100755 --- a/basilisk/basilisk_CMD.c +++ b/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; inumrelays; 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; inumrelays; 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; diff --git a/gecko/gecko_blocks.c b/gecko/gecko_blocks.c index cd3bed958..b16415f12 100755 --- a/gecko/gecko_blocks.c +++ b/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); diff --git a/gecko/gecko_miner.c b/gecko/gecko_miner.c index 19bc41f85..c41da819d 100755 --- a/gecko/gecko_miner.c +++ b/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; diff --git a/iguana/main.c b/iguana/main.c index a48337991..24d6c9243 100755 --- a/iguana/main.c +++ b/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; inumrelays; 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)); } diff --git a/iguana/tests/myip2 b/iguana/tests/myip2 new file mode 100755 index 000000000..c57c9c99e --- /dev/null +++ b/iguana/tests/myip2 @@ -0,0 +1 @@ +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"SuperNET\",\"method\":\"activehandle\",\"ipaddr\":\"5.9.102.210"}" diff --git a/iguana/tests/myip4 b/iguana/tests/myip4 new file mode 100755 index 000000000..d19757ae8 --- /dev/null +++ b/iguana/tests/myip4 @@ -0,0 +1 @@ +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"SuperNET\",\"method\":\"activehandle\",\"ipaddr\":\"78.47.196.146\"}" diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index ac12bde7b..319492a4c 100755 --- a/includes/iguana_funcs.h +++ b/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" diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index 4c0a8ac71..3bd177b20 100755 --- a/includes/iguana_structs.h +++ b/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; };