frp.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // Created by xcbosa on 2023/1/31.
  3. //
  4. #pragma once
  5. #include <string>
  6. #include <set>
  7. #include <functional>
  8. using namespace std;
  9. using namespace xc;
  10. using namespace xc::utils;
  11. namespace xc::frp {
  12. void frpDaemon();
  13. /*仅当用户没有更改,但用户要求强制重启时调用,FrpDaemon会自动检查文件变化并自动更新。*/
  14. void reloadProfileFilePath(string filePath);
  15. set<int> profileUsingPorts(string profile);
  16. set<int> serverUsingPorts(string serverIp);
  17. void addProfile(string name, string ip, string port, string token);
  18. vector<string> listingAvailableServerAndPortForUser(string username);
  19. class ProfilePortInfo {
  20. public:
  21. ProfilePortInfo();
  22. ProfilePortInfo(string localIp, int localPort, int remotePort);
  23. ProfilePortInfo(string localIp, int localPort, int remotePort, string uuid);
  24. string localIp;
  25. int localPort;
  26. int remotePort;
  27. string uuid;
  28. CONFIGOR_BIND(json::value, ProfilePortInfo, REQUIRED(localIp), REQUIRED(localPort), REQUIRED(remotePort), REQUIRED(uuid))
  29. };
  30. class ProfileInfo {
  31. public:
  32. ProfileInfo();
  33. ProfileInfo(string profileName);
  34. string getServerAddr();
  35. int getAllowPortLow();
  36. int getAllowPortCount();
  37. void addPortInfo(ProfilePortInfo portInfo);
  38. void removePort(int remotePort);
  39. bool availableForUser(string name);
  40. void addUser(string name);
  41. void removeUser(string name);
  42. void save() const;
  43. int getFirstFreeRemotePort();
  44. int getFirstFreeRemotePort(int ifNoneThenReturn);
  45. vector<int> getFreeRemotePorts();
  46. vector<int> getFreeRemotePorts(int maxCnt);
  47. vector<int> getFreeRemotePortsAndAppend(int me);
  48. CONFIGOR_BIND(json::value, ProfileInfo,
  49. REQUIRED(users),
  50. REQUIRED(profileName),
  51. REQUIRED(serverAddr),
  52. REQUIRED(serverPort),
  53. REQUIRED(token),
  54. REQUIRED(allowPortLow),
  55. REQUIRED(allowPortCount),
  56. REQUIRED(ports))
  57. vector<ProfilePortInfo> ports;
  58. private:
  59. set<string> users;
  60. string profileName;
  61. string serverAddr;
  62. int serverPort;
  63. string token;
  64. int allowPortLow;
  65. int allowPortCount;
  66. };
  67. vector<ProfileInfo> listUserAvailableProfiles(string user);
  68. }