Browse Source

Test

etomic
jl777 7 years ago
parent
commit
559338a0bb
  1. 2
      iguana/exchanges/LP_include.h
  2. 44
      iguana/exchanges/LP_nativeDEX.c
  3. 25
      iguana/exchanges/LP_peers.c
  4. 7
      iguana/exchanges/LP_signatures.c
  5. 35
      iguana/exchanges/LP_statemachine.c

2
iguana/exchanges/LP_include.h

@ -313,7 +313,7 @@ struct LP_peerinfo
{ {
UT_hash_handle hh; UT_hash_handle hh;
uint64_t ip_port; uint64_t ip_port;
uint32_t ipbits,errortime,errors,numpeers,needping,lasttime,connected,lastutxos,lastpeers,diduquery,good,sessionid; uint32_t numrecv,ipbits,errortime,errors,numpeers,needping,lasttime,connected,lastutxos,lastpeers,diduquery,good,sessionid;
int32_t pushsock,subsock,isLP; int32_t pushsock,subsock,isLP;
uint16_t port; uint16_t port;
char ipaddr[64]; char ipaddr[64];

44
iguana/exchanges/LP_nativeDEX.c

@ -18,8 +18,9 @@
// LP_nativeDEX.c // LP_nativeDEX.c
// marketmaker // marketmaker
// //
// dynamic adding of new LP node // detecting new deposits in inventory
// BTC swaps // BTC swaps
// bot progress
// swap started event for bot // swap started event for bot
// lack of full depth // lack of full depth
// withdraw too big // withdraw too big
@ -1100,12 +1101,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); printf("error launching LP_swapsloop for port.%u\n",myport);
exit(-1); exit(-1);
} }
/*char request[128]; int32_t nonz;
if ( IAMLP == 0 )
sprintf(request,"{\"method\":\"getpeers\",\"timestamp\":%u}",(uint32_t)time(NULL));
else sprintf(request,"{\"method\":\"getpeers\",\"LPnode\":\"%s\",\"timestamp\":%u}",myipaddr,(uint32_t)time(NULL));
LP_reserved_msg(0,"","",G.LP_mypub25519,clonestr(request)); */
int32_t nonz; //uint32_t lasthello = 0;
while ( 1 ) while ( 1 )
{ {
nonz = 0; nonz = 0;
@ -1121,40 +1117,6 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
usleep(1000); usleep(1000);
else if ( IAMLP == 0 ) else if ( IAMLP == 0 )
usleep(1000); usleep(1000);
/*if ( IAMLP != 0 && time(NULL) > lasthello+600 )
{
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, would have close bindsocket\n");
if ( 0 )
{
LP_bindsock = -1;
closesocket(sock);
LP_bindsock_reset++;
sleep(10);
printf("launch new rpcloop\n");
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 )
{
printf("error launching stats rpcloop for port.%u\n",myport);
exit(-1);
}
}
}
}*/
} }
#endif #endif
} }

25
iguana/exchanges/LP_peers.c

@ -206,6 +206,12 @@ int32_t LP_coinbus(uint16_t coin_busport)
return(bussock); return(bussock);
} }
void LP_peer_recv(char *ipaddr)
{
struct LP_peerinfo *peer;
if ( (peer= LP_peerfind((uint32_t)calc_ipbits(ipaddr),RPC_port)) != 0 )
peer->numrecv++;
}
int32_t LP_numpeers() int32_t LP_numpeers()
{ {
@ -242,3 +248,22 @@ uint16_t LP_randpeer(char *destip)
} }
return(port); return(port);
} }
uint16_t LP_rarestpeer(char *destip)
{
struct LP_peerinfo *peer,*tmp,*rarest = 0;
destip[0] = 0;
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
if ( peer->isLP != 0 )
{
if ( rarest == 0 || peer->numrecv < rarest->numrecv )
rarest = peer;
}
}
if ( rarest == 0 )
LP_randpeer(destip);
else strcpy(destip,rarest->ipaddr);
return(rarest != 0 ? rarest->port : RPC_port);
}

7
iguana/exchanges/LP_signatures.c

@ -571,7 +571,7 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock)
LP_pubkey_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp); LP_pubkey_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp);
if ( IAMLP != 0 ) if ( IAMLP != 0 )
{ {
if ( LP_randpeer(LPipaddr) != 0 ) if ( LP_rarestpeer(LPipaddr) != 0 )
jaddstr(reqjson,"isLP",LPipaddr); jaddstr(reqjson,"isLP",LPipaddr);
else printf("no LPipaddr\n"); else printf("no LPipaddr\n");
} }
@ -589,8 +589,9 @@ char *LP_notify_recv(cJSON *argjson)
LP_pubkey_sigcheck(pubp,argjson); LP_pubkey_sigcheck(pubp,argjson);
if ( (ipaddr= jstr(argjson,"isLP")) != 0 ) if ( (ipaddr= jstr(argjson,"isLP")) != 0 )
{ {
printf("notify got isLP %s\n",ipaddr); //printf("notify got isLP %s\n",ipaddr);
if ( strcmp(ipaddr,LP_myipaddr) == 0 ) LP_peer_recv(ipaddr);
if ( IAMLP != 0 && G.LP_IAMLP == 0 && strcmp(ipaddr,LP_myipaddr) == 0 )
{ {
if ( bits256_cmp(pub,G.LP_mypub25519) != 0 ) if ( bits256_cmp(pub,G.LP_mypub25519) != 0 )
{ {

35
iguana/exchanges/LP_statemachine.c

@ -132,6 +132,41 @@ FILE *basilisk_swap_save(struct basilisk_swap *swap,bits256 privkey,struct basil
}*/ }*/
return(fp); return(fp);
} }
/*if ( IAMLP != 0 && time(NULL) > lasthello+600 )
{
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, would have close bindsocket\n");
if ( 0 )
{
LP_bindsock = -1;
closesocket(sock);
LP_bindsock_reset++;
sleep(10);
printf("launch new rpcloop\n");
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 )
{
printf("error launching stats rpcloop for port.%u\n",myport);
exit(-1);
}
}
}
}*/
#ifdef oldway #ifdef oldway
int32_t LP_peersparse(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *retstr,uint32_t now) int32_t LP_peersparse(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *retstr,uint32_t now)
{ {

Loading…
Cancel
Save