Browse Source

test

etomic
jl777 8 years ago
parent
commit
2901ce44e6
  1. 40
      iguana/dpow/dpow_network.c
  2. 2
      iguana/dpow/dpow_tx.c
  3. 1
      iguana/iguana777.h
  4. 15
      iguana/iguana_notary.c
  5. 1
      includes/iguana_apideclares.h

40
iguana/dpow/dpow_network.c

@ -31,8 +31,13 @@ void dex_init(struct supernet_info *myinfo)
portable_mutex_init(&myinfo->dexmutex); 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); sprintf(str,"tcp://%s:%u",ipaddr,port);
return(str); return(str);
} }
@ -62,7 +67,7 @@ printf("dex_reqsend not active yet\n");
return; return;
if ( myinfo->reqsock < 0 && (myinfo->reqsock= nn_socket(AF_SP,NN_REQ)) >= 0 ) 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); nn_close(myinfo->reqsock);
myinfo->reqsock = -1; myinfo->reqsock = -1;
@ -71,7 +76,7 @@ return;
{ {
if ( myinfo->subsock < 0 && (myinfo->subsock= nn_socket(AF_SP,NN_SUB)) >= 0 ) 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); nn_close(myinfo->reqsock);
myinfo->reqsock = -1; myinfo->reqsock = -1;
@ -120,11 +125,11 @@ return;
if ( (myinfo->numdexipbits= n) < 3 ) if ( (myinfo->numdexipbits= n) < 3 )
{ {
if ( myinfo->subsock >= 0 ) 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); 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); nn_freemsg(retptr);
} }
free(dexp); free(dexp);
@ -238,9 +243,9 @@ int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *i
ptr[n] = ipbits; ptr[n] = ipbits;
if ( iter == 0 && strcmp(ipaddr,myinfo->ipaddr) != 0 ) 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); 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++; n++;
qsort(ptr,n,sizeof(uint32_t),_increasing_ipbits); 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); portable_mutex_lock(&myinfo->notarymutex);
if ( myinfo->dpowsock < 0 && (myinfo->dpowsock= nn_socket(AF_SP,NN_BUS)) >= 0 ) 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); nn_close(myinfo->dpowsock);
myinfo->dpowsock = -1; myinfo->dpowsock = -1;
} }
@ -281,9 +286,9 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
printf("NN_BIND to %s\n",str); printf("NN_BIND to %s\n",str);
if ( myinfo->dexsock < 0 && (myinfo->dexsock= nn_socket(AF_SP,NN_BUS)) >= 0 ) 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); nn_close(myinfo->dexsock);
myinfo->dexsock = -1; myinfo->dexsock = -1;
nn_close(myinfo->dpowsock); 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 ( 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); nn_close(myinfo->pubsock);
myinfo->pubsock = -1; myinfo->pubsock = -1;
nn_close(myinfo->dexsock); 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 ( 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); nn_close(myinfo->repsock);
myinfo->repsock = -1; myinfo->repsock = -1;
nn_close(myinfo->pubsock); 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->pendingbestk = bp->bestk;
bp->pendingbestmask = bp->bestmask; bp->pendingbestmask = bp->bestmask;
dpow_signedtxgen(myinfo,dp,bp->destcoin,bp,bp->bestk,bp->bestmask,bp->myind,DPOW_SIGBTCCHANNEL,1,0); 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 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; np->version1 = (DPOW_VERSION >> 8) & 0xff;
memcpy(np->packet,data,datalen); memcpy(np->packet,data,datalen);
sentbytes = -1; sentbytes = -1;
portable_mutex_lock(&myinfo->dpowmutex); // deadlocks! portable_mutex_lock(&myinfo->dpowmutex);
for (i=0; i<100; i++) for (i=0; i<100; i++)
{ {
struct nn_pollfd pfd; struct nn_pollfd pfd;
@ -808,7 +814,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo
} }
usleep(1000); usleep(1000);
} }
portable_mutex_unlock(&myinfo->dpowmutex); //portable_mutex_unlock(&myinfo->dpowmutex);
free(np); free(np);
if ( 0 && bp->myind <= 2 ) 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); 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);

2
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); vinitem = jitem(vins,j);
if ( (sobj= jobj(item,"scriptSig")) != 0 && (sigstr= jstr(sobj,"hex")) != 0 && strlen(sigstr) > 32 ) 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 ) if ( dp->ratifying != 0 && j == 0 && bp->myind == 0 )
valid = 1; valid = 1;
else if ( (pubstr= jstr(vinitem,"scriptPubKey")) != 0 && is_hexstr(pubstr,0) == 70 ) else if ( (pubstr= jstr(vinitem,"scriptPubKey")) != 0 && is_hexstr(pubstr,0) == 70 )

1
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 dpow_info DPOWS[64]; int32_t numdpows,dpowsock,dexsock,pubsock,repsock,subsock,reqsock;
struct delayedPoW_info dPoW; struct delayedPoW_info dPoW;
struct basilisk_spend *spends; int32_t numspends; struct basilisk_spend *spends; int32_t numspends;
char bindaddr[64];
// fadedreamz // fadedreamz
struct peggy_info *PEGS; struct peggy_info *PEGS;
void *PAXDATA; void *PAXDATA;

15
iguana/iguana_notary.c

@ -362,6 +362,21 @@ STRING_ARG(dpow,pending,fiat)
return(clonestr("[]")); 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) STRING_ARG(iguana,addnotary,ipaddr)
{ {
static int32_t didinit; static int32_t didinit;

1
includes/iguana_apideclares.h

@ -19,6 +19,7 @@ STRING_ARG(dpow,active,maskhex);
TWOINTS_AND_ARRAY(dpow,ratify,minsigs,timestamp,ratified); TWOINTS_AND_ARRAY(dpow,ratify,minsigs,timestamp,ratified);
ZERO_ARGS(dpow,cancelratify); ZERO_ARGS(dpow,cancelratify);
THREE_STRINGS(iguana,passthru,asset,function,hex); THREE_STRINGS(iguana,passthru,asset,function,hex);
STRING_ARG(dpow,bindaddr,ipaddr);
TWO_STRINGS(zcash,passthru,function,hex); TWO_STRINGS(zcash,passthru,function,hex);
TWO_STRINGS(komodo,passthru,function,hex); TWO_STRINGS(komodo,passthru,function,hex);

Loading…
Cancel
Save