From 9baf9a96b3008d3953d7a9851515922e95c80c38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Jan 2016 18:06:19 -0300 Subject: [PATCH] test --- iguana/iguana_json.c | 118 +++++++++++++++++++++++++++++++++- iguana/ramchain_api.c | 27 -------- includes/cJSON.h | 1 + includes/iguana_apideclares.h | 3 +- 4 files changed, 120 insertions(+), 29 deletions(-) diff --git a/iguana/iguana_json.c b/iguana/iguana_json.c index 9ca7ac70d..350b2a830 100755 --- a/iguana/iguana_json.c +++ b/iguana/iguana_json.c @@ -307,8 +307,122 @@ cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly) else return(array); } +cJSON *SuperNET_peerarray(struct iguana_info *coin,int32_t max,int32_t supernetflag) +{ + int32_t i,r,j,n = 0; struct iguana_peer *addr; cJSON *array = cJSON_CreateArray(); + r = rand(); + for (j=0; jpeers.active[i]; + if ( addr->usock >= 0 && (supernetflag == 0 || addr->supernet != 0) ) + { + jaddistr(array,addr->ipaddr); + if ( ++n >= max ) + break; + } + } + if ( n == 0 ) + { + free_json(array); + return(0); + } + return(array); +} + +int32_t SuperNET_coinpeers(struct iguana_info *coin,cJSON *SNjson,cJSON *rawjson,int32_t max) +{ + cJSON *array; + if ( (array= SuperNET_peerarray(coin,max,1)) != 0 ) + { + max -= cJSON_GetArraySize(array); + jadd(SNjson,coin->symbol,array); + } + if ( max > 0 && (array= SuperNET_peerarray(coin,max,0)) != 0 ) + { + max -= cJSON_GetArraySize(array); + jadd(rawjson,coin->symbol,array); + } + return(max); +} + +void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *ipaddr,int32_t supernetflag) +{ + printf("got %s remotepeer.(%s) supernet.%d\n",symbol,ipaddr,supernetflag); +} + +void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int32_t supernetflag) +{ + int32_t i,j,m; cJSON *coinarray; char *symbol,*ipaddr; struct iguana_info *ptr; + if ( (array= jarray(&n,array,"supernet")) != 0 ) + { + for (i=0; i0; i++) + if ( Coins[i] != 0 ) + max = SuperNET_coinpeers(Coins[i],SNjson,rawjson,max); + } + if ( max != 64 ) + { + jaddstr(retjson,"agent","SuperNET"); + jaddstr(retjson,"method","mypeers"); + jaddstr(retjson,"result","peers found"); + jadd(retjson,"supernet",SNjson); + jadd(retjson,"rawpeers",rawjson); + } + else + { + jaddstr(retjson,"error","no peers"); + free_json(SNjson); + free_json(rawjson); + } + return(jprint(retjson,1)); +} + STRING_ARG(iguana,peers,activecoin) { if ( coin != 0 ) @@ -540,7 +654,9 @@ TWO_STRINGS(SuperNET,html,agentform,htmlfile) char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSON *json,char *remoteaddr) { char *coinstr; struct iguana_info *coin = 0; - if ( (coinstr= jstr(json,"coin")) != 0 ) + if ( (coinstr= jstr(json,"activecoin")) != 0 ) + coin = iguana_coinfind(coinstr); + if ( coin == 0 && (coinstr= jstr(json,"coin")) != 0 ) coin = iguana_coinfind(coinstr); if ( strcmp(agent,"ramchain") == 0 && coin == 0 ) return(clonestr("{\"error\":\"ramchain needs coin\"}")); diff --git a/iguana/ramchain_api.c b/iguana/ramchain_api.c index 6f12a6374..2633d5f53 100755 --- a/iguana/ramchain_api.c +++ b/iguana/ramchain_api.c @@ -16,33 +16,6 @@ #include "iguana777.h" #include "../includes/iguana_apidefs.h" -STRING_ARG(ramchain,getpeers,activecoin) -{ - int32_t i,r,j,iter,n; struct iguana_peer *addr; cJSON *array = cJSON_CreateArray(); - cJSON *retjson = cJSON_CreateObject(); - printf("inside getpeers coin.%p\n",coin); - if ( coin != 0 ) - { - r = rand(); - for (iter=n=0; iter<2; iter++) - { - for (j=0; jpeers.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)); -} - ZERO_ARGS(ramchain,getinfo) { cJSON *retjson = cJSON_CreateObject(); diff --git a/includes/cJSON.h b/includes/cJSON.h index 4e7d8a40d..b5e84e69e 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -160,6 +160,7 @@ extern "C" /* When assigning an integer value, it needs to be propagated to valuedouble too. */ #define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val)) +#define jfieldstr get_cJSON_fieldname char *cJSON_str(cJSON *json); char *jstr(cJSON *json,char *field); diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 34d2c60fb..1a53ef227 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -16,6 +16,8 @@ ZERO_ARGS(SuperNET,help); TWO_STRINGS(SuperNET,html,agentform,htmlfile); STRING_ARG(SuperNET,bitcoinrpc,setcoin); +STRING_ARG(SuperNET,getpeers,activecoin); +STRING_ARG(SuperNET,mypeers,jsonstr); STRING_ARG(iguana,peers,activecoin); STRING_AND_INT(iguana,maxpeers,activecoin,max); @@ -28,7 +30,6 @@ TWO_STRINGS(iguana,removenode,activecoin,ipaddr); TWO_STRINGS(iguana,oneshot,activecoin,ipaddr); TWO_STRINGS(iguana,nodestatus,activecoin,ipaddr); -STRING_ARG(ramchain,getpeers,activecoin); ZERO_ARGS(ramchain,getinfo); ZERO_ARGS(ramchain,getbestblockhash); ZERO_ARGS(ramchain,getblockcount);