jl777 8 years ago
parent
commit
b3845c8947
  1. 2
      iguana/dPoW.h
  2. 80
      iguana/dpow/dpow_network.c
  3. 2
      includes/iguana_structs.h

2
iguana/dPoW.h

@ -22,7 +22,7 @@
#define DPOW_MINSIGS 7
#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1)
#define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries)
#define DPOW_VERSION 0x0404
#define DPOW_VERSION 0x0555
#define DPOW_UTXOSIZE 10000
#define DPOW_MINOUTPUT 6000
#define DPOW_DURATION 300

80
iguana/dpow/dpow_network.c

@ -19,9 +19,9 @@
struct dpow_nanomsghdr
{
bits256 srchash,desthash;
uint32_t channel,height,size,datalen,crc32;
uint32_t channel,height,size,datalen,crc32,ipbits[128];
char symbol[16];
uint8_t version0,version1,packet[];
uint8_t version0,version1,numipbits,packet[];
} PACKED;
char *nanomsg_tcpname(char *str,char *ipaddr)
@ -30,6 +30,39 @@ char *nanomsg_tcpname(char *str,char *ipaddr)
return(str);
}
static int _increasing_ipbits(const void *a,const void *b)
{
#define uint32_a (*(struct basilisk_relay *)a).ipbits
#define uint32_b (*(struct basilisk_relay *)b).ipbits
if ( uint32_b > uint32_a )
return(-1);
else if ( uint32_b < uint32_a )
return(1);
return(0);
#undef uint32_a
#undef uint32_b
}
int32_t dpow_addnotary(struct supernet_info *myinfo,char *ipaddr)
{
char str[512]; uint32_t ipbits; int32_t i,retval = -1;
if ( myinfo->dpowsock >= 0 && strcmp(ipaddr,myinfo->ipaddr) != 0 )
{
ipbits = (uint32_t)calc_ipbits(ipaddr);
for (i=0; i<myinfo->numdpowipbits; i++)
if ( ipbits == myinfo->dpowipbits[i] )
break;
if ( i == myinfo->numdpowipbits && myinfo->numdpowipbits < sizeof(myinfo->dpowipbits)/sizeof(*myinfo->dpowipbits) )
{
myinfo->dpowipbits[myinfo->numdpowipbits++] = ipbits;
retval = nn_connect(myinfo->dpowsock,nanomsg_tcpname(str,ipaddr));
qsort(myinfo->dpowipbits,myinfo->numdpowipbits,sizeof(myinfo->dpowipbits),_increasing_ipbits);
printf("addnotary.[%d] (%s) retval.%d\n",myinfo->numdpowipbits,ipaddr,retval);
}
}
return(retval);
}
void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
{
char str[512]; int32_t timeout,retval;
@ -48,18 +81,15 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
}
timeout = 1000;
nn_setsockopt(myinfo->dpowsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
myinfo->dpowipbits[0] = (uint32_t)calc_ipbits(myinfo->ipaddr);
myinfo->numdpowipbits = 1;
}
if ( myinfo->dpowsock >= 0 && strcmp(ipaddr,myinfo->ipaddr) != 0 )
{
retval = nn_connect(myinfo->dpowsock,nanomsg_tcpname(str,ipaddr));
printf("addnotary (%s) retval.%d\n",ipaddr,retval);
}
return(dpow_addnotary(myinfo,ipaddr));
}
int32_t dpow_crc32find(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t crc32,uint32_t channel)
{
int32_t i,firstz = -1;
//return(0);
for (i=0; i<sizeof(dp->crcs)/sizeof(*dp->crcs); i++)
{
if ( dp->crcs[i] == crc32 )
@ -83,7 +113,9 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo
{
//dp->crcs[firstz] = crc32;
size = (int32_t)(sizeof(*np) + datalen);
np = calloc(1,size);
np = calloc(1,size); // endian dependent!
np->numipbits = myinfo->numdpowipbits;
memcpy(np->ipbits,myinfo->dpowipbits,myinfo->numdpowipbits * sizeof(*myinfo->dpowipbits));
//printf("dpow_send.(%d) size.%d\n",datalen,size);
np->size = size;
np->datalen = datalen;
@ -102,6 +134,35 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo
}
}
void dpow_ipbitsadd(struct supernet_info *myinfo,uint32_t *ipbits,int32_t numipbits)
{
int32_t i,j,matched,missing; char ipaddr[64];
if ( numipbits < 1 )
return;
matched = missing = 0;
for (i=0; i<numipbits; i++)
{
for (j=0; j<myinfo->numdpowipbits; j++)
if ( ipbits[i] == myinfo->dpowipbits[j] )
{
matched++;
ipbits[i] = 0;
break;
}
if ( j == myinfo->numdpowipbits )
missing++;
}
if ( (numipbits == 1 || missing < matched) && missing > 0 )
{
for (i=0; i<numipbits; i++)
if ( ipbits[i] != 0 )
{
expand_ipbits(ipaddr,ipbits[i]);
dpow_addnotary(myinfo,ipaddr);
}
}
}
void dpow_nanomsg_update(struct supernet_info *myinfo)
{
int32_t i,n=0,size,firstz = -1; uint32_t crc32; struct dpow_nanomsghdr *np; struct dpow_info *dp;
@ -114,6 +175,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo)
if ( np->datalen == (size - sizeof(*np)) )
{
crc32 = calc_crc32(0,np->packet,np->datalen);
dpow_ipbitsadd(myinfo,np->ipbits,np->numipbits);
dp = 0;
for (i=0; i<myinfo->numdpows; i++)
{

2
includes/iguana_structs.h

@ -508,7 +508,7 @@ struct iguana_info
uint32_t utxoaddrlastcount,*utxoaddroffsets,lastunspentsupdate; uint8_t *utxoaddrtable; bits256 utxoaddrhash;
FILE *utxofp;
bits256 markedunspents[1024];
char seedipaddr[64];
char seedipaddr[64]; uint32_t dpowipbits[128]; int32_t numdpowipbits;
uint32_t lastbesthashtime; bits256 lastbesthash; int32_t lastbestheight;
struct iguana_block *RTblocks[65536]; uint8_t *RTrawdata[65536]; int32_t RTrecvlens[65536],RTnumtx[65536];
struct iguana_RTtxid *RTdataset; struct iguana_RTaddr *RTaddrs;

Loading…
Cancel
Save