You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
3.2 KiB

9 years ago
/******************************************************************************
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "iguana777.h"
int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 category,bits256 subhash,char *hexmsg,int32_t addflag)
9 years ago
{
static int lastpurge; static uint64_t Packetcache[1024];
bits256 packethash; int32_t i,datalen;
datalen = (int32_t)strlen(hexmsg) + 1;
vcalc_sha256(0,packethash.bytes,(void *)hexmsg,datalen);
if ( bits256_nonz(category) == 0 )
category = GENESIS_PUBKEY;
if ( bits256_nonz(subhash) == 0 )
subhash = GENESIS_PUBKEY;
packethash = curve25519(category,packethash);
9 years ago
//printf("addflag.%d packethash.%llx dest.%llx\n",addflag,(long long)packethash.txid,(long long)category.txid);
9 years ago
for (i=0; i<sizeof(Packetcache)/sizeof(*Packetcache); i++)
{
if ( Packetcache[i] == 0 )
{
if ( addflag != 0 )
{
Packetcache[i] = packethash.txid;
9 years ago
//printf("add.%llx packetcache(%s) -> slot[%d]\n",(long long)packethash.txid,hexmsg,i);
9 years ago
}
break;
}
else if ( Packetcache[i] == packethash.txid )
{
9 years ago
printf("SuperNET_DHTsend reject duplicate packet.%llx\n",(long long)packethash.txid);
9 years ago
return(i);
9 years ago
}
}
if ( i == sizeof(Packetcache)/sizeof(*Packetcache) )
{
if ( addflag != 0 )
{
printf("purge slot[%d]\n",lastpurge);
Packetcache[lastpurge++] = packethash.txid;
if ( lastpurge >= sizeof(Packetcache)/sizeof(*Packetcache) )
lastpurge = 0;
}
}
9 years ago
return(-1);
9 years ago
}
void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 category,bits256 subhash,char *hexmsg,struct tai now)
9 years ago
{
char str[512],str2[65];
if ( memcmp(category.bytes,GENESIS_PUBKEY.bytes,sizeof(category)) == 0 )
strcpy(str,"BROADCAST.");
else bits256_str(str,category);
if ( memcmp(subhash.bytes,GENESIS_PUBKEY.bytes,sizeof(subhash)) != 0 )
{
bits256_str(str2,subhash);
strcat(str,str2);
}
9 years ago
category_posthexmsg(myinfo,category,subhash,hexmsg,now);
9 years ago
//printf("HEXMSG.(%s) -> %s\n",hexmsg,str);
9 years ago
}