Browse Source

Merge pull request #427 from jl777/spvdex

fix connection reset for non-LP nodes
etomic
jl777 7 years ago
committed by GitHub
parent
commit
9d0d2bd51d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      iguana/exchanges/LP_rpc.c
  2. 1
      iguana/exchanges/LP_socket.c
  3. 14
      iguana/exchanges/stats.c

6
iguana/exchanges/LP_rpc.c

@ -111,7 +111,7 @@ char *LP_apicall(struct iguana_info *coin,char *method,char *params)
{
if ( (retjson= electrum_submit(coin->symbol,coin->electrum,&retjson,method,params,ELECTRUM_TIMEOUT)) != 0 )
{
retstr = jprint(retjson,0);
retstr = jprint(retjson,1);
//printf("got.%p (%s)\n",retjson,retstr);
return(retstr);
} return(clonestr("{\"error\":\"electrum no response\"}"));
@ -808,6 +808,8 @@ double _LP_getestimatedrate(struct iguana_info *coin)
sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2);
if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 )
{
if ( coin->electrum != 0 )
printf("estimatefee.(%s)\n",retstr);
if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 )
{
if ( jobj(errjson,"error") != 0 )
@ -828,7 +830,7 @@ double _LP_getestimatedrate(struct iguana_info *coin)
coin->ratetime = (uint32_t)time(NULL);
}
free(retstr);
}
} else rate = coin->rate;
} else rate = coin->rate;
return(rate);
}

1
iguana/exchanges/LP_socket.c

@ -592,6 +592,7 @@ cJSON *electrum_addpeer(char *symbol,struct electrum_info *ep,cJSON **retjsonp,c
cJSON *electrum_sendrawtransaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *rawtx) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.transaction.broadcast",rawtx,ELECTRUM_TIMEOUT)); }
cJSON *electrum_estimatefee(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t numblocks) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.estimatefee",numblocks,ELECTRUM_TIMEOUT)); }
cJSON *electrum_getchunk(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t n) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.block.get_chunk",n,ELECTRUM_TIMEOUT)); }
cJSON *electrum_getheader(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t n)

14
iguana/exchanges/stats.c

@ -219,7 +219,7 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
return(-1);
}
}
if ( listen(sock,512) != 0 )
if ( listen(sock,1) != 0 )
{
printf("listen(%s) port.%d failed: %s sock.%d. errno.%d\n",hostname,port,strerror(errno),sock,errno);
if ( sock >= 0 )
@ -730,13 +730,15 @@ void LP_rpc_processreq(void *_ptr)
free(jsonbuf);
}
extern int32_t IAMLP;
void stats_rpcloop(void *args)
{
static uint32_t counter;
uint16_t port; int32_t sock,bindsock=-1; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits; uint64_t arg64; void *arg64ptr;
uint16_t port; int32_t sock,bindsock=-1; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits; uint64_t arg64; void *arg64ptr;
if ( (port= *(uint16_t *)args) == 0 )
port = 7779;
RPC_port = port;
localhostbits = (uint32_t)calc_ipbits("127.0.0.1");
/*while ( (bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 )
{
//if ( coin->MAXPEERS == 1 )
@ -771,18 +773,18 @@ void stats_rpcloop(void *args)
{
LP_rpc_processreq((void *)&arg64);
free(arg64ptr);
//char remoteaddr[64];
//expand_ipbits(remoteaddr,ipbits);
//printf("finished RPC request from (%s) %x\n",remoteaddr,ipbits);
closesocket(sock);
}
else if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_rpc_processreq,arg64ptr) != 0 )
{
printf("error launching rpc handler on port %d\n",port);
// yes, small leak per command
}
if ( IAMLP != 0 && ipbits != localhostbits )
{
close(bindsock);
closesocket(sock);
bindsock = iguana_socket(1,"0.0.0.0",port);
} //else printf("skip close and rebind\n");
}
}

Loading…
Cancel
Save