@@ -274,6 +274,7 @@ Aggregator::Aggregator(const string &keypair, uint64_t epoch, uint32_t channel_i
274274 last_known_block ((uint64_t )-1), epoch(epoch), channel_id(channel_id)
275275{
276276 memset (session_key, ' \0 ' , sizeof (session_key));
277+ memset (session_hash, ' \0 ' , sizeof (session_hash));
277278
278279 FILE *fp;
279280 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
571572 uint8_t bandwidth, sockaddr_in *sockaddr)
572573{
573574 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+
574577 wsession_data_t * new_session_data = NULL ;
575578 // size_t new_session_tags_size = 0;
576579
@@ -608,6 +611,24 @@ void Aggregator::process_packet(const uint8_t *buf, size_t size, uint8_t wlan_id
608611 return ;
609612 }
610613
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+
611632 if (crypto_box_open_easy ((uint8_t *)session_tmp,
612633 buf + sizeof (wsession_hdr_t ),
613634 size - sizeof (wsession_hdr_t ),
@@ -678,6 +699,9 @@ void Aggregator::process_packet(const uint8_t *buf, size_t size, uint8_t wlan_id
678699 IPC_MSG_SEND ();
679700 }
680701
702+ // Cache already processed session
703+ memcpy (session_hash, new_session_hash, sizeof (session_hash));
704+
681705 return ;
682706
683707 default :
0 commit comments