|
@ -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 |
|
|