Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions reflector/AudioRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstring>
#include <ctime>
#include <sstream>
#include <random>

// Opus settings for Voice 8kHz Mono
#define SAMPLE_RATE 8000
Expand Down Expand Up @@ -41,10 +42,15 @@ std::string CAudioRecorder::Start(const std::string& directory)
std::lock_guard<std::mutex> lock(m_Mutex);
Cleanup();

// Use random_device for true randomness/seed
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<uint16_t> dist(0, 255);

// Generate UUIDv7 Filename
uint8_t uuid[16];
uint8_t rand_bytes[10];
for(int i=0; i<10; ++i) rand_bytes[i] = std::rand() & 0xFF; // Minimal entropy for now
for(int i=0; i<10; ++i) rand_bytes[i] = (uint8_t)dist(gen);

struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
Expand All @@ -68,7 +74,7 @@ std::string CAudioRecorder::Start(const std::string& directory)
}

InitOpus();
InitOgg();
InitOgg(); // No longer calls srand

m_StartTime = std::time(nullptr);
m_TotalBytes = 0;
Expand All @@ -91,8 +97,12 @@ void CAudioRecorder::InitOpus()
void CAudioRecorder::InitOgg()
{
// Initialize Ogg stream with random serial
std::srand(std::time(nullptr));
if (ogg_stream_init(&m_OggStream, std::rand()) != 0) {
// Use random_device for thread safety
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> dist; // full int range

if (ogg_stream_init(&m_OggStream, dist(gen)) != 0) {
std::cerr << "AudioRecorder: Failed to init Ogg stream" << std::endl;
return;
}
Expand Down Expand Up @@ -169,6 +179,7 @@ void CAudioRecorder::WriteOggPage(bool flush)
m_File.write((const char*)m_OggPage.header, m_OggPage.header_len);
m_File.write((const char*)m_OggPage.body, m_OggPage.body_len);
m_TotalBytes += m_OggPage.header_len + m_OggPage.body_len;
m_File.flush();
}
}

Expand Down
15 changes: 14 additions & 1 deletion reflector/DMRMMDVMProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#include <string.h>

#include <iostream>
#include <map>
#include <ctime>
#include <iomanip>
#include "Global.h"
#include "DMRMMDVMClient.h"
#include "DMRMMDVMProtocol.h"
Expand Down Expand Up @@ -677,7 +681,16 @@ bool CDmrmmdvmProtocol::IsValidDvFramePacket(const CIp &Ip, const CBuffer &Buffe
if ( !stream )
{
std::cout << std::showbase << std::hex;
std::cout << "Late entry DMR voice frame, creating DMR header for DMR stream ID " << ntohl(uiStreamId) << std::noshowbase << std::dec << " on " << Ip << std::endl;
static std::map<uint32_t, std::time_t> last_late_entry;
std::time_t now = std::time(nullptr);
uint32_t sid = ntohl(uiStreamId);

if (last_late_entry.find(sid) == last_late_entry.end() || (now - last_late_entry[sid]) > 60) {
std::cout << "Late entry DMR voice frame, creating DMR header for DMR stream ID " << std::hex << std::showbase << sid
<< std::noshowbase << std::dec << " on " << Ip
<< " (Suppressed for 60s)" << std::endl;
last_late_entry[sid] = now;
}
std::cout << std::noshowbase << std::dec;
uint8_t cmd;

Expand Down
16 changes: 15 additions & 1 deletion reflector/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#include <iostream>
#include <map>
#include <ctime>
#include <iomanip>
#include "Defines.h"
#include "Global.h"
#include "Protocol.h"
Expand Down Expand Up @@ -142,7 +146,17 @@ void CProtocol::OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &Frame, const
else
{
std::cout << std::showbase << std::hex;
std::cout << "Orphaned Frame with ID " << ntohs(Frame->GetStreamId()) << std::noshowbase << std::dec << " on " << *Ip << std::endl;
// Rate limit warnings: only log once every 60 seconds per stream ID
static std::map<uint16_t, std::time_t> last_warning;
std::time_t now = std::time(nullptr);
uint16_t sid = ntohs(Frame->GetStreamId());

if (last_warning.find(sid) == last_warning.end() || (now - last_warning[sid]) > 60) {
std::cout << "Orphaned Frame with ID " << std::hex << std::showbase << sid
<< std::noshowbase << std::dec << " on " << *Ip
<< " (Suppressed for 60s)" << std::endl;
last_warning[sid] = now;
}
Frame.reset();
}
//#endif
Expand Down