diff --git a/crypto777/hmac_sha512.c b/crypto777/hmac_sha512.c index e1fe4e523..7df6d978f 100755 --- a/crypto777/hmac_sha512.c +++ b/crypto777/hmac_sha512.c @@ -621,4 +621,28 @@ char *hmac_whirlpool_str(char *dest,char *key,int32_t key_size,char *message) return(dest); } +void calc_md2str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len) +{ + bits128 x; + calc_md2(hexstr,buf,msg,len); + decode_hex(buf,sizeof(x),hexstr); + //memcpy(buf,x.bytes,sizeof(x)); +} + +void calc_md4str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len) +{ + bits128 x; + calc_md4(hexstr,buf,msg,len); + decode_hex(buf,sizeof(x),hexstr); + //memcpy(buf,x.bytes,sizeof(x)); +} + +void calc_md5str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len) +{ + bits128 x; + calc_md5(hexstr,msg,len); + decode_hex(buf,sizeof(x),hexstr); + //memcpy(buf,x.bytes,sizeof(x)); +} + diff --git a/crypto777/iguana_utils.c b/crypto777/iguana_utils.c index 985a13789..5b0ce5743 100755 --- a/crypto777/iguana_utils.c +++ b/crypto777/iguana_utils.c @@ -1105,30 +1105,6 @@ void rmd160ofsha256(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len) calc_rmd160(hexstr,buf,sha256,sizeof(sha256)); } -void calc_md2str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len) -{ - bits128 x; - calc_md2(hexstr,buf,msg,len); - decode_hex(buf,sizeof(x),hexstr); - //memcpy(buf,x.bytes,sizeof(x)); -} - -void calc_md4str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len) -{ - bits128 x; - calc_md4(hexstr,buf,msg,len); - decode_hex(buf,sizeof(x),hexstr); - //memcpy(buf,x.bytes,sizeof(x)); -} - -void calc_md5str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len) -{ - bits128 x; - calc_md5(hexstr,msg,len); - decode_hex(buf,sizeof(x),hexstr); - //memcpy(buf,x.bytes,sizeof(x)); -} - void calc_crc32str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len) { uint32_t crc; uint8_t serialized[sizeof(crc)]; diff --git a/iguana/exchanges/DEXstats.h b/iguana/exchanges/DEXstats.h index 919e6d0ff..e31ff68e3 100644 --- a/iguana/exchanges/DEXstats.h +++ b/iguana/exchanges/DEXstats.h @@ -927,7 +927,7 @@ char *stats_prices(char *symbol,char *dest,struct DEXstats_disp *prices,int32_t } #ifndef FROM_MARKETMAKER -char *stats_JSON(char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port) +char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port) { char *method,*agent,*retstr,*source,*dest; struct tai T; uint32_t endtimestamp; struct DEXstats_disp prices[365]; int32_t leftdatenum,seconds,numdates; if ( (method= jstr(argjson,"method")) == 0 ) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 100b05080..035a90e28 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2028,6 +2028,11 @@ char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *meth return(bitcoind_RPC(0,coinstr,serverport,userpass,method,params,2)); } +char *bitcoind_passthrut(char *coinstr,char *serverport,char *userpass,char *method,char *params,int32_t timeout) +{ + return(bitcoind_RPC(0,coinstr,serverport,userpass,method,params,timeout)); +} + int32_t bitcoin_addr2rmd160(uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr) { bits256 hash; uint8_t *buf,_buf[26]; int32_t len,offset; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e023b0dea..14dff30a0 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -112,42 +112,6 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson return(retstr); } -int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) -{ - static uint32_t crcs[8192]; static unsigned long dup,total; - int32_t i; - *duplicatep = 0; - if ( ind < 0 ) - { - total++; - for (i=0; i 0 ) - { - crcs[i] = crcs[i >> 1]; - crcs[i >> 1] = crc32; - dup++; - //printf("duplicate %u in slot %d -> slot %d (%lu / %lu)\n",crc32,i,i>>1,dup,total); - } - *duplicatep = 1; - break; - } - else if ( crcs[i] == 0 ) - break; - } - if ( i >= sizeof(crcs)/sizeof(*crcs) ) - i = (rand() % (sizeof(crcs)/sizeof(*crcs))); - return(i); - } - else - { - crcs[ind] = crc32; - return(ind); - } -} - char *LP_decrypt(uint8_t *ptr,int32_t *recvlenp) { uint8_t decoded[LP_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES],*nonce,*cipher; int32_t recvlen,cipherlen; char *jsonstr = 0; diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 38fac9e0c..aadc2f485 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -62,24 +62,6 @@ int32_t LP_sockcheck(int32_t sock) else return(-1); } -int32_t LP_peerindsock(int32_t *peerindp) -{ - struct LP_peerinfo *peer,*tmp; int32_t peerind = 0; - HASH_ITER(hh,LP_peerinfos,peer,tmp) - { - peerind++; - if ( peer->errors < LP_MAXPEER_ERRORS && peer->pushsock >= 0 ) - { - if ( peerind < *peerindp ) - continue; - *peerindp = peerind; - //printf("peerind.%d -> sock %d\n",peerind,peer->pushsock); - return(peer->pushsock); - } - } - return(-1); -} - struct LP_queue { struct LP_queue *next,*prev; @@ -103,6 +85,60 @@ void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,in //printf("Q.%p: peerind.%d msglen.%d\n",ptr,peerind,msglen); } +int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) +{ + static uint32_t crcs[8192]; static unsigned long dup,total; + int32_t i; + *duplicatep = 0; + if ( ind < 0 ) + { + total++; + for (i=0; i 0 ) + { + crcs[i] = crcs[i >> 1]; + crcs[i >> 1] = crc32; + dup++; + //printf("duplicate %u in slot %d -> slot %d (%lu / %lu)\n",crc32,i,i>>1,dup,total); + } + *duplicatep = 1; + break; + } + else if ( crcs[i] == 0 ) + break; + } + if ( i >= sizeof(crcs)/sizeof(*crcs) ) + i = (rand() % (sizeof(crcs)/sizeof(*crcs))); + return(i); + } + else + { + crcs[ind] = crc32; + return(ind); + } +} + +int32_t LP_peerindsock(int32_t *peerindp) +{ + struct LP_peerinfo *peer,*tmp; int32_t peerind = 0; + HASH_ITER(hh,LP_peerinfos,peer,tmp) + { + peerind++; + if ( peer->errors < LP_MAXPEER_ERRORS && peer->pushsock >= 0 ) + { + if ( peerind < *peerindp ) + continue; + *peerindp = peerind; + //printf("peerind.%d -> sock %d\n",peerind,peer->pushsock); + return(peer->pushsock); + } + } + return(-1); +} + void queue_loop(void *ignore) { struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; @@ -575,6 +611,43 @@ char *LP_psock(char *myipaddr,int32_t ispaired) both are combined in LP_psock_get */ +char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired) +{ + char url[512],*retstr; + sprintf(url,"http://%s:%u/api/stats/psock?ispaired=%d",destip,destport,ispaired); + //return(LP_issue_curl("psock",destip,destport,url)); + retstr = issue_curlt(url,LP_HTTP_TIMEOUT*3); + printf("issue_LP_psock got (%s) from %s\n",retstr,destip); + return(retstr); +} + +uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired) +{ + uint16_t publicport = 0; char *retstr,*addr; cJSON *retjson; struct LP_peerinfo *peer,*tmp; + HASH_ITER(hh,LP_peerinfos,peer,tmp) + { + connectaddr[0] = publicaddr[0] = 0; + if ( peer->errors < LP_MAXPEER_ERRORS && (retstr= issue_LP_psock(peer->ipaddr,peer->port,ispaired)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + printf("from %s:%u (%s)\n",peer->ipaddr,peer->port,retstr); + if ( (addr= jstr(retjson,"publicaddr")) != 0 ) + safecopy(publicaddr,addr,128); + if ( (addr= jstr(retjson,"connectaddr")) != 0 ) + safecopy(connectaddr,addr,128); + if ( publicaddr[0] != 0 && connectaddr[0] != 0 ) + publicport = juint(retjson,"publicport"); + free_json(retjson); + } + printf("got.(%s) connect.%s public.%s\n",retstr,connectaddr,publicaddr); + free(retstr); + } else printf("error psock from %s:%u\n",peer->ipaddr,peer->port); + if ( publicport != 0 ) + break; + } + return(publicport); +} int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char *myipaddr,uint16_t mypullport,int32_t ispaired) { diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 33e7bcf51..e210b96df 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -103,44 +103,6 @@ char *issue_LP_getprices(char *destip,uint16_t destport) //return(issue_curlt(url,LP_HTTP_TIMEOUT)); } -char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired) -{ - char url[512],*retstr; - sprintf(url,"http://%s:%u/api/stats/psock?ispaired=%d",destip,destport,ispaired); - //return(LP_issue_curl("psock",destip,destport,url)); - retstr = issue_curlt(url,LP_HTTP_TIMEOUT*3); - printf("issue_LP_psock got (%s) from %s\n",retstr,destip); - return(retstr); -} - -uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired) -{ - uint16_t publicport = 0; char *retstr,*addr; cJSON *retjson; struct LP_peerinfo *peer,*tmp; - HASH_ITER(hh,LP_peerinfos,peer,tmp) - { - connectaddr[0] = publicaddr[0] = 0; - if ( peer->errors < LP_MAXPEER_ERRORS && (retstr= issue_LP_psock(peer->ipaddr,peer->port,ispaired)) != 0 ) - { - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - printf("from %s:%u (%s)\n",peer->ipaddr,peer->port,retstr); - if ( (addr= jstr(retjson,"publicaddr")) != 0 ) - safecopy(publicaddr,addr,128); - if ( (addr= jstr(retjson,"connectaddr")) != 0 ) - safecopy(connectaddr,addr,128); - if ( publicaddr[0] != 0 && connectaddr[0] != 0 ) - publicport = juint(retjson,"publicport"); - free_json(retjson); - } - printf("got.(%s) connect.%s public.%s\n",retstr,connectaddr,publicaddr); - free(retstr); - } else printf("error psock from %s:%u\n",peer->ipaddr,peer->port); - if ( publicport != 0 ) - break; - } - return(publicport); -} - cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params) { char *retstr; cJSON *retjson = 0; diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index c565fa78f..888cedd1c 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -21,11 +21,12 @@ #include #include -#include "OS_portable.h" +#include "../../crypto777/OS_portable.h" #define MAX(a,b) ((a) > (b) ? (a) : (b)) #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); #ifndef WIN32 #ifndef MSG_NOSIGNAL @@ -558,7 +559,7 @@ void stats_rpcloop(void *args) uint16_t port; char filetype[128],content_type[128]; int32_t recvlen,flag,bindsock,postflag=0,contentlen,sock,remains,numsent,jsonflag=0,hdrsize,len; socklen_t clilen; char helpname[512],remoteaddr[64],*buf,*retstr,*space; - struct sockaddr_in cli_addr; uint32_t ipbits,i,size = IGUANA_MAXPACKETSIZE + 512; + struct sockaddr_in cli_addr; uint32_t ipbits,i,size = 10*IGUANA_MAXPACKETSIZE + 512; if ( (port= *(uint16_t *)args) == 0 ) port = 7779; if ( jsonbuf == 0 ) @@ -665,7 +666,7 @@ void stats_rpcloop(void *args) if ( retstr != 0 ) { char *response,hdrs[1024]; - //printf("RETURN.(%s)\n",retstr); + //printf("RETURN.(%s) jsonflag.%d postflag.%d\n",retstr,jsonflag,postflag); if ( jsonflag != 0 || postflag != 0 ) { response = malloc(strlen(retstr)+1024+1+1); @@ -677,6 +678,7 @@ void stats_rpcloop(void *args) if ( retstr != space ) free(retstr); retstr = response; + //printf("RET.(%s)\n",retstr); } remains = (int32_t)strlen(retstr); i = 0; @@ -726,8 +728,8 @@ void stats_kvjson(FILE *logfp,int32_t height,int32_t savedheight,uint32_t timest void komodo_kvupdate(FILE *logfp,struct komodo_state *sp,int32_t ht,bits256 txid,int32_t vout,uint8_t *opretbuf,int32_t opretlen,uint64_t value) { - static bits256 zeroes; - uint32_t flags; bits256 pubkey,refpubkey,sig; cJSON *kvjson; char decodestr[10000]; int32_t i,refvaluesize,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,keyvalue[10000]; + //static bits256 zeroes; + uint32_t flags; bits256 pubkey,sig; cJSON *kvjson; char decodestr[10000]; int32_t i,hassig,coresize,haspubkey,height; uint16_t keylen,valuesize; uint8_t *key,*valueptr; // bits256 refpubkey; int32_t refvaluesize,kvheight; uint16_t newflag = 0; uint8_t keyvalue[10000]; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(height),&height); @@ -830,7 +832,7 @@ void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t heig void stats_pricefeed(struct komodo_state *sp,char *symbol,int32_t ht,uint32_t *pvals,int32_t numpvals) { - struct tai T; int32_t seconds,datenum,n; cJSON *argjson; + struct tai T; int32_t seconds,datenum; cJSON *argjson; if ( ht > 300000 && pvals[32] != 0 ) { datenum = OS_conv_unixtime(&T,&seconds,sp->SAVEDTIMESTAMP); @@ -930,7 +932,7 @@ int32_t komodo_parsestatefile(FILE *logfp,struct komodo_state *sp,FILE *fp,char { if ( fread(opret,1,olen,fp) != olen ) errs++; - if ( 0 && matched != 0 ) + if ( (0) && matched != 0 ) { int32_t i; for (i=0; i