|
@ -8,6 +8,8 @@ |
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
|
|
#define LP_PROPAGATION_SLACK 10 // txid ordering is not enforced, so getting extra recent txid
|
|
|
|
|
|
|
|
|
char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", "5.9.253.204" }; |
|
|
char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", "5.9.253.204" }; |
|
|
portable_mutex_t LP_peermutex,LP_utxomutex; |
|
|
portable_mutex_t LP_peermutex,LP_utxomutex; |
|
|
int32_t LP_numpeers,LP_numutxos; |
|
|
int32_t LP_numpeers,LP_numutxos; |
|
@ -405,6 +407,48 @@ uint64_t LP_privkey_init(char *coin,uint8_t addrtype,char *passphrase,char *wifs |
|
|
return(total); |
|
|
return(total); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char *stats_JSON(cJSON *argjson,char *remoteaddr,uint16_t port) |
|
|
|
|
|
{ |
|
|
|
|
|
char *method,*ipaddr,*coin,*retstr = 0; uint16_t argport; int32_t otherpeers,othernumutxos; struct LP_peerinfo *peer; cJSON *retjson; |
|
|
|
|
|
if ( (method= jstr(argjson,"method")) == 0 ) |
|
|
|
|
|
return(clonestr("{\"error\":\"need method in request\"}")); |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( (peer= LP_peerfind((uint32_t)calc_ipbits(ipaddr),argport)) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( (otherpeers= jint(argjson,"numpeers")) > 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( peer->numpeers < otherpeers ) |
|
|
|
|
|
peer->numpeers = otherpeers; |
|
|
|
|
|
} |
|
|
|
|
|
if ( (othernumutxos= jint(argjson,"numutxos")) > 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( peer->numutxos < othernumutxos ) |
|
|
|
|
|
peer->numutxos = othernumutxos; |
|
|
|
|
|
} |
|
|
|
|
|
} else LP_addpeer(ipaddr,argport,jdouble(argjson,"profit")); |
|
|
|
|
|
if ( strcmp(method,"getpeers") == 0 ) |
|
|
|
|
|
retstr = LP_peers(); |
|
|
|
|
|
else if ( strcmp(method,"getutxos") == 0 && (coin= jstr(argjson,"coin")) != 0 ) |
|
|
|
|
|
retstr = LP_utxos(coin,jint(argjson,"lastn")); |
|
|
|
|
|
else if ( strcmp(method,"notify") == 0 ) |
|
|
|
|
|
retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}"); |
|
|
|
|
|
else if ( strcmp(method,"utxonotify") == 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
LP_addutxo(jstr(argjson,"coin"),jbits256(argjson,"txid"),jint(argjson,"vout"),j64bits(argjson,"value"),jbits256(argjson,"deposit"),jint(argjson,"dvout"),j64bits(argjson,"dvalue"),jstr(argjson,"script"),jstr(argjson,"address"),ipaddr,argport,jdouble(argjson,"profit")); |
|
|
|
|
|
retstr = clonestr("{\"result\":\"success\",\"notifyutxo\":\"received\"}"); |
|
|
|
|
|
} |
|
|
|
|
|
} else printf("malformed request.(%s)\n",jprint(argjson,0)); |
|
|
|
|
|
} |
|
|
|
|
|
if ( retstr != 0 ) |
|
|
|
|
|
return(retstr); |
|
|
|
|
|
retjson = cJSON_CreateObject(); |
|
|
|
|
|
jaddstr(retjson,"error","unrecognized command"); |
|
|
|
|
|
return(clonestr(jprint(retjson,1))); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void LPinit(uint16_t myport,double profitmargin) |
|
|
void LPinit(uint16_t myport,double profitmargin) |
|
|
{ |
|
|
{ |
|
|
char *myipaddr=0; long filesize,n; int32_t i; struct LP_peerinfo *peer,*tmp,*mypeer=0; |
|
|
char *myipaddr=0; long filesize,n; int32_t i; struct LP_peerinfo *peer,*tmp,*mypeer=0; |
|
@ -443,7 +487,7 @@ void LPinit(uint16_t myport,double profitmargin) |
|
|
exit(-1); |
|
|
exit(-1); |
|
|
} |
|
|
} |
|
|
LP_privkey_init("KMD",60,"test",""); |
|
|
LP_privkey_init("KMD",60,"test",""); |
|
|
//printf("peers.(%s)\n",LP_peers());
|
|
|
printf("utxos.(%s)\n",LP_utxos("",10000)); |
|
|
while ( 1 ) |
|
|
while ( 1 ) |
|
|
{ |
|
|
{ |
|
|
if ( mypeer != 0 ) |
|
|
if ( mypeer != 0 ) |
|
@ -461,55 +505,11 @@ void LPinit(uint16_t myport,double profitmargin) |
|
|
} |
|
|
} |
|
|
if ( peer->numutxos > LP_numutxos ) |
|
|
if ( peer->numutxos > LP_numutxos ) |
|
|
{ |
|
|
{ |
|
|
printf("%s numutxos.%d vs %d\n",peer->ipaddr,peer->numutxos,LP_numutxos); |
|
|
printf("%s numutxos.%d vs %d lastn.%d\n",peer->ipaddr,peer->numutxos,LP_numutxos,peer->numutxos - LP_numutxos + LP_PROPAGATION_SLACK); |
|
|
if ( strcmp(peer->ipaddr,myipaddr) != 0 ) |
|
|
if ( strcmp(peer->ipaddr,myipaddr) != 0 ) |
|
|
LP_utxosquery(peer->ipaddr,peer->port,"",peer->numutxos - LP_numutxos + 10,myipaddr,myport,profitmargin); |
|
|
LP_utxosquery(peer->ipaddr,peer->port,"",peer->numutxos - LP_numutxos + LP_PROPAGATION_SLACK,myipaddr,myport,profitmargin); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
sleep(LP_numpeers); |
|
|
sleep(LP_numpeers); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Q sending of individual peer that is missing from the other
|
|
|
|
|
|
|
|
|
|
|
|
char *stats_JSON(cJSON *argjson,char *remoteaddr,uint16_t port) |
|
|
|
|
|
{ |
|
|
|
|
|
char *method,*ipaddr,*coin,*retstr = 0; uint16_t argport; int32_t otherpeers,othernumutxos; struct LP_peerinfo *peer; cJSON *retjson; |
|
|
|
|
|
if ( (method= jstr(argjson,"method")) == 0 ) |
|
|
|
|
|
return(clonestr("{\"error\":\"need method in request\"}")); |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( (peer= LP_peerfind((uint32_t)calc_ipbits(ipaddr),argport)) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( (otherpeers= jint(argjson,"numpeers")) > 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( peer->numpeers < otherpeers ) |
|
|
|
|
|
peer->numpeers = otherpeers; |
|
|
|
|
|
} |
|
|
|
|
|
if ( (othernumutxos= jint(argjson,"numutxos")) > 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( peer->numutxos < othernumutxos ) |
|
|
|
|
|
peer->numutxos = othernumutxos; |
|
|
|
|
|
} |
|
|
|
|
|
} else LP_addpeer(ipaddr,argport,jdouble(argjson,"profit")); |
|
|
|
|
|
if ( strcmp(method,"getpeers") == 0 ) |
|
|
|
|
|
retstr = LP_peers(); |
|
|
|
|
|
else if ( strcmp(method,"getutxos") == 0 && (coin= jstr(argjson,"coin")) != 0 ) |
|
|
|
|
|
retstr = LP_utxos(coin,jint(argjson,"lastn")); |
|
|
|
|
|
else if ( strcmp(method,"notify") == 0 ) |
|
|
|
|
|
retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}"); |
|
|
|
|
|
else if ( strcmp(method,"utxonotify") == 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
LP_addutxo(jstr(argjson,"coin"),jbits256(argjson,"txid"),jint(argjson,"vout"),j64bits(argjson,"value"),jbits256(argjson,"deposit"),jint(argjson,"dvout"),j64bits(argjson,"dvalue"),jstr(argjson,"script"),jstr(argjson,"address"),ipaddr,argport,jdouble(argjson,"profit")); |
|
|
|
|
|
retstr = clonestr("{\"result\":\"success\",\"notifyutxo\":\"received\"}"); |
|
|
|
|
|
} |
|
|
|
|
|
} else printf("malformed request.(%s)\n",jprint(argjson,0)); |
|
|
|
|
|
} |
|
|
|
|
|
if ( retstr != 0 ) |
|
|
|
|
|
return(retstr); |
|
|
|
|
|
retjson = cJSON_CreateObject(); |
|
|
|
|
|
jaddstr(retjson,"error","unrecognized command"); |
|
|
|
|
|
return(clonestr(jprint(retjson,1))); |
|
|
|
|
|
} |
|
|
|
|
|