From a89925ad46286f65eb0c436644b79a5457d30139 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Jan 2016 03:18:13 -0300 Subject: [PATCH] test --- iguana/SuperNET.c | 25 +++++++++++++++++-------- iguana/SuperNET_hexmsg.c | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/iguana/SuperNET.c b/iguana/SuperNET.c index 911525421..317e18540 100644 --- a/iguana/SuperNET.c +++ b/iguana/SuperNET.c @@ -452,7 +452,7 @@ struct iguana_peer *iguana_peerfind(struct supernet_info *myinfo,struct iguana_i char *SuperNET_DHTsend(struct supernet_info *myinfo,uint32_t destipbits,bits256 destpub,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext) { - int32_t i,j; char *jsonstr=0; struct iguana_peer *addr; cJSON *json; struct iguana_info *coin; + int32_t i,j; char *jsonstr=0; bits256 hash; struct iguana_peer *addr; cJSON *json; struct iguana_info *coin; if ( myinfo == 0 ) return(clonestr("{\"error\":\"no supernet_info\"}")); json = cJSON_CreateObject(); @@ -464,11 +464,11 @@ char *SuperNET_DHTsend(struct supernet_info *myinfo,uint32_t destipbits,bits256 if ( plaintext != 0 ) jaddnum(json,"plaintext",plaintext!=0); jsonstr = jprint(json,1); - if ( SuperNET_hexmsgfind(myinfo,destpub,hexmsg,1) < 0 ) + /*if ( SuperNET_hexmsgfind(myinfo,destpub,hexmsg,1) >= 0 ) { char str[65]; printf("duplicate hex.(%s) for %s\n",hexmsg,bits256_str(str,destpub)); return(clonestr("{\"error\":\"duplicate packet rejected\"}")); - } + }*/ if ( broadcastflag != 0 || destipbits == 0 ) { for (i=0; ipeers.active[j]; if ( addr->usock >= 0 && addr->supernet != 0 && (broadcastflag != 0 || category_peer(myinfo,Coins[i],addr,destpub) >= 0) ) { - char str[65]; printf("BROADCAST[%d] %s SEND.(%ld) to %s\n",j,bits256_str(str,destpub),strlen(jsonstr),addr->ipaddr); - iguana_send_supernet(Coins[i],addr,jsonstr,maxdelay==0?0:(rand()%maxdelay)); + hash = destpub, hash.uints[0] ^= addr->ipbits; + if ( SuperNET_hexmsgfind(myinfo,hash,hexmsg,1) >= 0 ) + { + char str[65]; printf("BROADCAST[%d] %s SEND.(%ld) to %s\n",j,bits256_str(str,destpub),strlen(jsonstr),addr->ipaddr); + iguana_send_supernet(Coins[i],addr,jsonstr,maxdelay==0?0:(rand()%maxdelay)); + } } } } @@ -490,9 +494,14 @@ char *SuperNET_DHTsend(struct supernet_info *myinfo,uint32_t destipbits,bits256 } if ( (addr= iguana_peerfind(myinfo,&coin,destipbits,destpub)) == 0 ) return(clonestr("{\"error\":\"no route found\"}")); - printf("SEND.(%s) to %s\n",jsonstr,addr->ipaddr); - iguana_send_supernet(coin,addr,jsonstr,maxdelay==0?0:(rand()%maxdelay)); - return(clonestr("{\"result\":\"packet sent directly\"}")); + hash = destpub, hash.uints[0] ^= addr->ipbits; + if ( SuperNET_hexmsgfind(myinfo,hash,hexmsg,1) >= 0 ) + { + printf("SEND.(%s) to %s\n",jsonstr,addr->ipaddr); + iguana_send_supernet(coin,addr,jsonstr,maxdelay==0?0:(rand()%maxdelay)); + return(clonestr("{\"result\":\"packet sent directly\"}")); + } + return(clonestr("{\"result\":\"no appropriate peers to send to\"}")); } char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 destpub,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext) diff --git a/iguana/SuperNET_hexmsg.c b/iguana/SuperNET_hexmsg.c index e532e5983..baa3bbc02 100644 --- a/iguana/SuperNET_hexmsg.c +++ b/iguana/SuperNET_hexmsg.c @@ -24,7 +24,7 @@ int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 dest,char *hexm if ( bits256_nonz(dest) == 0 ) dest = GENESIS_PUBKEY; packethash = curve25519(dest,packethash); - //printf("addflag.%d packethash.%llx dest.%llx\n",addflag,(long long)packethash.txid,(long long)dest.txid); + printf("addflag.%d packethash.%llx dest.%llx\n",addflag,(long long)packethash.txid,(long long)dest.txid); for (i=0; i