Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
a39d70b942
  1. 14
      iguana/SuperNET.c
  2. 4
      iguana/SuperNET.h
  3. 10
      iguana/iguana_json.c
  4. 2
      includes/iguana_apideclares.h
  5. 3
      includes/iguana_apidefs.h
  6. 2
      includes/iguana_apiundefs.h

14
iguana/SuperNET.c

@ -254,7 +254,7 @@ int32_t DHT_dist(bits256 desthash,bits256 hash)
return(dist); return(dist);
} }
char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexmsg,int32_t maxdelay) char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag)
{ {
static int lastpurge; static uint64_t Packetcache[1024]; static int lastpurge; static uint64_t Packetcache[1024];
bits256 packethash; char retbuf[512]; int32_t mydist,i,j,datalen,firstz,iter,n = 0; char *jsonstr=0; bits256 packethash; char retbuf[512]; int32_t mydist,i,j,datalen,firstz,iter,n = 0; char *jsonstr=0;
@ -269,7 +269,7 @@ char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexm
jsonstr = jprint(json,1); jsonstr = jprint(json,1);
vcalc_sha256(0,packethash.bytes,(void *)hexmsg,datalen); vcalc_sha256(0,packethash.bytes,(void *)hexmsg,datalen);
firstz = -1; firstz = -1;
for (i=0; i<sizeof(Packetcache)/sizeof(*Packetcache); i++) for (i=broadcastflag!=0; i<sizeof(Packetcache)/sizeof(*Packetcache); i++)
{ {
if ( Packetcache[i] == 0 ) if ( Packetcache[i] == 0 )
{ {
@ -329,7 +329,7 @@ char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexm
return(clonestr(retbuf)); return(clonestr(retbuf));
} }
char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 destpub,char *hexmsg,int32_t maxdelay) char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 destpub,char *hexmsg,int32_t maxdelay,int32_t broadcastflag)
{ {
uint32_t destipbits; bits256 routehash; char *retstr; cJSON *msgjson = cJSON_CreateObject(); uint32_t destipbits; bits256 routehash; char *retstr; cJSON *msgjson = cJSON_CreateObject();
if ( destip == 0 || destip[0] == 0 || strncmp(destip,"127.0.0.1",strlen("127.0.0.1")) == 0 ) if ( destip == 0 || destip[0] == 0 || strncmp(destip,"127.0.0.1",strlen("127.0.0.1")) == 0 )
@ -343,17 +343,17 @@ char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 destp
vcalc_sha256(0,routehash.bytes,(uint8_t *)&destipbits,sizeof(destipbits)); vcalc_sha256(0,routehash.bytes,(uint8_t *)&destipbits,sizeof(destipbits));
jaddstr(msgjson,"destip",destip); jaddstr(msgjson,"destip",destip);
} }
retstr = SuperNET_DHTsend(myinfo,routehash,hexmsg,maxdelay); retstr = SuperNET_DHTsend(myinfo,routehash,hexmsg,maxdelay,broadcastflag);
return(retstr); return(retstr);
} }
char *SuperNET_forward(struct supernet_info *myinfo,char *hexmsg,uint32_t destipbits,bits256 destpub,int32_t maxdelay) char *SuperNET_forward(struct supernet_info *myinfo,char *hexmsg,uint32_t destipbits,bits256 destpub,int32_t maxdelay,int32_t broadcastflag)
{ {
bits256 routehash; bits256 routehash;
if ( destipbits != 0 ) if ( destipbits != 0 )
vcalc_sha256(0,routehash.bytes,(uint8_t *)&destipbits,sizeof(destipbits)); vcalc_sha256(0,routehash.bytes,(uint8_t *)&destipbits,sizeof(destipbits));
else routehash = destpub; else routehash = destpub;
return(SuperNET_DHTsend(myinfo,routehash,hexmsg,maxdelay)); return(SuperNET_DHTsend(myinfo,routehash,hexmsg,maxdelay,broadcastflag));
} }
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)
@ -397,7 +397,7 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
jsonstr = jprint(json,0); jsonstr = jprint(json,0);
message = jsonstr; message = jsonstr;
} }
forwardstr = SuperNET_forward(myinfo,message,destipbits,destpub,maxdelay); forwardstr = SuperNET_forward(myinfo,message,destipbits,destpub,maxdelay,juint(json,"broadcast"));
} }
if ( (destflag & SUPERNET_ISMINE) && (agent= jstr(json,"agent")) != 0 && (method= jstr(json,"method")) != 0 ) if ( (destflag & SUPERNET_ISMINE) && (agent= jstr(json,"agent")) != 0 && (method= jstr(json,"method")) != 0 )
{ {

4
iguana/SuperNET.h

@ -108,10 +108,10 @@ void SuperNET_init(void *args);
char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr); char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr);
char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remoteaddr); char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remoteaddr);
char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 destpub,char *hexmsg,int32_t maxdelay); char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 destpub,char *hexmsg,int32_t maxdelay,int32_t broadcastflag);
char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSON *json,char *remoteaddr); 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_processJSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr);
char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexmessage,int32_t maxdelay); char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexmessage,int32_t maxdelay,int32_t broadcastflag);
uint16_t SuperNET_API2num(char *agent,char *method); uint16_t SuperNET_API2num(char *agent,char *method);
int32_t SuperNET_num2API(char *agent,char *method,uint16_t num); int32_t SuperNET_num2API(char *agent,char *method,uint16_t num);

10
iguana/iguana_json.c

@ -84,6 +84,7 @@ cJSON *SuperNET_helpjson()
#define IGUANA_HELP_SSS(agent,name,str,str2,str3) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#str2,"string"),helpitem(#str3,"string"))) #define IGUANA_HELP_SSS(agent,name,str,str2,str3) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#str2,"string"),helpitem(#str3,"string")))
#define IGUANA_HELP_SSH(agent,name,str,str2,hash) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#str2,"string"),helpitem(#hash,"hash"))) #define IGUANA_HELP_SSH(agent,name,str,str2,hash) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#str2,"string"),helpitem(#hash,"hash")))
#define IGUANA_HELP_SSHI(agent,name,str,str2,hash,val) array = helpjson(IGUANA_ARGS,#agent,#name,helparray4(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#str2,"string"),helpitem(#hash,"hash"),helpitem(#val,"int"))) #define IGUANA_HELP_SSHI(agent,name,str,str2,hash,val) array = helpjson(IGUANA_ARGS,#agent,#name,helparray4(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#str2,"string"),helpitem(#hash,"hash"),helpitem(#val,"int")))
#define IGUANA_HELP_SSHII(agent,name,str,str2,hash,val,val2) array = helpjson(IGUANA_ARGS,#agent,#name,helparray5(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#str2,"string"),helpitem(#hash,"hash"),helpitem(#val,"int"),helpitem(#val2,"int")))
#define IGUANA_HELP_SI(agent,name,str,val) array = helpjson(IGUANA_ARGS,#agent,#name,helparray2(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#val,"int"))) #define IGUANA_HELP_SI(agent,name,str,val) array = helpjson(IGUANA_ARGS,#agent,#name,helparray2(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#val,"int")))
#define IGUANA_HELP_SII(agent,name,str,val,val2) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#val,"int"),helpitem(#val2,"int"))) #define IGUANA_HELP_SII(agent,name,str,val,val2) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#val,"int"),helpitem(#val2,"int")))
#define IGUANA_HELP_SSI(agent,name,str,str2,val) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#str2,"string"),helpitem(#val,"int"))) #define IGUANA_HELP_SSI(agent,name,str,str2,val) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#str,"string"),helpitem(#str2,"string"),helpitem(#val,"int")))
@ -134,7 +135,7 @@ cJSON *SuperNET_helpjson()
#define STRING_AND_THREEINTS IGUANA_HELP_SIII #define STRING_AND_THREEINTS IGUANA_HELP_SIII
#define TWOSTRINGS_AND_INT IGUANA_HELP_SSI #define TWOSTRINGS_AND_INT IGUANA_HELP_SSI
#define TWOSTRINGS_AND_HASH IGUANA_HELP_SSH #define TWOSTRINGS_AND_HASH IGUANA_HELP_SSH
#define TWOSTRINGS_AND_HASH_AND_INT IGUANA_HELP_SSHI #define TWOSTRINGS_AND_HASH_AND_TWOINTS IGUANA_HELP_SSHII
#define THREE_INTS IGUANA_HELP_III #define THREE_INTS IGUANA_HELP_III
#include "../includes/iguana_apideclares.h" #include "../includes/iguana_apideclares.h"
@ -383,13 +384,13 @@ void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int
#include "../includes/iguana_apidefs.h" #include "../includes/iguana_apidefs.h"
TWOSTRINGS_AND_HASH_AND_INT(SuperNET,DHT,message,destip,destpub,maxdelay) TWOSTRINGS_AND_HASH_AND_TWOINTS(SuperNET,DHT,message,destip,destpub,maxdelay,broadcast)
{ {
if ( remoteaddr != 0 ) if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"cant remote DHT\"}")); return(clonestr("{\"error\":\"cant remote DHT\"}"));
else if ( is_hexstr(message,(int32_t)strlen(message)) <= 0 ) else if ( is_hexstr(message,(int32_t)strlen(message)) <= 0 )
return(clonestr("{\"error\":\"message must be in hex\"}")); return(clonestr("{\"error\":\"message must be in hex\"}"));
return(SuperNET_DHTencode(myinfo,destip,destpub,message,maxdelay)); return(SuperNET_DHTencode(myinfo,destip,destpub,message,maxdelay,broadcast));
} }
ZERO_ARGS(SuperNET,stop) ZERO_ARGS(SuperNET,stop)
@ -682,6 +683,7 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSO
#define IGUANA_DISPATCH_SSS(agent,name,str,str2,str3) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jstr(json,#str3))) #define IGUANA_DISPATCH_SSS(agent,name,str,str2,str3) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jstr(json,#str3)))
#define IGUANA_DISPATCH_SSH(agent,name,str,str2,hash) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash))) #define IGUANA_DISPATCH_SSH(agent,name,str,str2,hash) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash)))
#define IGUANA_DISPATCH_SSHI(agent,name,str,str2,hash,val) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash),juint(json,#val))) #define IGUANA_DISPATCH_SSHI(agent,name,str,str2,hash,val) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash),juint(json,#val)))
#define IGUANA_DISPATCH_SSHII(agent,name,str,str2,hash,val,val2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash),juint(json,#val),juint(json,#val2)))
#define IGUANA_DISPATCH_SI(agent,name,str,val) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),juint(json,#val))) #define IGUANA_DISPATCH_SI(agent,name,str,val) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),juint(json,#val)))
#define IGUANA_DISPATCH_SII(agent,name,str,val,val2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),juint(json,#val),juint(json,#val2))) #define IGUANA_DISPATCH_SII(agent,name,str,val,val2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),juint(json,#val),juint(json,#val2)))
#define IGUANA_DISPATCH_SSI(agent,name,str,str2,val) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),juint(json,#val))) #define IGUANA_DISPATCH_SSI(agent,name,str,str2,val) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),juint(json,#val)))
@ -733,7 +735,7 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSO
#define STRING_AND_THREEINTS IGUANA_DISPATCH_SIII #define STRING_AND_THREEINTS IGUANA_DISPATCH_SIII
#define TWOSTRINGS_AND_INT IGUANA_DISPATCH_SSI #define TWOSTRINGS_AND_INT IGUANA_DISPATCH_SSI
#define TWOSTRINGS_AND_HASH IGUANA_DISPATCH_SSH #define TWOSTRINGS_AND_HASH IGUANA_DISPATCH_SSH
#define TWOSTRINGS_AND_HASH_AND_INT IGUANA_DISPATCH_SSHI #define TWOSTRINGS_AND_HASH_AND_TWOINTS IGUANA_DISPATCH_SSHII
#define THREE_INTS IGUANA_DISPATCH_III #define THREE_INTS IGUANA_DISPATCH_III
#include "../includes/iguana_apideclares.h" #include "../includes/iguana_apideclares.h"

2
includes/iguana_apideclares.h

@ -16,7 +16,7 @@
ZERO_ARGS(SuperNET,help); ZERO_ARGS(SuperNET,help);
TWO_STRINGS(SuperNET,html,agentform,htmlfile); TWO_STRINGS(SuperNET,html,agentform,htmlfile);
STRING_ARG(SuperNET,bitcoinrpc,setcoin); STRING_ARG(SuperNET,bitcoinrpc,setcoin);
TWOSTRINGS_AND_HASH_AND_INT(SuperNET,DHT,message,destip,destpub,maxdelay); TWOSTRINGS_AND_HASH_AND_TWOINTS(SuperNET,DHT,message,destip,destpub,maxdelay,broadcast);
STRING_ARG(SuperNET,getpeers,activecoin); STRING_ARG(SuperNET,getpeers,activecoin);
TWO_ARRAYS(SuperNET,mypeers,supernet,rawpeers); TWO_ARRAYS(SuperNET,mypeers,supernet,rawpeers);
ZERO_ARGS(SuperNET,stop); ZERO_ARGS(SuperNET,stop);

3
includes/iguana_apidefs.h

@ -16,6 +16,7 @@
#define IGUANA_CFUNC_SSI(agent,name,str,str2,val) char *agent ## _ ## name(IGUANA_ARGS,char *str,char *str2,int32_t val) #define IGUANA_CFUNC_SSI(agent,name,str,str2,val) char *agent ## _ ## name(IGUANA_ARGS,char *str,char *str2,int32_t val)
#define IGUANA_CFUNC_SSH(agent,name,str,str2,hash) char *agent ## _ ## name(IGUANA_ARGS,char *str,char *str2,bits256 hash) #define IGUANA_CFUNC_SSH(agent,name,str,str2,hash) char *agent ## _ ## name(IGUANA_ARGS,char *str,char *str2,bits256 hash)
#define IGUANA_CFUNC_SSHI(agent,name,str,str2,hash,val) char *agent ## _ ## name(IGUANA_ARGS,char *str,char *str2,bits256 hash,int32_t val) #define IGUANA_CFUNC_SSHI(agent,name,str,str2,hash,val) char *agent ## _ ## name(IGUANA_ARGS,char *str,char *str2,bits256 hash,int32_t val)
#define IGUANA_CFUNC_SSHII(agent,name,str,str2,hash,val,val2) char *agent ## _ ## name(IGUANA_ARGS,char *str,char *str2,bits256 hash,int32_t val,int32_t val2)
#define IGUANA_CFUNC_SSS(agent,name,str,str2,str3) char *agent ## _ ## name(IGUANA_ARGS,char *str,char *str2,char *str3) #define IGUANA_CFUNC_SSS(agent,name,str,str2,str3) char *agent ## _ ## name(IGUANA_ARGS,char *str,char *str2,char *str3)
#define IGUANA_CFUNC_SI(agent,name,str,val) char *agent ## _ ## name(IGUANA_ARGS,char *str,int32_t val) #define IGUANA_CFUNC_SI(agent,name,str,val) char *agent ## _ ## name(IGUANA_ARGS,char *str,int32_t val)
#define IGUANA_CFUNC_SII(agent,name,str,val,val2) char *agent ## _ ## name(IGUANA_ARGS,char *str,int32_t val,int32_t val2) #define IGUANA_CFUNC_SII(agent,name,str,val,val2) char *agent ## _ ## name(IGUANA_ARGS,char *str,int32_t val,int32_t val2)
@ -52,5 +53,5 @@
#define STRING_AND_THREEINTS IGUANA_CFUNC_SIII #define STRING_AND_THREEINTS IGUANA_CFUNC_SIII
#define TWOSTRINGS_AND_INT IGUANA_CFUNC_SSI #define TWOSTRINGS_AND_INT IGUANA_CFUNC_SSI
#define TWOSTRINGS_AND_HASH IGUANA_CFUNC_SSH #define TWOSTRINGS_AND_HASH IGUANA_CFUNC_SSH
#define TWOSTRINGS_AND_HASH_AND_INT IGUANA_CFUNC_SSHI #define TWOSTRINGS_AND_HASH_AND_TWOINTS IGUANA_CFUNC_SSHII
#define THREE_INTS IGUANA_CFUNC_III #define THREE_INTS IGUANA_CFUNC_III

2
includes/iguana_apiundefs.h

@ -24,4 +24,4 @@
#undef TWOSTRINGS_AND_INT #undef TWOSTRINGS_AND_INT
#undef THREE_INTS #undef THREE_INTS
#undef TWOSTRINGS_AND_HASH #undef TWOSTRINGS_AND_HASH
#undef TWOSTRINGS_AND_HASH_AND_INT #undef TWOSTRINGS_AND_HASH_AND_TWOINTS

Loading…
Cancel
Save