From 7a187951d66b4ea5deccefa14a0401b0df5ece46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 15:42:02 +0400 Subject: [PATCH] Test --- iguana/exchanges/LP_peers.c | 21 +++++++++++++++++++++ iguana/exchanges/LP_privkey.c | 7 +++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 81674b0de..3695db113 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -181,6 +181,27 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char return(peer); } +uint64_t ip_port; +uint32_t recvtime,numrecv,ipbits,errortime,errors,numpeers,needping,lasttime,connected,lastutxos,lastpeers,diduquery,good,sessionid; +uint16_t port,netid; + + +void LP_closepeers() +{ + struct LP_peerinfo *peer,*tmp; + HASH_ITER(hh,LP_peerinfos,peer,tmp) + { + portable_mutex_lock(&LP_peermutex); + HASH_DELETE(hh,LP_peerinfos,peer); + portable_mutex_unlock(&LP_peermutex); + if ( peer->pushsock >= 0 ) + nn_close(peer->pushsock), peer->pushsock = -1; + if ( peer->subsock >= 0 ) + nn_close(peer->subsock), peer->subsock = -1; + // free(peer); a small memleak to avoid freein inflight requests + } +} + /*int32_t LP_coinbus(uint16_t coin_busport) { struct LP_peerinfo *peer,*tmp; char busaddr[64]; int32_t timeout,bussock = -1; diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index a028869ef..c66ec1192 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -382,6 +382,11 @@ int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seedn printf("sorry, LP nodes can only set netid during startup\n"); return(-1); } + else if ( IAMLP == 0 && netid != G.netid ) + { + LP_closepeers(); + LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,netid,seednode); + } G.initializing = 1; if ( gui == 0 ) gui = "cli"; @@ -392,8 +397,6 @@ int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seedn sleep(5); } memset(&G,0,sizeof(G)); - if ( IAMLP == 0 ) - LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,netid,seednode); G.netid = netid; safecopy(G.seednode,seednode,sizeof(G.seednode)); vcalc_sha256(0,G.LP_passhash.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));