Goddess of Justice DB, the database used for storage on IzaroDFS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
961 B

  1. #include <chrono>
  2. #include <sys/types.h>
  3. #include <sys/socket.h>
  4. #include <netinet/in.h>
  5. #include <string.h>
  6. #include <endian.hpp>
  7. #include <network.hpp>
  8. using namespace std::chrono_literals;
  9. int main(){
  10. uint16_t db_port = 32555;
  11. auto soc = socket(AF_INET, SOCK_DGRAM, 0);
  12. struct sockaddr_in addr;
  13. addr.sin_family = AF_INET;
  14. addr.sin_port = htons(db_port);
  15. memset((void*)&addr.sin_addr, 0, sizeof(addr.sin_addr));
  16. bind(soc,(struct sockaddr*)&addr,sizeof(addr));
  17. req_rep buffer;
  18. sockaddr_in client;
  19. socklen_t packet_sz;
  20. while(true)
  21. {
  22. recvfrom(
  23. soc,
  24. (void*)&buffer,
  25. sizeof(req_rep),
  26. MSG_WAITFORONE,
  27. (struct sockaddr*)&client,
  28. &packet_sz
  29. );
  30. buffer.server_ts = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
  31. sendto(
  32. soc,
  33. (void*)&buffer,
  34. sizeof(req_rep),
  35. 0,
  36. (struct sockaddr*)&client,
  37. (socklen_t)sizeof(client)
  38. );
  39. }
  40. }