Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
784aedd812
  1. 31
      iguana/SuperNET.c
  2. 3
      iguana/iguana_accept.c

31
iguana/SuperNET.c

@ -139,7 +139,7 @@ cJSON *SuperNET_bits2json(struct supernet_info *myinfo,bits256 prevpub,uint8_t *
uint16_t apinum; uint32_t destipbits,myipbits; bits256 seed,seed2,senderpub; cJSON *json = cJSON_CreateObject(); uint16_t apinum; uint32_t destipbits,myipbits; bits256 seed,seed2,senderpub; cJSON *json = cJSON_CreateObject();
int32_t i; for (i=0; i<datalen; i++) int32_t i; for (i=0; i<datalen; i++)
printf("%02x ",serialized[i]); printf("%02x ",serialized[i]);
printf("bits[%d]\n",datalen); printf("bits[%d] iscompressed.%d\n",datalen,iscompressed);
if ( iscompressed != 0 ) if ( iscompressed != 0 )
{ {
len = serialized[0]; len = serialized[0];
@ -151,6 +151,9 @@ cJSON *SuperNET_bits2json(struct supernet_info *myinfo,bits256 prevpub,uint8_t *
numbits = ramcoder_decompress(space,IGUANA_MAXPACKETSIZE,&serialized[3],len<<3,seed2); numbits = ramcoder_decompress(space,IGUANA_MAXPACKETSIZE,&serialized[3],len<<3,seed2);
datalen = (int32_t)hconv_bitlen(numbits); datalen = (int32_t)hconv_bitlen(numbits);
serialized = space; serialized = space;
int32_t i; for (i=0; i<datalen; i++)
printf("%02x ",serialized[i]);
printf("bits[%d]\n",datalen);
} }
len += iguana_rwnum(0,&serialized[len],sizeof(uint32_t),&destipbits); len += iguana_rwnum(0,&serialized[len],sizeof(uint32_t),&destipbits);
len += iguana_rwnum(0,&serialized[len],sizeof(uint32_t),&myipbits); len += iguana_rwnum(0,&serialized[len],sizeof(uint32_t),&myipbits);
@ -192,7 +195,7 @@ int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,c
printf("SUPERSEND.(%s) -> (%s) delaymillis.%d datalen.%d\n",jsonstr,addr->ipaddr,delaymillis,datalen); printf("SUPERSEND.(%s) -> (%s) delaymillis.%d datalen.%d\n",jsonstr,addr->ipaddr,delaymillis,datalen);
if ( datalen >= 0 ) if ( datalen >= 0 )
{ {
if ( complen >= 0 && complen < (((datalen-3) * 7) >> 3) ) if ( complen >= 0 )//&& complen < (((datalen-3) * 7) >> 3) )
qlen = iguana_queue_send(coin,addr,delaymillis,compressed,"SuperNETb",complen,0,0); qlen = iguana_queue_send(coin,addr,delaymillis,compressed,"SuperNETb",complen,0,0);
else qlen = iguana_queue_send(coin,addr,delaymillis,serialized,"SuperNET",datalen,0,0); else qlen = iguana_queue_send(coin,addr,delaymillis,serialized,"SuperNET",datalen,0,0);
} }
@ -304,19 +307,25 @@ char *SuperNET_forward(struct supernet_info *myinfo,char *hexmsg,uint32_t destip
int32_t SuperNET_destination(struct supernet_info *myinfo,uint32_t *destipbitsp,bits256 *destpubp,int32_t *maxdelayp,cJSON *json,char *remoteaddr) int32_t SuperNET_destination(struct supernet_info *myinfo,uint32_t *destipbitsp,bits256 *destpubp,int32_t *maxdelayp,cJSON *json,char *remoteaddr)
{ {
char *destip; int32_t destflag = 0; char *destip; int32_t destflag = 0;
if ( remoteaddr != 0 && remoteaddr[0] != 0 )
destflag = SUPERNET_FORWARD;
else destflag = SUPERNET_ISMINE;
if ( (destip= jstr(json,"destip")) != 0 ) if ( (destip= jstr(json,"destip")) != 0 )
*destipbitsp = (uint32_t)calc_ipbits(destip); *destipbitsp = (uint32_t)calc_ipbits(destip);
else *destipbitsp = 0; else *destipbitsp = 0;
*maxdelayp = juint(json,"delay"); *maxdelayp = juint(json,"delay");
*destpubp = jbits256(json,"destpub"); *destpubp = jbits256(json,"destpub");
if ( *destipbitsp == myinfo->myaddr.selfipbits ) if ( *destipbitsp != 0 )
destflag = SUPERNET_ISMINE; {
else if ( memcmp(destpubp,myinfo->myaddr.pubkey.bytes,sizeof(*destpubp)) == 0 ) if ( *destipbitsp == myinfo->myaddr.selfipbits )
destflag = SUPERNET_ISMINE; destflag |= SUPERNET_ISMINE;
// check for encrypted packets else destflag |= SUPERNET_FORWARD;
}
else if ( bits256_nonz(*destpubp) > 0 )
{
if ( memcmp(destpubp,myinfo->myaddr.pubkey.bytes,sizeof(*destpubp)) == 0 )
destflag |= SUPERNET_ISMINE;
else destflag |= SUPERNET_FORWARD;
}
else if ( remoteaddr == 0 || remoteaddr[0] == 0 )
destflag |= SUPERNET_ISMINE;
return(destflag); return(destflag);
} }
@ -391,7 +400,7 @@ char *SuperNET_p2p(struct iguana_info *coin,struct iguana_peer *addr,int32_t *de
return(clonestr("{\"result\":\"peer marked as dead\"}")); return(clonestr("{\"result\":\"peer marked as dead\"}"));
} }
retstr = SuperNET_JSON(myinfo,json,ipaddr); retstr = SuperNET_JSON(myinfo,json,ipaddr);
printf("p2pret.(%s)\n",retstr); //printf("p2pret.(%s)\n",retstr);
*delaymillisp = SuperNET_delaymillis(myinfo,maxdelay); *delaymillisp = SuperNET_delaymillis(myinfo,maxdelay);
free_json(json); free_json(json);
} }

3
iguana/iguana_accept.c

@ -67,7 +67,8 @@ void iguana_acceptloop(void *args)
socklen_t clilen; struct sockaddr_in cli_addr; char ipaddr[64]; uint32_t i,ipbits; socklen_t clilen; struct sockaddr_in cli_addr; char ipaddr[64]; uint32_t i,ipbits;
while ( (coin->bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 ) while ( (coin->bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 )
sleep(5); sleep(5);
printf("iguana_bindloop 127.0.0.1:%d bind sock.%d\n",coin->chain->portp2p,coin->bindsock); printf(">>>>>>>>>>>>>>>> iguana_bindloop 127.0.0.1:%d bind sock.%d\n",coin->chain->portp2p,coin->bindsock);
printf("START ACCEPTING\n");
while ( coin->bindsock >= 0 ) while ( coin->bindsock >= 0 )
{ {
memset(&pfd,0,sizeof(pfd)); memset(&pfd,0,sizeof(pfd));

Loading…
Cancel
Save