#include "comboaddress.hh" #include "sclasses.hh" #include #include #include "navmon.pb.h" #include "fmt/format.h" #include "fmt/printf.h" #include #include "storage.hh" #include #include #include #include #include "CLI/CLI.hpp" #include "version.hh" static char program[]="navrecv"; using namespace std; extern const char* g_gitHash; /* Goals in life: 1) NEVER EVER GO DOWN 2) Receive all frames without thinking (see 1) 3) Put the frames in a scalable directory structure */ string g_storagedir="./storage/"; struct FatalException : public std::runtime_error { FatalException(const std::string& str) : std::runtime_error(str){} }; int getfd(const char* path, int mode, int permission) { struct FileID { string path; int mode; int permission; bool operator<(const FileID& rhs) const { return std::tie(path, mode, permission) < std::tie(rhs.path, rhs.mode, rhs. permission); } }; struct FDID { explicit FDID(int fd_) { fd = fd_; lastUsed = time(0); } FDID(const FDID& rhs) = delete; FDID& operator=(const FDID& rhs) = delete; FDID(FDID&& rhs) { fd = rhs.fd; lastUsed = rhs.lastUsed; rhs.fd = -1; } ~FDID() { if(fd >= 0) { cout<<"Closing fd "< lock(mut); static map fds; // do some cleanup time_t now = time(0); for(auto iter = fds.begin(); iter != fds.end(); ) { if(now - iter->second.lastUsed > 60) { cout<<"Found stale entry for "<first.path< 0) { cout<<"Need to erase "<second.lastUsed = time(0); return iter->second.fd; } // cout<<"Did not find it, first doing some cleaning"<