diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index aeea1c86f..90f13e0ec 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -441,6 +441,8 @@ void iguana_bundlestats(struct iguana_info *coin,char *str) { printf("%s\n",str); lastdisp = (uint32_t)time(NULL); + if ( coin->peers.ranked[0] != 0 ) + iguana_send_ping(coin,coin->peers.ranked[0]); } strcpy(coin->statusstr,str); coin->estsize = estsize; diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index ea20fc202..871a7840d 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -587,6 +587,8 @@ void iguana_startconnection(void *arg) printf("PEER CONNECTED.%d:%d of max.%d! %s:%d usock.%d\n",coin->peers.numconnected,n,coin->MAXPEERS,addr->ipaddr,coin->chain->portp2p,addr->usock); if ( strcmp("127.0.0.1",addr->ipaddr) == 0 ) coin->peers.localaddr = addr; + else if ( coin->peers.numranked == 0 ) + coin->peers.ranked[0] = addr; #ifdef IGUANA_DEDICATED_THREADS //iguana_launch("recv",iguana_dedicatedrecv,addr,IGUANA_RECVTHREAD); iguana_dedicatedloop(coin,addr); diff --git a/iguana/main.c b/iguana/main.c index d45f2c08f..2eebcbffb 100644 --- a/iguana/main.c +++ b/iguana/main.c @@ -71,10 +71,10 @@ int32_t iguana_jsonQ() } if ( (ptr= queue_dequeue(&jsonQ,0)) != 0 ) { - //printf("process.(%s)\n",ptr->jsonstr); +printf("process.(%s)\n",ptr->jsonstr); if ( (*ptr->retjsonstrp= SuperNET_jsonstr(ptr->myinfo,ptr->jsonstr,ptr->remoteaddr)) == 0 ) *ptr->retjsonstrp = clonestr("{\"error\":\"null return from iguana_jsonstr\"}"); - //printf("finished.(%s)\n",ptr->jsonstr); +printf("finished.(%s)\n",ptr->jsonstr); queue_enqueue("finishedQ",&finishedQ,&ptr->DL,0); return(1); } @@ -114,7 +114,7 @@ char *iguana_blockingjsonstr(struct supernet_info *myinfo,char *jsonstr,uint64_t char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr) { cJSON *retjson; uint64_t tag; uint32_t timeout; char *jsonstr; char *retjsonstr,*retstr = 0; - printf("SuperNET_JSON.(%s)\n",jprint(json,0)); + printf("SuperNET_JSON.(%s) remoteaddr.(%s)\n",jprint(json,0),remoteaddr!=0?remoteaddr:""); if ( json != 0 ) { if ( (tag= j64bits(json,"tag")) == 0 ) @@ -170,10 +170,12 @@ char *SuperNET_p2p(struct iguana_info *coin,int32_t *delaymillisp,char *ipaddr,u jaddstr(json,"fromp2p",coin->symbol); if ( (retstr= SuperNET_JSON(0,json,ipaddr)) != 0 ) { + printf("retstr.(%s)\n",retstr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) { if ( jobj(retjson,"result") != 0 || jobj(retjson,"error") != 0 || jobj(retjson,"method") == 0 ) { + printf("it is a result, dont return\n"); free(retstr); retstr = 0; } @@ -241,7 +243,7 @@ void iguana_main(void *arg) #ifdef __APPLE__ sleep(1); char *str; - if ( (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":0,\"maxpeers\":2,\"activecoin\":\"BTC\",\"active\":1}"),0)) != 0 ) + if ( (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":0,\"maxpeers\":2,\"activecoin\":\"BTCD\",\"active\":1}"),0)) != 0 ) { printf("got.(%s)\n",str); free(str); diff --git a/iguana/ramchain_api.c b/iguana/ramchain_api.c index 314503c10..6f12a6374 100755 --- a/iguana/ramchain_api.c +++ b/iguana/ramchain_api.c @@ -16,25 +16,30 @@ #include "iguana777.h" #include "../includes/iguana_apidefs.h" -ZERO_ARGS(ramchain,getpeers) +STRING_ARG(ramchain,getpeers,activecoin) { int32_t i,r,j,iter,n; struct iguana_peer *addr; cJSON *array = cJSON_CreateArray(); cJSON *retjson = cJSON_CreateObject(); - r = rand(); - for (iter=n=0; iter<2; iter++) + printf("inside getpeers coin.%p\n",coin); + if ( coin != 0 ) { - for (j=0; jpeers.active[i]; - if ( addr->usock >= 0 && (iter == 1 || addr->supernet != 0) ) + for (j=0; jipaddr); - if ( ++n >= 64 ) - break; + i = (r + j) % IGUANA_MAXPEERS; + addr = &coin->peers.active[i]; + if ( addr->usock >= 0 && (iter == 1 || addr->supernet != 0) ) + { + jaddistr(array,addr->ipaddr); + if ( ++n >= 64 ) + break; + } } } } + jadd(retjson,"peers",array); return(jprint(retjson,1)); } diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 86e369a11..34d2c60fb 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -28,7 +28,7 @@ TWO_STRINGS(iguana,removenode,activecoin,ipaddr); TWO_STRINGS(iguana,oneshot,activecoin,ipaddr); TWO_STRINGS(iguana,nodestatus,activecoin,ipaddr); -ZERO_ARGS(ramchain,getpeers); +STRING_ARG(ramchain,getpeers,activecoin); ZERO_ARGS(ramchain,getinfo); ZERO_ARGS(ramchain,getbestblockhash); ZERO_ARGS(ramchain,getblockcount);