From 764c122b10ecfc959493dc68a3486fb644f0b1de Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 13 May 2016 01:18:28 -0500 Subject: [PATCH] test --- iguana/iguana777.c | 2 +- iguana/iguana_accept.c | 21 +++++++++++-------- iguana/iguana_instantdex.c | 7 +++++-- iguana/iguana_msg.c | 42 ++++++++++++++++++++++++++++++-------- iguana/iguana_peers.c | 7 +++---- iguana/iguana_tx.c | 19 +++++++++++++++++ 6 files changed, 74 insertions(+), 24 deletions(-) diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 0b4d3978f..cb7f11121 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -156,7 +156,7 @@ int32_t iguana_inv2poll(struct supernet_info *myinfo,struct iguana_info *coin) addr = &coin->peers.active[i]; if ( addr->supernet != 0 ) { - printf("iguana_inv2poll (%s) usock.%d dead.%u ready.%u ipbits.%u supernet.%d\n",addr->ipaddr,addr->usock,addr->dead,addr->ready,(uint32_t)addr->ipbits,addr->supernet); + //printf("iguana_inv2poll (%s) usock.%d dead.%u ready.%u ipbits.%u supernet.%d\n",addr->ipaddr,addr->usock,addr->dead,addr->ready,(uint32_t)addr->ipbits,addr->supernet); if ( addr->usock >= 0 && addr->dead == 0 && addr->ready != 0 && addr->ipbits != 0 ) { instantdex_inv2data(myinfo,coin,addr,exchange); diff --git a/iguana/iguana_accept.c b/iguana/iguana_accept.c index 0d3dd8dc2..acc0efa12 100755 --- a/iguana/iguana_accept.c +++ b/iguana/iguana_accept.c @@ -331,9 +331,9 @@ int32_t iguana_peergetrequest(struct iguana_info *coin,struct iguana_peer *addr, break; if ( flag == 0 ) { - if ( getblock != 0 && iguana_peerblockrequest(coin,addr->blockspace,sizeof(addr->blockspace),addr,hash2,0) > 0 ) + if ( getblock != 0 && iguana_peerblockrequest(coin,addr->blockspace,IGUANA_MAXPACKETSIZE,addr,hash2,0) > 0 ) flag = 1; - else if ( getblock == 0 && iguana_peerhdrrequest(coin,addr->blockspace,sizeof(addr->blockspace),addr,hash2) > 0 ) + else if ( getblock == 0 && iguana_peerhdrrequest(coin,addr->blockspace,IGUANA_MAXPACKETSIZE,addr,hash2) > 0 ) flag = 1; } } @@ -346,27 +346,32 @@ int32_t iguana_peergetrequest(struct iguana_info *coin,struct iguana_peer *addr, int32_t iguana_peeraddrrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t spacesize) { - int32_t i,iter,n,max,sendlen; uint64_t x; struct iguana_msghdr H; struct iguana_peer *tmpaddr; + int32_t i,iter,n,max,sendlen; uint64_t x; struct iguana_peer *tmpaddr; sendlen = 0; max = (IGUANA_MINPEERS + IGUANA_MAXPEERS) / 2; if ( max > coin->peers.numranked ) max = coin->peers.numranked; x = 0; - sendlen = iguana_rwvarint(1,&space[sizeof(H)],&x); + sendlen = iguana_rwvarint(1,&space[sendlen],&x); for (iter=0; iter<2; iter++) { for (i=n=0; ipeers.ranked[i]) != 0 && ((iter == 0 && tmpaddr->supernet != 0) || (iter == 1 && tmpaddr->supernet == 0)) && tmpaddr->ipaddr[0] != 0 ) { - sendlen += iguana_rwaddr(1,&space[sizeof(H) + sendlen],&tmpaddr->A,(int32_t)tmpaddr->protover); - //printf("(%s) ",tmpaddr->ipaddr); + //printf("(%s).%d ",tmpaddr->ipaddr,sendlen); + iguana_rwnum(1,&tmpaddr->A.ip[12],sizeof(uint32_t),&tmpaddr->ipbits); + sendlen += iguana_rwaddr(1,&space[sendlen],&tmpaddr->A,(int32_t)tmpaddr->protover); x++; + if ( x == 0xf8 ) + break; } } } - iguana_rwvarint(1,&space[sizeof(H)],&x); - //printf("addrrequest: sendlen.%d x.%d\n",sendlen,(int32_t)x); + iguana_rwvarint(1,space,&x); + //for (i=0; ioffer.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,ap->offer.offer64); + printf("%llu ",(long long)ap->orderid); + } queue_enqueue("acceptableQ",&exchange->acceptableQ,&ap->DL,0); } else free(ap); } @@ -845,7 +848,7 @@ struct instantdex_accept *instantdex_quotefind(struct supernet_info *myinfo,stru { char base[9],rel[9]; int64_t pricetoshis; uint64_t orderid,offer64; orderid = instantdex_decodehash(base,rel,&pricetoshis,&offer64,encodedhash); - printf("search for orderid.%llu (%s/%s) %.8f from %llu\n",(long long)orderid,base,rel,dstr(pricetoshis),(long long)offer64); + //printf("search for orderid.%llu (%s/%s) %.8f from %llu\n",(long long)orderid,base,rel,dstr(pricetoshis),(long long)offer64); return(instantdex_offerfind(myinfo,exchanges777_find("bitcoin"),0,0,orderid,base,rel,1,0)); } @@ -899,7 +902,7 @@ int32_t instantdex_quotep2p(struct supernet_info *myinfo,struct iguana_info *coi encodedhash = instantdex_encodehash(A.offer.base,A.offer.rel,A.offer.price64 * instantdex_bidaskdir(&A.offer),A.orderid,A.offer.offer64); if ( (ap= instantdex_quotefind(myinfo,coin,addr,encodedhash)) == 0 ) { - printf("add quote here!\n"); + //printf("add quote here!\n"); if ( exchange != 0 ) { ap = calloc(1,sizeof(*ap)); diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index ad154be02..a99f21139 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -567,6 +567,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc bloom = intvectors = srvmsg = -1; if ( addr != 0 ) { + iguana_peerblockrequest(coin,addr->blockspace,IGUANA_MAXPACKETSIZE,addr,iguana_blockhash(coin,100),0); addr->lastcontact = (uint32_t)time(NULL); strcpy(addr->lastcommand,H->command); //printf("iguana_msgparser from (%s) parse.(%s) len.%d\n",addr->ipaddr,H->command,recvlen); @@ -611,19 +612,23 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc { if ( addr != 0 ) { + struct iguana_txblock txdata; + iguana_memreset(rawmem), iguana_memreset(txmem); + memset(&txdata,0,sizeof(txdata)); if ( ishost == 0 ) { - struct iguana_txblock txdata; addr->msgcounts.block++; - iguana_memreset(rawmem), iguana_memreset(txmem); - memset(&txdata,0,sizeof(txdata)); if ( (n= iguana_gentxarray(coin,rawmem,&txdata,&len,data,recvlen)) == recvlen ) { len = n; iguana_gotblockM(coin,addr,&txdata,rawmem->ptr,H,data,recvlen); } else printf("parse error block txn_count.%d, n.%d len.%d vs recvlen.%d from.(%s)\n",txdata.block.RO.txn_count,n,len,recvlen,addr->ipaddr); - } else len = iguana_peergetrequest(coin,addr,data,recvlen,1); + } + else + { + len = iguana_peergetrequest(coin,addr,data,recvlen,1); + } } } else if ( (ishost= (strncmp(H->command,"inv",3) == 0)) || strncmp(H->command,"getdata",7) == 0 ) @@ -638,7 +643,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc else { intvectors = 'I', addr->msgcounts.inv++; - if ( strcmp(H->command,"inv2") == 0 ) + if ( 0 && strcmp(H->command,"inv2") == 0 ) printf("GOT INV2.%d\n",recvlen); len = iguana_intvectors(coin,addr,1,data,recvlen); // indirectly issues getdata } @@ -725,11 +730,10 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc for (i=0; iprotover); + len += iguana_rwaddr(0,&data[len],&A,(int32_t)addr->protover); iguana_gotaddr(coin,addr,&A); } - if ( len == recvlen && addr != 0 ) + if ( len == recvlen ) { addr->lastgotaddr = (uint32_t)time(NULL); addr->msgcounts.addr++; @@ -738,8 +742,28 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc else { len = 0; - if ( (sendlen= iguana_peeraddrrequest(coin,addr,addr->blockspace,sizeof(addr->blockspace))) > 0 ) + if ( (sendlen= iguana_peeraddrrequest(coin,addr,&addr->blockspace[sizeof(H)],IGUANA_MAXPACKETSIZE)) > 0 ) + { + if ( 0 ) + { + int32_t checklen; uint32_t checkbits; uint16_t checkport; char checkaddr[64]; + checklen = iguana_rwvarint(0,&addr->blockspace[sizeof(H)],&x); + for (i=0; iblockspace[sizeof(H)+i]); + printf(" %p addr sendlen.%d\n",&addr->blockspace[sizeof(H)],sendlen); + for (i=0; iblockspace[sizeof(H) + checklen],&A,(int32_t)addr->protover); + iguana_rwnum(0,&A.ip[12],sizeof(uint32_t),&checkbits); + iguana_rwnum(0,(void *)&A.port,sizeof(uint16_t),&checkport); + expand_ipbits(checkaddr,checkbits); + printf("checkaddr.(%s:%u) ",checkaddr,checkport); + } + printf("x.%d\n",(int32_t)x); + } retval = iguana_queue_send(coin,addr,0,addr->blockspace,"addr",sendlen,0,0); + } addr->msgcounts.getaddr++; } } diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index 2a6f59712..90796b1b6 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -1171,7 +1171,6 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin, } if ( addr->persistent_peer != 0 ) { - uint16_t port; if ( addr->usock < 0 || addr->dead != 0 ) { if ( addr->usock >= 0 ) @@ -1181,9 +1180,9 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin, { printf("persistent peer.(%s) disconnected... reconnect\n",addr->ipaddr); sleep(addr->persistent_peer); - if ( (port= (uint16_t)(addr->ipbits >> 32)) == 0 ) - port = coin->chain->portp2p; - addr->usock = iguana_socket(0,addr->ipaddr,port); + if ( (addr->A.port= (uint16_t)(addr->ipbits >> 32)) == 0 ) + addr->A.port = coin->chain->portp2p; + addr->usock = iguana_socket(0,addr->ipaddr,addr->A.port); } } } diff --git a/iguana/iguana_tx.c b/iguana/iguana_tx.c index 492455cf2..865516232 100755 --- a/iguana/iguana_tx.c +++ b/iguana/iguana_tx.c @@ -264,6 +264,25 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int if ( addr != 0 ) { printf("Send block.%d to %s\n",total,addr->ipaddr); + { + struct iguana_txblock txdata; int32_t checklen; static struct OS_memspace RAWMEM; + if ( RAWMEM.ptr == 0 ) + iguana_meminit(&RAWMEM,addr->ipaddr,0,IGUANA_MAXPACKETSIZE * 2,0); + else iguana_memreset(&RAWMEM); + memset(&txdata,0,sizeof(txdata)); + /*int32_t i; for (i=0; iblockspace[i + sizeof(struct iguana_msghdr)]); + } + printf(" blocksize.%d\n",total); + for (i=0; i<16; i++) + printf("%02x",blockspace[i + sizeof(struct iguana_msghdr)+81]); + printf(" txhdr\n");*/ + if ( (checklen= iguana_gentxarray(coin,&RAWMEM,&txdata,&checklen,&blockspace[sizeof(struct iguana_msghdr)],total)) != total ) + printf("Error reconstructing txarray checklen.%d total.%d\n",checklen,total); + } return(iguana_queue_send(coin,addr,0,blockspace,"block",total,0,0)); } else