From 6c165fa0732f66b63952ad98734f0d23b9146f0d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 8 Jan 2016 10:40:49 -0300 Subject: [PATCH] test --- iguana/iguana777.h | 3 ++- iguana/iguana_html.c | 15 ++++++++++----- iguana/iguana_json.c | 24 +++++++++++++----------- iguana/iguana_msg.c | 7 ++++++- iguana/iguana_rpc.c | 11 +++++++++++ 5 files changed, 42 insertions(+), 18 deletions(-) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index a10416d0d..7ee9d2df9 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -553,7 +553,8 @@ double dxblend(double *destp,double val,double decay); // json int32_t iguana_processjsonQ(struct iguana_info *coin); // reentrant, can be called during any idletime -char *iguana_JSON(char *jsonstr); +char *iguana_JSON(struct iguana_info *coin,char *jsonstr,char *remoteaddr); +char *SuperNET_p2p(struct iguana_info *coin,char *ipaddr,uint8_t *data,int32_t datalen); char *mbstr(char *str,double); int init_hexbytes_noT(char *hexbytes,unsigned char *message,long len); diff --git a/iguana/iguana_html.c b/iguana/iguana_html.c index a8d41ffc6..9136cca0f 100755 --- a/iguana/iguana_html.c +++ b/iguana/iguana_html.c @@ -152,12 +152,12 @@ char *HTMLfooter = #define HTML_EMIT(str) if ( (str) != 0 && (str)[0] != 0 ) strcpy(&retbuf[size],str), size += (int32_t)strlen(str) char Prevjsonstr[1024],Currentjsonstr[1024]; -char *iguana_rpc(char *agent,cJSON *json,char *data,int32_t datalen) +char *iguana_rpc(char *agent,cJSON *json,char *data,int32_t datalen,char *remoteaddr) { //printf("agent.(%s) json.(%s) data[%d] %s\n",agent,jprint(json,0),datalen,data!=0?data:""); if ( data == 0 ) - return(iguana_JSON(jprint(json,0))); - else return(iguana_JSON(data)); + return(iguana_JSON(0,jprint(json,0),remoteaddr)); + else return(iguana_JSON(0,data,remoteaddr)); } void iguana_urldecode(char *str) @@ -578,7 +578,12 @@ char *iguana_rpcparse(char *retbuf,int32_t bufsize,int32_t *postflagp,char *json char *key,*reststr,*str,*retstr,remoteaddr[65],porturl[65],*data = 0,*value,*agent = "SuperNET"; //printf("rpcparse.(%s)\n",jsonstr); localaccess = 1; - strcpy(remoteaddr,"127.0.0.1"); // need to verify this + if ( (str= strstr("Referer: ",jsonstr)) != 0 ) + { + for (i=0; str[i]!=' '&&str[i]!=0&&str[i]!='\n'&&str[i]!='\r'; i++) + remoteaddr[i] = str[i]; + remoteaddr[i] = 0; + } else strcpy(remoteaddr,"127.0.0.1"); // need to verify this *postflagp = 0; if ( strncmp("POST",jsonstr,4) == 0 ) jsonstr += 6, *postflagp = postflag = 1; @@ -687,7 +692,7 @@ char *iguana_rpcparse(char *retbuf,int32_t bufsize,int32_t *postflagp,char *json } } } - retstr = iguana_rpc(agent,json,data,datalen); + retstr = iguana_rpc(agent,json,data,datalen,remoteaddr); free_json(json); return(retstr); //printf("post.%d json.(%s) data[%d] %s\n",postflag,jprint(json,0),datalen,data!=0?data:""); diff --git a/iguana/iguana_json.c b/iguana/iguana_json.c index e91a0ca80..5874045f8 100755 --- a/iguana/iguana_json.c +++ b/iguana/iguana_json.c @@ -452,14 +452,16 @@ char *iguana_blockingjsonstr(struct iguana_info *coin,char *jsonstr,uint64_t tag } } -char *iguana_JSON(char *jsonstr) +char *iguana_JSON(struct iguana_info *coin,char *jsonstr,char *remoteaddr) { - cJSON *json,*retjson; uint64_t tag; uint32_t timeout; int32_t retval; - struct iguana_info *coin; char *method,*retjsonstr,*symbol,*retstr = 0; - printf("iguana_JSON.(%s)\n",jsonstr); + cJSON *json,*retjson; uint64_t tag; uint32_t timeout; int32_t retval,localaccess = 0; + char *method,*retjsonstr,*symbol,*retstr = 0; + if ( remoteaddr == 0 || strcmp(remoteaddr,"127.0.0.1") == 0 ) // || strcmp(remoteaddr,myipaddr) == 0 ) + localaccess = 1; + printf("iguana_JSON.(%s) from %s\n",jsonstr,localaccess==0?remoteaddr:"local access"); if ( (json= cJSON_Parse(jsonstr)) != 0 ) { - if ( (method= jstr(json,"method")) != 0 && strcmp(method,"addcoin") == 0 ) + if ( localaccess != 0 && (method= jstr(json,"method")) != 0 && strcmp(method,"addcoin") == 0 ) { if ( (retval= iguana_launchcoin(jstr(json,"coin"),json)) > 0 ) return(clonestr("{\"result\":\"launched coin\"}")); @@ -470,10 +472,10 @@ char *iguana_JSON(char *jsonstr) OS_randombytes((uint8_t *)&tag,sizeof(tag)); if ( (symbol= jstr(json,"coin")) != 0 ) { - if ( (coin= iguana_coinfind(symbol)) != 0 && coin->launched == 0 ) + coin = iguana_coinfind(symbol); + if ( coin != 0 && localaccess != 0 && coin->launched == 0 ) iguana_launchcoin(symbol,json); } - else coin = 0; if ( (timeout= juint(json,"timeout")) == 0 ) timeout = IGUANA_JSONTIMEOUT; if ( (retjsonstr= iguana_blockingjsonstr(coin,jsonstr,tag,timeout)) != 0 ) @@ -496,7 +498,7 @@ char *iguana_JSON(char *jsonstr) return(retstr); } -void iguana_issuejsonstrM(void *arg) +/*void iguana_issuejsonstrM(void *arg) { cJSON *json; int32_t fd; char *retjsonstr,*jsonstr = arg; retjsonstr = iguana_JSON(jsonstr); @@ -512,7 +514,7 @@ void iguana_issuejsonstrM(void *arg) printf("%s\n",retjsonstr); free(retjsonstr);//,strlen(retjsonstr)+1); free(jsonstr);//,strlen(jsonstr)+1); -} +}*/ void iguana_main(void *arg) { @@ -563,11 +565,11 @@ void iguana_main(void *arg) { #ifdef __APPLE__ sleep(1); - iguana_JSON("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":0,\"maxpeers\":4,\"coin\":\"BTCD\",\"active\":1}"); + iguana_JSON(iguana_coinfind("BTCD"),"{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":0,\"maxpeers\":4,\"coin\":\"BTCD\",\"active\":1}",0); #endif } if ( arg != 0 ) - iguana_JSON(arg); + iguana_JSON(0,arg,0); //init_InstantDEX(); while ( 1 ) { diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index 066aa411e..27b48266c 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -399,7 +399,7 @@ int32_t iguana_send_hashes(struct iguana_info *coin,char *command,struct iguana_ int32_t iguana_parser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen) { - uint8_t serialized[512]; + uint8_t serialized[512]; char *retstr; int32_t i,retval,srvmsg,bloom,intvectors,len= -100; uint64_t nonce,x; uint32_t type; bits256 hash2; bloom = intvectors = srvmsg = -1; if ( addr != 0 ) @@ -412,6 +412,11 @@ int32_t iguana_parser(struct iguana_info *coin,struct iguana_peer *addr,struct O if ( strcmp(H->command,"SuperNET") == 0 ) { printf("GOT.(%s) len.%d from %s\n",H->command,recvlen,addr->ipaddr); + len = recvlen; + if ( (retstr= SuperNET_p2p(coin,addr->ipaddr,data,recvlen)) != 0 ) + { + free(retstr); // dont respond immediate due to privacy + } } else if ( strcmp(H->command,"version") == 0 ) { diff --git a/iguana/iguana_rpc.c b/iguana/iguana_rpc.c index 7e2ca1a93..50bc436a8 100755 --- a/iguana/iguana_rpc.c +++ b/iguana/iguana_rpc.c @@ -499,3 +499,14 @@ char *ramchain_parser(struct iguana_agent *agent,struct iguana_info *coin,char * return(ramchain_coinparser(coin,method,json)); } +char *SuperNET_p2p(struct iguana_info *coin,char *ipaddr,uint8_t *data,int32_t datalen) +{ + cJSON *json; char *retstr = 0; + if ( (json= cJSON_Parse((char *)data)) != 0 ) + { + printf("SUPERNET P2P.(%s)\n",(char *)data); + retstr = iguana_JSON(coin,(char *)data,ipaddr); + free_json(json); + } + return(retstr); +}