Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
c03045fce1
  1. 4
      crypto777/nanosrc/core/sock.c
  2. 2
      crypto777/nanosrc/nn_config.h
  3. 52
      iguana/SuperNET.c
  4. 5
      iguana/SuperNET.h

4
crypto777/nanosrc/core/sock.c

@ -478,7 +478,7 @@ int nn_sock_add_ep(struct nn_sock *self,struct nn_transport *transport,int32_t b
{ {
int rc,eid; struct nn_ep *ep; int rc,eid; struct nn_ep *ep;
nn_ctx_enter (&self->ctx); nn_ctx_enter (&self->ctx);
if ( (ep= nn_find_ep(self,0,addr,transport,bind)) == NULL ) // The endpoint doesn't exist //if ( (ep= nn_find_ep(self,0,addr,transport,bind)) == NULL ) // The endpoint doesn't exist
{ {
ep = nn_alloc(sizeof(struct nn_ep),"endpoint"); // Instantiate the endpoint ep = nn_alloc(sizeof(struct nn_ep),"endpoint"); // Instantiate the endpoint
rc = nn_ep_init(ep,NN_SOCK_SRC_EP,self,self->eid,transport,bind,addr); rc = nn_ep_init(ep,NN_SOCK_SRC_EP,self,self->eid,transport,bind,addr);
@ -493,7 +493,7 @@ int nn_sock_add_ep(struct nn_sock *self,struct nn_transport *transport,int32_t b
eid = self->eid++; // Increase the endpoint ID for the next endpoint eid = self->eid++; // Increase the endpoint ID for the next endpoint
nn_list_insert(&self->eps,&ep->item,nn_list_end(&self->eps)); // Add to the list of active endpoints nn_list_insert(&self->eps,&ep->item,nn_list_end(&self->eps)); // Add to the list of active endpoints
nn_ctx_leave (&self->ctx); nn_ctx_leave (&self->ctx);
} else PNACL_message("self->sock.(%s) %p already has (%s)\n",self->socket_name,self->sockbase->sock,addr); } //else PNACL_message("self->sock.(%s) %p already has (%s)\n",self->socket_name,self->sockbase->sock,addr);
return(ep->eid); return(ep->eid);
} }

2
crypto777/nanosrc/nn_config.h

@ -62,7 +62,7 @@ void PNACL_message(const char* format, ...);
/* Size of the buffer used for batch-reads of inbound data. To keep the /* Size of the buffer used for batch-reads of inbound data. To keep the
performance optimal make sure that this value is larger than network MTU. */ performance optimal make sure that this value is larger than network MTU. */
#define NN_USOCK_BATCH_SIZE (65536) #define NN_USOCK_BATCH_SIZE (2048)
//#define NN_USOCK_BATCH_SIZE (_NN_USOCK_BATCH_SIZE - 5 - 256 - 16) // adjust for veclen/clen + sizeof(ctrl) //#define NN_USOCK_BATCH_SIZE (_NN_USOCK_BATCH_SIZE - 5 - 256 - 16) // adjust for veclen/clen + sizeof(ctrl)
#define NN_USE_MYMSG 1 #define NN_USE_MYMSG 1

52
iguana/SuperNET.c

@ -529,18 +529,18 @@ int32_t SuperNET_reqhandler(struct supernet_info *myinfo,struct supernet_msghdr
int32_t SuperNET_LBrequest(struct supernet_info *myinfo,bits256 *dest,uint8_t type,char *agent,uint8_t func,uint8_t *data,int32_t datalen,int32_t duration) int32_t SuperNET_LBrequest(struct supernet_info *myinfo,bits256 *dest,uint8_t type,char *agent,uint8_t func,uint8_t *data,int32_t datalen,int32_t duration)
{ {
struct supernet_msghdr *msg,*retmsg; int32_t sendlen,recvlen,sock; uint32_t nonce; struct supernet_msghdr *msg,*retmsg; int32_t sendlen,recvlen,sock; uint32_t nonce;
if ( (sock= myinfo->reqsock) < 0 ) if ( (sock= myinfo->reqsocks[rand() % (sizeof(myinfo->reqsocks)/sizeof(*myinfo->reqsocks))]) < 0 )
{ {
printf("SuperNET_LBrequest no reqsock for.(%s)\n",agent); printf("SuperNET_LBrequest no reqsock for.(%s)\n",agent);
return(-1); return(-1);
} }
if ( myinfo->recvbuf[1] == 0 ) if ( myinfo->recvbuf[1] == 0 )
myinfo->recvbuf[1] = calloc(1,SUPERNET_MAXRECVBUF+sizeof(*msg)); myinfo->recvbuf[1] = calloc(1,SUPERNET_MAXRECVBUF+sizeof(*msg));
if ( myinfo->recvbuf[4] == 0 ) if ( myinfo->recvbuf[SUPERNET_REQSOCKS*2] == 0 )
myinfo->recvbuf[4] = calloc(1,SUPERNET_MAXRECVBUF+sizeof(*msg)); myinfo->recvbuf[SUPERNET_REQSOCKS*2] = calloc(1,SUPERNET_MAXRECVBUF+sizeof(*msg));
if ( myinfo->recvbuf[5] == 0 ) if ( myinfo->recvbuf[SUPERNET_REQSOCKS*2+1] == 0 )
myinfo->recvbuf[5] = calloc(1,SUPERNET_MAXRECVBUF+sizeof(*msg)); myinfo->recvbuf[SUPERNET_REQSOCKS*2+1] = calloc(1,SUPERNET_MAXRECVBUF+sizeof(*msg));
msg = (void *)myinfo->recvbuf[4]; msg = (void *)myinfo->recvbuf[SUPERNET_REQSOCKS*2];
if ( (sendlen= SuperNET_send(myinfo,sock,dest,type,msg,agent,func,data,datalen,duration,0)) == datalen+sizeof(*msg) ) if ( (sendlen= SuperNET_send(myinfo,sock,dest,type,msg,agent,func,data,datalen,duration,0)) == datalen+sizeof(*msg) )
{ {
retmsg = (void *)myinfo->recvbuf[1]; retmsg = (void *)myinfo->recvbuf[1];
@ -633,15 +633,32 @@ void SuperNET_subloop(void *args)
void SuperNET_loop(void *args) void SuperNET_loop(void *args)
{ {
struct supernet_info *myinfo = args; static int counter;
printf("start SuperNET_loop\n"); int32_t myid; struct supernet_info *myinfo = args;
myid = ++counter;
printf("start SuperNET_loop[%d]\n",myid);
while ( myinfo->LBsock >= 0 ) while ( myinfo->LBsock >= 0 )
{ {
SuperNET_recv(myinfo,myinfo->LBsock,1); // req SuperNET_recv(myinfo,myinfo->LBsock,myid); // req
//printf("SuperNET_loop\n"); //printf("SuperNET_loop\n");
} }
} }
void SuperNET_testloop(void *args)
{
static int counter;
int32_t i,myid; struct supernet_info *myinfo = args;
double startmillis = OS_milliseconds();
myid = ++counter;
printf("start testloop %d\n",myid);
for (i=0; i<512; i++)
{
SuperNET_LBrequest(myinfo,0,'A',SUPERNET_PANGEA,0,0,0,0);
printf("%d.%d: %.3f [%.4f]\n",myid,i,OS_milliseconds() - startmillis,(OS_milliseconds() - startmillis)/(i+1));
//sleep(10);
}
}
void SuperNET_init(struct supernet_info *myinfo,uint16_t PUBport,uint16_t LBport) void SuperNET_init(struct supernet_info *myinfo,uint16_t PUBport,uint16_t LBport)
{ {
int32_t i,sendtimeout,recvtimeout,len,c; int64_t allocsize; char *ipaddr; int32_t i,sendtimeout,recvtimeout,len,c; int64_t allocsize; char *ipaddr;
@ -676,10 +693,18 @@ void SuperNET_init(struct supernet_info *myinfo,uint16_t PUBport,uint16_t LBport
} else myinfo->subsock = -1; } else myinfo->subsock = -1;
if ( (myinfo->LBport= LBport) != 0 ) if ( (myinfo->LBport= LBport) != 0 )
{ {
myinfo->reqsock = nn_reqsocket(myinfo,myinfo->LBport,myinfo->PUBport,myinfo->subsock,60000); for (i=0; i<SUPERNET_REQSOCKS; i++)
{
myinfo->reqsocks[i] = nn_reqsocket(myinfo,myinfo->LBport,myinfo->PUBport,myinfo->subsock,60000);
}
for (i=0; i<SUPERNET_REQSOCKS; i++)
iguana_launch(iguana_coinadd("BTCD"),"SuperNET_testloop",SuperNET_testloop,myinfo,IGUANA_PERMTHREAD);
if ( ipaddr != 0 ) if ( ipaddr != 0 )
myinfo->LBsock = nn_createsocket(myinfo,myinfo->LBpoint,1,"NN_REP",NN_REP,myinfo->LBport,sendtimeout,0*recvtimeout); myinfo->LBsock = nn_createsocket(myinfo,myinfo->LBpoint,1,"NN_REP",NN_REP,myinfo->LBport,sendtimeout,0*recvtimeout);
} else myinfo->reqsock = -1; }
else
for (i=0; i<SUPERNET_REQSOCKS; i++)
myinfo->reqsocks[i] = -1;
iguana_launch(iguana_coinadd("BTCD"),"SuperNET_sub",SuperNET_subloop,myinfo,IGUANA_PERMTHREAD); iguana_launch(iguana_coinadd("BTCD"),"SuperNET_sub",SuperNET_subloop,myinfo,IGUANA_PERMTHREAD);
if ( myinfo->LBsock >= 0 || myinfo->PUBsock >= 0 ) if ( myinfo->LBsock >= 0 || myinfo->PUBsock >= 0 )
{ {
@ -691,7 +716,7 @@ void SuperNET_init(struct supernet_info *myinfo,uint16_t PUBport,uint16_t LBport
sleep(10); sleep(10);
}*/ }*/
} }
else if ( 1 ) else if ( 0 )
{ {
double startmillis = OS_milliseconds(); double startmillis = OS_milliseconds();
for (i=0; i<1825; i++) for (i=0; i<1825; i++)
@ -701,7 +726,8 @@ void SuperNET_init(struct supernet_info *myinfo,uint16_t PUBport,uint16_t LBport
//sleep(10); //sleep(10);
} }
} }
printf("%s LBsock.%d %d, %s PUBsock.%d %d\n",myinfo->LBpoint,myinfo->LBsock,myinfo->reqsock,myinfo->PUBpoint,myinfo->PUBsock,myinfo->subsock); printf("%s LBsock.%d %d, %s PUBsock.%d %d\n",myinfo->LBpoint,myinfo->LBsock,myinfo->reqsocks[0],myinfo->PUBpoint,myinfo->PUBsock,myinfo->subsock);
getchar();
} }
#endif #endif

5
iguana/SuperNET.h

@ -67,6 +67,7 @@ struct supernet_agent
}; };
struct supernet_address { bits256 pubkey; }; struct supernet_address { bits256 pubkey; };
#define SUPERNET_REQSOCKS 64
struct supernet_info struct supernet_info
{ {
@ -74,9 +75,9 @@ struct supernet_info
int32_t Debuglevel,readyflag,dead,POLLTIMEOUT; char rpcsymbol[16],LBpoint[64],PUBpoint[64]; int32_t Debuglevel,readyflag,dead,POLLTIMEOUT; char rpcsymbol[16],LBpoint[64],PUBpoint[64];
//int32_t pullsock,subclient,lbclient,lbserver,servicesock,pubglobal,pubrelays,numservers; //int32_t pullsock,subclient,lbclient,lbserver,servicesock,pubglobal,pubrelays,numservers;
bits256 privkey; bits256 privkey;
uint8_t *recvbuf[6]; uint8_t *recvbuf[(SUPERNET_REQSOCKS+2)*2];
struct supernet_address myaddr; struct supernet_address myaddr;
int32_t LBsock,PUBsock,reqsock,subsock,networktimeout; int32_t LBsock,PUBsock,reqsocks[SUPERNET_REQSOCKS],subsock,networktimeout;
uint16_t LBport,PUBport,reqport,subport; uint16_t LBport,PUBport,reqport,subport;
struct nn_pollfd pfd[SUPERNET_MAXAGENTS]; //struct relay_info active; struct nn_pollfd pfd[SUPERNET_MAXAGENTS]; //struct relay_info active;
struct supernet_agent agents[SUPERNET_MAXAGENTS]; queue_t acceptQ; int32_t numagents; struct supernet_agent agents[SUPERNET_MAXAGENTS]; queue_t acceptQ; int32_t numagents;

Loading…
Cancel
Save