Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
7e1dcb383c
  1. 1
      crypto777/inet.c
  2. 2
      iguana/exchanges777.h
  3. 14
      iguana/iguana777.c
  4. 6
      iguana/iguana777.h
  5. 27
      iguana/iguana_accept.c
  6. 2
      iguana/iguana_exchanges.c
  7. 28
      iguana/iguana_instantdex.c
  8. 2
      iguana/iguana_peers.c

1
crypto777/inet.c

@ -404,6 +404,7 @@ uint64_t calc_ipbits(char *ip_port)
expand_ipbits(ipaddr2,ipbits);
if ( ipbits != 0 && strcmp(ipaddr,ipaddr2) != 0 )
{
if ( ipaddr[0] != 0 )
printf("calc_ipbits error: (%s) -> %llx -> (%s)\n",ip_port,(long long)ipbits,ipaddr);//, getchar();
ipbits = 0;
}

2
iguana/exchanges777.h

@ -108,7 +108,7 @@ struct exchange_request
struct instantdex_offer
{
char base[24],rel[24];
uint64_t price64,basevolume64,offer64;
int64_t price64,basevolume64; uint64_t offer64;
uint32_t expiration,nonce;
char myside,acceptdir,minperc,pad;
};

14
iguana/iguana777.c

@ -15,6 +15,7 @@
#include "iguana777.h"
#include "exchanges777.h"
#include "secp256k1/include/secp256k1.h"
#include "secp256k1/include/secp256k1_schnorr.h"
#include "secp256k1/include/secp256k1_rangeproof.h"
@ -141,10 +142,11 @@ double iguana_metric(struct iguana_peer *addr,uint32_t now,double decay)
return(metric);
}
int32_t iguana_peermetrics(struct iguana_info *coin)
int32_t iguana_peermetrics(struct supernet_info *myinfo,struct iguana_info *coin)
{
int32_t i,ind,n; double *sortbuf,sum; uint32_t now; struct iguana_peer *addr,*slowest = 0;
struct exchange_info *exchange; int32_t i,ind,n; double *sortbuf,sum; uint32_t now; struct iguana_peer *addr,*slowest = 0;
//printf("peermetrics\n");
exchange = exchanges777_find("bitcoin");
sortbuf = mycalloc('s',coin->MAXPEERS,sizeof(double)*2);
coin->peers.mostreceived = 0;
now = (uint32_t)time(NULL);
@ -159,6 +161,8 @@ int32_t iguana_peermetrics(struct iguana_info *coin)
//printf("[%.0f %.0f] ",addr->recvblocks,addr->recvtotal);
sortbuf[n*2 + 0] = iguana_metric(addr,now,.995);
sortbuf[n*2 + 1] = i;
if ( exchange != 0 && addr->supernet != 0 )
instantdex_inv2data(myinfo,coin,addr,exchange);
n++;
}
if ( n > 0 )
@ -213,10 +217,10 @@ void *iguana_kviAddriterator(struct iguana_info *coin,struct iguanakv *kv,struct
return(0);
}
uint32_t iguana_updatemetrics(struct iguana_info *coin)
uint32_t iguana_updatemetrics(struct supernet_info *myinfo,struct iguana_info *coin)
{
char fname[512],tmpfname[512],oldfname[512],ipaddr[64]; int32_t i,j; struct iguana_peer *addr,*tmpaddr; FILE *fp;
iguana_peermetrics(coin);
iguana_peermetrics(myinfo,coin);
sprintf(fname,"%s/%s_peers.txt",GLOBAL_CONFSDIR,coin->symbol), OS_compatible_path(fname);
sprintf(oldfname,"%s/%s_oldpeers.txt",GLOBAL_CONFSDIR,coin->symbol), OS_compatible_path(oldfname);
sprintf(tmpfname,"%s/%s/peers.txt",GLOBAL_TMPDIR,coin->symbol), OS_compatible_path(tmpfname);
@ -711,7 +715,7 @@ void iguana_coinloop(void *arg)
if ( now > coin->peers.lastmetrics+10 )
{
//fprintf(stderr,"metrics\n");
coin->peers.lastmetrics = iguana_updatemetrics(coin); // ranks peers
coin->peers.lastmetrics = iguana_updatemetrics(myinfo,coin); // ranks peers
}
if ( coin->longestchain+10000 > coin->blocks.maxbits )
iguana_recvalloc(coin,coin->longestchain + 100000);

6
iguana/iguana777.h

@ -548,7 +548,7 @@ struct bitcoin_spend
// peers
int32_t iguana_verifypeer(struct iguana_info *coin,void *key,void *value,int32_t itemind,int32_t itemsize);
int32_t iguana_peermetrics(struct iguana_info *coin);
int32_t iguana_peermetrics(struct supernet_info *myinfo,struct iguana_info *coin);
void iguana_peersloop(void *arg);
int32_t iguana_queue_send(struct iguana_info *coin,struct iguana_peer *addr,int32_t delay,uint8_t *serialized,char *cmd,int32_t len,int32_t getdatablock,int32_t forceflag);
uint32_t iguana_rwiAddrind(struct iguana_info *coin,int32_t rwflag,struct iguana_iAddr *iA,uint32_t ind);
@ -562,7 +562,7 @@ void iguana_shutdownpeers(struct iguana_info *coin,int32_t forceflag);
void iguana_acceptloop(void *args);
void iguana_recvloop(void *args);
int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *serialized,int32_t len);
uint32_t iguana_updatemetrics(struct iguana_info *coin);
uint32_t iguana_updatemetrics(struct supernet_info *myinfo,struct iguana_info *coin);
void *iguana_peeralloc(struct iguana_info *coin,struct iguana_peer *addr,int32_t datalen);
int64_t iguana_peerfree(struct iguana_info *coin,struct iguana_peer *addr,void *ptr,int32_t datalen);
int64_t iguana_peerallocated(struct iguana_info *coin,struct iguana_peer *addr);
@ -975,6 +975,8 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
int64_t iguana_availunspents(struct supernet_info *myinfo,uint64_t **unspentsp,int32_t *nump,struct iguana_info *coin,int32_t minconf,char *account,void *ptr,int32_t maxsize);
char *iguana_signunspents(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *txobj,uint64_t satoshis,char *changeaddr,uint64_t txfee,uint64_t *unspents,int32_t num);
bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *signedtx);
int32_t iguana_inv2packet(uint8_t *serialized,int32_t maxsize,int32_t type,bits256 *hashes,int32_t n);
int32_t instantdex_inv2data(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct exchange_info *exchange);
extern int32_t HDRnet,netBLOCKS;

27
iguana/iguana_accept.c

@ -227,15 +227,9 @@ int32_t iguana_process_msgrequestQ(struct supernet_info *myinfo,struct iguana_in
else if ( msg->type == MSG_QUOTE )
{
if ( (ap= instantdex_quotefind(myinfo,coin,msg->addr,msg->hash2)) == 0 )
{
if ( GETBIT(ap->peerhas,msg->addr->addrind) == 0 )
{
if ( (len= instantdex_quoterequest(myinfo,coin,&coin->blockspace[sizeof(struct iguana_msghdr)],sizeof(coin->blockspace),msg->addr,msg->hash2)) > 0 )
{
iguana_queue_send(coin,msg->addr,0,coin->blockspace,"quote",len,0,0);
SETBIT(ap->peerhas,msg->addr->addrind);
}
}
}
}
}
@ -263,6 +257,27 @@ int32_t iguana_peerdatarequest(struct iguana_info *coin,struct iguana_peer *addr
return(len);
}
int32_t iguana_inv2packet(uint8_t *serialized,int32_t maxsize,int32_t type,bits256 *hashes,int32_t n)
{
int32_t i,len = sizeof(struct iguana_msghdr); uint64_t x = n;
memset(serialized,0,len);
len += iguana_rwvarint(1,&serialized[len],&x);
//for (i=0; i<10; i++)
// printf("%02x ",data[i]);
//printf("x.%d recvlen.%d\n",(int32_t)x,recvlen);
if ( x < IGUANA_MAXINV )
{
for (i=0; i<x; i++)
{
len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),&type);
len += iguana_rwbignum(1,&serialized[len],sizeof(bits256),hashes[i].bytes);
}
}
if ( len > maxsize )
return(-1);
return(len);
}
int32_t iguana_peerhdrrequest(struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_peer *addr,bits256 hash2)
{
int32_t len=0,i,flag=0,height,hdrsi,bundlei,bundlesize,firstvout,retval=-1; struct iguana_block *block; struct iguana_msgblock msgB; bits256 checkhash2; struct iguana_bundle *bp;

2
iguana/iguana_exchanges.c

@ -968,8 +968,6 @@ THREE_STRINGS_AND_THREE_INTS(InstantDEX,orderbook,exchange,base,rel,depth,allfie
struct exchange_info *ptr;
if ( remoteaddr == 0 )
{
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
if ( exchange != 0 && exchange[0] != 0 )
{
if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 )

28
iguana/iguana_instantdex.c

@ -793,6 +793,32 @@ bits256 instantdex_encodehash(char *base,char *rel,int64_t price,uint64_t orderi
return(encodedhash);
}
int32_t instantdex_inv2data(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct exchange_info *exchange)
{
struct instantdex_accept PAD,*ap; uint32_t now,n=0,len; bits256 hashes[100]; uint8_t serialized[100*36 + 1024];
if ( exchange == 0 )
return(0);
now = (uint32_t)time(NULL);
memset(&PAD,0,sizeof(PAD));
queue_enqueue("acceptableQ",&exchange->acceptableQ,&PAD.DL,0);
while ( (ap= queue_dequeue(&exchange->acceptableQ,0)) != 0 && ap != &PAD )
{
if ( now < ap->offer.expiration && ap->dead == 0 )
{
if ( n < sizeof(hashes)/sizeof(*hashes) && GETBIT(ap->peerhas,addr->addrind) == 0 )
hashes[n++] = instantdex_encodehash(ap->offer.base,ap->offer.rel,ap->offer.price64*instantdex_bidaskdir(&ap->offer),ap->orderid);
queue_enqueue("acceptableQ",&exchange->acceptableQ,&ap->DL,0);
} else free(ap);
}
if ( n > 0 )
{
len = iguana_inv2packet(serialized,sizeof(serialized),MSG_QUOTE,hashes,n);
printf("Send inv2[%d] -> (%s)\n",n,addr->ipaddr);
return(iguana_queue_send(coin,addr,0,serialized,"inv2",len,0,0));
}
return(-1);
}
struct instantdex_accept *instantdex_quotefind(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,bits256 encodedhash)
{
char base[9],rel[9]; int64_t pricetoshis; uint64_t orderid;
@ -820,7 +846,7 @@ int32_t instantdex_quote(struct supernet_info *myinfo,struct iguana_info *coin,s
orderhash = instantdex_rwoffer(0,&checklen,serialized,&A.offer);
if ( checklen == recvlen )
{
encodedhash = instantdex_encodehash(A.offer.base,A.offer.rel,A.offer.price64,A.orderid);
encodedhash = instantdex_encodehash(A.offer.base,A.offer.rel,A.offer.price64 * instantdex_bidaskdir(&A.offer),A.orderid);
if ( (ap= instantdex_quotefind(myinfo,coin,addr,encodedhash)) == 0 )
{
init_hexbytes_noT(hexstr,serialized,recvlen);

2
iguana/iguana_peers.c

@ -819,6 +819,8 @@ uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
return((uint32_t)time(NULL));
if ( strncmp("0.0.0",ipaddr,5) != 0 && strcmp("0.0.255.255",ipaddr) != 0 && strcmp("1.0.0.0",ipaddr) != 0 )
{
if ( ipaddr[strlen(ipaddr)-1] == ':' )
ipaddr[strlen(ipaddr)-1] = 0;
if ( (ipbits= calc_ipbits(ipaddr)) != 0 )
{
expand_ipbits(checkaddr,ipbits);

Loading…
Cancel
Save