Browse Source

Merge pull request #445 from jl777/spvdex

dICO release candidate
etomic
jl777 7 years ago
committed by GitHub
parent
commit
c3ca74d254
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      iguana/exchanges/LP_include.h
  2. 49
      iguana/exchanges/LP_nativeDEX.c
  3. 8
      iguana/exchanges/LP_rpc.c
  4. 7
      iguana/exchanges/LP_socket.c
  5. 26
      iguana/exchanges/stats.c

4
iguana/exchanges/LP_include.h

@ -39,7 +39,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping
#define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL)
#define LP_AUTOTRADE_TIMEOUT 20
#define ELECTRUM_TIMEOUT 20
#define ELECTRUM_TIMEOUT 5
#define LP_ELECTRUM_KEEPALIVE 60
#define LP_ELECTRUM_MAXERRORS 777
#define LP_MEMPOOL_TIMEINCR 10
@ -255,7 +255,7 @@ struct iguana_info
portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses;
uint64_t txfee;
int32_t numutxos,longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport;
uint32_t lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint32_t electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms;
char symbol[16],smartaddr[64],userpass[1024],serverport[128];
// portfolio

49
iguana/exchanges/LP_nativeDEX.c

@ -18,11 +18,9 @@
// LP_nativeDEX.c
// marketmaker
//
// selftest and fix rpc port
// verify portfolio, interest to KMD withdraw
// BCH signing
// dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections
// bigendian architectures need to use little endian for sighash calcs
// BCH signing
#include <stdio.h>
struct LP_millistats
@ -620,13 +618,6 @@ void LP_coinsloop(void *_coins)
}
}
}
if ( time(NULL) > coin->lastunspent+30 )
{
//printf("call electrum listunspent.%s\n",coin->symbol);
if ( (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,coin->smartaddr,2)) != 0 )
free_json(retjson);
coin->lastunspent = (uint32_t)time(NULL);
}
while ( ep != 0 )
{
if ( time(NULL) > ep->keepalive+LP_ELECTRUM_KEEPALIVE )
@ -836,13 +827,23 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint
void LP_pubkeysloop(void *ctx)
{
static uint32_t lasttime;
static uint32_t lasttime; cJSON *retjson; struct iguana_info *coin,*tmp;
strcpy(LP_pubkeysloop_stats.name,"LP_pubkeysloop");
LP_pubkeysloop_stats.threshold = 5000.;
sleep(10);
while ( 1 )
{
LP_millistats_update(&LP_pubkeysloop_stats);
HASH_ITER(hh,LP_coins,coin,tmp) // firstrefht,firstscanht,lastscanht
{
if ( coin->electrum != 0 && time(NULL) > coin->lastunspent+30 )
{
//printf("call electrum listunspent.%s\n",coin->symbol);
if ( (retjson= electrum_address_listunspent(coin->symbol,coin->electrum,&retjson,coin->smartaddr,2)) != 0 )
free_json(retjson);
coin->lastunspent = (uint32_t)time(NULL);
}
}
if ( time(NULL) > lasttime+60 )
{
//printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL));
@ -1163,7 +1164,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching LP_swapsloop for port.%u\n",myport);
exit(-1);
}
int32_t nonz;
int32_t nonz; uint32_t lasthello = 0;
while ( 1 )
{
nonz = 0;
@ -1179,13 +1180,29 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
usleep(1000);
else if ( IAMLP == 0 )
usleep(1000);
/*if ( (rand() % 10000) == 0 )
if ( time(NULL) > lasthello+60 )
{
int32_t sock = LP_bindsock;
printf("bindsock reset test\n");
char *hellostr,*retstr; cJSON *retjson; int32_t allgood,sock = LP_bindsock;
allgood = 0;
if ( (retstr= issue_hello(myport)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (hellostr= jstr(retjson,"status")) != 0 && strcmp(hellostr,"got hello") == 0 )
allgood = 1;
else printf("strange return.(%s)\n",jprint(retjson,0));
free_json(retjson);
} else printf("couldnt parse hello return.(%s)\n",retstr);
free(retstr);
} else printf("issue_hello NULL return\n");
lasthello = (uint32_t)time(NULL);
if ( allgood == 0 )
{
printf("RPC port got stuck, close bindsocket\n");
LP_bindsock = -1;
closesocket(sock);
}*/
}
}
}
#endif
}

8
iguana/exchanges/LP_rpc.c

@ -93,6 +93,14 @@ char *issue_LP_getprices(char *destip,uint16_t destport)
//return(issue_curlt(url,LP_HTTP_TIMEOUT));
}
char *issue_hello(uint16_t port)
{
char url[512];
sprintf(url,"http://127.0.0.1:%u/api/stats/hello",port);
//printf("getutxo.(%s)\n",url);
return(issue_curlt(url,60)); // might be starting a trade
}
char *issue_LP_listunspent(char *destip,uint16_t destport,char *symbol,char *coinaddr)
{
char url[512],*retstr;

7
iguana/exchanges/LP_socket.c

@ -408,12 +408,12 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch
sitem->expiration = timeout;
sitem->DL.type = ep->stratumid++;
sitem->retptrp = (void **)retjsonp;*/
portable_mutex_lock(&ep->mutex);
//portable_mutex_lock(&ep->mutex);
//queue_enqueue("sendQ",&ep->sendQ,&sitem->DL);
expiration = (uint32_t)time(NULL) + timeout + 1;
while ( *retjsonp == 0 && time(NULL) <= expiration )
usleep(5000);
portable_mutex_unlock(&ep->mutex);
//portable_mutex_unlock(&ep->mutex);
if ( *retjsonp == 0 || jobj(*retjsonp,"error") != 0 )
{
if ( ++ep->numerrors >= LP_ELECTRUM_MAXERRORS )
@ -597,7 +597,8 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON
{
if ( jobj(retjson,"error") == 0 && is_cJSON_Array(retjson) != 0 )
{
//printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0)));
if ( 0 && electrumflag > 1 )
printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0)));
updatedflag = 0;
if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 )
LP_postutxos(coin->symbol,addr), updatedflag = 1;

26
iguana/exchanges/stats.c

@ -740,29 +740,33 @@ void LP_rpc_processreq(void *_ptr)
}
extern int32_t IAMLP;
int32_t LP_bindsock = -1;
int32_t LP_bindsock_reset,LP_bindsock = -1;
void stats_rpcloop(void *args)
{
static uint32_t counter;
uint16_t port; int32_t retval,sock; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits; struct rpcrequest_info *req,*req2,*rtmp;
uint16_t port; int32_t retval,sock,initial_bindsock_reset; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits; struct rpcrequest_info *req,*req2,*rtmp;
if ( (port= *(uint16_t *)args) == 0 )
port = 7779;
RPC_port = port;
localhostbits = (uint32_t)calc_ipbits("127.0.0.1");
while ( 1 )
initial_bindsock_reset = LP_bindsock_reset;
while ( LP_bindsock_reset == initial_bindsock_reset )
{
//printf("LP_bindsock.%d\n",LP_bindsock);
if ( LP_bindsock < 0 )
{
while ( (LP_bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 )
usleep(10000);
if ( counter++ < 1 )
#ifndef _WIN32
fcntl(LP_bindsock, F_SETFL, fcntl(LP_bindsock, F_GETFL, 0) | O_NONBLOCK);
#endif
//if ( counter++ < 1 )
printf(">>>>>>>>>> DEX stats 127.0.0.1:%d bind sock.%d DEX stats API enabled <<<<<<<<<\n",port,LP_bindsock);
}
//printf("after LP_bindsock.%d\n",LP_bindsock);
clilen = sizeof(cli_addr);
sock = accept(LP_bindsock,(struct sockaddr *)&cli_addr,&clilen);
#ifdef _WIN32
if ( sock < 0 )
{
printf("iguana_rpcloop ERROR on accept usock.%d errno %d %s\n",sock,errno,strerror(errno));
@ -770,12 +774,23 @@ void stats_rpcloop(void *args)
LP_bindsock = -1;
continue;
}
#else
if ( sock < 0 )
{
//fprintf(stderr,".");
if ( IAMLP == 0 )
usleep(50000);
else usleep(2500);
continue;
}
#endif
memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits));
req = calloc(1,sizeof(*req));
req->sock = sock;
req->ipbits = ipbits;
LP_rpc_processreq(req);
continue;
// this leads to cant open file errors
if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 )
{
printf("error launching rpc handler on port %d, retval.%d\n",port,retval);
@ -795,6 +810,7 @@ continue;
}
}
}
printf("i got killed\n");
}
#ifndef FROM_MARKETMAKER

Loading…
Cancel
Save