Browse Source

Test

etomic
jl777 7 years ago
parent
commit
9b57afb323
  1. 3
      iguana/exchanges/LP_nativeDEX.c
  2. 18
      iguana/exchanges/LP_network.c

3
iguana/exchanges/LP_nativeDEX.c

@ -299,6 +299,9 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
else printf("%s got recv.%d\n",typestr,recvlen); else printf("%s got recv.%d\n",typestr,recvlen);
#endif #endif
double millis = OS_milliseconds(); double millis = OS_milliseconds();
if ( strlen((char *)ptr)+sizeof(bits256) <= recvlen )
if ( LP_magic_check(ptr,recvlen) < 0 )
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);
if ( Broadcaststr != 0 ) if ( Broadcaststr != 0 )

18
iguana/exchanges/LP_network.c

@ -166,13 +166,29 @@ bits256 LP_calc_magic(uint8_t *msg,int32_t len)
{ {
magic = rand256(1); magic = rand256(1);
pubkey = curve25519(magic,curve25519_basepoint9()); pubkey = curve25519(magic,curve25519_basepoint9());
shared = curve25519(magic,pubkey); shared = curve25519(hash,pubkey);
if ( shared.bytes[1] == LP_BARTERDEX_VERSION ) if ( shared.bytes[1] == LP_BARTERDEX_VERSION )
break; break;
} }
return(magic); return(magic);
} }
int32_t LP_magic_check(uint8_t *msg,int32_t recvlen)
{
bits256 magic,hash,pubkey,shared;
recvlen -= sizeof(bits256);
if ( recvlen > 0 )
{
vcalc_sha256(0,hash.bytes,msg,recvlen);
memcpy(magic.bytes,&msg[recvlen],sizeof(magic));
pubkey = curve25519(magic,curve25519_basepoint9());
shared = curve25519(hash,pubkey);
printf("shared.[1] = %d\n",shared.bytes[1]);
return(shared.bytes[1] == LP_BARTERDEX_VERSION);
}
return(-1);
}
int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32)
{ {
static uint32_t crcs[1024]; static unsigned long dup,total; static uint32_t crcs[1024]; static unsigned long dup,total;

Loading…
Cancel
Save