From 2901ce44e62d7985cfef3ed6789d42afc3524ff9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 22 Dec 2016 09:57:57 +0200 Subject: [PATCH] test --- iguana/dpow/dpow_network.c | 40 ++++++++++++++++++++--------------- iguana/dpow/dpow_tx.c | 2 +- iguana/iguana777.h | 1 + iguana/iguana_notary.c | 15 +++++++++++++ includes/iguana_apideclares.h | 1 + 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 3e18c47ed..1e2ecd453 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -31,8 +31,13 @@ void dex_init(struct supernet_info *myinfo) portable_mutex_init(&myinfo->dexmutex); } -char *nanomsg_tcpname(char *str,char *ipaddr,uint16_t port) +char *nanomsg_tcpname(struct supernet_info *myinfo,char *str,char *ipaddr,uint16_t port) { + if ( myinfo != 0 ) // bind path) + { + if ( myinfo->bindaddr[0] != 0 && strcmp(ipaddr,myinfo->ipaddr) == 0 ) + ipaddr = myinfo->bindaddr; + } sprintf(str,"tcp://%s:%u",ipaddr,port); return(str); } @@ -62,7 +67,7 @@ printf("dex_reqsend not active yet\n"); return; if ( myinfo->reqsock < 0 && (myinfo->reqsock= nn_socket(AF_SP,NN_REQ)) >= 0 ) { - if ( nn_connect(myinfo->reqsock,nanomsg_tcpname(str,myinfo->dexseed_ipaddr,REP_SOCK)) < 0 ) + if ( nn_connect(myinfo->reqsock,nanomsg_tcpname(0,str,myinfo->dexseed_ipaddr,REP_SOCK)) < 0 ) { nn_close(myinfo->reqsock); myinfo->reqsock = -1; @@ -71,7 +76,7 @@ return; { if ( myinfo->subsock < 0 && (myinfo->subsock= nn_socket(AF_SP,NN_SUB)) >= 0 ) { - if ( nn_connect(myinfo->subsock,nanomsg_tcpname(str,myinfo->dexseed_ipaddr,PUB_SOCK)) < 0 ) + if ( nn_connect(myinfo->subsock,nanomsg_tcpname(0,str,myinfo->dexseed_ipaddr,PUB_SOCK)) < 0 ) { nn_close(myinfo->reqsock); myinfo->reqsock = -1; @@ -120,11 +125,11 @@ return; if ( (myinfo->numdexipbits= n) < 3 ) { if ( myinfo->subsock >= 0 ) - nn_connect(myinfo->subsock,nanomsg_tcpname(str,ipaddr,PUB_SOCK)); + nn_connect(myinfo->subsock,nanomsg_tcpname(0,str,ipaddr,PUB_SOCK)); } } portable_mutex_unlock(&myinfo->dexmutex); - nn_connect(myinfo->reqsock,nanomsg_tcpname(str,ipaddr,REP_SOCK)); + nn_connect(myinfo->reqsock,nanomsg_tcpname(0,str,ipaddr,REP_SOCK)); nn_freemsg(retptr); } free(dexp); @@ -238,9 +243,9 @@ int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *i ptr[n] = ipbits; if ( iter == 0 && strcmp(ipaddr,myinfo->ipaddr) != 0 ) { - retval = nn_connect(myinfo->dpowsock,nanomsg_tcpname(str,ipaddr,DPOW_SOCK)); + retval = nn_connect(myinfo->dpowsock,nanomsg_tcpname(0,str,ipaddr,DPOW_SOCK)); printf("NN_CONNECT to (%s)\n",str); - retval = nn_connect(myinfo->dexsock,nanomsg_tcpname(str,ipaddr,DEX_SOCK)); + retval = nn_connect(myinfo->dexsock,nanomsg_tcpname(0,str,ipaddr,DEX_SOCK)); } n++; qsort(ptr,n,sizeof(uint32_t),_increasing_ipbits); @@ -270,9 +275,9 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) portable_mutex_lock(&myinfo->notarymutex); if ( myinfo->dpowsock < 0 && (myinfo->dpowsock= nn_socket(AF_SP,NN_BUS)) >= 0 ) { - if ( nn_bind(myinfo->dpowsock,nanomsg_tcpname(str,myinfo->ipaddr,DPOW_SOCK)) < 0 ) + if ( nn_bind(myinfo->dpowsock,nanomsg_tcpname(myinfo,str,myinfo->ipaddr,DPOW_SOCK)) < 0 ) { - printf("error binding to dpowsock (%s)\n",nanomsg_tcpname(str,myinfo->ipaddr,DPOW_SOCK)); + printf("error binding to dpowsock (%s)\n",nanomsg_tcpname(myinfo,str,myinfo->ipaddr,DPOW_SOCK)); nn_close(myinfo->dpowsock); myinfo->dpowsock = -1; } @@ -281,9 +286,9 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) printf("NN_BIND to %s\n",str); if ( myinfo->dexsock < 0 && (myinfo->dexsock= nn_socket(AF_SP,NN_BUS)) >= 0 ) { - if ( nn_bind(myinfo->dexsock,nanomsg_tcpname(str,myinfo->ipaddr,DEX_SOCK)) < 0 ) + if ( nn_bind(myinfo->dexsock,nanomsg_tcpname(myinfo,str,myinfo->ipaddr,DEX_SOCK)) < 0 ) { - printf("error binding to dexsock (%s)\n",nanomsg_tcpname(str,myinfo->ipaddr,DEX_SOCK)); + printf("error binding to dexsock (%s)\n",nanomsg_tcpname(myinfo,str,myinfo->ipaddr,DEX_SOCK)); nn_close(myinfo->dexsock); myinfo->dexsock = -1; nn_close(myinfo->dpowsock); @@ -293,9 +298,9 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) { if ( myinfo->pubsock < 0 && (myinfo->pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) { - if ( nn_bind(myinfo->pubsock,nanomsg_tcpname(str,myinfo->ipaddr,PUB_SOCK)) < 0 ) + if ( nn_bind(myinfo->pubsock,nanomsg_tcpname(myinfo,str,myinfo->ipaddr,PUB_SOCK)) < 0 ) { - printf("error binding to pubsock (%s)\n",nanomsg_tcpname(str,myinfo->ipaddr,PUB_SOCK)); + printf("error binding to pubsock (%s)\n",nanomsg_tcpname(myinfo,str,myinfo->ipaddr,PUB_SOCK)); nn_close(myinfo->pubsock); myinfo->pubsock = -1; nn_close(myinfo->dexsock); @@ -307,9 +312,9 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) { if ( myinfo->repsock < 0 && (myinfo->repsock= nn_socket(AF_SP,NN_REP)) >= 0 ) { - if ( nn_bind(myinfo->repsock,nanomsg_tcpname(str,myinfo->ipaddr,REP_SOCK)) < 0 ) + if ( nn_bind(myinfo->repsock,nanomsg_tcpname(myinfo,str,myinfo->ipaddr,REP_SOCK)) < 0 ) { - printf("error binding to repsock (%s)\n",nanomsg_tcpname(str,myinfo->ipaddr,REP_SOCK)); + printf("error binding to repsock (%s)\n",nanomsg_tcpname(myinfo,str,myinfo->ipaddr,REP_SOCK)); nn_close(myinfo->repsock); myinfo->repsock = -1; nn_close(myinfo->pubsock); @@ -712,6 +717,7 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru bp->pendingbestk = bp->bestk; bp->pendingbestmask = bp->bestmask; dpow_signedtxgen(myinfo,dp,bp->destcoin,bp,bp->bestk,bp->bestmask,bp->myind,DPOW_SIGBTCCHANNEL,1,0); + printf("finished signing\n"); } if ( bp->destsigsmasks[bp->bestk] == bp->bestmask ) // have all sigs { @@ -795,7 +801,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo np->version1 = (DPOW_VERSION >> 8) & 0xff; memcpy(np->packet,data,datalen); sentbytes = -1; - portable_mutex_lock(&myinfo->dpowmutex); + // deadlocks! portable_mutex_lock(&myinfo->dpowmutex); for (i=0; i<100; i++) { struct nn_pollfd pfd; @@ -808,7 +814,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo } usleep(1000); } - portable_mutex_unlock(&myinfo->dpowmutex); + //portable_mutex_unlock(&myinfo->dpowmutex); free(np); if ( 0 && bp->myind <= 2 ) printf("%d NANOSEND.%d ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",i,sentbytes,np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index ccc1f736d..3f17aacad 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -436,7 +436,7 @@ void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct igu vinitem = jitem(vins,j); if ( (sobj= jobj(item,"scriptSig")) != 0 && (sigstr= jstr(sobj,"hex")) != 0 && strlen(sigstr) > 32 ) { - valid = 1; + valid = 0; if ( dp->ratifying != 0 && j == 0 && bp->myind == 0 ) valid = 1; else if ( (pubstr= jstr(vinitem,"scriptPubKey")) != 0 && is_hexstr(pubstr,0) == 70 ) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index f9e4c9ee5..77da1eaee 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -105,6 +105,7 @@ struct supernet_info struct dpow_info DPOWS[64]; int32_t numdpows,dpowsock,dexsock,pubsock,repsock,subsock,reqsock; struct delayedPoW_info dPoW; struct basilisk_spend *spends; int32_t numspends; + char bindaddr[64]; // fadedreamz struct peggy_info *PEGS; void *PAXDATA; diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 4afc005d7..3a3be5af6 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -362,6 +362,21 @@ STRING_ARG(dpow,pending,fiat) return(clonestr("[]")); } +STRING_ARG(dpow,bindaddr,ipaddr) +{ + uint32_t ipbits; char checkbuf[64]; + if ( ipaddr != 0 && ipaddr[0] != 0 ) + { + ipbits = (uint32_t)calc_ipbits(ipaddr); + expand_ipbits(checkbuf,ipbits); + if ( strcmp(ipaddr,checkbuf) == 0 ) + { + strcpy(myinfo->bindaddr,ipaddr); + return(clonestr("{\"result\":\"success\"}")); + } else return(clonestr("{\"error\":\"invalid bind ipaddr\"}")); + } else return(clonestr("{\"error\":\"no bind ipaddr\"}")); +} + STRING_ARG(iguana,addnotary,ipaddr) { static int32_t didinit; diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 0bc2c0e5b..9cb4a8419 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -19,6 +19,7 @@ STRING_ARG(dpow,active,maskhex); TWOINTS_AND_ARRAY(dpow,ratify,minsigs,timestamp,ratified); ZERO_ARGS(dpow,cancelratify); THREE_STRINGS(iguana,passthru,asset,function,hex); +STRING_ARG(dpow,bindaddr,ipaddr); TWO_STRINGS(zcash,passthru,function,hex); TWO_STRINGS(komodo,passthru,function,hex);