Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
89a518b3d6
  1. 1
      iguana/SuperNET.h
  2. 2
      iguana/SuperNET_category.c
  3. 1
      iguana/main.c
  4. 2
      iguana/pangea777.h
  5. 19
      iguana/pangea_api.c
  6. 44
      iguana/pangea_hand.c

1
iguana/SuperNET.h

@ -141,6 +141,7 @@ 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);
void pangea_queues(struct supernet_info *myinfo);
int32_t SuperNET_str2hex(uint8_t *hex,char *str);
void SuperNET_hex2str(char *str,uint8_t *hex,int32_t len);

2
iguana/SuperNET_category.c

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

1
iguana/main.c

@ -513,6 +513,7 @@ void iguana_main(void *arg)
flag += iguana_bundleiters(ptr->coin,ptr->bp,ptr->timelimit);
myfree(ptr,ptr->allocsize);
}
else pangea_queues(SuperNET_MYINFO(0));
}
if ( flag == 0 )
sleep(1);

2
iguana/pangea777.h

@ -167,6 +167,8 @@ int32_t pangea_playerparse(struct player_info *p,cJSON *json);
int32_t pangea_newdeck(struct supernet_info *myinfo,struct table_info *tp);
int32_t pangea_tableismine(struct supernet_info *myinfo,struct table_info *tp);
void pangea_playeradd(struct supernet_info *myinfo,struct table_info *tp,struct player_info *p,cJSON *json);
int32_t pangea_queueprocess(struct supernet_info *myinfo,struct table_info *tp);
void pangea_update(struct supernet_info *myinfo);
void pangea_checkantes(struct supernet_info *myinfo,struct table_info *tp);
int32_t pangea_bet(struct supernet_info *myinfo,struct table_info *tp,struct player_info *player,int64_t bet,int32_t action);

19
iguana/pangea_api.c

@ -188,6 +188,9 @@ struct table_info *pangea_table(bits256 tablehash,int32_t N)
if ( (tp= category_info(pangeahash,tablehash)) == 0 )
{
tp = pangea_tablealloc(0,N);
memset(tp,0,sizeof(*tp));
iguana_initQ(&tp->stateQ[0],"stateQ[0]");
iguana_initQ(&tp->stateQ[1],"stateQ[1]");
//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));
@ -258,29 +261,37 @@ char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct p
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)
{
struct player_info *p; struct pangea_msghdr *pm; char *str,*hexstr;
struct player_info *p; struct pangea_msghdr *pm; char *str,*hexstr; int32_t plaintext,loopback = 0;
pm = calloc(1,sizeof(*pm) + datalen);//(void *)tp->space;
memset(pm,0,sizeof(*pm));
strncpy(pm->cmd,cmdstr,8);
pm->turni = turni, pm->myind = tp->priv.myind, pm->cardi = cardi, pm->destplayer = destplayer;
if ( data != 0 )
pangea_rwdata(1,pm->serialized,datalen,data);
// additional layer of encryption can be added here, make sure to decrypt on incoming
plaintext = 1; // for now
if ( pangea_msgcreate(myinfo,tp->G.tablehash,pm,datalen) != 0 )
{
hexstr = malloc(pm->sig.allocsize*2 + 1);
init_hexbytes_noT(hexstr,(uint8_t *)pm,pm->sig.allocsize);
if ( destplayer == tp->priv.myind )
loopback = 1;
if ( destplayer < 0 )
{
if ( (str= SuperNET_categorymulticast(myinfo,0,tp->G.gamehash,tp->G.tablehash,hexstr,0,2,1)) != 0 )
if ( (str= SuperNET_categorymulticast(myinfo,0,tp->G.gamehash,tp->G.tablehash,hexstr,0,2,plaintext)) != 0 )
free(str);
loopback = 1;
}
else if ( (p= tp->active[destplayer]) != 0 )
{
// encrypt here!
int32_t plaintext = 1; // for now
if ( (str= SuperNET_DHTsend(myinfo,p->ipbits,tp->G.gamehash,tp->G.tablehash,hexstr,0,0,plaintext)) != 0 )
free(str);
}
if ( loopback != 0 )
{
printf("LOOPBACK\n");
category_posthexmsg(myinfo,tp->G.gamehash,GENESIS_PUBKEY,hexstr,tai_now(),0);
}
free(hexstr);
}
free(pm);

44
iguana/pangea_hand.c

@ -266,7 +266,7 @@ void pangea_newhand(PANGEA_HANDARGS)
}
}
int32_t pangea_checkstart(struct supernet_info *myinfo,int32_t N,int32_t turni,int32_t cardi,int32_t destplayer,int32_t senderind,struct table_info *tp)
int32_t pangea_checkstart(struct supernet_info *myinfo,struct table_info *tp)
{
int32_t i,matches = 0; struct hand_info *hand = &tp->hand;
if ( bits256_nonz(hand->checkprod) > 0 && hand->encodestarted == 0 )
@ -281,17 +281,13 @@ int32_t pangea_checkstart(struct supernet_info *myinfo,int32_t N,int32_t turni,i
{
if ( time(NULL) > (tp->priv.myind + hand->startdecktime) )
{
if ( PANGEA_PAUSE > 0 )
sleep(PANGEA_PAUSE);
//if ( PANGEA_PAUSE > 0 )
// sleep(PANGEA_PAUSE);
hand->encodestarted = (uint32_t)time(NULL);
tp->hand.sentencoded |= (1 << tp->priv.myind);
pangea_queuestate(tp,PANGEA_GOTDECKS,PANGEA_GOTFINAL);
PNACL_message("start encoded %llx destplayer.%d vs myind.%d\n",(long long)hand->checkprod.txid,destplayer,tp->priv.myind);
if ( pangea_slotB(tp) == tp->priv.myind )
{
printf("encode to myself\n");
pangea_encoded(myinfo,N,turni,cardi,pangea_slotB(tp),tp->priv.myind,tp,tp->priv.outcards[0].bytes,sizeof(bits256) * tp->G.numactive * tp->G.numcards);
}
else pangea_sendcmd(myinfo,tp,"encoded",pangea_slotB(tp),tp->priv.outcards[0].bytes,sizeof(bits256) * tp->G.numactive * tp->G.numcards,tp->G.numactive*tp->G.numcards,-1);
PNACL_message("start encoded %llx destplayer.%d vs myind.%d\n",(long long)hand->checkprod.txid,pangea_slotB(tp),tp->priv.myind);
pangea_sendcmd(myinfo,tp,"encoded",pangea_slotB(tp),tp->priv.outcards[0].bytes,sizeof(bits256) * tp->G.numactive * tp->G.numcards,tp->G.numactive*tp->G.numcards,-1);
return(matches);
}
} else printf("i.%d != numactive.%d\n",matches,tp->G.numactive);
@ -314,7 +310,7 @@ void pangea_gothand(PANGEA_HANDARGS)
PNACL_message("balances %.8f [%.8f] | ",dstr(total),dstr(total + tp->G.hostrake + tp->G.pangearake));
PNACL_message("player.%d pangea_gotdeck from P.%d otherpubs.%llx\n",tp->priv.myind,senderind,(long long)tp->hand.othercardpubs[senderind].txid);
}
pangea_checkstart(myinfo,N,turni,cardi,destplayer,senderind,tp);
pangea_checkstart(myinfo,tp);
}
void pangea_sentencoded(PANGEA_HANDARGS)
@ -381,9 +377,10 @@ void pangea_final(PANGEA_HANDARGS)
pangea_sendcmd(myinfo,tp,"gotfinal",-1,0,0,tp->priv.myind,tp->priv.myind);
}
int32_t pangea_queueprocess(struct supernet_info *myinfo,int32_t N,int32_t turni,int32_t cardi,int32_t destplayer,int32_t senderind,struct table_info *tp)
int32_t pangea_queueprocess(struct supernet_info *myinfo,struct table_info *tp)
{
int32_t iter,retval,flag = 0; double diff; struct pangea_queueitem *ptr;
//char str[65]; printf("queueprocess.(%s)\n",bits256_str(str,tp->G.tablehash));
for (iter=0; iter<2; iter++)
{
while ( (ptr= queue_dequeue(&tp->stateQ[iter],0)) != 0 )
@ -397,11 +394,11 @@ int32_t pangea_queueprocess(struct supernet_info *myinfo,int32_t N,int32_t turni
switch ( ptr->waitevent )
{
case PANGEA_GOTDECKS:
if ( pangea_checkstart(myinfo,N,turni,cardi,destplayer,senderind,tp) > 0 )
if ( pangea_checkstart(myinfo,tp) > 0 )
return(1);
break;
case PANGEA_GOTFINAL:
printf("sentencoded.%x\n",tp->hand.sentencoded);
//printf("sentencoded.%x, waiting for gotfinal\n",tp->hand.sentencoded);
break;
}
if ( retval != 0 )
@ -419,6 +416,20 @@ int32_t pangea_queueprocess(struct supernet_info *myinfo,int32_t N,int32_t turni
return(flag);
}
void pangea_queues(struct supernet_info *myinfo)
{
struct category_info *cat,*sub,*tmp; struct table_info *tp;
pangea_update(myinfo);
if ( (cat= category_find(calc_categoryhashes(0,"pangea",0),GENESIS_PUBKEY)) != 0 )
{
HASH_ITER(hh,cat->sub,sub,tmp)
{
if ( (tp= sub->info) != 0 )
pangea_queueprocess(myinfo,tp);
}
}
}
void pangea_preflop(PANGEA_HANDARGS)
{
int32_t i,iter,maxlen; bits256 audit[CARDS777_MAXPLAYERS];
@ -462,9 +473,10 @@ void pangea_preflop(PANGEA_HANDARGS)
if ( destplayer == tp->priv.myind )
{
printf("send card to myself\n");
pangea_card(myinfo,N,turni,cardi,destplayer,tp->priv.myind,tp,audit[0].bytes,sizeof(bits256)*N);
// pangea_card(myinfo,N,turni,cardi,destplayer,tp->priv.myind,tp,audit[0].bytes,sizeof(bits256)*N);
}
else pangea_sendcmd(myinfo,tp,"card",destplayer,audit[0].bytes,sizeof(bits256)*N,cardi,-1);
// else
pangea_sendcmd(myinfo,tp,"card",destplayer,audit[0].bytes,sizeof(bits256)*N,cardi,-1);
}
}
}

Loading…
Cancel
Save