Browse Source

Test

etomic
jl777 7 years ago
parent
commit
e2c3f2d5fc
  1. 2
      iguana/exchanges/LP_nativeDEX.c
  2. 10
      iguana/exchanges/LP_network.c

2
iguana/exchanges/LP_nativeDEX.c

@ -300,7 +300,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
#endif #endif
double millis = OS_milliseconds(); double millis = OS_milliseconds();
if ( strlen((char *)ptr)+sizeof(bits256) <= recvlen ) if ( strlen((char *)ptr)+sizeof(bits256) <= recvlen )
if ( LP_magic_check(ptr,recvlen) < 0 ) if ( LP_magic_check(ptr,recvlen,remoteaddr) <= 0 )
printf("magic check error\n"); printf("magic check error\n");
if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 )
free(retstr); free(retstr);

10
iguana/exchanges/LP_network.c

@ -168,7 +168,7 @@ uint32_t _LP_magic_check(bits256 hash,bits256 magic)
bits256 LP_calc_magic(uint8_t *msg,int32_t len) bits256 LP_calc_magic(uint8_t *msg,int32_t len)
{ {
static uint32_t maxn,counter; static double sum; static uint32_t maxn,counter,nsum; static double sum;
bits256 magic,hash; int32_t n = 0; double millis; bits256 magic,hash; int32_t n = 0; double millis;
millis = OS_milliseconds(); millis = OS_milliseconds();
vcalc_sha256(0,hash.bytes,msg,len); vcalc_sha256(0,hash.bytes,msg,len);
@ -180,6 +180,7 @@ bits256 LP_calc_magic(uint8_t *msg,int32_t len)
n++; n++;
} }
sum += (OS_milliseconds() - millis); sum += (OS_milliseconds() - millis);
nsum += n;
counter++; counter++;
if ( n > maxn || (rand() % 100) == 0 ) if ( n > maxn || (rand() % 100) == 0 )
{ {
@ -188,12 +189,12 @@ bits256 LP_calc_magic(uint8_t *msg,int32_t len)
printf("LP_calc_magic maxn.%d <- %d\n",maxn,n); printf("LP_calc_magic maxn.%d <- %d\n",maxn,n);
maxn = n; maxn = n;
} }
printf("millis %.3f ave %.3f\n",OS_milliseconds() - millis,sum/counter); printf("millis %.3f ave %.3f, aveiters %.1f\n",OS_milliseconds() - millis,sum/counter,(double)nsum/counter);
} }
return(magic); return(magic);
} }
int32_t LP_magic_check(uint8_t *msg,int32_t recvlen) int32_t LP_magic_check(uint8_t *msg,int32_t recvlen,char *remoteaddr)
{ {
bits256 magic,hash; uint32_t val; bits256 magic,hash; uint32_t val;
recvlen -= sizeof(bits256); recvlen -= sizeof(bits256);
@ -202,7 +203,8 @@ int32_t LP_magic_check(uint8_t *msg,int32_t recvlen)
vcalc_sha256(0,hash.bytes,msg,recvlen); vcalc_sha256(0,hash.bytes,msg,recvlen);
memcpy(magic.bytes,&msg[recvlen],sizeof(magic)); memcpy(magic.bytes,&msg[recvlen],sizeof(magic));
val = _LP_magic_check(hash,magic); val = _LP_magic_check(hash,magic);
printf("magicval = %x\n",val); if ( val != LP_BARTERDEX_VERSION )
printf("magicval = %x from %s\n",val,remoteaddr);
return(val == LP_BARTERDEX_VERSION); return(val == LP_BARTERDEX_VERSION);
} }
return(-1); return(-1);

Loading…
Cancel
Save