Browse Source

tai_diff, embargo

release/v0.1
jl777 9 years ago
parent
commit
1e3381d779
  1. 1
      crypto777/OS_portable.h
  2. 9
      crypto777/OS_time.c
  3. 21
      iguana/iguana_json.c
  4. 2
      iguana/iguana_msg.c
  5. 13
      iguana/iguana_peers.c
  6. 1
      iguana/main.c
  7. 2
      includes/iguana_apideclares.h

1
crypto777/OS_portable.h

@ -120,6 +120,7 @@ uint64_t tai2utime(struct tai t);
struct tai taitime2tai(struct taitime ct);
char *tai_str(char *str,struct tai t);
char *utc_str(char *str,struct tai t);
double tai_diff(struct tai reftai,struct tai cmptai);
//int32_t msync(void *addr,size_t len,int32_t flags);

9
crypto777/OS_time.c

@ -393,6 +393,15 @@ struct tai taitime2tai(struct taitime ct)
return(leapsecs_add(t,ct.second == 60));
}
double tai_diff(struct tai reftai,struct tai cmptai)
{
double diff;
reftai = taitime2tai(tai2time(reftai,0,0));
cmptai = taitime2tai(tai2time(cmptai,0,0));
diff = ((double)cmptai.x - reftai.x) * 1000 + (cmptai.millis - reftai.millis);
return(diff);
}
struct tai taidate_scan(char *s,int32_t numleaps)
{
int32_t z,c,sign = 1; char *t = s; struct taidate cd; struct tai st;

21
iguana/iguana_json.c

@ -315,7 +315,7 @@ cJSON *SuperNET_peerarray(struct iguana_info *coin,int32_t max,int32_t supernetf
{
i = (r + j) % IGUANA_MAXPEERS;
addr = &coin->peers.active[i];
if ( addr->usock >= 0 && (supernetflag == 0 || addr->supernet != 0) )
if ( addr->usock >= 0 && supernetflag == (addr->supernet != 0) )
{
jaddistr(array,addr->ipaddr);
if ( ++n >= max )
@ -354,7 +354,7 @@ void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,c
void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int32_t supernetflag)
{
int32_t i,j,m; cJSON *coinarray; char *symbol,*ipaddr; struct iguana_info *ptr;
if ( (array= jarray(&n,array,"supernet")) != 0 )
if ( array != 0 && n > 0 )
{
for (i=0; i<n; i++)
{
@ -369,6 +369,7 @@ void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int
SuperNET_remotepeer(myinfo,ptr,symbol,ipaddr,supernetflag);
}
}
printf("parsed.%d %s.peers supernet.%d\n",m,symbol,supernetflag);
}
}
}
@ -376,19 +377,11 @@ void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int
#include "../includes/iguana_apidefs.h"
STRING_ARG(SuperNET,mypeers,jsonstr)
TWO_ARRAYS(SuperNET,mypeers,supernet,rawpeers)
{
cJSON *argjson,*SNarray,*rawarray; int32_t n;
if ( (argjson= cJSON_Parse(jsonstr)) != 0 )
{
if ( (SNarray= jarray(&n,argjson,"supernet")) != 0 )
SuperNET_parsepeers(myinfo,SNarray,n,1);
if ( (rawarray= jarray(&n,argjson,"rawpeers")) != 0 )
SuperNET_parsepeers(myinfo,SNarray,n,1);
free_json(argjson);
return(clonestr("{\"result\":\"peers parsed\"}"));
}
return(clonestr("{\"error\":\"couldnt parse jsonstr\"}"));
SuperNET_parsepeers(myinfo,supernet,cJSON_GetArraySize(supernet),1);
SuperNET_parsepeers(myinfo,rawpeers,cJSON_GetArraySize(rawpeers),0);
return(clonestr("{\"result\":\"peers parsed\"}"));
}
STRING_ARG(SuperNET,getpeers,activecoin)

2
iguana/iguana_msg.c

@ -130,7 +130,7 @@ int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,c
if ( (len= (int32_t)strlen(jsonstr)) < sizeof(serialized)-sizeof(struct iguana_msghdr) )
{
memcpy(&serialized[sizeof(struct iguana_msghdr)],jsonstr,len+1);
printf("SEND.(%s) -> (%s)\n",jsonstr,addr->ipaddr);
printf("SUPERSEND.(%s) -> (%s) delaymillis.%d\n",jsonstr,addr->ipaddr,delaymillis);
return(iguana_queue_send(coin,addr,delaymillis,serialized,"SuperNET",len+1,0,1));
}
else return(-1);

13
iguana/iguana_peers.c

@ -333,7 +333,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s
remains = len;
if ( strcmp((char *)&serialized[4],"SuperNET") == 0 )
{
printf(" >>>>>>> send.(%s) %d bytes to %s supernet.%d\n",(char *)&serialized[4],len,addr->ipaddr,addr->supernet);// getchar();
printf(" >>>>>>> send.(%s) %d bytes to %s supernet.%d\n",(char *)&serialized[4],len,addr->ipaddr,addr->supernet);
}
else if ( addr->msgcounts.verack == 0 && (strcmp((char *)&serialized[4],"version") != 0 && strcmp((char *)&serialized[4],"verack") != 0) != 0 )
{
@ -394,9 +394,10 @@ int32_t iguana_queue_send(struct iguana_info *coin,struct iguana_peer *addr,int3
if ( delay > IGUANA_MAXDELAY_MILLIS )
delay = IGUANA_MAXDELAY_MILLIS;
packet->embargo = tai_now();
packet->embargo.millis += delay;
}
memcpy(packet->serialized,serialized,datalen);
//printf("%p queue send.(%s) %d to (%s) %x\n",packet,serialized+4,datalen,addr->ipaddr,addr->ipbits);
printf("%p queue send.(%s) %d to (%s)\n",packet,serialized+4,datalen,addr->ipaddr);
queue_enqueue("sendQ",&addr->sendQ,&packet->DL,0);
return(datalen);
}
@ -741,13 +742,17 @@ int32_t iguana_pollsendQ(struct iguana_info *coin,struct iguana_peer *addr)
printf("unexpected getdata for %s\n",addr->ipaddr);
myfree(packet,sizeof(*packet) + packet->datalen);
}
else if ( packet->embargo.x == 0 )
else if ( packet->embargo.x == 0 || tai_diff(packet->embargo,tai_now()) < 0 )
{
iguana_send(coin,addr,packet->serialized,packet->datalen);
myfree(packet,sizeof(*packet) + packet->datalen);
return(1);
}
else queue_enqueue("embargo",&addr->sendQ,&packet->DL,0);
else
{
printf("embargo.x %f\n",tai_diff(packet->embargo,tai_now()));
queue_enqueue("embargo",&addr->sendQ,&packet->DL,0);
}
}
return(0);
}

1
iguana/main.c

@ -188,6 +188,7 @@ char *SuperNET_p2p(struct iguana_info *coin,int32_t *delaymillisp,char *ipaddr,u
return(retstr);
}
#include <signal.h>
void sigint_func() { printf("SIGINT\n"); exit(0); }
void sigillegal_func() { printf("SIGILL\n"); exit(0); }
void sighangup_func() { printf("SIGHUP\n"); exit(0); }

2
includes/iguana_apideclares.h

@ -17,7 +17,7 @@ ZERO_ARGS(SuperNET,help);
TWO_STRINGS(SuperNET,html,agentform,htmlfile);
STRING_ARG(SuperNET,bitcoinrpc,setcoin);
STRING_ARG(SuperNET,getpeers,activecoin);
STRING_ARG(SuperNET,mypeers,jsonstr);
TWO_ARRAYS(SuperNET,mypeers,supernet,rawpeers);
STRING_ARG(iguana,peers,activecoin);
STRING_AND_INT(iguana,maxpeers,activecoin,max);

Loading…
Cancel
Save