Browse Source

Merge pull request #154 from jl777/dev

test
win-cross
jl777 8 years ago
committed by GitHub
parent
commit
c86d34de5f
  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);
}
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);

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);
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 )

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 delayedPoW_info dPoW;
struct basilisk_spend *spends; int32_t numspends;
char bindaddr[64];
// fadedreamz
struct peggy_info *PEGS;
void *PAXDATA;

15
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;

1
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);

Loading…
Cancel
Save