From 8f2eda1a5297a8071c68cccbe80ce43e7389c3ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Jan 2016 22:28:52 -0300 Subject: [PATCH] youip returned --- iguana/iguana_msg.c | 12 ------------ iguana/main.c | 27 +++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index bc097396b..8687b2f24 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -124,18 +124,6 @@ int32_t iguana_rwblockhash(int32_t rwflag,uint8_t *serialized,uint32_t *nVersion return(len); }*/ -int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,char *jsonstr,int32_t delaymillis) -{ - int32_t len; uint8_t serialized[8192]; - if ( (len= (int32_t)strlen(jsonstr)) < sizeof(serialized)-sizeof(struct iguana_msghdr) ) - { - memcpy(&serialized[sizeof(struct iguana_msghdr)],jsonstr,len+1); - printf("SUPERSEND.(%s) -> (%s) delaymillis.%d\n",jsonstr,addr->ipaddr,delaymillis); - return(iguana_queue_send(coin,addr,delaymillis,serialized,"SuperNET",len+1,0,1)); - } - else return(-1); -} - void iguana_gotversion(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msgversion *vers) { uint8_t serialized[sizeof(struct iguana_msghdr)]; diff --git a/iguana/main.c b/iguana/main.c index eb7e322ef..6cf0969a8 100644 --- a/iguana/main.c +++ b/iguana/main.c @@ -134,8 +134,6 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr) { jdelete(retjson,"tag"); jadd64bits(retjson,"tag",tag); - if ( remoteaddr != 0 && remoteaddr[0] != 0 && strncmp(remoteaddr,"127.0.0.1",strlen("127.0.0.1")) != 0 ) - jaddstr(retjson,"yourip",remoteaddr); retstr = jprint(retjson,1); //printf("retstr.(%s) retjsonstr.%p retjson.%p\n",retstr,retjsonstr,retjson); free(retjsonstr);//,strlen(retjsonstr)+1); @@ -198,6 +196,31 @@ char *SuperNET_p2p(struct iguana_info *coin,struct iguana_peer *addr,int32_t *de return(retstr); } +int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,char *jsonstr,int32_t delaymillis) +{ + int32_t len,flag=0,qlen = -1; uint8_t serialized[8192],*buf; cJSON *json; + if ( (json= cJSON_Parse(jsonstr)) != 0 ) + { + jdelete(json,"yourip"); + jaddstr(json,"yourip",addr->ipaddr); + jsonstr = jprint(json,1); + flag = 1; + } + buf = serialized; + if ( (len= (int32_t)strlen(jsonstr)) > sizeof(serialized)-sizeof(struct iguana_msghdr) ) + buf = calloc(1,len+sizeof(struct iguana_msghdr)); + { + memcpy(&buf[sizeof(struct iguana_msghdr)],jsonstr,len+1); + printf("SUPERSEND.(%s) -> (%s) delaymillis.%d\n",jsonstr,addr->ipaddr,delaymillis); + qlen = iguana_queue_send(coin,addr,delaymillis,serialized,"SuperNET",len+1,0,1); + } + if ( buf != serialized ) + free(buf); + if ( flag != 0 ) + free(jsonstr); + return(qlen); +} + void iguana_exit() { int32_t i,j,k; char *stopstr = "{\"agent\":\"SuperNET\",\"method\":\"stop\"}";