From 9ef676bdbdebe0b390fc054cc40b5bb37b49994d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 17:45:58 +0200 Subject: [PATCH 01/15] Test --- .gitignore | 2 ++ iguana/iguana777.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3f5723493..7a7e1c423 100755 --- a/.gitignore +++ b/.gitignore @@ -147,3 +147,5 @@ iguana/confs/cc577d22ca76351d495f147b470103392b5f2ab0948e45608623a7d9728e2c6f iguana/confs/cc577d22ca76351d495f147b470103392b5f2ab0948e45608623a7d9728e2c6f.old iguana/DB/DEX.log + +iguana/iguana_notary.o-54f98cc3 diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 29fa7195c..5ccae82ba 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -133,7 +133,7 @@ struct supernet_info struct liquidity_info linfos[512]; cJSON *liquidity_currencies; struct pending_trade *trades; portable_mutex_t pending_mutex; struct komodo_notaries NOTARY; char seedipaddr[64]; uint32_t dpowipbits[128]; int32_t numdpowipbits; portable_mutex_t notarymutex,dpowmutex; - char dexseed_ipaddrs[2][64]; uint32_t dexipbits[128]; int32_t numdexipbits; portable_mutex_t dexmutex; + char dexseed_ipaddrs[8][64]; uint32_t dexipbits[128]; int32_t numdexipbits; portable_mutex_t dexmutex; // compatibility bits256 pangea_category,instantdex_category; uint8_t logs[256],exps[510]; From 3f60bfa7bad8acff204a066efe4d305d2a4b46c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 18:40:11 +0200 Subject: [PATCH 02/15] Test --- iguana/iguana_payments.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index f593034b4..82386e4b9 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -366,7 +366,7 @@ uint64_t _iguana_interest(uint32_t now,int32_t chainheight,uint32_t txlocktime,u uint64_t iguana_interest(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout,uint64_t value) { - char *retstr; int32_t height; cJSON *retjson; struct iguana_txid T,*tx; uint64_t interest=0; + char *retstr; int32_t height; cJSON *retjson=0; struct iguana_txid T,*tx; uint64_t interest=0; if ( coin->FULLNODE < 0 ) // komodod is running { if ( (retjson= dpow_gettxout(myinfo,coin,txid,vout)) != 0 ) @@ -394,7 +394,7 @@ uint64_t iguana_interest(struct supernet_info *myinfo,struct iguana_info *coin,b interest = _iguana_interest((uint32_t)time(NULL),coin->longestchain,tx->locktime,value); } } - char str[65]; printf("interest for %s.v%d %.8f %.8f\n",bits256_str(str,txid),vout,dstr(value),dstr(interest)); + char str[65]; printf("interest for %s.v%d %.8f %.8f (%s)\n",bits256_str(str,txid),vout,dstr(value),dstr(interest),retjson!=0?jprint(retjson,0):""); return(interest); } From b07fdb9054d814ce4d26f9e3101a17a95725aac5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 20:30:16 +0200 Subject: [PATCH 03/15] Test --- iguana/dpow/dpow_network.c | 4 ++-- iguana/iguana777.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index c493ef03d..4bb5b6a9d 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -408,14 +408,14 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32 printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str); } } -//#ifndef __APPLE__ +#ifndef __APPLE__ if ( (rand() % 100) < 40 ) { nanomsg_tcpname(0,str,ipaddr,REP_SOCK); nn_connect(myinfo->reqsock,str); printf("%d: req connect (%s)\n",myinfo->numdexipbits,str); } -//#endif +#endif } } if ( freeptr != 0 ) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 5ccae82ba..471fa8187 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -133,7 +133,7 @@ struct supernet_info struct liquidity_info linfos[512]; cJSON *liquidity_currencies; struct pending_trade *trades; portable_mutex_t pending_mutex; struct komodo_notaries NOTARY; char seedipaddr[64]; uint32_t dpowipbits[128]; int32_t numdpowipbits; portable_mutex_t notarymutex,dpowmutex; - char dexseed_ipaddrs[8][64]; uint32_t dexipbits[128]; int32_t numdexipbits; portable_mutex_t dexmutex; + char dexseed_ipaddrs[1][64]; uint32_t dexipbits[128]; int32_t numdexipbits; portable_mutex_t dexmutex; // compatibility bits256 pangea_category,instantdex_category; uint8_t logs[256],exps[510]; From cabd692e8b26b94e9c6b74fdd5fd8423d95fba00 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 20:36:10 +0200 Subject: [PATCH 04/15] Test --- iguana/dpow/dpow_network.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 4bb5b6a9d..7fe852fa7 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -960,6 +960,7 @@ char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *si char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address) { struct dex_request dexreq; +return(clonestr("{\"error\":\"importaddress deprecated\"}")); memset(&dexreq,0,sizeof(dexreq)); safecopy(dexreq.name,symbol,sizeof(dexreq.name)); dexreq.func = 'A'; @@ -1262,12 +1263,12 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) } else { - timeout = 500; + timeout = 100; nn_setsockopt(repsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(dexsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); timeout = 10; nn_setsockopt(dexsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); - timeout = 500; + timeout = 10; nn_setsockopt(repsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); maxsize = 1024 * 1024; printf("RCVBUF.%d\n",nn_setsockopt(dexsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize))); @@ -1986,8 +1987,8 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) free(retstr); if ( broadcastflag != 0 ) { - printf("BROADCAST dexp request.[%d]\n",size); - signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); + //printf("BROADCAST dexp request.[%d]\n",size); + //signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); } } else From 9a193d0a9ddbd9c6613176299544ec38b0764c04 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 20:45:38 +0200 Subject: [PATCH 05/15] Test --- iguana/dpow/dpow_network.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 7fe852fa7..907bae6d7 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -287,9 +287,9 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32 { timeout = 1000; nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); - timeout = 5000; - nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout)); - timeout = 10000; + //timeout = 5000; + //nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout)); + timeout = 1000; nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); for (i=0; idexseed_ipaddrs)/sizeof(*myinfo->dexseed_ipaddrs); i++) if ( nn_connect(reqsock,nanomsg_tcpname(0,str,myinfo->dexseed_ipaddrs[i],REP_SOCK)) < 0 ) @@ -318,8 +318,8 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32 nn_setsockopt(subsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(subsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0); printf("CLIENT sockets req.%d sub.%d\n",reqsock,subsock); - timeout = 5000; - nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout)); + //timeout = 5000; + //nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout)); timeout = 10000; nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); } @@ -1266,6 +1266,7 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) timeout = 100; nn_setsockopt(repsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(dexsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); + nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); timeout = 10; nn_setsockopt(dexsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); timeout = 10; @@ -1979,11 +1980,11 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) while ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 ) { num++; - //printf("REP got %d crc.%08x\n",size,calc_crc32(0,(void *)dexp,size)); + printf("REP got %d crc.%08x\n",size,calc_crc32(0,(void *)dexp,size)); if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 ) { signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1); - //printf("send back[%ld]\n",strlen(retstr)+1); + printf("send back[%ld]\n",strlen(retstr)+1); free(retstr); if ( broadcastflag != 0 ) { @@ -1997,13 +1998,13 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) { r = myinfo->dpowipbits[rand() % m]; signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,&r,sizeof(r)); - //printf("REP.%08x <- rand ip m.%d %x\n",dexp->crc32,m,r); + printf("REP.%08x <- rand ip m.%d %x\n",dexp->crc32,m,r); } else printf("illegal state without dpowipbits?\n"); if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size); - //printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp)); + printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp)); dex_packet(myinfo,dexp,size); } else printf("failed dexpacketcheck\n"); } @@ -2015,6 +2016,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) if ( num > 1000 ) break; } + printf("num.%d rep packets\n",num); } portable_mutex_unlock(&myinfo->dpowmutex); return(num); From 0f3522adf3ab2205758ba415f2280239e4e4308c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 20:50:00 +0200 Subject: [PATCH 06/15] Test --- iguana/dpow/dpow_network.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 907bae6d7..70e51cd9f 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -1977,6 +1977,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) } if ( myinfo->repsock >= 0 ) // from clients { + num = 0; while ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 ) { num++; From c0ff755abb51f1bd02f72e571e2102b708ae3151 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 21:04:51 +0200 Subject: [PATCH 07/15] Test --- basilisk/basilisk.c | 5 +- iguana/dpow/dpow_network.c | 195 ++++++++++++++++++------------------- 2 files changed, 97 insertions(+), 103 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 1ea4ac20d..4a9a8da34 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -893,7 +893,7 @@ void basilisks_loop(void *arg) basilisk_ping_send(myinfo,relay); } counter++; - //fprintf(stderr,"E "); + fprintf(stderr,"E "); if ( myinfo->numdpows == 1 ) { iguana_dPoWupdate(myinfo,&myinfo->DPOWS[0]); @@ -903,13 +903,14 @@ void basilisks_loop(void *arg) { dp = &myinfo->DPOWS[counter % myinfo->numdpows]; iguana_dPoWupdate(myinfo,dp); - if ( (counter % myinfo->numdpows) != 0 ) + //if ( (counter % myinfo->numdpows) != 0 ) { //fprintf(stderr,"F "); iguana_dPoWupdate(myinfo,&myinfo->DPOWS[0]); } endmilli = startmilli + 30; } + fprintf(stderr,"F "); } else { diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 70e51cd9f..d0c0115a8 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -1888,7 +1888,7 @@ void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t * int32_t dpow_nanomsg_update(struct supernet_info *myinfo) { - int32_t i,n=0,num=0,size,broadcastflag,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; void *freeptr; + int32_t i,n,num,num2,flags=0,size,iter,broadcastflag,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; void *freeptr; if ( time(NULL) < myinfo->nanoinit+5 || (myinfo->dpowsock < 0 && myinfo->dexsock < 0 && myinfo->repsock < 0) ) return(-1); if ( myinfo->IAMNOTARY != 0 && myinfo->numnotaries <= 0 ) @@ -1897,127 +1897,120 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) printf("INIT with %d notaries\n",myinfo->numnotaries); } portable_mutex_lock(&myinfo->dpowmutex); - /*for (i=0; i<100; i++) + num = num2 = n = 0; + for (iter=0; iter<1000; iter++) { - struct nn_pollfd pfd; - pfd.fd = myinfo->dpowsock; - pfd.events = NN_POLLIN; - if ( nn_poll(&pfd,1,100) > 0 ) - break; - usleep(1000); - }*/ - while ( (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) >= 0 && num < 1000 ) - { - num++; - if ( size > 0 ) + if ( (flags & 1) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) >= 0 ) { - //fprintf(stderr,"%d ",size); - if ( np->version0 == (DPOW_VERSION & 0xff) && np->version1 == ((DPOW_VERSION >> 8) & 0xff) ) + num++; + if ( size > 0 ) { - //printf("v.%02x %02x datalen.%d size.%d %d vs %d\n",np->version0,np->version1,np->datalen,size,np->datalen,(int32_t)(size - sizeof(*np))); - if ( np->datalen == (size - sizeof(*np)) ) + //fprintf(stderr,"%d ",size); + if ( np->version0 == (DPOW_VERSION & 0xff) && np->version1 == ((DPOW_VERSION >> 8) & 0xff) ) { - crc32 = calc_crc32(0,np->packet,np->datalen); - dp = 0; - for (i=0; inumdpows; i++) + //printf("v.%02x %02x datalen.%d size.%d %d vs %d\n",np->version0,np->version1,np->datalen,size,np->datalen,(int32_t)(size - sizeof(*np))); + if ( np->datalen == (size - sizeof(*np)) ) { - if ( strcmp(np->symbol,myinfo->DPOWS[i].symbol) == 0 ) + crc32 = calc_crc32(0,np->packet,np->datalen); + dp = 0; + for (i=0; inumdpows; i++) { - dp = &myinfo->DPOWS[i]; - break; + if ( strcmp(np->symbol,myinfo->DPOWS[i].symbol) == 0 ) + { + dp = &myinfo->DPOWS[i]; + break; + } } - } - if ( dp != 0 && crc32 == np->crc32 ) - { - if ( i == myinfo->numdpows ) - printf("received nnpacket for (%s)\n",np->symbol); - else + if ( dp != 0 && crc32 == np->crc32 ) { - dpow_ipbitsadd(myinfo,dp,np->ipbits,np->numipbits,np->senderind,np->myipbits); - if ( (bp= dpow_heightfind(myinfo,dp,np->height)) != 0 && bp->state != 0xffffffff && bp->myind >= 0 ) + if ( i == myinfo->numdpows ) + printf("received nnpacket for (%s)\n",np->symbol); + else { - //char str[65]; printf("%s RECV ht.%d ch.%08x (%d) crc32.%08x:%08x datalen.%d:%d firstz.%d i.%d senderind.%d myind.%d\n",bits256_str(str,np->srchash),np->height,np->channel,size,np->crc32,crc32,np->datalen,(int32_t)(size - sizeof(*np)),firstz,i,np->senderind,bp->myind); - if ( np->senderind >= 0 && np->senderind < bp->numnotaries ) + dpow_ipbitsadd(myinfo,dp,np->ipbits,np->numipbits,np->senderind,np->myipbits); + if ( (bp= dpow_heightfind(myinfo,dp,np->height)) != 0 && bp->state != 0xffffffff && bp->myind >= 0 ) { - if ( memcmp(bp->notaries[np->senderind].pubkey+1,np->srchash.bytes,32) == 0 && bits256_nonz(np->srchash) != 0 ) + //char str[65]; printf("%s RECV ht.%d ch.%08x (%d) crc32.%08x:%08x datalen.%d:%d firstz.%d i.%d senderind.%d myind.%d\n",bits256_str(str,np->srchash),np->height,np->channel,size,np->crc32,crc32,np->datalen,(int32_t)(size - sizeof(*np)),firstz,i,np->senderind,bp->myind); + if ( np->senderind >= 0 && np->senderind < bp->numnotaries ) { - if ( bp->isratify == 0 ) - dpow_nanoutxoget(myinfo,dp,bp,&np->notarize,0,np->senderind,np->channel); - else dpow_nanoutxoget(myinfo,dp,bp,&np->ratify,1,np->senderind,np->channel); - dpow_datahandler(myinfo,dp,bp,np->senderind,np->channel,np->height,np->packet,np->datalen); - } else printf("wrong senderind.%d\n",np->senderind); - } - } //else printf("height.%d bp.%p state.%x senderind.%d\n",np->height,bp,bp!=0?bp->state:0,np->senderind); - //dp->crcs[firstz] = crc32; - } - } //else printf("crc error from.%d %x vs %x or no dp.%p [%s]\n",np->senderind,crc32,np->crc32,dp,np->symbol); - } else printf("ignore.%d np->datalen.%d %d (size %d - %ld) [%s]\n",np->senderind,np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np),np->symbol); - } //else printf("wrong version from.%d %02x %02x size.%d [%s]\n",np->senderind,np->version0,np->version1,size,np->symbol); - } //else printf("illegal size.%d\n",size); - if ( freeptr != 0 ) - nn_freemsg(freeptr), np = 0, freeptr = 0; - } //else printf("no packets\n"); - n = 0; - if ( myinfo->dexsock >= 0 ) // from servers - { - while ( (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dexsock,&dexp)) > 0 && n < 1000 ) - { - //fprintf(stderr,"%d ",size); - n++; - if ( dex_packetcheck(myinfo,dexp,size) == 0 ) - { - //printf("FROM BUS.%08x -> pub\n",dexp->crc32); - signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size); - dex_packet(myinfo,dexp,size); + if ( memcmp(bp->notaries[np->senderind].pubkey+1,np->srchash.bytes,32) == 0 && bits256_nonz(np->srchash) != 0 ) + { + if ( bp->isratify == 0 ) + dpow_nanoutxoget(myinfo,dp,bp,&np->notarize,0,np->senderind,np->channel); + else dpow_nanoutxoget(myinfo,dp,bp,&np->ratify,1,np->senderind,np->channel); + dpow_datahandler(myinfo,dp,bp,np->senderind,np->channel,np->height,np->packet,np->datalen); + } else printf("wrong senderind.%d\n",np->senderind); + } + } //else printf("height.%d bp.%p state.%x senderind.%d\n",np->height,bp,bp!=0?bp->state:0,np->senderind); + //dp->crcs[firstz] = crc32; + } + } //else printf("crc error from.%d %x vs %x or no dp.%p [%s]\n",np->senderind,crc32,np->crc32,dp,np->symbol); + } else printf("ignore.%d np->datalen.%d %d (size %d - %ld) [%s]\n",np->senderind,np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np),np->symbol); + } //else printf("wrong version from.%d %02x %02x size.%d [%s]\n",np->senderind,np->version0,np->version1,size,np->symbol); } - //printf("GOT DEX bus PACKET.%d\n",size); if ( freeptr != 0 ) - nn_freemsg(freeptr), dexp = 0, freeptr = 0; - } - } - if ( myinfo->repsock >= 0 ) // from clients - { - num = 0; - while ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 ) + nn_freemsg(freeptr), np = 0, freeptr = 0; + } else flag |= 1; + if ( myinfo->dexsock >= 0 ) // from servers { - num++; - printf("REP got %d crc.%08x\n",size,calc_crc32(0,(void *)dexp,size)); - if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 ) + if ( (flags & 2) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dexsock,&dexp)) > 0 ) { - signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1); - printf("send back[%ld]\n",strlen(retstr)+1); - free(retstr); - if ( broadcastflag != 0 ) + //fprintf(stderr,"%d ",size); + n++; + if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { - //printf("BROADCAST dexp request.[%d]\n",size); - //signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); + //printf("FROM BUS.%08x -> pub\n",dexp->crc32); + signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size); + dex_packet(myinfo,dexp,size); } - } - else + //printf("GOT DEX bus PACKET.%d\n",size); + if ( freeptr != 0 ) + nn_freemsg(freeptr), dexp = 0, freeptr = 0; + } else flags |= 2; + } + if ( myinfo->repsock >= 0 ) // from clients + { + if ( (flags & 4) == 0 && (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 ) { - if ( (m= myinfo->numdpowipbits) > 0 ) + num2++; + printf("REP got %d crc.%08x\n",size,calc_crc32(0,(void *)dexp,size)); + if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 ) { - r = myinfo->dpowipbits[rand() % m]; - signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,&r,sizeof(r)); - printf("REP.%08x <- rand ip m.%d %x\n",dexp->crc32,m,r); - } else printf("illegal state without dpowipbits?\n"); - if ( dex_packetcheck(myinfo,dexp,size) == 0 ) + signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1); + printf("send back[%ld]\n",strlen(retstr)+1); + free(retstr); + if ( broadcastflag != 0 ) + { + //printf("BROADCAST dexp request.[%d]\n",size); + //signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); + } + } + else { - signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); - signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size); - printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp)); - dex_packet(myinfo,dexp,size); - } else printf("failed dexpacketcheck\n"); - } - //printf("GOT DEX rep PACKET.%d\n",size); - //if ( freeptr != 0 ) - // nn_freemsg(freeptr), dexp = 0, freeptr = 0; - if ( dexp != 0 ) - nn_freemsg(dexp), dexp = 0; - if ( num > 1000 ) - break; + if ( (m= myinfo->numdpowipbits) > 0 ) + { + r = myinfo->dpowipbits[rand() % m]; + signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,&r,sizeof(r)); + printf("REP.%08x <- rand ip m.%d %x\n",dexp->crc32,m,r); + } else printf("illegal state without dpowipbits?\n"); + if ( dex_packetcheck(myinfo,dexp,size) == 0 ) + { + signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); + signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size); + printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp)); + dex_packet(myinfo,dexp,size); + } else printf("failed dexpacketcheck\n"); + } + //printf("GOT DEX rep PACKET.%d\n",size); + //if ( freeptr != 0 ) + // nn_freemsg(freeptr), dexp = 0, freeptr = 0; + if ( dexp != 0 ) + nn_freemsg(dexp), dexp = 0; + //if ( num > 1000 ) + // break; + } else flags |= 4; + printf("num.%d n.%d num2.%d rep packets\n",num,n,num2); } - printf("num.%d rep packets\n",num); } portable_mutex_unlock(&myinfo->dpowmutex); return(num); From 4da9054842f087b9174d359c4b8158e2a3ea4d01 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 21:06:10 +0200 Subject: [PATCH 08/15] Test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index d0c0115a8..cf451388b 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -1950,7 +1950,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) } if ( freeptr != 0 ) nn_freemsg(freeptr), np = 0, freeptr = 0; - } else flag |= 1; + } else flags |= 1; if ( myinfo->dexsock >= 0 ) // from servers { if ( (flags & 2) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dexsock,&dexp)) > 0 ) From 3832c13dc4ba8139597c472c5eef7f0aff5a1caa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 21:10:49 +0200 Subject: [PATCH 09/15] Test --- basilisk/basilisk.c | 4 ++-- iguana/dpow/dpow_network.c | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 4a9a8da34..3ab1ea6a3 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -893,7 +893,7 @@ void basilisks_loop(void *arg) basilisk_ping_send(myinfo,relay); } counter++; - fprintf(stderr,"E "); + //fprintf(stderr,"E "); if ( myinfo->numdpows == 1 ) { iguana_dPoWupdate(myinfo,&myinfo->DPOWS[0]); @@ -910,7 +910,7 @@ void basilisks_loop(void *arg) } endmilli = startmilli + 30; } - fprintf(stderr,"F "); + //fprintf(stderr,"F "); } else { diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index cf451388b..99d91392b 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -1888,7 +1888,7 @@ void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t * int32_t dpow_nanomsg_update(struct supernet_info *myinfo) { - int32_t i,n,num,num2,flags=0,size,iter,broadcastflag,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; void *freeptr; + int32_t i,n,num,num2,flags=0,size,iter,lastval=0,broadcastflag,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; void *freeptr; if ( time(NULL) < myinfo->nanoinit+5 || (myinfo->dpowsock < 0 && myinfo->dexsock < 0 && myinfo->repsock < 0) ) return(-1); if ( myinfo->IAMNOTARY != 0 && myinfo->numnotaries <= 0 ) @@ -2009,8 +2009,12 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) //if ( num > 1000 ) // break; } else flags |= 4; - printf("num.%d n.%d num2.%d rep packets\n",num,n,num2); } + if ( (num + n + num2) != lastval ) + { + printf("lastval.%d: num.%d n.%d num2.%d rep packets\n",num,n,num2); + lastval = (num + n + num2); + } else break; } portable_mutex_unlock(&myinfo->dpowmutex); return(num); From 9b0212e600050b63c64c8fe1ba2789fc6320375d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 21:12:17 +0200 Subject: [PATCH 10/15] Test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 99d91392b..0e2a5d690 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -2012,7 +2012,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) } if ( (num + n + num2) != lastval ) { - printf("lastval.%d: num.%d n.%d num2.%d rep packets\n",num,n,num2); + printf("lastval.%d: num.%d n.%d num2.%d rep packets\n",lastval,num,n,num2); lastval = (num + n + num2); } else break; } From 740197ef7a738aec1bc1728d9b74d8e24735bc2d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 21:17:08 +0200 Subject: [PATCH 11/15] Test --- iguana/dpow/dpow_network.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 0e2a5d690..d44226d3a 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -1900,7 +1900,8 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) num = num2 = n = 0; for (iter=0; iter<1000; iter++) { - if ( (flags & 1) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) >= 0 ) + freeptr = 0; + if ( (flags & 1) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) > 0 ) { num++; if ( size > 0 ) @@ -1948,11 +1949,12 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) } else printf("ignore.%d np->datalen.%d %d (size %d - %ld) [%s]\n",np->senderind,np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np),np->symbol); } //else printf("wrong version from.%d %02x %02x size.%d [%s]\n",np->senderind,np->version0,np->version1,size,np->symbol); } - if ( freeptr != 0 ) - nn_freemsg(freeptr), np = 0, freeptr = 0; } else flags |= 1; + if ( freeptr != 0 ) + nn_freemsg(freeptr), np = 0, freeptr = 0; if ( myinfo->dexsock >= 0 ) // from servers { + freeptr = 0; if ( (flags & 2) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dexsock,&dexp)) > 0 ) { //fprintf(stderr,"%d ",size); @@ -1964,12 +1966,13 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) dex_packet(myinfo,dexp,size); } //printf("GOT DEX bus PACKET.%d\n",size); - if ( freeptr != 0 ) - nn_freemsg(freeptr), dexp = 0, freeptr = 0; } else flags |= 2; + if ( freeptr != 0 ) + nn_freemsg(freeptr), dexp = 0, freeptr = 0; } if ( myinfo->repsock >= 0 ) // from clients { + dexp = 0; if ( (flags & 4) == 0 && (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 ) { num2++; @@ -2004,11 +2007,11 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) //printf("GOT DEX rep PACKET.%d\n",size); //if ( freeptr != 0 ) // nn_freemsg(freeptr), dexp = 0, freeptr = 0; - if ( dexp != 0 ) - nn_freemsg(dexp), dexp = 0; //if ( num > 1000 ) // break; } else flags |= 4; + if ( dexp != 0 ) + nn_freemsg(dexp), dexp = 0; } if ( (num + n + num2) != lastval ) { From 5b7efc4a49b9984c2e60d8afddde96de83c09192 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 21:21:01 +0200 Subject: [PATCH 12/15] Test --- iguana/dpow/dpow_network.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index d44226d3a..b26c2e72c 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -1267,9 +1267,9 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) nn_setsockopt(repsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(dexsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); - timeout = 10; + timeout = 1; nn_setsockopt(dexsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); - timeout = 10; + timeout = 1; nn_setsockopt(repsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); maxsize = 1024 * 1024; printf("RCVBUF.%d\n",nn_setsockopt(dexsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize))); @@ -1283,7 +1283,7 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) } myinfo->dpowipbits[0] = (uint32_t)calc_ipbits(myinfo->ipaddr); myinfo->numdpowipbits = 1; - timeout = 10; + timeout = 1; nn_setsockopt(dpowsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); maxsize = 1024 * 1024; printf("RCVBUF.%d\n",nn_setsockopt(dpowsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize))); @@ -1898,7 +1898,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) } portable_mutex_lock(&myinfo->dpowmutex); num = num2 = n = 0; - for (iter=0; iter<1000; iter++) + for (iter=0; iter<100; iter++) { freeptr = 0; if ( (flags & 1) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) > 0 ) @@ -1976,16 +1976,16 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) if ( (flags & 4) == 0 && (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 ) { num2++; - printf("REP got %d crc.%08x\n",size,calc_crc32(0,(void *)dexp,size)); + //printf("REP got %d crc.%08x\n",size,calc_crc32(0,(void *)dexp,size)); if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 ) { signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1); - printf("send back[%ld]\n",strlen(retstr)+1); + //printf("send back[%ld]\n",strlen(retstr)+1); free(retstr); if ( broadcastflag != 0 ) { //printf("BROADCAST dexp request.[%d]\n",size); - //signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); + signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); } } else @@ -1994,13 +1994,13 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) { r = myinfo->dpowipbits[rand() % m]; signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,&r,sizeof(r)); - printf("REP.%08x <- rand ip m.%d %x\n",dexp->crc32,m,r); + //printf("REP.%08x <- rand ip m.%d %x\n",dexp->crc32,m,r); } else printf("illegal state without dpowipbits?\n"); if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size); signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size); - printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp)); + //printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp)); dex_packet(myinfo,dexp,size); } else printf("failed dexpacketcheck\n"); } From 0d29607fb53c2a898fd7c145f7b4f7e2b58f91ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 21:21:44 +0200 Subject: [PATCH 13/15] Test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index b26c2e72c..ba89d18d4 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -2015,7 +2015,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) } if ( (num + n + num2) != lastval ) { - printf("lastval.%d: num.%d n.%d num2.%d rep packets\n",lastval,num,n,num2); + //printf("lastval.%d: num.%d n.%d num2.%d rep packets\n",lastval,num,n,num2); lastval = (num + n + num2); } else break; } From c84ff5420c73b3c827ba49479e998ea7c0b121de Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 21:25:11 +0200 Subject: [PATCH 14/15] Test --- iguana/iguana777.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 471fa8187..29fa7195c 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -133,7 +133,7 @@ struct supernet_info struct liquidity_info linfos[512]; cJSON *liquidity_currencies; struct pending_trade *trades; portable_mutex_t pending_mutex; struct komodo_notaries NOTARY; char seedipaddr[64]; uint32_t dpowipbits[128]; int32_t numdpowipbits; portable_mutex_t notarymutex,dpowmutex; - char dexseed_ipaddrs[1][64]; uint32_t dexipbits[128]; int32_t numdexipbits; portable_mutex_t dexmutex; + char dexseed_ipaddrs[2][64]; uint32_t dexipbits[128]; int32_t numdexipbits; portable_mutex_t dexmutex; // compatibility bits256 pangea_category,instantdex_category; uint8_t logs[256],exps[510]; From a53883fc0769f766e4ff52e7a677d20262cb370d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Feb 2017 21:30:50 +0200 Subject: [PATCH 15/15] Test --- iguana/dpow/dpow_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index ba89d18d4..017d35973 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -408,14 +408,14 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32 printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str); } } -#ifndef __APPLE__ +//#ifndef __APPLE__ if ( (rand() % 100) < 40 ) { nanomsg_tcpname(0,str,ipaddr,REP_SOCK); nn_connect(myinfo->reqsock,str); printf("%d: req connect (%s)\n",myinfo->numdexipbits,str); } -#endif +//#endif } } if ( freeptr != 0 )