Browse Source

Merge pull request #448 from jl777/spvdex

automatic electrum kickstart on calling electrum api again
etomic
jl777 7 years ago
committed by GitHub
parent
commit
c7faf4cb93
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      iguana/exchanges/LP_nativeDEX.c
  2. 42
      iguana/exchanges/LP_socket.c

8
iguana/exchanges/LP_nativeDEX.c

@ -1202,6 +1202,14 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("RPC port got stuck, close bindsocket\n");
LP_bindsock = -1;
closesocket(sock);
LP_bindsock_reset++;
sleep(10);
printf("launch new rpcloop\n");
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 )
{
printf("error launching stats rpcloop for port.%u\n",myport);
exit(-1);
}
}
}
}

42
iguana/exchanges/LP_socket.c

@ -124,9 +124,9 @@ int32_t LP_socket(int32_t bindflag,char *hostname,uint16_t port)
#endif
if ( bindflag == 0 )
{
printf("call connect sock.%d\n",sock);
//printf("call connect sock.%d\n",sock);
result = connect(sock,(struct sockaddr *)&saddr,addrlen);
printf("called connect result.%d\n",result);
//printf("called connect result.%d\n",result);
timeout.tv_sec = 2;
timeout.tv_usec = 0;
setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(void *)&timeout,sizeof(timeout));
@ -389,6 +389,25 @@ void electrum_initial_requests(struct electrum_info *ep)
electrum_sitem(ep,stratumreq,3,&retjson);
}
int32_t electrum_kickstart(struct electrum_info *ep)
{
closesocket(ep->sock), ep->sock = -1;
sleep(1);
if ( (ep->sock= LP_socket(0,ep->ipaddr,ep->port)) < 0 )
{
printf("error RE-connecting to %s:%u\n",ep->ipaddr,ep->port);
return(-1);
}
else
{
ep->stratumid = 0;
electrum_initial_requests(ep);
printf("RECONNECT ep.%p %s numerrors.%d too big -> new %s:%u sock.%d\n",ep,ep->symbol,ep->numerrors,ep->ipaddr,ep->port,ep->sock);
ep->numerrors = 0;
}
return(0);
}
cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,char *params,int32_t timeout)
{
// queue id and string and callback
@ -417,20 +436,9 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch
if ( *retjsonp == 0 || jobj(*retjsonp,"error") != 0 )
{
if ( ++ep->numerrors >= LP_ELECTRUM_MAXERRORS )
{
closesocket(ep->sock), ep->sock = -1;
if ( (ep->sock= LP_socket(0,ep->ipaddr,ep->port)) < 0 )
printf("error RE-connecting to %s:%u\n",ep->ipaddr,ep->port);
else
{
ep->stratumid = 0;
electrum_initial_requests(ep);
printf("ep.%p %s numerrors.%d too big -> new %s:%u sock.%d\n",ep,ep->symbol,ep->numerrors,ep->ipaddr,ep->port,ep->sock);
ep->numerrors = 0;
}
}
electrum_kickstart(ep);
} else if ( ep->numerrors > 0 )
ep->numerrors++;
ep->numerrors--;
if ( ep->prev == 0 )
{
if ( *retjsonp == 0 )
@ -1038,7 +1046,7 @@ void LP_dedicatedloop(void *arg)
cJSON *LP_electrumserver(struct iguana_info *coin,char *ipaddr,uint16_t port)
{
struct electrum_info *ep; int32_t already; cJSON *retjson;
struct electrum_info *ep; int32_t kickval,already; cJSON *retjson;
if ( ipaddr == 0 || ipaddr[0] == 0 || port == 0 )
{
//coin->electrum = 0;
@ -1070,8 +1078,10 @@ cJSON *LP_electrumserver(struct iguana_info *coin,char *ipaddr,uint16_t port)
}
else
{
kickval = electrum_kickstart(ep);
jaddstr(retjson,"result","success");
jaddstr(retjson,"status","already there");
jaddstr(retjson,"restart",kickval);
}
//printf("(%s)\n",jprint(retjson,0));
return(retjson);

Loading…
Cancel
Save