Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
4669461e8e
  1. 14
      crypto777/cJSON.c
  2. 2
      iguana/SuperNET.c
  3. 1
      iguana/SuperNET_category.c
  4. 2
      iguana/SuperNET_hexmsg.c
  5. 2
      iguana/iguana_rpc.c
  6. 48
      iguana/pangea_api.c

14
crypto777/cJSON.c

@ -798,15 +798,15 @@ char *cJSON_str(cJSON *json)
return(0); return(0);
} }
void jadd(cJSON *json,char *field,cJSON *item) { cJSON_AddItemToObject(json,field,item); } void jadd(cJSON *json,char *field,cJSON *item) { if ( json != 0 )cJSON_AddItemToObject(json,field,item); }
void jaddstr(cJSON *json,char *field,char *str) { cJSON_AddItemToObject(json,field,cJSON_CreateString(str)); } void jaddstr(cJSON *json,char *field,char *str) { if ( json != 0 ) cJSON_AddItemToObject(json,field,cJSON_CreateString(str)); }
void jaddnum(cJSON *json,char *field,double num) { cJSON_AddItemToObject(json,field,cJSON_CreateNumber(num)); } void jaddnum(cJSON *json,char *field,double num) { if ( json != 0 )cJSON_AddItemToObject(json,field,cJSON_CreateNumber(num)); }
void jadd64bits(cJSON *json,char *field,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddstr(json,field,numstr); } void jadd64bits(cJSON *json,char *field,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddstr(json,field,numstr); }
void jaddi(cJSON *json,cJSON *item) { cJSON_AddItemToArray(json,item); } void jaddi(cJSON *json,cJSON *item) { if ( json != 0 ) cJSON_AddItemToArray(json,item); }
void jaddistr(cJSON *json,char *str) { cJSON_AddItemToArray(json,cJSON_CreateString(str)); } void jaddistr(cJSON *json,char *str) { if ( json != 0 ) cJSON_AddItemToArray(json,cJSON_CreateString(str)); }
void jaddinum(cJSON *json,double num) { cJSON_AddItemToArray(json,cJSON_CreateNumber(num)); } void jaddinum(cJSON *json,double num) { if ( json != 0 ) cJSON_AddItemToArray(json,cJSON_CreateNumber(num)); }
void jaddi64bits(cJSON *json,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddistr(json,numstr); } void jaddi64bits(cJSON *json,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddistr(json,numstr); }
char *jstr(cJSON *json,char *field) { if ( field == 0 ) return(cJSON_str(json)); return(cJSON_str(cJSON_GetObjectItem(json,field))); } char *jstr(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == 0 ) return(cJSON_str(json)); return(cJSON_str(cJSON_GetObjectItem(json,field))); }
char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); } char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); }
char *jprint(cJSON *json,int32_t freeflag) { char *str; if ( json == 0 ) return(clonestr("{}")); str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); return(str); } char *jprint(cJSON *json,int32_t freeflag) { char *str; if ( json == 0 ) return(clonestr("{}")); str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); return(str); }

2
iguana/SuperNET.c

@ -452,7 +452,7 @@ int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,c
if ( (datalen= SuperNET_json2bits(&serialized[sizeof(struct iguana_msghdr)],IGUANA_MAXPACKETSIZE,json,nextpubkey,checkc,(uint32_t)calc_ipbits(myinfo->ipaddr),(uint32_t)calc_ipbits(addr->ipaddr),addr->othervalid)) > 0 ) if ( (datalen= SuperNET_json2bits(&serialized[sizeof(struct iguana_msghdr)],IGUANA_MAXPACKETSIZE,json,nextpubkey,checkc,(uint32_t)calc_ipbits(myinfo->ipaddr),(uint32_t)calc_ipbits(addr->ipaddr),addr->othervalid)) > 0 )
{ {
if ( jstr(json,"method") != 0 && strcmp("getpeers",jstr(json,"method")) != 0 ) if ( jstr(json,"method") != 0 && strcmp("getpeers",jstr(json,"method")) != 0 )
printf("SUPERSEND.(%s) -> (%s) (%s) delaymillis.%d datalen.%d\n",jsonstr,jprint(SuperNET_bits2json(&serialized[sizeof(struct iguana_msghdr)],datalen),1),addr->ipaddr,delaymillis,datalen); printf("SUPERSEND -> (%s) (%s) delaymillis.%d datalen.%d\n",jprint(SuperNET_bits2json(&serialized[sizeof(struct iguana_msghdr)],datalen),1),addr->ipaddr,delaymillis,datalen);
if ( 0 && memcmp(destpub.bytes,GENESIS_PUBKEY.bytes,sizeof(destpub)) == 0 ) if ( 0 && memcmp(destpub.bytes,GENESIS_PUBKEY.bytes,sizeof(destpub)) == 0 )
qlen = iguana_queue_send(coin,addr,delaymillis,serialized,"SuperNET",datalen,0,0); qlen = iguana_queue_send(coin,addr,delaymillis,serialized,"SuperNET",datalen,0,0);
else else

1
iguana/SuperNET_category.c

@ -49,6 +49,7 @@ queue_t *category_Q(bits256 categoryhash,bits256 subhash)
struct category_msg *category_gethexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash) struct category_msg *category_gethexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash)
{ {
queue_t *Q; queue_t *Q;
char str[65]; printf("getmsg.(%s) %llx\n",bits256_str(str,categoryhash),(long long)subhash.txid);
if ( (Q= category_Q(categoryhash,subhash)) != 0 ) if ( (Q= category_Q(categoryhash,subhash)) != 0 )
return(queue_dequeue(Q,0)); return(queue_dequeue(Q,0));
else return(0); else return(0);

2
iguana/SuperNET_hexmsg.c

@ -40,7 +40,7 @@ int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 category,bits25
} }
else if ( Packetcache[i] == packethash.txid ) else if ( Packetcache[i] == packethash.txid )
{ {
printf("SuperNET_DHTsend reject duplicate packet.%llx (%s)\n",(long long)packethash.txid,hexmsg); printf("SuperNET_DHTsend reject duplicate packet.%llx\n",(long long)packethash.txid);
return(i); return(i);
} }
} }

2
iguana/iguana_rpc.c

@ -718,7 +718,7 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
url[i++] = 0; url[i++] = 0;
n += i; n += i;
j = i = 0; j = i = 0;
printf("url.(%s) method.(%s)\n",&url[i],urlmethod); //printf("url.(%s) method.(%s)\n",&url[i],urlmethod);
if ( strcmp(&url[i],"/") == 0 && strcmp(urlmethod,"GET") == 0 ) if ( strcmp(&url[i],"/") == 0 && strcmp(urlmethod,"GET") == 0 )
{ {
SuperNET_htmlstr("index7778.html",retbuf,bufsize,0); SuperNET_htmlstr("index7778.html",retbuf,bufsize,0);

48
iguana/pangea_api.c

@ -34,6 +34,17 @@ int32_t pangea_updatemsg(struct supernet_info *myinfo,struct pangea_msghdr *pm,i
return(0); return(0);
} }
void pangea_update(struct supernet_info *myinfo)
{
struct category_msg *m; bits256 pangeahash;
pangeahash = calc_categoryhashes(0,"pangea",0);
while ( (m= category_gethexmsg(myinfo,pangeahash,GENESIS_PUBKEY)) != 0 )
{
pangea_updatemsg(myinfo,(struct pangea_msghdr *)m->msg,m->len);
free(m);
}
}
int32_t pangea_validate(struct pangea_msghdr *pm,bits256 privkey,bits256 pubkey) int32_t pangea_validate(struct pangea_msghdr *pm,bits256 privkey,bits256 pubkey)
{ {
uint64_t signerbits; uint64_t signerbits;
@ -59,17 +70,6 @@ struct pangea_msghdr *pangea_msgcreate(struct supernet_info *myinfo,uint8_t *spa
return(0); return(0);
} }
void pangea_update(struct supernet_info *myinfo)
{
struct category_msg *m; bits256 pangeahash;
pangeahash = calc_categoryhashes(0,"pangea",0);
while ( (m= category_gethexmsg(myinfo,pangeahash,GENESIS_PUBKEY)) != 0 )
{
pangea_updatemsg(myinfo,(struct pangea_msghdr *)m->msg,m->len);
free(m);
}
}
void pangea_sendcmd(char *hex,union pangeanet777 *hn,char *cmdstr,int32_t destplayer,uint8_t *data,int32_t datalen,int32_t cardi,int32_t turni) void pangea_sendcmd(char *hex,union pangeanet777 *hn,char *cmdstr,int32_t destplayer,uint8_t *data,int32_t datalen,int32_t cardi,int32_t turni)
{ {
int32_t n,hexlen,blindflag = 0; uint64_t destbits; bits256 destpub; cJSON *json; char hoststr[1024]; struct pangea_info *sp; int32_t n,hexlen,blindflag = 0; uint64_t destbits; bits256 destpub; cJSON *json; char hoststr[1024]; struct pangea_info *sp;
@ -570,7 +570,6 @@ INT_AND_ARRAY(pangea,handsummary,senderind,params)
return(jprint(retjson,1)); return(jprint(retjson,1));
} }
HASH_AND_ARRAY(pangea,status,tablehash,params) HASH_AND_ARRAY(pangea,status,tablehash,params)
{ {
cJSON *retjson = cJSON_CreateObject(); cJSON *retjson = cJSON_CreateObject();
@ -597,6 +596,8 @@ HASH_AND_ARRAY(pangea,history,tablehash,params)
ZERO_ARGS(pangea,lobby) ZERO_ARGS(pangea,lobby)
{ {
bits256 pangeahash = calc_categoryhashes(0,"pangea",0);
category_sub(myinfo,pangeahash,GENESIS_PUBKEY);
pangea_update(myinfo); pangea_update(myinfo);
return(jprint(pangea_lobbyjson(myinfo),1)); return(jprint(pangea_lobbyjson(myinfo),1));
} }
@ -607,10 +608,12 @@ INT_AND_ARRAY(pangea,host,minplayers,params)
bits256 pangeahash,tablehash; struct pangea_msghdr *pm; uint8_t space[sizeof(*pm) + 512]; bits256 pangeahash,tablehash; struct pangea_msghdr *pm; uint8_t space[sizeof(*pm) + 512];
pangeahash = calc_categoryhashes(0,"pangea",0); pangeahash = calc_categoryhashes(0,"pangea",0);
OS_randombytes(tablehash.bytes,sizeof(tablehash)); OS_randombytes(tablehash.bytes,sizeof(tablehash));
category_sub(myinfo,pangeahash,GENESIS_PUBKEY);
category_sub(myinfo,pangeahash,tablehash);
argjson = cJSON_CreateObject(); argjson = cJSON_CreateObject();
jaddbits256(argjson,"newtable",tablehash); jaddbits256(argjson,"newtable",tablehash);
jaddnum(argjson,"minplayers",minplayers); jaddnum(argjson,"minplayers",minplayers);
jaddstr(argjson,"ipaddr",myinfo->ipaddr); jaddstr(argjson,"myipaddr",myinfo->ipaddr);
reqstr = jprint(argjson,1); reqstr = jprint(argjson,1);
if ( (pm= pangea_msgcreate(myinfo,space,tablehash,(void *)reqstr,(int32_t)strlen(reqstr)+1)) != 0 ) if ( (pm= pangea_msgcreate(myinfo,space,tablehash,(void *)reqstr,(int32_t)strlen(reqstr)+1)) != 0 )
{ {
@ -632,15 +635,26 @@ INT_AND_ARRAY(pangea,host,minplayers,params)
HASH_AND_ARRAY(pangea,join,tablehash,params) HASH_AND_ARRAY(pangea,join,tablehash,params)
{ {
char hexstr[512],*req = "{\"lobby\":\"join\"}"; cJSON *argjson; char hexstr[512],*reqstr;
bits256 pangeahash; struct pangea_msghdr *pm; uint8_t space[sizeof(*pm) + 512]; bits256 pangeahash; struct pangea_msghdr *pm; uint8_t space[sizeof(*pm) + 512];
pangeahash = calc_categoryhashes(0,"pangea",0); pangeahash = calc_categoryhashes(0,"pangea",0);
if ( (pm= pangea_msgcreate(myinfo,space,tablehash,(void *)req,(int32_t)strlen(req))) != 0 ) category_sub(myinfo,pangeahash,GENESIS_PUBKEY);
category_sub(myinfo,pangeahash,tablehash);
argjson = cJSON_CreateObject();
jaddbits256(argjson,"join",tablehash);
jaddstr(argjson,"myipaddr",myinfo->ipaddr);
reqstr = jprint(argjson,1);
if ( (pm= pangea_msgcreate(myinfo,space,tablehash,(void *)reqstr,(int32_t)strlen(reqstr))) != 0 )
{ {
free(reqstr);
init_hexbytes_noT(hexstr,(uint8_t *)pm,pm->sig.allocsize); init_hexbytes_noT(hexstr,(uint8_t *)pm,pm->sig.allocsize);
return(SuperNET_categorymulticast(myinfo,0,pangeahash,tablehash,hexstr,0,1,1)); return(SuperNET_categorymulticast(myinfo,0,pangeahash,tablehash,hexstr,0,1,1));
} else return(clonestr("{\"error\":\"couldnt create pangea message\"}")); }
else
{
free(reqstr);
return(clonestr("{\"error\":\"couldnt create pangea message\"}"));
}
} }
#undef IGUANA_ARGS #undef IGUANA_ARGS

Loading…
Cancel
Save