ReplicationClients/Makefile.am SUBDIRS = src ReplicationClients/build-aux/dir_use.txt This directory is used to store autoconf script files. It should be automatically populated with "autoreconf -i"...

Instructions are attached, along with everything else needed. No particular referencing style needed i.e. mla, harvard, etc.



ReplicationClients/Makefile.am SUBDIRS = src ReplicationClients/build-aux/dir_use.txt This directory is used to store autoconf script files. It should be automatically populated with "autoreconf -i" ReplicationClients/configure.ac # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS]) AC_CONFIG_SRCDIR([src/FileDesc.cpp]) AC_CONFIG_HEADERS([include/config.h]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) # Checks for programs. AC_PROG_CXX AC_PROG_CC # Checks for header files. AC_CHECK_HEADERS([arpa/inet.h fcntl.h netinet/in.h stdlib.h string.h strings.h sys/socket.h termios.h unistd.h]) # Checks for typedefs, structures, and compiler characteristics. AC_CHECK_HEADER_STDBOOL AC_TYPE_SSIZE_T AC_TYPE_UINT32_T AC_TYPE_UINT8_T # Checks for library functions. AC_CHECK_FUNCS([bzero socket strtol select]) AC_CHECK_LIB([crypto++], [main], [], [ echo "You are missing libcrypto++. It is required for link AES encryption." exit -1; ]) AM_INIT_AUTOMAKE([subdir-objects -Wall]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT ReplicationClients/data/SingleDroneN1.bin ReplicationClients/data/SingleDroneN2.bin ReplicationClients/data/SingleDroneN3.bin ReplicationClients/data/ThreeDronesN1.bin ReplicationClients/data/ThreeDronesN2.bin ReplicationClients/data/ThreeDronesN3.bin ReplicationClients/data/dir_use.txt This directory is used to store autoconf macro files. It might have specialized scripts in it for some of the homeworks. ReplicationClients/include/ALMgr.h #ifndef ALMGR_H #define ALMGR_H #include /******************************************************************************** * ALMgr - Access List manager, basically reads from a text document to find the * IP address given. If it's a whitelist, then returns true for allowed * if found and opposite for blacklists ********************************************************************************/ class ALMgr { public: ALMgr(const char *al_file, bool is_whitelist = true); ~ALMgr(); bool isAllowed(const char *ipaddr); bool isAllowed(unsigned long ipaddr); private: std::string _al_file; bool _is_whitelist; }; #endif // ALMGR_H ReplicationClients/include/AntennaSim.h #ifndef ANTENNASIM_H #define ANTENNASIM_H #include #include #include "exceptions.h" #include "DronePlotDB.h" // Simulates an antenna receiving drone information and populates the DronePlotDB class as it "receives" // information. // // Students should not change anything with this class class AntennaSim { public: AntennaSim(DronePlotDB &dpdb, const char *source_filename, float time_mult, int verbosity); virtual ~AntennaSim(); // Load the data that will be fed to the accessible DB to simulate drone updates void loadSourceDB(const char *filename); // Run the simulation (usually in a thread) void simulate(); // Terminate the simulation (and probably exit the thread) void terminate() { _exiting = true; }; // Are we in the process of exiting the simulation? bool isExiting() { return _exiting; }; int getOffset(); private: double getAdjustedTime(); // Simulation checks periodically to know when to exit the thread bool _exiting; DronePlotDB &_to_db; DronePlotDB _source_db; float _time_mult; int _time_offset; int _verbosity; pthread_mutex_t _offset_mutex; time_t _start_time; }; #endif ReplicationClients/include/DronePlotDB.h #ifndef DRONEPLOTDB_H #define DRONEPLOTDB_H #include #include #include #include #include "exceptions.h" // Flags for the DronePlot object. The first two are already coded in and // you can define more. It's based off bitwise and/or operations so just // create a new one up to 0x128 #define DBFLAG_NEW 0x1 // Was newly added to the database #define DBFLAG_SYNCD 0x2 // Has been sync'd #define DBFLAG_USER1 0x4 // Change as needed #define DBFLAG_USER2 0x8 // Change as needed #define DBFLAG_USER3 0x16 // Change as needed #define DBFLAG_USER4 0x32 // Manages the drone plot database for a particular node. class DronePlot { public: DronePlot(); DronePlot(int in_droneid, int in_nodeid, int in_timestamp, float in_latitude, float in_longitude); virtual ~DronePlot(); // Function to serialize, or convert this data into a binary stream in a vector class and back void serialize(std::vector &buf); void deserialize(std::vector &buf, unsigned int start_pt = 0); // Reads and writes this plot to/from a buffer in comma-separated format int readCSV(std::string &buf); void writeCSV(std::string &buf); static size_t getDataSize(); // Num of bytes required to store the data (for serialization) // Flag manipulation -- pass in a define above as in setFlags(DBFLAG_NEW); void setFlags(unsigned short flags); void clrFlags(unsigned short flags); bool isFlagSet(unsigned short flags); // attributes - freely accessible to modify as needed unsigned int drone_id; unsigned int node_id; time_t timestamp; float latitude; float longitude; private: unsigned short _flags; }; /************************************************************************************************** * DronePlotDB - class to manage a database of DronePlot objects, which manage drone GPS plots that * are "received" by the antenna or another replication server * **************************************************************************************************/ class DronePlotDB { public: DronePlotDB(); virtual ~DronePlotDB(); // Add a plot to the database with the given attributes (mutex'd) void addPlot(int drone_id, int node_id, time_t timestamp, float lattitude, float longitude); // Load or write the database to/from a CSV file, int loadCSVFile(const char *filename); int writeCSVFile(const char *filename); // Direct binary load/write to/from the specified file int loadBinaryFile(const char *filename); int writeBinaryFile(const char *filename); // Sort the database in order of timestamp void sortByTime(); // Remove all plotpoints of a particular node (used to generate binary, not for student use) void removeNodeID(unsigned int node_id); // Iterators for simple access to the database. Can use these to modify drone plot points // but won't be able to add/delete PlotObjects. Use erase (below) for that as it is mutex'd std::list::iterator begin() { return _dbdata.begin(); }; std::list::iterator end() { return _dbdata.end(); }; // Manipulate database entries (mutex'd functions) void popFront(); void erase(unsigned int i); std::list::iterator erase(std::list::iterator dptr); // Return the number of plot points stored size_t size() { return _dbdata.size(); }; // Wipe the database void clear(); private: std::list _dbdata; pthread_mutex_t _mutex; }; #endif ReplicationClients/include/FileDesc.h #ifndef FILEDESC_H #define FILEDESC_H #include #include #include #include #include #include "exceptions.h" // Manages File Descriptors by largely simplfying their interfaces for specific purposes. // FileDesc provides some limited functionality and could be instantiated, but child // classes may provide specialized capability. These include: // // SocketFD - Network socket FD with stored IP/port information in sockaddr_in // TermFD - Stdin terminal // FileFD - non-buffered file FD with ability to write/read binary data class FileDesc { public: FileDesc(); virtual ~FileDesc(); // Ensures certain functions do not block void setNonBlocking(); // Basic write function to write data to the FD ssize_t writeFD(std::string &str); ssize_t writeFD(const char *data); ssize_t writeFD(const char *data, unsigned int len); // Basic read function to read all string data off the FD ssize_t readFD(std::string &buf); // Reads one character from the buffer at a time until it finds a newline ssize_t readStr(std::string &buf); // Read a single byte from the FD ssize_t readByte(unsigned char &buf); // Writes a single byte to the FD ssize_t writeByte(unsigned char data); // Checks if the FD has data available to be read bool hasData(long ms_timeout = 10); // Checks if the FD is still open (network connections will still appear open even if lost link) bool isOpen(); int getFD() { return _fd; }; void closeFD(); // The code must be defined here for a template for the next two functions /***************************************************************************************** * readBytes - Template method--for an FD, reads in sizeof(T) * n bytes and stores in a * vector of type T * * Params: buf - the STL vector to store the bytes * * Returns: number of bytes read, or -1 for read error, -2 if not enough bytes * were available to fill a complete set of size T variables * *****************************************************************************************/ template int readBytes(std::vector &buf, int n) { int datasize = sizeof(T); int bufsize = datasize * n; unsigned char *bytebuf = new unsigned char[bufsize]; buf.clear(); int results; if ((results = read(_fd, bytebuf, bufsize)) < 0)="" {="" delete="" bytebuf;="" return="" -1;="" }="" if="" (results="">< bufsize)="" {="" if="" (results="" %="" datasize="" !="0)" {="" delete="" bytebuf;="" return="" -2;="" }="" }="" unsigned="" int="" read_units="results" datasize;="" buf.reserve(read_units);="" for="" (unsigned="" int="" i="0;">< read_units; i++) { buf.push_back((t) bytebuf[i*datasize]); read_units;="" i++)="" {="" buf.push_back((t)="">
Mar 07, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here