Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
3fe17e16a3
  1. 20
      crypto777/curve25519.c
  2. 52
      deprecated/obsolete.h
  3. 8
      iguana/SuperNET.c
  4. 16
      iguana/SuperNET.h
  5. 15
      iguana/SuperNET_category.c
  6. 38
      iguana/SuperNET_hexmsg.c
  7. 2
      iguana/iguana_peers.c
  8. 3
      iguana/iguana_rpc.c
  9. 15
      iguana/main.c
  10. 230
      iguana/pangea_api.c
  11. 1
      includes/curve25519.h

20
crypto777/curve25519.c

@ -1770,6 +1770,24 @@ void acct777_rwsig(int32_t rwflag,uint8_t *serialized,struct acct777_sig *sig)
iguana_rwnum(rwflag,&serialized[len],sizeof(sig->allocsize),&sig->allocsize),len += sizeof(sig->allocsize);
}
int32_t acct777_sigcheck(struct acct777_sig *sig)
{
#define IGUANA_GENESIS 1453075200
#define IGUANA_MAXPACKETSIZE (1024 * 1024 * 2)
#define TEN_YEARS (10 * 365 * 24 * 3600)
if ( sig->allocsize < sizeof(*sig) || sig->allocsize > IGUANA_MAXPACKETSIZE )
{
printf("acct777_sign: invalid datalen.%d hex.%08x\n",sig->allocsize,sig->allocsize);
return(-1);
}
if ( sig->timestamp < IGUANA_GENESIS || sig->timestamp > (long)IGUANA_GENESIS+TEN_YEARS )
{
printf("acct777_sign: invalid timestamp.%u (%u %u)\n",sig->timestamp,IGUANA_GENESIS,IGUANA_GENESIS+TEN_YEARS);
return(-1);
}
return(sig->allocsize);
}
uint64_t acct777_sign(struct acct777_sig *sig,bits256 privkey,bits256 otherpubkey,uint32_t timestamp,uint8_t *serialized,int32_t datalen)
{
bits256 pubkey; bits256 shared; uint8_t buf[sizeof(*sig)];
@ -1784,6 +1802,8 @@ uint64_t acct777_sign(struct acct777_sig *sig,bits256 privkey,bits256 otherpubke
sig->signer64bits = acct777_nxt64bits(sig->pubkey);
}
sig->sigbits = shared = curve25519(privkey,otherpubkey);
if ( acct777_sigcheck(sig) < 0 )
return(0);
memset(buf,0,sizeof(buf));
acct777_rwsig(1,buf,sig);
//int32_t i; for (i=0; i<sizeof(buf); i++)

52
deprecated/obsolete.h

@ -12707,4 +12707,56 @@ len = 0;
}
free_json(json);
hexlen = (int32_t)strlen(hex)+1;*/
int32_t pangea_hexmsg(struct supernet_info *myinfo,struct pangea_msghdr *pm,int32_t len)
{
cJSON *argjson; char *method; bits256 tablehash; struct table_info *tp; int32_t flag = 0;
int32_t datalen; uint8_t *serialized; uint8_t tmp[sizeof(pm->sig)];
acct777_rwsig(0,(void *)&pm->sig,(void *)tmp);
memcpy(&pm->sig,tmp,sizeof(pm->sig));
datalen = len - (int32_t)sizeof(pm->sig);
serialized = (void *)((long)pm + sizeof(pm->sig));
if ( pangea_validate(pm,acct777_msgprivkey(serialized,datalen),pm->sig.pubkey) == 0 )
{
flag++;
iguana_rwbignum(0,pm->tablehash.bytes,sizeof(bits256),tablehash.bytes);
pm->tablehash = tablehash;
printf("<<<<<<<<<<<<< sigsize.%ld VALIDATED [%ld] len.%d t%u allocsize.%d (%s) [%d]\n",sizeof(pm->sig),(long)serialized-(long)pm,datalen,pm->sig.timestamp,pm->sig.allocsize,(char *)pm->serialized,serialized[datalen-1]);
if ( serialized[datalen-1] == 0 && (argjson= cJSON_Parse((char *)pm->serialized)) != 0 )
{
tablehash = jbits256(argjson,"subhash");
if ( (method= jstr(argjson,"cmd")) != 0 )
{
if ( strcmp(method,"lobby") == 0 )
{
//categoryhash = jbits256(argjson,"categoryhash");
}
else if ( strcmp(method,"host") == 0 )
{
if ( (tp= pangea_table(tablehash)) != 0 )
{
pangea_gamecreate(&tp->G,pm->sig.timestamp,pm->tablehash,argjson);
tp->G.creatorbits = pm->sig.signer64bits;
}
char str[65],str2[65]; printf("new game detected (%s) vs (%s)\n",bits256_str(str,tablehash),bits256_str(str2,pm->tablehash));
}
else if ( strcmp(method,"join") == 0 )
{
printf("JOIN.(%s)\n",jprint(argjson,0));
}
}
free_json(argjson);
} else printf("ERROR >>>>>>> (%s) cant parse\n",(char *)pm->serialized);
}
else
{
int32_t i; char str[65],str2[65];
for (i=0; i<datalen; i++)
printf("%02x",serialized[i]);
printf("<<<<<<<<<<<<< sigsize.%ld SIG ERROR [%ld] len.%d (%s + %s)\n",sizeof(pm->sig),(long)serialized-(long)pm,datalen,bits256_str(str,acct777_msgprivkey(serialized,datalen)),bits256_str(str2,pm->sig.pubkey));
}
return(flag);
}
#endif

8
iguana/SuperNET.c

@ -401,7 +401,7 @@ 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;
if ( (bits = calloc(1,len)) != 0 )
if ( (bits= calloc(1,len)) != 0 )
{
decode_hex(bits,len,hexmsg);
if ( (json= cJSON_Parse((char *)bits)) != 0 )
@ -681,7 +681,7 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
//printf("check.(%s)\n",hexmsg);
if ( SuperNET_hexmsgfind(myinfo,category,subhash,hexmsg,0) < 0 )
{
SuperNET_hexmsgadd(myinfo,category,subhash,hexmsg,tai_now());
SuperNET_hexmsgadd(myinfo,category,subhash,hexmsg,tai_now(),remoteaddr);
forwardstr = SuperNET_forward(myinfo,hexmsg,destipbits,category,subhash,maxdelay,juint(json,"broadcast"),juint(json,"plaintext")!=0);
}
}
@ -689,7 +689,7 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
if ( (destflag & SUPERNET_ISMINE) != 0 && agent != 0 && method != 0 )
{
if ( hexmsg != 0 && SuperNET_hexmsgfind(myinfo,category,subhash,hexmsg,0) < 0 )
SuperNET_hexmsgadd(myinfo,category,subhash,hexmsg,tai_now());
SuperNET_hexmsgadd(myinfo,category,subhash,hexmsg,tai_now(),remoteaddr);
if ( (retstr= SuperNET_processJSON(myinfo,json,remoteaddr)) != 0 )
{
//printf("retstr.(%s)\n",retstr);
@ -1154,7 +1154,7 @@ THREE_STRINGS(SuperNET,posthexmsg,category,subcategory,hexmsg)
{
bits256 categoryhash,subhash;
categoryhash = calc_categoryhashes(&subhash,category,subcategory);
category_posthexmsg(myinfo,categoryhash,subhash,hexmsg,tai_now());
category_posthexmsg(myinfo,categoryhash,subhash,hexmsg,tai_now(),remoteaddr);
return(clonestr("{\"result\":\"posted message\"}"));
}

16
iguana/SuperNET.h

@ -126,19 +126,27 @@ int32_t SuperNET_decrypt(bits256 *senderpubp,uint64_t *senderbitsp,uint32_t *tim
cJSON *SuperNET_argjson(cJSON *json);
struct category_info { UT_hash_handle hh; queue_t Q; bits256 hash; void *info; struct category_info *sub; };
struct category_info
{
UT_hash_handle hh; queue_t Q;
int32_t (*process_func)(struct supernet_info *myinfo,void *data,int32_t datalen,char *remoteaddr);
bits256 hash; void *info; struct category_info *sub;
};
extern struct category_info *Categories;
struct category_msg { struct queueitem DL; struct tai t; int32_t len; uint8_t msg[]; };
struct category_msg { struct queueitem DL; struct tai t; uint64_t remoteipbits; int32_t len; uint8_t msg[]; };
void *category_info(bits256 categoryhash,bits256 subhash);
void *category_infoset(bits256 categoryhash,bits256 subhash,void *info);
struct category_info *category_find(bits256 categoryhash,bits256 subhash);
void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *json,char *hexmsg,char *remoteaddr);
struct category_info *category_funcset(bits256 categoryhash,int32_t (*process_func)(struct supernet_info *myinfo,void *data,int32_t datalen,char *remoteaddr));
int32_t pangea_hexmsg(struct supernet_info *myinfo,void *data,int32_t len,char *remoteaddr);
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);
void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr);
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_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr);
void *category_subscribe(struct supernet_info *myinfo,bits256 category,bits256 subhash);
struct category_msg *category_gethexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash);
char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr);

15
iguana/SuperNET_category.c

@ -74,6 +74,17 @@ void *category_infoset(bits256 categoryhash,bits256 subhash,void *info)
return(0);
}
struct category_info *category_funcset(bits256 categoryhash,int32_t (*process_func)(struct supernet_info *myinfo,void *data,int32_t datalen,char *remoteaddr))
{
struct category_info *cat;
if ( (cat= category_find(categoryhash,GENESIS_PUBKEY)) != 0 )
{
cat->process_func = process_func;
return(cat);
}
return(0);
}
struct category_msg *category_gethexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash)
{
queue_t *Q;
@ -83,7 +94,7 @@ struct category_msg *category_gethexmsg(struct supernet_info *myinfo,bits256 cat
else return(0);
}
void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now)
void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr)
{
int32_t len; struct category_msg *m; queue_t *Q = 0;
if ( (Q= category_Q(categoryhash,subhash)) != 0 )
@ -91,6 +102,8 @@ void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits2
len = (int32_t)strlen(hexmsg) >> 1;
m = calloc(1,sizeof(*m) + len);
m->t = now, m->len = len;
if ( remoteaddr != 0 && remoteaddr[0] != 0 )
m->remoteipbits = calc_ipbits(remoteaddr);
decode_hex(m->msg,m->len,hexmsg);
queue_enqueue("categoryQ",Q,&m->DL,0);
//char str[65]; printf("POST HEXMSG.(%s) -> %s.%llx len.%d\n",hexmsg,bits256_str(str,categoryhash),(long long)subhash.txid,m->len);

38
iguana/SuperNET_hexmsg.c

@ -57,7 +57,7 @@ int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 category,bits25
return(-1);
}
void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now)
void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr)
{
char str[512],str2[65];
str[0] = 0;
@ -69,6 +69,40 @@ void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 categoryhash,bits25
bits256_str(str2,subhash);
strcat(str,str2);
}
category_posthexmsg(myinfo,categoryhash,subhash,hexmsg,now);
category_posthexmsg(myinfo,categoryhash,subhash,hexmsg,now,remoteaddr);
//printf("HEXMSG.(%s).%llx -> %s\n",hexmsg,(long long)subhash.txid,str);
}
void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *json,char *hexmsg,char *remoteaddr)
{
int32_t len,flag=0; uint8_t _buf[8192],*buf = _buf; bits256 categoryhash; struct category_info *cat;
if ( hexmsg != 0 )
{
len = (int32_t)strlen(hexmsg);
if ( is_hexstr(hexmsg,len) > 0 )
{
len >>= 1;
if ( len > sizeof(_buf) )
buf = malloc(len);
decode_hex(buf,len,hexmsg);
categoryhash = jbits256(json,"categoryhash");
if ( (cat= category_find(categoryhash,GENESIS_PUBKEY)) != 0 )
{
if ( cat->process_func != 0 )
{
(*cat->process_func)(myinfo,buf,len,remoteaddr);
flag = 1;
printf("PROCESSFUNC\n");
}
}
if ( flag == 0 )
{
printf("no processfunc, posthexmsg\n");
category_posthexmsg(myinfo,categoryhash,jbits256(json,"subhash"),hexmsg,tai_now(),remoteaddr);
}
char str[65]; printf("HEXPROCESS.(%s) -> %s\n",hexmsg,bits256_str(str,categoryhash));
if ( buf != _buf )
free(buf);
}
}
}

2
iguana/iguana_peers.c

@ -315,6 +315,8 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
if ( errno == EADDRINUSE )
{
printf("%s(%s) port.%d try again: %s sock.%d. errno.%d\n",bindflag!=0?"bind":"connect",hostname,port,strerror(errno),sock,errno);
if ( bindflag == 1 )
return(-1);
sleep(13);
continue;
}

3
iguana/iguana_rpc.c

@ -884,9 +884,8 @@ void iguana_rpcloop(void *args)
char remoteaddr[64],jsonbuf[8192],*buf,*retstr,*space;//,*retbuf; ,n,i,m
struct sockaddr_in cli_addr; uint32_t ipbits,i,size = IGUANA_WIDTH*IGUANA_HEIGHT*16 + 512; uint16_t port;
port = IGUANA_RPCPORT;
while ( (bindsock= iguana_socket(1,"127.0.0.1",port)) < 0 )
sleep(3);
exit(-1);
printf("iguana_rpcloop 127.0.0.1:%d bind sock.%d\n",port,bindsock);
space = calloc(1,size);
while ( bindsock >= 0 )

15
iguana/main.c

@ -194,7 +194,7 @@ char *iguana_blockingjsonstr(struct supernet_info *myinfo,char *jsonstr,uint64_t
char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
{
cJSON *retjson; uint64_t tag; uint32_t timeout; char *jsonstr,*method; char *retjsonstr,*retstr = 0;
cJSON *retjson; uint64_t tag; uint32_t timeout; char *jsonstr,*method,*retjsonstr,*retstr = 0;
//char str[65]; printf("processJSON %p %s\n",&myinfo->privkey,bits256_str(str,myinfo->privkey));
if ( json != 0 )
{
@ -205,8 +205,13 @@ char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remote
}
if ( (timeout= juint(json,"timeout")) == 0 )
timeout = IGUANA_JSONTIMEOUT;
if ( (method= jstr(json,"method")) != 0 && strcmp(method,"DHT") == 0 && remoteaddr != 0 )
{
SuperNET_hexmsgprocess(myinfo,json,jstr(json,"hexmsg"),remoteaddr);
return(clonestr("{\"result\":\"processed remote DHT\"}"));
}
jsonstr = jprint(json,0);
if ( remoteaddr == 0 || jstr(json,"immediate") != 0 || ((method= jstr(json,"method")) != 0 && strcmp(method,"DHT") == 0) )
if ( remoteaddr == 0 || jstr(json,"immediate") != 0 )
retjsonstr = SuperNET_jsonstr(myinfo,jsonstr,remoteaddr);
else retjsonstr = iguana_blockingjsonstr(myinfo,jsonstr,tag,timeout,remoteaddr);
if ( retjsonstr != 0 )
@ -273,7 +278,7 @@ void sigcontinue_func() { printf("\nSIGCONT\n"); signal(SIGCONT,sigcontinue_func
void iguana_main(void *arg)
{
FILE *fp; cJSON *json; uint8_t *space,secretbuf[512]; uint32_t r; long allocsize;
FILE *fp; cJSON *json; uint8_t *space,secretbuf[512]; uint32_t r; long allocsize; bits256 pangeahash;
char helperstr[64],fname[512],*wallet2,*wallet2str,*tmpstr,*confstr,*helperargs,*ipaddr,*coinargs=0,*secret,*jsonstr = arg;
struct supernet_info *myinfo;
int32_t i,len,flag,c; bits256 acct,seed,checkhash,wallethash,walletpub,wallet2shared,wallet2priv,wallet2pub;
@ -457,7 +462,9 @@ void iguana_main(void *arg)
if ( IGUANA_NUMHELPERS == 0 )
IGUANA_NUMHELPERS = 1;
category_subscribe(&MYINFO,GENESIS_PUBKEY,GENESIS_PUBKEY);
category_subscribe(myinfo,calc_categoryhashes(0,"pangea",0),GENESIS_PUBKEY);
pangeahash = calc_categoryhashes(0,"pangea",0);
category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY);
category_funcset(pangeahash,pangea_hexmsg);
for (i=0; i<IGUANA_NUMHELPERS; i++)
{
sprintf(helperstr,"{\"name\":\"helper.%d\"}",i);

230
iguana/pangea_api.c

@ -50,10 +50,14 @@ int32_t pangea_datalen(struct pangea_msghdr *pm)
int32_t pangea_validate(struct pangea_msghdr *pm,bits256 privkey,bits256 pubkey)
{
uint64_t signerbits;
if ( (signerbits= acct777_validate(&pm->sig,privkey,pubkey)) != 0 )
uint64_t signerbits; //uint8_t buf[sizeof(pm->sig)];
//acct777_rwsig(0,(void *)&pm->sig,(void *)buf);
//if ( acct777_sigcheck((void *)buf) == 0 )
{
return(0);
if ( (signerbits= acct777_validate(&pm->sig,privkey,pubkey)) != 0 )
{
return(0);
}
}
return(-1);
}
@ -176,6 +180,119 @@ void pangea_sendcmd(struct supernet_info *myinfo,struct table_info *tp,char *cmd
}
}
struct table_info *pangea_table(bits256 tablehash)
{
struct table_info *tp; int32_t allocsize; bits256 pangeahash; char str[65];
pangeahash = calc_categoryhashes(0,"pangea",0);
if ( (tp= category_info(pangeahash,tablehash)) == 0 )
{
allocsize = (int32_t)(sizeof(tp->G) + sizeof(void *)*2);
if ( (tp= calloc(1,allocsize)) == 0 )
printf("error: couldnt create table.(%s)\n",bits256_str(str,tablehash));
}
if ( tp != 0 )
{
category_subscribe(SuperNET_MYINFO(0),pangeahash,tablehash);
if ( category_infoset(pangeahash,tablehash,tp) == 0 )
printf("error: couldnt set table.(%s)\n",bits256_str(str,tablehash)), tp = 0;
else tp->G.allocsize = allocsize;
}
return(tp);
}
int32_t pangea_allocsize(struct table_info *tp,int32_t setptrs)
{
long allocsize = sizeof(*tp); int32_t N,numcards = tp->G.numcards;
N = tp->G.numactive;
allocsize += sizeof(bits256) * (2 * ((N * numcards * N) + (N * numcards)));
allocsize += sizeof(bits256) * ((numcards + 1) + (N * numcards));
if ( setptrs != 0 )
{
tp->hand.cardpubs = tp->priv.data;
tp->hand.final = &tp->hand.cardpubs[numcards + 1 + N];
tp->priv.audits = &tp->hand.final[N * numcards];
tp->priv.outcards = &tp->priv.audits[N * numcards * N];
tp->priv.xoverz = &tp->priv.outcards[N * numcards];
tp->priv.allshares = (void *)&tp->priv.xoverz[N * numcards]; // N*numcards*N
}
return((int32_t)allocsize);
}
struct table_info *pangea_tablealloc(struct table_info *tp)
{
int32_t allocsize = pangea_allocsize(tp,0);
if ( tp->G.allocsize != allocsize )
{
tp = realloc(tp,allocsize);
pangea_allocsize(tp,1);
}
return(tp);
}
void pangea_parse(struct supernet_info *myinfo,struct pangea_msghdr *pm,cJSON *argjson)
{
bits256 tablehash; char *method; struct table_info *tp;
tablehash = jbits256(argjson,"subhash");
if ( (method= jstr(argjson,"cmd")) != 0 )
{
if ( strcmp(method,"lobby") == 0 )
{
//categoryhash = jbits256(argjson,"categoryhash");
}
else if ( strcmp(method,"host") == 0 )
{
if ( (tp= pangea_table(tablehash)) != 0 )
{
pangea_gamecreate(&tp->G,pm->sig.timestamp,pm->tablehash,argjson);
tp->G.creatorbits = pm->sig.signer64bits;
}
char str[65],str2[65]; printf("new game detected (%s) vs (%s)\n",bits256_str(str,tablehash),bits256_str(str2,pm->tablehash));
}
else if ( strcmp(method,"join") == 0 )
{
printf("JOIN.(%s)\n",jprint(argjson,0));
}
}
}
int32_t pangea_hexmsg(struct supernet_info *myinfo,void *data,int32_t len,char *remoteaddr)
{
struct pangea_msghdr *pm = data; cJSON *argjson; bits256 tablehash; int32_t i,datalen,flag = 0;
uint8_t *serialized; uint8_t tmp[sizeof(pm->sig)]; char str[65],str2[65];
acct777_rwsig(0,(void *)&pm->sig,(void *)tmp);
memcpy(&pm->sig,tmp,sizeof(pm->sig));
datalen = len - (int32_t)sizeof(pm->sig);
serialized = (void *)((long)pm + sizeof(pm->sig));
if ( remoteaddr != 0 && remoteaddr[0] == 0 && strcmp("127.0.0.1",remoteaddr) == 0 && ((uint8_t *)pm)[len-1] == 0 && (argjson= cJSON_Parse((char *)pm)) != 0 )
{
printf("pangea_hexmsg RESULT.(%s)\n",jprint(argjson,0));
pangea_parse(myinfo,pm,argjson);
free_json(argjson);
return(1);
}
printf("pm.%p len.%d serialized.%p datalen.%d crc.%u %s\n",pm,len,serialized,datalen,calc_crc32(0,(void *)pm,len),bits256_str(str,pm->sig.pubkey));
//return(0);
if ( pangea_validate(pm,acct777_msgprivkey(serialized,datalen),pm->sig.pubkey) == 0 )
{
flag++;
iguana_rwbignum(0,pm->tablehash.bytes,sizeof(bits256),tablehash.bytes);
pm->tablehash = tablehash;
printf("<<<<<<<<<<<<< sigsize.%ld VALIDATED [%ld] len.%d t%u allocsize.%d (%s) [%d]\n",sizeof(pm->sig),(long)serialized-(long)pm,datalen,pm->sig.timestamp,pm->sig.allocsize,(char *)pm->serialized,serialized[datalen-1]);
if ( serialized[datalen-1] == 0 && (argjson= cJSON_Parse((char *)pm->serialized)) != 0 )
{
pangea_parse(myinfo,pm,argjson);
free_json(argjson);
} else printf("ERROR >>>>>>> (%s) cant parse\n",(char *)pm->serialized);
}
else
{
for (i=0; i<datalen; i++)
printf("%02x",serialized[i]);
printf("<<<<<<<<<<<<< sigsize.%ld SIG ERROR [%ld] len.%d (%s + %s)\n",sizeof(pm->sig),(long)serialized-(long)pm,datalen,bits256_str(str,acct777_msgprivkey(serialized,datalen)),bits256_str(str2,pm->sig.pubkey));
}
return(flag);
}
void pangea_ping(PANGEA_HANDARGS)
{
@ -221,35 +338,6 @@ void pangea_tablejoin(PANGEA_HANDARGS)
} else printf("tablejoin cant parse json\n");
}
int32_t pangea_allocsize(struct table_info *tp,int32_t setptrs)
{
long allocsize = sizeof(*tp); int32_t N,numcards = tp->G.numcards;
N = tp->G.numactive;
allocsize += sizeof(bits256) * (2 * ((N * numcards * N) + (N * numcards)));
allocsize += sizeof(bits256) * ((numcards + 1) + (N * numcards));
if ( setptrs != 0 )
{
tp->hand.cardpubs = tp->priv.data;
tp->hand.final = &tp->hand.cardpubs[numcards + 1 + N];
tp->priv.audits = &tp->hand.final[N * numcards];
tp->priv.outcards = &tp->priv.audits[N * numcards * N];
tp->priv.xoverz = &tp->priv.outcards[N * numcards];
tp->priv.allshares = (void *)&tp->priv.xoverz[N * numcards]; // N*numcards*N
}
return((int32_t)allocsize);
}
struct table_info *pangea_tablealloc(struct table_info *tp)
{
int32_t allocsize = pangea_allocsize(tp,0);
if ( tp->G.allocsize != allocsize )
{
tp = realloc(tp,allocsize);
pangea_allocsize(tp,1);
}
return(tp);
}
void pangea_tableaccept(PANGEA_HANDARGS)
{
cJSON *json; char ipaddr[64]; struct iguana_peer *addr; uint64_t ipbits = 0;
@ -324,26 +412,6 @@ void pangea_tablecreate(PANGEA_HANDARGS)
}
}
struct table_info *pangea_table(bits256 tablehash)
{
struct table_info *tp; int32_t allocsize; bits256 pangeahash; char str[65];
pangeahash = calc_categoryhashes(0,"pangea",0);
if ( (tp= category_info(pangeahash,tablehash)) == 0 )
{
allocsize = (int32_t)(sizeof(tp->G) + sizeof(void *)*2);
if ( (tp= calloc(1,allocsize)) == 0 )
printf("error: couldnt create table.(%s)\n",bits256_str(str,tablehash));
}
if ( tp != 0 )
{
category_subscribe(SuperNET_MYINFO(0),pangeahash,tablehash);
if ( category_infoset(pangeahash,tablehash,tp) == 0 )
printf("error: couldnt set table.(%s)\n",bits256_str(str,tablehash)), tp = 0;
else tp->G.allocsize = allocsize;
}
return(tp);
}
void pangea_update(struct supernet_info *myinfo)
{
static struct { char *cmdstr; void (*func)(PANGEA_HANDARGS); uint64_t cmdbits; } tablecmds[] =
@ -358,9 +426,9 @@ void pangea_update(struct supernet_info *myinfo)
{ "turn", pangea_turn }, { "confirm", pangea_confirm }, { "action", pangea_action },
{ "showdown", pangea_showdown }, { "summary", pangea_summary },
};
struct category_msg *m; bits256 pangeahash,tablehash;
struct pangea_msghdr *pm; int32_t i; cJSON *argjson; char *agent,*method;
uint64_t cmdbits; struct table_info *tp; uint8_t buf[sizeof(pm->sig)];
struct category_msg *m; bits256 pangeahash,tablehash; char remoteaddr[64];
struct pangea_msghdr *pm; int32_t i; //cJSON *argjson; char *agent,*method,remoteaddr[64];
uint64_t cmdbits; struct table_info *tp; //uint8_t buf[sizeof(pm->sig)];
if ( tablecmds[0].cmdbits == 0 )
{
for (i=0; i<sizeof(tablecmds)/sizeof(*tablecmds); i++)
@ -370,43 +438,25 @@ void pangea_update(struct supernet_info *myinfo)
while ( (m= category_gethexmsg(myinfo,pangeahash,GENESIS_PUBKEY)) != 0 )
{
pm = (struct pangea_msghdr *)m->msg;
if ( m->msg[m->len-1] == 0 )
if ( m->remoteipbits != 0 )
expand_ipbits(remoteaddr,m->remoteipbits);
if ( pangea_hexmsg(myinfo,pm,m->len,remoteaddr) > 0 )
{
if ( (argjson= cJSON_Parse((char *)m->msg)) != 0 )
if ( (tp= pangea_table(tablehash)) != 0 && pangea_rwdata(0,pm->serialized,m->len-(int32_t)((long)pm->serialized-(long)pm),pm->serialized) > 0 )
{
printf("parsed pangea hex.(%s)\n",(char *)m->msg);
if ( (agent= jstr(argjson,"agent")) != 0 && strcmp(agent,"pangea") == 0 && (method= jstr(argjson,"method")) != 0 )
cmdbits = stringbits(pm->cmd);
for (i=0; i<sizeof(tablecmds)/sizeof(*tablecmds); i++)
{
if ( strcmp(method,"lobby") == 0 )
if ( tablecmds[i].cmdbits == cmdbits )
{
//categoryhash = jbits256(argjson,"categoryhash");
(*tablecmds[i].func)(myinfo,pm,tp,pm->serialized,(int32_t)(pm->sig.allocsize - sizeof(*pm)));
break;
}
}
free_json(argjson);
free(m);
continue;
}
}
///for (i=0; i<16; i++)
/// printf("%02x ",m->msg[i]);
///printf("pangeahash.%s len.%d (%02x %02x)\n",bits256_str(str,pangeahash),m->len,m->msg[m->len-2],m->msg[m->len-1]);
acct777_rwsig(0,(void *)&pm->sig,(void *)buf), memcpy(&pm->sig,buf,sizeof(pm->sig));
iguana_rwbignum(0,pm->tablehash.bytes,sizeof(bits256),tablehash.bytes);
pm->tablehash = tablehash;
if ( (tp= pangea_table(tablehash)) != 0 && pangea_rwdata(0,pm->serialized,m->len-(int32_t)((long)pm->serialized-(long)pm),pm->serialized) > 0 )
{
cmdbits = stringbits(pm->cmd);
for (i=0; i<sizeof(tablecmds)/sizeof(*tablecmds); i++)
{
if ( tablecmds[i].cmdbits == cmdbits )
{
(*tablecmds[i].func)(myinfo,pm,tp,pm->serialized,(int32_t)(pm->sig.allocsize - sizeof(*pm)));
break;
}
}
}
free(m);
}
}
}
/*
char *_pangea_status(struct supernet_info *myinfo,bits256 tablehash,cJSON *json)
@ -554,8 +604,8 @@ ZERO_ARGS(pangea,lobby)
cJSON *retjson,*argjson; char *retstr,*result; uint8_t *buf; int32_t flag,len; struct pangea_msghdr *pm;
bits256 pangeahash = calc_categoryhashes(0,"pangea",0);
category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY);
//pangea_update(myinfo);
while ( (retstr= SuperNET_gethexmsg(IGUANA_CALLARGS,"pangea",0)) != 0 )
pangea_update(myinfo);
while ( 0 && (retstr= SuperNET_gethexmsg(IGUANA_CALLARGS,"pangea",0)) != 0 )
{
flag = 0;
if ( (retjson= cJSON_Parse(retstr)) != 0 )
@ -569,25 +619,29 @@ ZERO_ARGS(pangea,lobby)
len >>= 1;
buf = malloc(len);
decode_hex(buf,len,result);
if ( buf[len-1] == 0 && (argjson= cJSON_Parse((char *)buf)) != 0 )
pangea_hexmsg(myinfo,(struct pangea_msghdr *)buf,len,remoteaddr);
if ( 0 && buf[len-1] == 0 && (argjson= cJSON_Parse((char *)buf)) != 0 )
{
printf("RESULT.(%s)\n",jprint(argjson,0));
free_json(argjson);
}
else
else if ( 0 )
{
char *method; bits256 tablehash; struct table_info *tp;
int32_t datalen; uint8_t *serialized; uint8_t tmp[sizeof(pm->sig)];
decode_hex(buf,len,result);
pm = (struct pangea_msghdr *)buf;
acct777_rwsig(0,(void *)&pm->sig,(void *)tmp);
memcpy(&pm->sig,tmp,sizeof(pm->sig));
datalen = len - (int32_t)sizeof(pm->sig);
serialized = (void *)((long)pm + sizeof(pm->sig));
char str[65]; printf("OLD pm.%p len.%d serialized.%p datalen.%d crc.%u %s\n",pm,len,serialized,datalen,calc_crc32(0,(void *)pm,len),bits256_str(str,pm->sig.pubkey));
if ( pangea_validate(pm,acct777_msgprivkey(serialized,datalen),pm->sig.pubkey) == 0 )
{
iguana_rwbignum(0,pm->tablehash.bytes,sizeof(bits256),tablehash.bytes);
pm->tablehash = tablehash;
printf("<<<<<<<<<<<<< sigsize.%ld VALIDATED [%ld] len.%d t%u allocsize.%d (%s) [%d]\n",sizeof(pm->sig),(long)serialized-(long)pm,datalen,pm->sig.timestamp,pm->sig.allocsize,(void *)pm->serialized,serialized[datalen-1]);
printf("<<<<<<<<<<<<< sigsize.%ld VALIDATED [%ld] len.%d t%u allocsize.%d (%s) [%d]\n",sizeof(pm->sig),(long)serialized-(long)pm,datalen,pm->sig.timestamp,pm->sig.allocsize,(char *)pm->serialized,serialized[datalen-1]);
if ( serialized[datalen-1] == 0 && (argjson= cJSON_Parse((char *)pm->serialized)) != 0 )
{
tablehash = jbits256(argjson,"subhash");

1
includes/curve25519.h

@ -65,6 +65,7 @@ bits128 calc_md5(char digeststr[33],void *buf,int32_t len);
bits256 acct777_msgprivkey(uint8_t *data,int32_t datalen);
bits256 acct777_msgpubkey(uint8_t *data,int32_t datalen);
void acct777_rwsig(int32_t rwflag,uint8_t *serialized,struct acct777_sig *sig);
int32_t acct777_sigcheck(struct acct777_sig *sig);
bits256 acct777_pubkey(bits256 privkey);
uint64_t acct777_nxt64bits(bits256 pubkey);

Loading…
Cancel
Save