#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 using namespace std; /* 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){} }; void writeToDisk(time_t s, uint64_t sourceid, std::string_view message) { auto path = getPath(g_storagedir, s, sourceid, true); int fd = open(path.c_str(), O_CREAT | O_WRONLY | O_APPEND, 0600); if(fd < 0) { throw FatalException("Unable to open file for storage: "+string(strerror(errno))); } int res = write(fd, &message[0], message.size()); if(res < 0) { close(fd); throw FatalException("Unable to open file for storage: "+string(strerror(errno))); } if((unsigned int)res != message.size()) { close(fd); throw FatalException("Partial write to storage"); } close(fd); } void recvSession(int s, ComboAddress client) { try { Socket sock(s); cerr<<"Receiving messages from "<