samserver.h 902 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // acetone, 2024
  2. // I hate copyright of any kind. This is a public domain.
  3. // Original source: https://notabug.org/acetone/samty
  4. #pragma once
  5. #include "i2psam.h"
  6. #include <thread>
  7. #include <atomic>
  8. namespace Samty {
  9. using PendingConnectionCallbackPointer = void (*)(const std::string& b32, std::unique_ptr<I2pSocket> socket);
  10. class SAMServer
  11. {
  12. public:
  13. SAMServer(const Samty::Configuration& samConfiguration,
  14. PendingConnectionCallbackPointer callback);
  15. virtual ~SAMServer() { stop(); }
  16. std::string myAddress() const;
  17. bool isOk() const;
  18. std::string errorString() const;
  19. bool start();
  20. void stop(); // Object is broken after this called
  21. protected:
  22. void loop();
  23. StreamSession m_streamSession;
  24. PendingConnectionCallbackPointer m_connectionCallback;
  25. std::thread m_mainThread;
  26. std::atomic<bool> m_started = false;
  27. };
  28. } // namespace Samty