Browse Source

Test

etomic
jl777 8 years ago
parent
commit
898227421e
  1. 3
      iguana/exchanges/LP_commands.c
  2. 23
      iguana/exchanges/LP_forwarding.c
  3. 18
      iguana/exchanges/LP_nativeDEX.c
  4. 4
      iguana/exchanges/LP_ordermatch.c
  5. 10
      iguana/exchanges/LP_peers.c

3
iguana/exchanges/LP_commands.c

@ -77,6 +77,7 @@ orderbook(base, rel)\n\
getprices(base, rel)\n\
trust(pubkey, trust)\n\
register(pubkey,pushaddr)\n\
registerall(numnodes)\n\
lookup(pubkey)\n\
forward(pubkey,method2,<argjson>)\n\
forward(pubkey,method2=publish,<argjson>)\n\
@ -199,6 +200,8 @@ forwardhex(pubkey,hex)\n\
return(LP_prices());
else if ( strcmp(method,"orderbook") == 0 )
return(LP_orderbook(base,rel));
else if ( strcmp(method,"registerall") == 0 )
return(LP_registerall(jint(argjson,"numnodes")));
else if ( strcmp(method,"forward") == 0 )
{
cJSON *reqjson;

23
iguana/exchanges/LP_forwarding.c

@ -149,13 +149,13 @@ char *LP_register(bits256 pubkey,char *ipaddr,uint16_t port)
}
}
void LP_forwarding_register(bits256 pubkey,char *pushaddr,uint16_t pushport,int32_t max)
int32_t LP_forwarding_register(bits256 pubkey,char *pushaddr,uint16_t pushport,int32_t max)
{
char *retstr,ipaddr[64]; cJSON *retjson; struct LP_peerinfo *peer,*tmp; int32_t j,n=0,retval = -1;
if ( pushaddr == 0 || pushaddr[0] == 0 || bits256_nonz(pubkey) == 0 )
{
printf("LP_forwarding_register illegal pushaddr or null pubkey\n");
return;
return(0);
}
for (j=0; pushaddr[j]!=0; j++)
if ( pushaddr[j] >= '0' && pushaddr[j] <= '9' )
@ -178,6 +178,25 @@ void LP_forwarding_register(bits256 pubkey,char *pushaddr,uint16_t pushport,int3
if ( retval == 0 )
break;
}
return(n);
}
char *LP_registerall(int32_t numnodes)
{
int32_t i,maxnodes,n=0; cJSON *retjson;
if ( numnodes < sizeof(default_LPnodes)/sizeof(*default_LPnodes) )
numnodes = (int32_t)(sizeof(default_LPnodes)/sizeof(*default_LPnodes));
if ( (maxnodes= LP_numpeers()) < numnodes )
numnodes = maxnodes;
for (i=0; i<numnodes; i++)
if ( (n= LP_forwarding_register(LP_mypubkey,LP_publicaddr,LP_publicport,numnodes)) >= numnodes )
break;
retjson = cJSON_CreateObject();
if ( i < numnodes )
jaddstr(retjson,"error","not enough nodes");
jaddnum(retjson,"numnodes",numnodes);
jaddnum(retjson,"registered",n);
return(jprint(retjson,1));
}
cJSON *LP_dereference(cJSON *argjson,char *excludemethod)

18
iguana/exchanges/LP_nativeDEX.c

@ -30,12 +30,12 @@ struct LP_forwardinfo *LP_forwardinfos;
char *activecoins[] = { "BTC", "KMD" };
char GLOBAL_DBDIR[] = { "DB" };
char USERPASS[65],USERPASS_WIFSTR[64],LP_myipaddr[64],USERHOME[512] = { "/root" };
char USERPASS[65],USERPASS_WIFSTR[64],LP_myipaddr[64],LP_publicaddr[64],USERHOME[512] = { "/root" };
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" }; //
uint32_t LP_deadman_switch;
uint16_t LP_fixed_pairport;
uint16_t LP_fixed_pairport,LP_publicport;
int32_t LP_mypubsock = -1;
int32_t USERPASS_COUNTER,IAMLP = 0;
double LP_profitratio = 1.;
@ -73,8 +73,8 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_
#include "LP_swap.c"
#include "LP_peers.c"
#include "LP_utxos.c"
#include "LP_ordermatch.c"
#include "LP_forwarding.c"
#include "LP_ordermatch.c"
#include "LP_commands.c"
char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin)
@ -240,11 +240,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
if ( mypeer == 0 )
myipaddr = "127.0.0.1";
//if ( LP_canbind == 0 ) printf("counter.%d canbind.%d peers\n",counter,LP_canbind);
numpeers = 0;
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
numpeers++;
}
numpeers = LP_numpeers();
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
if ( now > peer->lastpeers+60 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 10000) == 0) )
@ -275,7 +271,9 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
LP_myutxo_updates(ctx,pubsock,passphrase,profitmargin);
if ( lastforward < now-3600 )
{
LP_forwarding_register(LP_mypubkey,pushaddr,pushport,10);
if ( (retstr= LP_registerall(0)) != 0 )
free(retstr);
//LP_forwarding_register(LP_mypubkey,pushaddr,pushport,10);
lastforward = now;
}
}
@ -500,6 +498,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profit
nn_close(pullsock);
pullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0);
LP_deadman_switch = (uint32_t)time(NULL);
strcpy(LP_publicaddr,pushaddr);
LP_publicport = mypullport;
LP_forwarding_register(LP_mypubkey,pushaddr,mypullport,MAX_PSOCK_PORT);
}
}

4
iguana/exchanges/LP_ordermatch.c

@ -554,7 +554,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,double profitmargin,char *base,char *rel,double maxprice,double volume,int32_t timeout)
{
int64_t satoshis,destsatoshis,desttxfee,txfee,bestdestsatoshis=0; bits256 txid,pubkey; char *obookstr; cJSON *orderbook,*asks,*item,*bestitem=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; int32_t i,vout,numasks,DEXselector=0; uint32_t expiration; double ordermatchprice,bestmetric,metric,bestprice=0.,vol,price; struct LP_quoteinfo Q; struct LP_pubkeyinfo *pubp;
int64_t satoshis,destsatoshis,desttxfee,txfee,bestdestsatoshis=0; bits256 txid,pubkey; char *obookstr,*retstr; cJSON *orderbook,*asks,*item,*bestitem=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; int32_t i,vout,numasks,DEXselector=0; uint32_t expiration; double ordermatchprice,bestmetric,metric,bestprice=0.,vol,price; struct LP_quoteinfo Q; struct LP_pubkeyinfo *pubp;
if ( maxprice <= 0. || volume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 )
return(clonestr("{\"error\":\"invalid parameter\"}"));
if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * volume)) == 0 )
@ -631,6 +631,8 @@ char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,double profitmargi
if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypubkey,autxo->coinaddr) < 0 )
return(clonestr("{\"error\":\"cant set ordermatch quote info\"}"));
bestutxo->T.bestflag = (uint32_t)time(NULL);
if ( (retstr= LP_registerall(0)) != 0 )
free(retstr);
price = LP_query(ctx,myipaddr,mypubsock,profitmargin,"request",&Q);
bestitem = LP_quotejson(&Q);
if ( price > SMALLVAL )

10
iguana/exchanges/LP_peers.c

@ -182,3 +182,13 @@ void LP_peersquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr
}
}
}
int32_t LP_numpeers()
{
struct LP_peerinfo *peer,*tmp; int32_t numpeers = 0;
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
numpeers++;
}
return(numpeers);
}

Loading…
Cancel
Save