Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
040d48fe1e
  1. 2
      crypto777/curve25519.c
  2. 4
      iguana/pangea777.h
  3. 120
      iguana/pangea_api.c
  4. 1
      includes/iguana_apideclares.h

2
crypto777/curve25519.c

@ -1777,7 +1777,7 @@ int32_t acct777_sigcheck(struct acct777_sig *sig)
#define TEN_YEARS (10 * 365 * 24 * 3600) #define TEN_YEARS (10 * 365 * 24 * 3600)
if ( sig->allocsize < sizeof(*sig) || sig->allocsize > IGUANA_MAXPACKETSIZE ) if ( sig->allocsize < sizeof(*sig) || sig->allocsize > IGUANA_MAXPACKETSIZE )
{ {
printf("acct777_sign: invalid datalen.%d hex.%08x\n",sig->allocsize,sig->allocsize); //printf("acct777_sign: invalid datalen.%d hex.%08x\n",sig->allocsize,sig->allocsize);
return(-1); return(-1);
} }
if ( sig->timestamp < IGUANA_GENESIS || sig->timestamp > (long)IGUANA_GENESIS+TEN_YEARS ) if ( sig->timestamp < IGUANA_GENESIS || sig->timestamp > (long)IGUANA_GENESIS+TEN_YEARS )

4
iguana/pangea777.h

@ -82,8 +82,8 @@ struct player_info
struct game_info struct game_info
{ {
bits256 tablehash,gamehash; bits256 tablehash,gamehash;
uint8_t M,N,numcards,ismine,numactive; uint8_t M,N,numcards,ismine;
uint32_t allocsize,rakemillis,minbuyin,maxbuyin,minplayers,maxplayers,opentime,started,finished; uint32_t numactive,allocsize,rakemillis,minbuyin,maxbuyin,minplayers,maxplayers,opentime,started,finished;
uint64_t maxrake,hostrake,bigblind,ante,pangearake,hostipbits,creatorbits; uint64_t maxrake,hostrake,bigblind,ante,pangearake,hostipbits,creatorbits;
struct player_info P[CARDS777_MAXPLAYERS]; struct player_info P[CARDS777_MAXPLAYERS];
}; };

120
iguana/pangea_api.c

@ -134,28 +134,69 @@ struct pangea_msghdr *pangea_msgcreate(struct supernet_info *myinfo,bits256 tabl
void pangea_playeradd(struct supernet_info *myinfo,struct table_info *tp,struct player_info *p,cJSON *json) void pangea_playeradd(struct supernet_info *myinfo,struct table_info *tp,struct player_info *p,cJSON *json)
{ {
if ( jobj(json,"playerpub") != 0 )
p->playerpub = jbits256(json,"playerpub"); p->playerpub = jbits256(json,"playerpub");
else p->playerpub = GENESIS_PUBKEY;
p->ipbits = calc_ipbits(jstr(json,"playeripaddr")); p->ipbits = calc_ipbits(jstr(json,"playeripaddr"));
safecopy(p->handle,jstr(json,"handle"), sizeof(p->handle)); safecopy(p->handle,jstr(json,"handle"), sizeof(p->handle));
p->balance = 100 * SATOSHIDEN; p->balance = 100 * SATOSHIDEN;
p->nxt64bits = acct777_nxt64bits(p->playerpub); p->nxt64bits = acct777_nxt64bits(p->playerpub);
} }
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);
}
char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct pangea_msghdr *pm,cJSON *json,char *cmdstr,char *ipaddr) char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct pangea_msghdr *pm,cJSON *json,char *cmdstr,char *ipaddr)
{ {
cJSON *argjson; char *reqstr,hexstr[8192]; int32_t datalen; bits256 pangeahash; cJSON *argjson; char *reqstr,hexstr[8192]; uint64_t nxt64bits;
struct table_info *tp; int32_t i,datalen; bits256 pangeahash;
pangeahash = calc_categoryhashes(0,"pangea",0); pangeahash = calc_categoryhashes(0,"pangea",0);
category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY); category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY);
category_subscribe(myinfo,pangeahash,tablehash); category_subscribe(myinfo,pangeahash,tablehash);
argjson = SuperNET_argjson(json); argjson = cJSON_CreateObject();//SuperNET_argjson(json);
jaddstr(argjson,"cmd",cmdstr); jaddstr(argjson,"cmd",cmdstr);
if ( myinfo->ipaddr[0] == 0 || strncmp(myinfo->ipaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 ) if ( myinfo->ipaddr[0] == 0 || strncmp(myinfo->ipaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 )
return(clonestr("{\"error\":\"need to send your ipaddr for now\"}")); return(clonestr("{\"error\":\"need to send your ipaddr for now\"}"));
jaddstr(argjson,"playeripaddr",myinfo->ipaddr); jaddstr(argjson,"playeripaddr",ipaddr);
jaddbits256(argjson,"categoryhash",pangeahash); jaddbits256(argjson,"categoryhash",pangeahash);
jaddbits256(argjson,"subhash",tablehash); jaddbits256(argjson,"subhash",tablehash);
jaddbits256(argjson,"playerpub",myinfo->myaddr.persistent); jaddbits256(argjson,"playerpub",myinfo->myaddr.persistent);
jaddstr(argjson,"handle",jstr(json,"handle")); jaddstr(argjson,"handle",jstr(json,"handle"));
nxt64bits = acct777_nxt64bits(myinfo->myaddr.persistent);
if ( (tp= pangea_table(tablehash)) != 0 && tp->G.numactive < tp->G.maxplayers )
{
for (i=0; i<tp->G.numactive; i++)
if ( tp->G.P[i].nxt64bits == nxt64bits )
break;
if ( i == tp->G.numactive )
{
printf("self join\n");
struct player_info *p = &tp->G.P[tp->G.numactive++];
p->playerpub = myinfo->myaddr.persistent;
p->ipbits = calc_ipbits(myinfo->ipaddr);
safecopy(p->handle,jstr(json,"handle"),sizeof(p->handle));
p->balance = 100 * SATOSHIDEN;
p->nxt64bits = nxt64bits;
//pangea_playeradd(myinfo,tp,&tp->G.P[tp->G.numactive++],argjson);
}
}
reqstr = jprint(argjson,1); reqstr = jprint(argjson,1);
datalen = (int32_t)(strlen(reqstr) + 1); datalen = (int32_t)(strlen(reqstr) + 1);
memcpy(pm->serialized,reqstr,datalen); memcpy(pm->serialized,reqstr,datalen);
@ -165,7 +206,12 @@ char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct p
printf("pangea send.(%s)\n",cmdstr); printf("pangea send.(%s)\n",cmdstr);
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,2,1)); return(SuperNET_categorymulticast(myinfo,0,pangeahash,tablehash,hexstr,0,2,1));
} else return(clonestr("{\"error\":\"couldnt create pangea message\"}")); }
else
{
printf("cant msgcreate\n");
return(clonestr("{\"error\":\"couldnt create pangea message\"}"));
}
} }
void pangea_sendcmd(struct supernet_info *myinfo,struct table_info *tp,char *cmdstr,int32_t destplayer,uint8_t *data,int32_t datalen,int32_t cardi,int32_t turni) void pangea_sendcmd(struct supernet_info *myinfo,struct table_info *tp,char *cmdstr,int32_t destplayer,uint8_t *data,int32_t datalen,int32_t cardi,int32_t turni)
@ -194,26 +240,6 @@ 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) int32_t pangea_allocsize(struct table_info *tp,int32_t setptrs)
{ {
long allocsize = sizeof(*tp); int32_t N,numcards = tp->G.numcards; long allocsize = sizeof(*tp); int32_t N,numcards = tp->G.numcards;
@ -279,7 +305,6 @@ void pangea_tablejoin(PANGEA_HANDARGS)
{ {
pangea_playeradd(myinfo,tp,&tp->G.P[tp->G.numactive++],json); pangea_playeradd(myinfo,tp,&tp->G.P[tp->G.numactive++],json);
printf("add player.%d %p\n",i,tp); printf("add player.%d %p\n",i,tp);
printf("NEW LOBBY.(%s)\n",jprint(pangea_lobbyjson(myinfo),1));
if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits ) if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits )
{ {
pangea_jsondatacmd(myinfo,pm->tablehash,(struct pangea_msghdr *)space,json,"accept",myinfo->ipaddr); pangea_jsondatacmd(myinfo,pm->tablehash,(struct pangea_msghdr *)space,json,"accept",myinfo->ipaddr);
@ -294,7 +319,7 @@ void pangea_tablejoin(PANGEA_HANDARGS)
void pangea_tableaccept(PANGEA_HANDARGS) void pangea_tableaccept(PANGEA_HANDARGS)
{ {
cJSON *json; char ipaddr[64]; struct iguana_peer *addr; uint64_t ipbits = 0; cJSON *json; char ipaddr[64]; struct iguana_peer *addr; uint64_t ipbits = 0;
struct iguana_info *coin; struct player_info p; int32_t allocsize; struct iguana_info *coin; struct player_info p;
ipaddr[0] = 0; ipaddr[0] = 0;
if ( pm->sig.signer64bits == tp->G.creatorbits && tp->G.numactive < tp->G.maxplayers ) if ( pm->sig.signer64bits == tp->G.creatorbits && tp->G.numactive < tp->G.maxplayers )
{ {
@ -333,17 +358,6 @@ void pangea_tableaccept(PANGEA_HANDARGS)
addr->persistent_peer = 1; addr->persistent_peer = 1;
} }
} else printf("no open iguana peer slots, cant connect\n"); } else printf("no open iguana peer slots, cant connect\n");
if ( tp->G.numactive >= tp->G.minplayers && pangea_tableismine(myinfo,tp) >= 0 )
{
allocsize = pangea_allocsize(tp,0);
if ( tp->G.allocsize < allocsize )
{
tp = pangea_tablealloc(tp);
category_infoset(tp->G.gamehash,tp->G.tablehash,tp);
}
if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits )
pangea_newdeck(myinfo,tp);
}
} }
} }
} }
@ -427,7 +441,7 @@ int32_t pangea_hexmsg(struct supernet_info *myinfo,void *data,int32_t len,char *
free_json(argjson); free_json(argjson);
} else printf("ERROR >>>>>>> (%s) cant parse\n",(char *)pm->serialized); } else printf("ERROR >>>>>>> (%s) cant parse\n",(char *)pm->serialized);
} }
else else if ( 0 )
{ {
for (i=0; i<datalen; i++) for (i=0; i<datalen; i++)
printf("%02x",serialized[i]); printf("%02x",serialized[i]);
@ -451,8 +465,7 @@ void pangea_update(struct supernet_info *myinfo)
{ "showdown", pangea_showdown }, { "summary", pangea_summary }, { "showdown", pangea_showdown }, { "summary", pangea_summary },
}; };
struct category_msg *m; bits256 pangeahash,tablehash; char remoteaddr[64]; struct category_msg *m; bits256 pangeahash,tablehash; char remoteaddr[64];
struct pangea_msghdr *pm; int32_t i; //cJSON *argjson; char *agent,*method,remoteaddr[64]; struct pangea_msghdr *pm; int32_t i,allocsize; uint64_t cmdbits; struct table_info *tp;
uint64_t cmdbits; struct table_info *tp; //uint8_t buf[sizeof(pm->sig)];
if ( tablecmds[0].cmdbits == 0 ) if ( tablecmds[0].cmdbits == 0 )
{ {
for (i=0; i<sizeof(tablecmds)/sizeof(*tablecmds); i++) for (i=0; i<sizeof(tablecmds)/sizeof(*tablecmds); i++)
@ -473,6 +486,13 @@ void pangea_update(struct supernet_info *myinfo)
{ {
if ( tablecmds[i].cmdbits == cmdbits ) if ( tablecmds[i].cmdbits == cmdbits )
{ {
printf("PANGEA.(%s)\n",tablecmds[i].cmdstr);
allocsize = pangea_allocsize(tp,0);
if ( tp->G.allocsize < allocsize )
{
tp = pangea_tablealloc(tp);
category_infoset(tp->G.gamehash,tp->G.tablehash,tp);
}
(*tablecmds[i].func)(myinfo,pm,tp,pm->serialized,(int32_t)(pm->sig.allocsize - sizeof(*pm))); (*tablecmds[i].func)(myinfo,pm,tp,pm->serialized,(int32_t)(pm->sig.allocsize - sizeof(*pm)));
break; break;
} }
@ -651,6 +671,26 @@ HASH_AND_ARRAY(pangea,join,tablehash,params)
return(pangea_jsondatacmd(myinfo,tablehash,(struct pangea_msghdr *)space,json,"join",myinfo->ipaddr)); return(pangea_jsondatacmd(myinfo,tablehash,(struct pangea_msghdr *)space,json,"join",myinfo->ipaddr));
} }
HASH_AND_ARRAY(pangea,start,tablehash,params)
{
struct table_info *tp; int32_t allocsize;
if ( (tp= pangea_table(tablehash)) != 0 )
{
if ( tp->G.numactive >= tp->G.minplayers && pangea_tableismine(myinfo,tp) >= 0 )
{
allocsize = pangea_allocsize(tp,0);
if ( tp->G.allocsize < allocsize )
{
tp = pangea_tablealloc(tp);
category_infoset(tp->G.gamehash,tp->G.tablehash,tp);
}
if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits )
pangea_newdeck(myinfo,tp);
}
return(clonestr("{\"result\":\"started tablehash\"}"));
}
return(clonestr("{\"error\":\"cant find tablehash\"}"));
}
#undef IGUANA_ARGS #undef IGUANA_ARGS
#include "../includes/iguana_apiundefs.h" #include "../includes/iguana_apiundefs.h"

1
includes/iguana_apideclares.h

@ -21,6 +21,7 @@
INT_AND_ARRAY(pangea,host,minplayers,params); INT_AND_ARRAY(pangea,host,minplayers,params);
ZERO_ARGS(pangea,lobby); ZERO_ARGS(pangea,lobby);
HASH_AND_ARRAY(pangea,join,tablehash,params); HASH_AND_ARRAY(pangea,join,tablehash,params);
HASH_AND_ARRAY(pangea,start,tablehash,params);
ZERO_ARGS(SuperNET,help); ZERO_ARGS(SuperNET,help);
STRING_ARG(SuperNET,bitcoinrpc,setcoin); STRING_ARG(SuperNET,bitcoinrpc,setcoin);

Loading…
Cancel
Save