@@ -274,6 +274,7 @@ Aggregator::Aggregator(const string &keypair, uint64_t epoch, uint32_t channel_i
274
274
last_known_block ((uint64_t )-1), epoch(epoch), channel_id(channel_id)
275
275
{
276
276
memset (session_key, ' \0 ' , sizeof (session_key));
277
+ memset (session_hash, ' \0 ' , sizeof (session_hash));
277
278
278
279
FILE *fp;
279
280
if ((fp = fopen (keypair.c_str (), " r" )) == NULL )
@@ -571,6 +572,8 @@ void Aggregator::process_packet(const uint8_t *buf, size_t size, uint8_t wlan_id
571
572
uint8_t bandwidth, sockaddr_in *sockaddr)
572
573
{
573
574
uint8_t session_tmp[MAX_SESSION_PACKET_SIZE - crypto_box_MACBYTES - sizeof (wsession_hdr_t )];
575
+ uint8_t new_session_hash[sizeof (session_hash)];
576
+
574
577
wsession_data_t * new_session_data = NULL ;
575
578
// size_t new_session_tags_size = 0;
576
579
@@ -608,6 +611,24 @@ void Aggregator::process_packet(const uint8_t *buf, size_t size, uint8_t wlan_id
608
611
return ;
609
612
}
610
613
614
+ if (crypto_generichash (new_session_hash,
615
+ sizeof (new_session_hash),
616
+ buf + sizeof (wsession_hdr_t ),
617
+ size - sizeof (wsession_hdr_t ),
618
+ ((wsession_hdr_t *)buf)->session_nonce ,
619
+ sizeof (((wsession_hdr_t *)buf)->session_nonce )) != 0 )
620
+ {
621
+ // Should newer happened
622
+ assert (0 );
623
+ }
624
+
625
+ if (memcmp (session_hash, new_session_hash, sizeof (session_hash)) == 0 )
626
+ {
627
+ // Session is equal to current so we can ignore it
628
+ count_p_session += 1 ;
629
+ return ;
630
+ }
631
+
611
632
if (crypto_box_open_easy ((uint8_t *)session_tmp,
612
633
buf + sizeof (wsession_hdr_t ),
613
634
size - sizeof (wsession_hdr_t ),
@@ -678,6 +699,9 @@ void Aggregator::process_packet(const uint8_t *buf, size_t size, uint8_t wlan_id
678
699
IPC_MSG_SEND ();
679
700
}
680
701
702
+ // Cache already processed session session
703
+ memcpy (session_hash, new_session_hash, sizeof (session_hash));
704
+
681
705
return ;
682
706
683
707
default :
0 commit comments