jl777 8 years ago
parent
commit
471ff46cc7
  1. 20
      basilisk/basilisk.c
  2. 2
      basilisk/basilisk_MSG.c
  3. 2
      iguana/iguana_msg.c
  4. 2
      iguana/iguana_peers.c
  5. 14
      iguana/iguana_wallet.c
  6. 2
      iguana/tests/addnotarys

20
basilisk/basilisk.c

@ -153,7 +153,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
else if ( fanout > BASILISK_MAXFANOUT ) else if ( fanout > BASILISK_MAXFANOUT )
fanout = BASILISK_MAXFANOUT; fanout = BASILISK_MAXFANOUT;
if ( type == 0 ) if ( type == 0 )
type = "BTCD"; type = "INF";
if ( strlen(type) > 3 ) if ( strlen(type) > 3 )
{ {
printf("basilisk_sendcmd illegal type(%s)\n",type); printf("basilisk_sendcmd illegal type(%s)\n",type);
@ -213,6 +213,8 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
{ {
if ( coin->peers == 0 ) if ( coin->peers == 0 )
continue; continue;
//if ( basilisk_notarycmd(type) != 0 && strcmp(coin->symbol,"NOTARY") != 0 )
// continue;
if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 ) if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 )
cmd[0] = 's'; cmd[0] = 's';
else cmd[0] = 'S'; else cmd[0] = 'S';
@ -228,21 +230,21 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
{ {
s = 0; s = 0;
valid = (addr->supernet != 0); valid = (addr->supernet != 0);
if ( basilisk_notarycmd(type) != 0 && myinfo->IAMNOTARY != 0 ) if ( basilisk_notarycmd(type) != 0 )
{ {
valid = 0; valid = 0;
OS_randombytes((void *)&r2,sizeof(r2)); /*OS_randombytes((void *)&r2,sizeof(r2));
if ( (r2 % myinfo->NOTARY.NUMRELAYS) >= sqrt(myinfo->NOTARY.NUMRELAYS) ) if ( (r2 % myinfo->NOTARY.NUMRELAYS) >= sqrt(myinfo->NOTARY.NUMRELAYS) )
{ {
//printf("fanout.%d s.%d n.%d skip %s\n",fanout,s,n,addr->ipaddr); printf("fanout.%d s.%d n.%d skip %s\n",fanout,s,n,addr->ipaddr);
continue; continue;
} }*/
for (s=0; s<myinfo->NOTARY.NUMRELAYS; s++) for (s=0; s<myinfo->NOTARY.NUMRELAYS; s++)
if ( addr->ipbits != myinfo->myaddr.myipbits && myinfo->NOTARY.RELAYS[s].ipbits == addr->ipbits ) if ( addr->ipbits != myinfo->myaddr.myipbits && myinfo->NOTARY.RELAYS[s].ipbits == addr->ipbits )
break; break;
if ( s == myinfo->NOTARY.NUMRELAYS ) if ( s == myinfo->NOTARY.NUMRELAYS )
{ {
//printf("skip non-relay.(%s)\n",addr->ipaddr); printf("skip non-relay.(%s)\n",addr->ipaddr);
continue; continue;
} }
valid = 1; valid = 1;
@ -256,7 +258,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
} }
if ( s == n && valid == 1 && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) ) if ( s == n && valid == 1 && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) )
{ {
//fprintf(stderr,"(%s) ",addr->ipaddr); fprintf(stderr,"(%s).%u ",addr->ipaddr,coin->chain->portp2p);
//printf("n.%d/fanout.%d i.%d l.%d [%s].tag%u send %s.(%s) [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",n,fanout,i,l,cmd,*(uint32_t *)data,type,(char *)&data[4],*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast"); //printf("n.%d/fanout.%d i.%d l.%d [%s].tag%u send %s.(%s) [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",n,fanout,i,l,cmd,*(uint32_t *)data,type,(char *)&data[4],*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast");
if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 ) if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 )
{ {
@ -676,7 +678,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
return; return;
} else if ( basilisk_notarycmd(CMD) != 0 ) } else if ( basilisk_notarycmd(CMD) != 0 )
return; return;
symbol = "BTCD"; symbol = "NOTARY";
if ( senderipbits == 0 ) if ( senderipbits == 0 )
expand_ipbits(remoteaddr,myinfo->myaddr.myipbits); expand_ipbits(remoteaddr,myinfo->myaddr.myipbits);
else expand_ipbits(remoteaddr,senderipbits); else expand_ipbits(remoteaddr,senderipbits);
@ -723,7 +725,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
data += jsonlen, datalen -= jsonlen; data += jsonlen, datalen -= jsonlen;
else data = 0, datalen = 0; else data = 0, datalen = 0;
if ( coin == 0 ) if ( coin == 0 )
coin = iguana_coinfind("BTCD"); coin = iguana_coinfind(symbol);
if ( coin != 0 ) if ( coin != 0 )
{ {
symbol = coin->symbol; symbol = coin->symbol;

2
basilisk/basilisk_MSG.c

@ -207,7 +207,7 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t
jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"msgid",msgid);
jaddnum(valsobj,"duration",duration); jaddnum(valsobj,"duration",duration);
jaddbits256(valsobj,"sender",myinfo->myaddr.persistent); jaddbits256(valsobj,"sender",myinfo->myaddr.persistent);
//char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d:%d\n",datalen,channel,msgid,bits256_str(str,hash),NUMRELAYS,juint(valsobj,"fanout")); char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d:%d\n",datalen,channel,msgid,bits256_str(str,hash),myinfo->NOTARY.NUMRELAYS,juint(valsobj,"fanout"));
if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,hash,valsobj,hexstr)) != 0 ) if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,hash,valsobj,hexstr)) != 0 )
free(retstr); free(retstr);
free_json(valsobj); free_json(valsobj);

2
iguana/iguana_msg.c

@ -1010,7 +1010,7 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s
{ {
struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg; struct iguana_zblock *zblocks; uint32_t tmp,n=0; struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg; struct iguana_zblock *zblocks; uint32_t tmp,n=0;
len = 0; len = 0;
if ( addr != 0 && recvlen >= sizeof(bits256) && strcmp("BTCD",coin->symbol) != 0 ) if ( addr != 0 && recvlen >= sizeof(bits256) && strcmp("NOTARY",coin->symbol) != 0 )
{ {
if ( ishost == 0 ) if ( ishost == 0 )
{ {

2
iguana/iguana_peers.c

@ -584,7 +584,7 @@ int32_t iguana_recv(char *ipaddr,int32_t usock,uint8_t *recvbuf,int32_t len)
remains -= recvlen; remains -= recvlen;
//int32_t i; for (i=0; i<recvlen; i++) //int32_t i; for (i=0; i<recvlen; i++)
// printf("%02x",recvbuf[i]); // printf("%02x",recvbuf[i]);
//printf("got %d remains.%d of total.%d from (%s)\n",recvlen,remains,len,ipaddr); printf("got %d remains.%d of total.%d from (%s)\n",recvlen,remains,len,ipaddr);
recvbuf = &recvbuf[recvlen]; recvbuf = &recvbuf[recvlen];
} else usleep(10000); } else usleep(10000);
} }

14
iguana/iguana_wallet.c

@ -1140,7 +1140,7 @@ cJSON *iguana_getinfo(struct supernet_info *myinfo,struct iguana_info *coin)
ZERO_ARGS(bitcoinrpc,getinfo) ZERO_ARGS(bitcoinrpc,getinfo)
{ {
struct basilisk_item Lptr,*ptr; int32_t i,j,m,n,longest; cJSON *valsobj,*getinfoobj=0,*array,*item,*fullnodes; struct basilisk_item Lptr,*ptr; int32_t incr,i,j,m,n,longest; cJSON *valsobj,*getinfoobj=0,*array,*item,*fullnodes;
if ( remoteaddr != 0 ) if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}")); return(clonestr("{\"error\":\"no remote\"}"));
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 ) if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
@ -1174,7 +1174,17 @@ ZERO_ARGS(bitcoinrpc,getinfo)
} }
if ( (fullnodes= jarray(&m,item,"supernet")) != 0 ) if ( (fullnodes= jarray(&m,item,"supernet")) != 0 )
{ {
for (j=0; j<m; j++) incr = 1;
if ( strcmp(coin->symbol,"NOTARY") == 0 )
{
for (j=0; j<m; j++)
basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(jstri(fullnodes,j)),GENESIS_PUBKEY);
incr = sqrt(m);
if ( incr < 1 )
incr = 1, j = 0;
else j = (myinfo->myaddr.pubkey.uints[0] % incr);
} else j = 0;
for (; j<m; j+=incr)
{ {
//fprintf(stderr,"[%s] ",jstri(fullnodes,j)); //fprintf(stderr,"[%s] ",jstri(fullnodes,j));
iguana_launchpeer(coin,jstri(fullnodes,j),1); iguana_launchpeer(coin,jstri(fullnodes,j),1);

2
iguana/tests/addnotarys

@ -7,3 +7,5 @@ curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"ad
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.242\"}" curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.242\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.243\"}" curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.243\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.244\"}" curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.244\"}"
sleep 3
./getinfoN

Loading…
Cancel
Save