|
|
@ -28,7 +28,7 @@ |
|
|
|
#define STATS_DESTDIR "/var/www/html" |
|
|
|
#define STATS_DEST "/var/www/html/DEXstats.json" |
|
|
|
#include "DEXstats.h" |
|
|
|
char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port); |
|
|
|
char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port); |
|
|
|
void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats_JSONonly,uint32_t queueid); |
|
|
|
extern uint32_t DOCKERFLAG; |
|
|
|
|
|
|
@ -331,6 +331,10 @@ cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr) |
|
|
|
|
|
|
|
extern void *bitcoin_ctx(); |
|
|
|
extern int32_t IPC_ENDPOINT; |
|
|
|
extern portable_mutex_t LP_gcmutex,LP_commandmutex; |
|
|
|
extern struct rpcrequest_info *LP_garbage_collector; |
|
|
|
uint16_t RPC_port; |
|
|
|
static int32_t spawned,maxspawned; |
|
|
|
|
|
|
|
char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port) |
|
|
|
{ |
|
|
@ -530,7 +534,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po |
|
|
|
//free(buf);
|
|
|
|
//while ( retstr == 0 )
|
|
|
|
// usleep(10000);
|
|
|
|
if ( (retstr= stats_JSON(ctx,"127.0.0.1",-1,argjson,remoteaddr,port)) != 0 ) |
|
|
|
if ( (retstr= stats_JSON(ctx,0,"127.0.0.1",-1,argjson,remoteaddr,port)) != 0 ) |
|
|
|
{ |
|
|
|
if ( (retitem= cJSON_Parse(retstr)) != 0 ) |
|
|
|
jaddi(retarray,retitem); |
|
|
@ -543,7 +547,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po |
|
|
|
//free(buf);
|
|
|
|
//while ( retstr == 0 )
|
|
|
|
// usleep(10000);
|
|
|
|
if ( (retstr= stats_JSON(ctx,myipaddr,-1,argjson,remoteaddr,port)) != 0 ) |
|
|
|
if ( (retstr= stats_JSON(ctx,0,myipaddr,-1,argjson,remoteaddr,port)) != 0 ) |
|
|
|
{ |
|
|
|
if ( (retitem= cJSON_Parse(retstr)) != 0 ) |
|
|
|
jaddi(retarray,retitem); |
|
|
@ -557,7 +561,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
cJSON *arg; char *buf; |
|
|
|
cJSON *arg; char *buf,*method; int32_t fastflag; |
|
|
|
if ( jstr(argjson,"agent") != 0 && strcmp(jstr(argjson,"agent"),"bitcoinrpc") != 0 && jobj(argjson,"params") != 0 ) |
|
|
|
{ |
|
|
|
arg = jobj(argjson,"params"); |
|
|
@ -567,16 +571,24 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po |
|
|
|
//printf("ARGJSON.(%s)\n",jprint(arg,0));
|
|
|
|
if ( userpass != 0 && jstr(arg,"userpass") == 0 ) |
|
|
|
jaddstr(arg,"userpass",userpass); |
|
|
|
if ( (fastflag= jint(arg,"fast")) == 0 ) |
|
|
|
{ |
|
|
|
if ( (method= jstr(arg,"method")) != 0 && (strcmp(method,"orderbook") == 0 || strcmp(method,"portfolio") == 0) ) |
|
|
|
fastflag = 1; |
|
|
|
} |
|
|
|
if ( fastflag == 0 ) |
|
|
|
portable_mutex_lock(&LP_commandmutex); |
|
|
|
#ifdef FROM_MARKETMAKER |
|
|
|
if ( strcmp(remoteaddr,"127.0.0.1") == 0 || LP_valid_remotemethod(arg) > 0 ) |
|
|
|
{ |
|
|
|
if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 ) |
|
|
|
{ |
|
|
|
buf = jprint(arg,0); |
|
|
|
//printf("Q command\n");
|
|
|
|
LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid); |
|
|
|
free(buf); |
|
|
|
retstr = clonestr("{\"result\":\"success\",\"status\":\"queued\"}"); |
|
|
|
} else retstr = stats_JSON(ctx,"127.0.0.1",-1,arg,remoteaddr,port); |
|
|
|
} else retstr = stats_JSON(ctx,jint(arg,"fast"),"127.0.0.1",-1,arg,remoteaddr,port); |
|
|
|
} else retstr = clonestr("{\"error\":\"invalid remote method\"}"); |
|
|
|
#else |
|
|
|
if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 ) |
|
|
@ -584,8 +596,10 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po |
|
|
|
buf = jprint(arg,0); |
|
|
|
LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid); |
|
|
|
free(buf); |
|
|
|
} else retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port); |
|
|
|
} else retstr = stats_JSON(ctx,jint(arg,"fast"),myipaddr,-1,arg,remoteaddr,port); |
|
|
|
#endif |
|
|
|
if ( fastflag == 0 ) |
|
|
|
portable_mutex_unlock(&LP_commandmutex); |
|
|
|
} |
|
|
|
free_json(argjson); |
|
|
|
} |
|
|
@ -625,13 +639,8 @@ int32_t iguana_getheadersize(char *buf,int32_t recvlen) |
|
|
|
return(recvlen); |
|
|
|
} |
|
|
|
|
|
|
|
uint16_t RPC_port; |
|
|
|
extern portable_mutex_t LP_commandmutex,LP_gcmutex; |
|
|
|
extern struct rpcrequest_info *LP_garbage_collector; |
|
|
|
|
|
|
|
void LP_rpc_processreq(void *_ptr) |
|
|
|
{ |
|
|
|
static uint32_t spawned,maxspawned; |
|
|
|
char filetype[128],content_type[128]; |
|
|
|
int32_t recvlen,flag,postflag=0,contentlen,remains,sock,numsent,jsonflag=0,hdrsize,len; |
|
|
|
char helpname[512],remoteaddr[64],*buf,*retstr,space[8192],space2[32786],*jsonbuf; struct rpcrequest_info *req = _ptr; |
|
|
@ -641,11 +650,11 @@ void LP_rpc_processreq(void *_ptr) |
|
|
|
sock = req->sock; |
|
|
|
recvlen = flag = 0; |
|
|
|
retstr = 0; |
|
|
|
//space = calloc(1,size);
|
|
|
|
jsonbuf = calloc(1,size); |
|
|
|
//printf("alloc jsonbuf.%p\n",jsonbuf);
|
|
|
|
remains = size-1; |
|
|
|
buf = jsonbuf; |
|
|
|
if ( spawned < 0 ) |
|
|
|
spawned = 0; |
|
|
|
spawned++; |
|
|
|
if ( spawned > maxspawned ) |
|
|
|
{ |
|
|
@ -708,9 +717,7 @@ void LP_rpc_processreq(void *_ptr) |
|
|
|
if ( recvlen > 0 ) |
|
|
|
{ |
|
|
|
jsonflag = postflag = 0; |
|
|
|
//portable_mutex_lock(&LP_commandmutex);
|
|
|
|
retstr = stats_rpcparse(space,size,&jsonflag,&postflag,jsonbuf,remoteaddr,filetype,req->port); |
|
|
|
//portable_mutex_unlock(&LP_commandmutex);
|
|
|
|
if ( filetype[0] != 0 ) |
|
|
|
{ |
|
|
|
static cJSON *mimejson; char *tmp,*typestr=0; long tmpsize; |
|
|
@ -795,6 +802,7 @@ void LP_rpc_processreq(void *_ptr) |
|
|
|
//printf("free req.%p\n",req);
|
|
|
|
free(req); |
|
|
|
} |
|
|
|
if ( spawned > 0 ) |
|
|
|
spawned--; |
|
|
|
} |
|
|
|
|
|
|
@ -854,14 +862,14 @@ void stats_rpcloop(void *args) |
|
|
|
continue; |
|
|
|
} |
|
|
|
req = calloc(1,sizeof(*req)); |
|
|
|
//printf("alloc req.%p\n",req);
|
|
|
|
//printf("LP_rpc_processreq req.%p\n",req);
|
|
|
|
req->sock = sock; |
|
|
|
req->ipbits = ipbits; |
|
|
|
req->port = port; |
|
|
|
if ( spawned > 0 ) |
|
|
|
LP_rpc_processreq(req); |
|
|
|
continue; |
|
|
|
// this might lead to "cant open file errors"
|
|
|
|
if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 ) |
|
|
|
else 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); |
|
|
|
LP_rpc_processreq(req); |
|
|
|