Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
2d8b57c6ed
  1. 60
      iguana/SuperNET.c
  2. 7
      iguana/SuperNET.h
  3. 66
      iguana/SuperNET_category.c
  4. 1
      iguana/SuperNET_hexmsg.c
  5. 4
      includes/iguana_apideclares.h

60
iguana/SuperNET.c

@ -382,7 +382,8 @@ char *SuperNET_hexconv(char *hexmsg)
{
cJSON *json; char *myip,*yourip,*retstr = hexmsg; uint32_t myipbits=0,destipbits=0;
uint8_t *bits; int32_t n,len = (int32_t)strlen(hexmsg) >> 1;
bits = calloc(1,len*2);
if ( (bits = calloc(1,len)) != 0 )
{
decode_hex(bits,len,hexmsg);
if ( (json= cJSON_Parse((char *)bits)) != 0 )
{
@ -392,11 +393,12 @@ char *SuperNET_hexconv(char *hexmsg)
destipbits = (uint32_t)calc_ipbits(yourip);
n = SuperNET_json2bits(bits,len,json,jbits256(json,"mypub"),juint(json,"checkc"),myipbits,destipbits,(int32_t)jdouble(json,"ov"));
cJSON *json2 = SuperNET_bits2json(bits,n); printf("hexconv.(%s) -> (%s)\n",jprint(json,0),jprint(json2,1));
retstr = calloc(1,n*2+1);
if ( (retstr= calloc(1,n*2+1)) != 0 )
init_hexbytes_noT(retstr,bits,n);
}
if ( bits != 0 )
else retstr = hexmsg;
} else printf("SuperNET_hexconv cant parse.(%s)\n",hexmsg);
free(bits);
}
return(retstr);
}
@ -1076,19 +1078,61 @@ HASH_ARRAY_STRING(SuperNET,layer,mypriv,otherpubs,str)
return(clonestr("{\"result\":\"layer encrypt here\"}"));
}
bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory)
{
bits256 categoryhash;
if ( category == 0 || category[0] == 0 || strcmp(category,"broadcast") == 0 )
categoryhash = GENESIS_PUBKEY;
else vcalc_sha256(0,categoryhash.bytes,(uint8_t *)category,(int32_t)strlen(category));
if ( subcategory == 0 || subcategory[0] == 0 || strcmp(subcategory,"broadcast") == 0 )
*subhashp = GENESIS_PUBKEY;
else vcalc_sha256(0,subhashp->bytes,(uint8_t *)subcategory,(int32_t)strlen(subcategory));
return(categoryhash);
}
THREE_STRINGS(SuperNET,announce,category,subcategory,message)
{
bits256 categoryhash,subhash;
vcalc_sha256(0,categoryhash.bytes,(uint8_t *)category,(int32_t)strlen(category));
vcalc_sha256(0,subhash.bytes,(uint8_t *)subcategory,(int32_t)strlen(subcategory));
categoryhash = calc_categoryhashes(&subhash,category,subcategory);
return(SuperNET_categorymulticast(myinfo,0,categoryhash,subhash,message,juint(json,"maxdelay"),juint(json,"broadcast"),juint(json,"plaintext")));
}
TWO_STRINGS(SuperNET,subscribe,category,subcategory)
{
bits256 categoryhash,subhash;
categoryhash = calc_categoryhashes(&subhash,category,subcategory);
if ( category_sub(myinfo,categoryhash,subhash) != 0 )
return(clonestr("{\"result\":\"subscribed\"}"));
else return(clonestr("{\"error\":\"couldnt subscribe\"}"));
}
TWO_STRINGS(SuperNET,gethexmsg,category,subcategory)
{
bits256 categoryhash,subhash; struct category_msg *m; char *hexstr; cJSON *retjson;
categoryhash = calc_categoryhashes(&subhash,category,subcategory);
if ( (m= category_gethexmsg(myinfo,categoryhash,subhash)) != 0 )
{
hexstr = calloc(1,m->len*2+1);
init_hexbytes_noT(hexstr,m->msg,m->len);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",hexstr);
free(hexstr);
return(jprint(retjson,1));
} else return(clonestr("{\"result\":\"no message\"}"));
}
THREE_STRINGS(SuperNET,posthexmsg,category,subcategory,hexmsg)
{
bits256 categoryhash,subhash;
categoryhash = calc_categoryhashes(&subhash,category,subcategory);
category_posthexmsg(myinfo,categoryhash,subhash,hexmsg,tai_now());
return(clonestr("{\"result\":\"posted message\"}"));
}
THREE_STRINGS(SuperNET,survey,category,subcategory,message)
{
bits256 categoryhash,subhash;
vcalc_sha256(0,categoryhash.bytes,(uint8_t *)category,(int32_t)strlen(category));
vcalc_sha256(0,subhash.bytes,(uint8_t *)subcategory,(int32_t)strlen(subcategory));
categoryhash = calc_categoryhashes(&subhash,category,subcategory);
return(SuperNET_categorymulticast(myinfo,1,categoryhash,subhash,message,juint(json,"maxdelay"),juint(json,"broadcast"),juint(json,"plaintext")));
}
#include "../includes/iguana_apiundefs.h"

7
iguana/SuperNET.h

@ -124,10 +124,17 @@ int32_t SuperNET_num2API(char *agent,char *method,uint16_t num);
bits256 SuperNET_sharedseed(bits256 privkey,bits256 otherpub);
int32_t SuperNET_decrypt(bits256 *senderpubp,uint64_t *senderbitsp,uint32_t *timestampp,bits256 mypriv,bits256 mypub,uint8_t *dest,int32_t maxlen,uint8_t *src,int32_t len);
struct category_info { UT_hash_handle hh; queue_t Q; bits256 hash; struct category_info *sub; } *Categories;
struct category_msg { struct queueitem DL; struct tai t; int32_t len; uint8_t msg[]; };
int32_t SuperNET_str2hex(uint8_t *hex,char *str);
void SuperNET_hex2str(char *str,uint8_t *hex,int32_t len);
void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 category,bits256 subhash,char *hexmsg,struct tai now);
int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 category,bits256 subhash,char *hexmsg,int32_t addflag);
void category_posthexmsg(struct supernet_info *myinfo,bits256 category,bits256 subhash,char *hexmsg,struct tai now);
void *category_sub(struct supernet_info *myinfo,bits256 category,bits256 subhash);
struct category_msg *category_gethexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash);
char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag,bits256 categoryhash,bits256 subcategory,char *message,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext);

66
iguana/SuperNET_category.c

@ -15,6 +15,68 @@
#include "iguana777.h"
queue_t *category_Q(bits256 categoryhash,bits256 subhash)
{
struct category_info *cat,*sub; queue_t *Q = 0;
HASH_FIND(hh,Categories,categoryhash.bytes,sizeof(categoryhash),cat);
if ( cat != 0 )
{
if ( bits256_nonz(subhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,subhash.bytes,sizeof(subhash)) != 0 )
{
HASH_FIND(hh,cat->sub,subhash.bytes,sizeof(subhash),sub);
if ( sub != 0 )
Q = &sub->Q;
} else Q = &cat->Q;
}
return(Q);
}
struct category_msg *category_gethexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash)
{
queue_t *Q;
if ( (Q= category_Q(categoryhash,subhash)) != 0 )
return(queue_dequeue(Q,0));
else return(0);
}
void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now)
{
int32_t len; struct category_msg *m; queue_t *Q = 0;
if ( (Q= category_Q(categoryhash,subhash)) != 0 )
{
len = (int32_t)strlen(hexmsg) >> 1;
m = calloc(1,sizeof(*m) + len);
m->t = now, m->len = len;
decode_hex(m->msg,m->len,hexmsg);
queue_enqueue("categoryQ",Q,&m->DL,0);
return;
}
char str[65]; printf("no subscription for category.(%s) %llx\n",bits256_str(str,categoryhash),(long long)subhash.txid);
}
void *category_sub(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash)
{
struct category_info *cat,*sub; bits256 hash;
HASH_FIND(hh,Categories,categoryhash.bytes,sizeof(categoryhash),cat);
if ( cat == 0 )
{
cat = mycalloc('c',1,sizeof(*cat));
cat->hash = hash = categoryhash;
HASH_ADD(hh,Categories,hash,sizeof(hash),cat);
}
if ( bits256_nonz(subhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,subhash.bytes,sizeof(subhash)) != 0 && cat != 0 )
{
HASH_FIND(hh,cat->sub,subhash.bytes,sizeof(subhash),sub);
if ( sub == 0 )
{
sub = mycalloc('c',1,sizeof(*sub));
sub->hash = hash = subhash;
HASH_ADD(hh,cat->sub,hash,sizeof(hash),sub);
}
}
return(cat);
}
int32_t category_peer(struct supernet_info *myinfo,struct iguana_peer *addr,bits256 category,bits256 subhash)
{
return(1);
@ -30,7 +92,7 @@ int32_t category_maxdelay(struct supernet_info *myinfo,bits256 category,bits256
return(maxdelay);
}
int32_t category_broadcast(struct supernet_info *myinfo,bits256 category,bits256 subhash,int32_t broadcastflag)
int32_t category_broadcastflag(struct supernet_info *myinfo,bits256 category,bits256 subhash,int32_t broadcastflag)
{
if ( broadcastflag < 1 )
broadcastflag = 1;
@ -49,7 +111,7 @@ char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag
init_hexbytes_noT(hexmsg,(uint8_t *)message,len+1);
} else hexmsg = message;
plaintext = category_plaintext(myinfo,category,subhash,plaintext);
broadcastflag = category_broadcast(myinfo,category,subhash,broadcastflag);
broadcastflag = category_broadcastflag(myinfo,category,subhash,broadcastflag);
maxdelay = category_maxdelay(myinfo,category,subhash,maxdelay);
retstr = SuperNET_DHTsend(myinfo,0,category,subhash,hexmsg,maxdelay,broadcastflag,plaintext);
if ( hexmsg != message)

1
iguana/SuperNET_hexmsg.c

@ -68,5 +68,6 @@ void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 category,bits256 su
bits256_str(str2,subhash);
strcat(str,str2);
}
category_posthexmsg(myinfo,category,subhash,hexmsg,now);
printf("HEXMSG.(%s) -> %s\n",hexmsg,str);
}

4
includes/iguana_apideclares.h

@ -41,6 +41,10 @@ HASH_AND_STRING(SuperNET,multicastdecipher,privkey,cipherstr);
THREE_STRINGS(SuperNET,announce,category,subcategory,message);
THREE_STRINGS(SuperNET,survey,category,subcategory,message);
TWO_STRINGS(SuperNET,subscribe,category,subcategory);
TWO_STRINGS(SuperNET,gethexmsg,category,subcategory);
THREE_STRINGS(SuperNET,posthexmsg,category,subcategory,hexmsg);
STRING_ARG(SuperNET,getpeers,activecoin);
TWO_ARRAYS(SuperNET,mypeers,supernet,rawpeers);
ZERO_ARGS(SuperNET,stop);

Loading…
Cancel
Save