Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
02c10e7dec
  1. 83
      iguana/SuperNET.c
  2. 4
      iguana/SuperNET.h
  3. 50
      iguana/SuperNET_category.c
  4. 1
      iguana/iguana777.h
  5. 2
      iguana/iguana_json.c

83
iguana/SuperNET.c

@ -425,7 +425,7 @@ int32_t DHT_dist(bits256 desthash,bits256 hash)
return(dist*0);
}
struct iguana_peer *iguana_peerfind(struct supernet_info *myinfo,struct iguana_info **coinp,bits256 routehash)
struct iguana_peer *iguana_peerfind(struct supernet_info *myinfo,struct iguana_info **coinp,uint32_t destipbits,bits256 destpub)
{
int32_t i,j; struct iguana_peer *addr;
*coinp = 0;
@ -438,7 +438,7 @@ struct iguana_peer *iguana_peerfind(struct supernet_info *myinfo,struct iguana_i
addr = &Coins[i]->peers.active[j];
if ( addr->usock >= 0 )
{
if ( memcmp(addr->iphash.bytes,routehash.bytes,sizeof(addr->iphash)) == 0 )
if ( destipbits == addr->ipbits || category_peer(myinfo,Coins[i],addr,destpub) >= 0 )
{
*coinp = Coins[i];
return(addr);
@ -450,10 +450,9 @@ struct iguana_peer *iguana_peerfind(struct supernet_info *myinfo,struct iguana_i
return(0);
}
char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext)
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; struct iguana_peer *addr; cJSON *json; struct iguana_info *coin;
if ( myinfo == 0 )
return(clonestr("{\"error\":\"no supernet_info\"}"));
json = cJSON_CreateObject();
@ -465,9 +464,12 @@ char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexm
if ( plaintext != 0 )
jaddnum(json,"plaintext",plaintext!=0);
jsonstr = jprint(json,1);
if ( SuperNET_hexmsguniq(myinfo,routehash,hexmsg,1) < 0 )
if ( SuperNET_hexmsguniq(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 )
}
if ( broadcastflag != 0 || destipbits == 0 )
{
for (i=0; i<IGUANA_MAXCOINS; i++)
{
@ -476,9 +478,9 @@ char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexm
for (j=0; j<IGUANA_MAXPEERS; j++)
{
addr = &Coins[i]->peers.active[j];
if ( addr->usock >= 0 && addr->supernet != 0 )
if ( addr->usock >= 0 && addr->supernet != 0 && (broadcastflag != 0 || category_peer(myinfo,Coins[i],addr,destpub) >= 0) )
{
printf("BROADCAST[%d] SEND.(%ld) to %s\n",j,strlen(jsonstr),addr->ipaddr);
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));
}
}
@ -486,7 +488,7 @@ char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexm
}
return(clonestr("{\"result\":\"packet sent to all peers\"}"));
}
if ( (addr= iguana_peerfind(myinfo,&coin,routehash)) == 0 )
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));
@ -495,26 +497,16 @@ char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexm
char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 destpub,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext)
{
uint32_t destipbits; bits256 routehash; char *retstr;
if ( destip == 0 || destip[0] == 0 || strncmp(destip,"127.0.0.1",strlen("127.0.0.1")) == 0 )
routehash = destpub;
else
{
destipbits = (uint32_t)calc_ipbits(destip);
vcalc_sha256(0,routehash.bytes,(uint8_t *)&destipbits,sizeof(destipbits));
}
if ( (retstr = SuperNET_DHTsend(myinfo,routehash,hexmsg,maxdelay,broadcastflag,plaintext)) != 0 )
uint32_t destipbits; char *retstr;
destipbits = (uint32_t)calc_ipbits(destip);
if ( (retstr = SuperNET_DHTsend(myinfo,destipbits,destpub,hexmsg,maxdelay,broadcastflag,plaintext)) != 0 )
free(retstr);
return(clonestr("{\"result\":\"DHT sent\"}"));
}
char *SuperNET_forward(struct supernet_info *myinfo,char *hexmsg,uint32_t destipbits,bits256 destpub,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext)
{
bits256 routehash;
if ( destipbits != 0 )
vcalc_sha256(0,routehash.bytes,(uint8_t *)&destipbits,sizeof(destipbits));
else routehash = destpub;
return(SuperNET_DHTsend(myinfo,routehash,hexmsg,maxdelay,broadcastflag,plaintext));
return(SuperNET_DHTsend(myinfo,destipbits,destpub,hexmsg,maxdelay,broadcastflag,plaintext));
}
int32_t SuperNET_destination(struct supernet_info *myinfo,uint32_t *destipbitsp,bits256 *destpubp,int32_t *maxdelayp,cJSON *json,char *remoteaddr)
@ -561,15 +553,15 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
//printf("SuperNET_JSON.(%s) remote.(%s)\n",jprint(json,0),remoteaddr!=0?remoteaddr:"");
destflag = SuperNET_destination(myinfo,&destipbits,&destpub,&maxdelay,json,remoteaddr);
//printf("destflag.%d\n",destflag);
if ( (hexmsg= jstr(json,"hexmsg")) == 0 && (message= jstr(json,"message")) == 0 )
{
jsonstr = jprint(json,0);
hexmsg = malloc(strlen(jsonstr)*2+1);
init_hexbytes_noT(hexmsg,(uint8_t *)jsonstr,(int32_t)strlen(jsonstr)+1);
flag = 1;
}
if ( (destflag & SUPERNET_FORWARD) != 0 )
{
if ( (hexmsg= jstr(json,"hexmsg")) == 0 && (message= jstr(json,"message")) == 0 )
{
jsonstr = jprint(json,0);
hexmsg = malloc(strlen(jsonstr)*2+1);
init_hexbytes_noT(hexmsg,(uint8_t *)jsonstr,(int32_t)strlen(jsonstr)+1);
flag = 1;
}
if ( hexmsg != 0 )
{
//printf("check.(%s)\n",hexmsg);
@ -578,12 +570,12 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
SuperNET_hexmsgadd(myinfo,destpub,hexmsg,tai_now());
forwardstr = SuperNET_forward(myinfo,hexmsg,destipbits,destpub,maxdelay,juint(json,"broadcast"),juint(json,"plaintext")!=0);
}
if ( flag != 0 )
free(hexmsg);
}
}
if ( (destflag & SUPERNET_ISMINE) && (agent= jstr(json,"agent")) != 0 && (method= jstr(json,"method")) != 0 )
{
if ( SuperNET_hexmsguniq(myinfo,destpub,hexmsg,0) >= 0 )
SuperNET_hexmsgadd(myinfo,destpub,hexmsg,tai_now());
if ( (retstr= SuperNET_processJSON(myinfo,json,remoteaddr)) != 0 )
{
//printf("retstr.(%s)\n",retstr);
@ -599,6 +591,8 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
}
} else printf("null retstr from SuperNET_JSON\n");
}
if ( flag != 0 )
free(hexmsg);
if ( retstr == 0 )
retstr = forwardstr, forwardstr = 0;
if ( forwardstr != 0 )
@ -819,8 +813,6 @@ TWOHASHES_AND_STRING(SuperNET,cipher,privkey,destpubkey,message)
init_hexbytes_noT(hexstr,cipher,cipherlen);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",hexstr);
//jaddstr(retjson,"message",message);
//jaddstr(retjson,"cipher",hexstr);
onetimeflag = memcmp(origprivkey.bytes,privkey.bytes,sizeof(privkey));
if ( onetimeflag != 0 )
{
@ -1013,24 +1005,15 @@ HASH_ARRAY_STRING(SuperNET,layer,mypriv,otherpubs,str)
THREE_STRINGS(SuperNET,announce,category,subcategory,message)
{
cJSON *argjson = cJSON_CreateObject(); int32_t len; char *hexmsg=0,*retstr = 0;
//SuperNET_ann(myinfo,category,subcategory,message);
if ( remoteaddr == 0 )
{
len = (int32_t)strlen(message);
if ( is_hexstr(message,len) == 0 )
{
}
else hexmsg = message;
retstr = SuperNET_DHTsend(myinfo,GENESIS_PUBKEY,hexmsg,0,1,1);
if ( hexmsg != message)
free(hexmsg);
}
return(jprint(argjson,1));
bits256 categoryhash;
vcalc_sha256(0,categoryhash.bytes,(uint8_t *)category,(int32_t)strlen(category));
return(SuperNET_categorymulticast(myinfo,0,categoryhash,subcategory,message,juint(json,"maxdelay"),juint(json,"plaintext")));
}
THREE_STRINGS(SuperNET,survey,category,subcategory,message)
{
return(clonestr("{\"result\":\"survey here\"}"));
bits256 categoryhash;
vcalc_sha256(0,categoryhash.bytes,(uint8_t *)category,(int32_t)strlen(category));
return(SuperNET_categorymulticast(myinfo,1,categoryhash,subcategory,message,juint(json,"maxdelay"),juint(json,"plaintext")));
}
#include "../includes/iguana_apiundefs.h"

4
iguana/SuperNET.h

@ -118,7 +118,7 @@ char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remotead
char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 destpub,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext);
char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSON *json,char *remoteaddr);
char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr);
char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexmessage,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext);
char *SuperNET_DHTsend(struct supernet_info *myinfo,uint32_t destipbits,bits256 destpub,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext);
uint16_t SuperNET_API2num(char *agent,char *method);
int32_t SuperNET_num2API(char *agent,char *method,uint16_t num);
bits256 SuperNET_sharedseed(bits256 privkey,bits256 otherpub);
@ -129,5 +129,7 @@ void SuperNET_hex2str(char *str,uint8_t *hex,int32_t len);
void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 destpub,char *hexmsg,struct tai now);
int32_t SuperNET_hexmsguniq(struct supernet_info *myinfo,bits256 dest,char *hexmsg,int32_t addflag);
char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag,bits256 categoryhash,char *subcategory,char *message,int32_t maxdelay,int32_t plaintext);
#endif

50
iguana/SuperNET_category.c

@ -0,0 +1,50 @@
/******************************************************************************
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "iguana777.h"
int32_t category_peer(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,bits256 destpub)
{
if ( memcmp(addr->pubkey.bytes,destpub.bytes,sizeof(destpub)) == 0 )
return(1);
else return(-1);
}
int32_t category_plaintext(struct supernet_info *myinfo,bits256 categoryhash,int32_t plaintext)
{
return(plaintext);
}
int32_t category_maxdelay(struct supernet_info *myinfo,bits256 categoryhash,int32_t maxdelay)
{
return(maxdelay);
}
char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag,bits256 categoryhash,char *subcategory,char *message,int32_t maxdelay,int32_t plaintext)
{
char *hexmsg,*retstr; int32_t len,broadcastflag=1;
len = (int32_t)strlen(message);
if ( is_hexstr(message,len) == 0 )
{
hexmsg = malloc((len << 1) + 1);
init_hexbytes_noT(hexmsg,(uint8_t *)message,len+1);
} else hexmsg = message;
plaintext = category_plaintext(myinfo,categoryhash,plaintext);
maxdelay = category_maxdelay(myinfo,categoryhash,maxdelay);
retstr = SuperNET_DHTsend(myinfo,0,categoryhash,hexmsg,maxdelay,broadcastflag,plaintext);
if ( hexmsg != message)
free(hexmsg);
return(retstr);
}

1
iguana/iguana777.h

@ -696,6 +696,7 @@ char *iguana_blockingjsonstr(struct supernet_info *myinfo,char *jsonstr,uint64_t
void iguana_iAkill(struct iguana_info *coin,struct iguana_peer *addr,int32_t markflag);
cJSON *SuperNET_bits2json(struct iguana_peer *addr,uint8_t *serialized,int32_t datalen);
int32_t SuperNET_sendmsg(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,bits256 destpub,bits256 mypriv,bits256 mypub,uint8_t *msg,int32_t len,uint8_t *data,int32_t delaymillis);
int32_t category_peer(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,bits256 destpub);
extern queue_t bundlesQ;

2
iguana/iguana_json.c

@ -571,6 +571,8 @@ TWO_STRINGS(SuperNET,html,agentform,htmlfile)
char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSON *json,char *remoteaddr)
{
char *coinstr; struct iguana_info *coin = 0;
if ( remoteaddr != 0 && (remoteaddr[0] == 0 || strcmp(remoteaddr,"127.0.0.1") == 0) )
remoteaddr = 0;
if ( (coinstr= jstr(json,"activecoin")) != 0 )
coin = iguana_coinfind(coinstr);
if ( coin == 0 && (coinstr= jstr(json,"coin")) != 0 )

Loading…
Cancel
Save