From 36c4a5918c7ae71f71f36671d878224b6f5fce07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Jan 2016 21:52:27 -0300 Subject: [PATCH] test --- iguana/iguana777.h | 2 +- iguana/iguana_json.c | 7 +++++-- iguana/iguana_msg.c | 3 ++- iguana/main.c | 17 ++++++++++++++--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 6d56e6c58..c0e880200 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -561,7 +561,7 @@ 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 *SuperNET_p2p(struct iguana_info *coin,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen); +char *SuperNET_p2p(struct iguana_info *coin,struct iguana_peer *addr,int32_t *delaymillisp,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_json.c b/iguana/iguana_json.c index b31dd9d7e..cd5cfbcc1 100755 --- a/iguana/iguana_json.c +++ b/iguana/iguana_json.c @@ -386,8 +386,11 @@ void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int ZERO_ARGS(SuperNET,stop) { - iguana_exit(); - return(clonestr("{\"result\":\"exit started\"}")); + if ( remoteaddr == 0 || strncmp(remoteaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 ) + { + iguana_exit(); + return(clonestr("{\"result\":\"exit started\"}")); + } else return(clonestr("{\"error\":\"cant do a remote stop of this node\"}")); } TWO_ARRAYS(SuperNET,mypeers,supernet,rawpeers) diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index 4898cff64..bc097396b 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -446,8 +446,9 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc if ( strcmp(H->command,"SuperNET") == 0 ) { addr->supernet = 1; + addr->msgcounts.verack++; len = recvlen; - if ( (retstr= SuperNET_p2p(coin,&delay,addr->ipaddr,data,recvlen)) != 0 ) + if ( (retstr= SuperNET_p2p(coin,addr,&delay,addr->ipaddr,data,recvlen)) != 0 ) { iguana_send_supernet(coin,addr,retstr,delay); free(retstr); diff --git a/iguana/main.c b/iguana/main.c index b73bd6df3..f04fc282a 100644 --- a/iguana/main.c +++ b/iguana/main.c @@ -159,7 +159,7 @@ char *iguana_JSON(char *jsonstr) return(retstr); } -char *SuperNET_p2p(struct iguana_info *coin,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen) +char *SuperNET_p2p(struct iguana_info *coin,struct iguana_peer *addr,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen) { cJSON *json,*retjson; char *agent,*method,*retstr = 0; *delaymillisp = 0; @@ -168,6 +168,12 @@ char *SuperNET_p2p(struct iguana_info *coin,int32_t *delaymillisp,char *ipaddr,u printf("GOT >>>>>>>> SUPERNET P2P.(%s) from.%s\n",(char *)data,coin->symbol); if ( (agent= jstr(json,"agent")) != 0 && (method= jstr(json,"method")) != 0 ) { + if ( strcmp(agent,"SuperNET") == 0 && strcmp(method,"stop") == 0 ) + { + addr->dead = (uint32_t)time(NULL); + free_json(json); + return(clonestr("{\"result\":\"peer marked as dead\"}")); + } jaddstr(json,"fromp2p",coin->symbol); if ( (retstr= SuperNET_JSON(0,json,ipaddr)) != 0 ) { @@ -191,22 +197,27 @@ char *SuperNET_p2p(struct iguana_info *coin,int32_t *delaymillisp,char *ipaddr,u void iguana_exit() { - int32_t i,j,k; + int32_t i,j,k; char *stopstr = "{\"agent\":\"SuperNET\",\"method\":\"stop\"}"; printf("start EXIT\n"); for (i=0; ipeers.active[j].dead = (uint32_t)time(NULL); + { + if ( Coins[i]->peers.active[j].usock >= 0 ) + iguana_send_supernet(Coins[i],&Coins[i]->peers.active[j],stopstr,0); + } } } + sleep(3); for (i=0; ipeers.active[j].dead = (uint32_t)time(NULL); for (k=0; k<3; k++) { if ( Coins[i]->peers.active[j].usock >= 0 )