2023-07-10 08:36:19 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
#include "ProtocolBase.h"
|
2023-08-17 02:03:59 +00:00
|
|
|
|
#include "common.h"
|
2023-07-10 08:36:19 +00:00
|
|
|
|
|
2023-08-15 03:01:31 +00:00
|
|
|
|
#if !USER_REAL_PLATFORM
|
|
|
|
|
class PlatformReqServerCfgParms {
|
|
|
|
|
public:
|
2023-09-21 09:54:55 +00:00
|
|
|
|
std::string extVmId;
|
|
|
|
|
AIGC_JSON_HELPER(extVmId)
|
2023-08-15 03:01:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PlatformReqClientCfgParms {
|
|
|
|
|
public:
|
|
|
|
|
std::string userName;
|
|
|
|
|
std::string token;
|
|
|
|
|
AIGC_JSON_HELPER(userName)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PlatformRspUserSvrCfgParams {
|
|
|
|
|
public:
|
|
|
|
|
PlatformRspUserSvrCfgParams() {
|
|
|
|
|
this->svrHost = TEXT("");
|
|
|
|
|
this->svrPort = 0;
|
|
|
|
|
this->svrPriKey = TEXT("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int svrPort;
|
|
|
|
|
std::string svrPriKey;
|
|
|
|
|
std::string svrHost;
|
|
|
|
|
|
|
|
|
|
AIGC_JSON_HELPER(svrPort, svrPriKey, svrHost)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class VitrualMathineInfo {
|
|
|
|
|
public:
|
|
|
|
|
VitrualMathineInfo() {
|
2023-09-01 02:40:08 +00:00
|
|
|
|
this->vmId = 0;
|
|
|
|
|
this->scgPort = 0;
|
|
|
|
|
this->vmName = TEXT("");
|
|
|
|
|
this->scgIp = TEXT("");
|
|
|
|
|
this->vmNetwork = TEXT("");
|
|
|
|
|
this->svrPubKey = TEXT("");
|
2023-08-17 02:03:59 +00:00
|
|
|
|
#if USED_PORTMAP_TUNNEL
|
|
|
|
|
this->portMapIp = TEXT("");
|
|
|
|
|
this->portMapPort = 0;
|
|
|
|
|
#endif
|
2023-08-15 03:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int vmId;
|
|
|
|
|
std::string vmName;
|
|
|
|
|
std::string svrPubKey;
|
|
|
|
|
std::string vmNetwork;
|
|
|
|
|
std::string scgIp;
|
|
|
|
|
int scgPort;
|
2023-08-17 02:03:59 +00:00
|
|
|
|
#if USED_PORTMAP_TUNNEL
|
|
|
|
|
std::string portMapIp;
|
|
|
|
|
int portMapPort;
|
|
|
|
|
AIGC_JSON_HELPER(vmId, vmName, svrPubKey, vmNetwork, scgIp, scgPort, portMapIp, portMapPort)
|
|
|
|
|
#else
|
2023-08-15 03:01:31 +00:00
|
|
|
|
AIGC_JSON_HELPER(vmId, vmName, svrPubKey, vmNetwork, scgIp, scgPort)
|
2023-08-17 02:03:59 +00:00
|
|
|
|
#endif
|
2023-08-15 03:01:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PlatformRspUserClientCfgParams {
|
|
|
|
|
public:
|
|
|
|
|
PlatformRspUserClientCfgParams() {
|
|
|
|
|
this->scgTunnelAppId = WG_TUNNEL_SCG_ID;
|
|
|
|
|
this->scgCtrlAppId = WG_CTRL_SCG_ID;
|
|
|
|
|
this->cliHost = TEXT("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int scgCtrlAppId;
|
|
|
|
|
int scgTunnelAppId;
|
|
|
|
|
std::string cliPriKey;
|
|
|
|
|
std::string cliPubKey;
|
|
|
|
|
std::string cliHost;
|
|
|
|
|
std::list<VitrualMathineInfo> vmInfoList;
|
|
|
|
|
|
2023-09-01 02:40:08 +00:00
|
|
|
|
AIGC_JSON_HELPER(cliPriKey, cliPubKey, vmInfoList, cliHost)
|
2023-08-15 03:01:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PlatformRspServerCfgParams {
|
|
|
|
|
public:
|
|
|
|
|
std::string code;
|
|
|
|
|
std::string message;
|
|
|
|
|
PlatformRspUserSvrCfgParams data;
|
|
|
|
|
|
|
|
|
|
AIGC_JSON_HELPER(code, data)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PlatformRspClientCfgParams {
|
|
|
|
|
public:
|
|
|
|
|
std::string code;
|
|
|
|
|
std::string message;
|
|
|
|
|
PlatformRspUserClientCfgParams data;
|
|
|
|
|
|
|
|
|
|
AIGC_JSON_HELPER(code, data)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
|
class ReqClientCfgParams {
|
|
|
|
|
public:
|
|
|
|
|
std::string identifier;
|
|
|
|
|
|
|
|
|
|
AIGC_JSON_HELPER(identifier)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ReqHeartParams {
|
|
|
|
|
public:
|
|
|
|
|
std::string message;
|
|
|
|
|
|
|
|
|
|
AIGC_JSON_HELPER(message)
|
2023-07-14 09:29:02 +00:00
|
|
|
|
AIGC_JSON_HELPER_DEFAULT(message = TEXT("PING"))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RspHeartParams : public ResponseStatus {
|
|
|
|
|
public:
|
|
|
|
|
std::string message;
|
|
|
|
|
|
|
|
|
|
AIGC_JSON_HELPER(message)
|
|
|
|
|
AIGC_JSON_HELPER_BASE((ResponseStatus *)this)
|
|
|
|
|
AIGC_JSON_HELPER_DEFAULT(message = TEXT("PONG"))
|
2023-07-10 08:36:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ReqGetUserCfgParams {
|
|
|
|
|
public:
|
|
|
|
|
std::string user;
|
|
|
|
|
std::string token;
|
|
|
|
|
|
|
|
|
|
AIGC_JSON_HELPER(user, token)
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
class RspUserSevrCfgParams {
|
|
|
|
|
public:
|
2023-07-17 10:55:01 +00:00
|
|
|
|
RspUserSevrCfgParams() {
|
|
|
|
|
this->svrAddress = TEXT("");
|
|
|
|
|
this->svrListenPort = 0;
|
|
|
|
|
this->svrPrivateKey = TEXT("");
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
int svrListenPort;
|
|
|
|
|
std::string svrPrivateKey;
|
|
|
|
|
std::string svrAddress;
|
|
|
|
|
|
|
|
|
|
AIGC_JSON_HELPER(svrListenPort, svrPrivateKey, svrAddress)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ReqStartTunnelParams {
|
|
|
|
|
public:
|
|
|
|
|
bool isStart;
|
|
|
|
|
AIGC_JSON_HELPER(isStart)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ReqUserSetCliCfgParams {
|
|
|
|
|
public:
|
|
|
|
|
std::string cliPublicKey;
|
|
|
|
|
std::string cliNetwork;
|
|
|
|
|
std::string cliTunnelAddr;
|
|
|
|
|
|
|
|
|
|
AIGC_JSON_HELPER(cliPublicKey, cliNetwork, cliTunnelAddr)
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-17 10:55:01 +00:00
|
|
|
|
class RspUserSetCliCfgParams : public ResponseStatus {
|
|
|
|
|
public:
|
|
|
|
|
std::string svrNetwork;
|
|
|
|
|
|
|
|
|
|
AIGC_JSON_HELPER(svrNetwork)
|
|
|
|
|
AIGC_JSON_HELPER_BASE((ResponseStatus *)this)
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
|
class VitrualMathineCfg {
|
|
|
|
|
public:
|
2023-07-17 10:55:01 +00:00
|
|
|
|
VitrualMathineCfg() {
|
|
|
|
|
this->vmId = 0;
|
|
|
|
|
this->vmName = TEXT("");
|
|
|
|
|
this->scgGateway = TEXT("");
|
|
|
|
|
this->vmNetwork = TEXT("");
|
|
|
|
|
this->svrPublicKey = TEXT("");
|
2023-08-17 02:03:59 +00:00
|
|
|
|
#if USED_PORTMAP_TUNNEL
|
|
|
|
|
this->portMapIp = TEXT("");
|
|
|
|
|
this->portMapPort = 0;
|
|
|
|
|
#endif
|
2023-07-17 10:55:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
|
int vmId;
|
|
|
|
|
std::string vmName;
|
|
|
|
|
std::string svrPublicKey;
|
|
|
|
|
std::string vmNetwork;
|
|
|
|
|
std::string scgGateway;
|
2023-08-17 02:03:59 +00:00
|
|
|
|
#if USED_PORTMAP_TUNNEL
|
|
|
|
|
std::string portMapIp;
|
|
|
|
|
int portMapPort;
|
|
|
|
|
AIGC_JSON_HELPER(vmId, vmName, svrPublicKey, vmNetwork, scgGateway, portMapIp, portMapPort)
|
|
|
|
|
#else
|
2023-07-10 08:36:19 +00:00
|
|
|
|
AIGC_JSON_HELPER(vmId, vmName, svrPublicKey, vmNetwork, scgGateway)
|
2023-08-17 02:03:59 +00:00
|
|
|
|
#endif
|
2023-07-10 08:36:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
class RspUsrCliConfigParams {
|
2023-07-10 08:36:19 +00:00
|
|
|
|
public:
|
|
|
|
|
int scgCtrlAppId;
|
|
|
|
|
int scgTunnelAppId;
|
|
|
|
|
std::string cliPrivateKey;
|
2023-07-14 09:29:02 +00:00
|
|
|
|
std::string cliPublicKey;
|
2023-07-10 08:36:19 +00:00
|
|
|
|
std::string cliAddress;
|
|
|
|
|
std::list<VitrualMathineCfg> vmConfig;
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
AIGC_JSON_HELPER(scgCtrlAppId, scgTunnelAppId, cliPrivateKey, cliPublicKey, cliAddress, vmConfig)
|
2023-07-10 08:36:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-08-15 03:01:31 +00:00
|
|
|
|
#if USER_REAL_PLATFORM
|
|
|
|
|
#define GET_CLIENTCFG_PATH TEXT("/tunnel/getuserconfig")
|
|
|
|
|
#define GET_SERVERCFG_PATH TEXT("/tunnel/getserverconfig")
|
|
|
|
|
#else
|
|
|
|
|
#define GET_CLIENTCFG_PATH TEXT("/sc/open-portal/openapi/scc/cliTunnelCfg")
|
|
|
|
|
#define GET_SERVERCFG_PATH TEXT("/sc/open-portal/openapi/scc/svrTunnelCfg")
|
|
|
|
|
#endif
|
2023-07-14 09:29:02 +00:00
|
|
|
|
|
|
|
|
|
#define SET_CLIENTCFG_PATH TEXT("/tunnel/setconfig")
|
|
|
|
|
#define SET_CLIENTSTART_TUNNEL TEXT("/tunnel/start")
|
|
|
|
|
#define SET_CLIENTHEART_PATH TEXT("/tunnel/heart")
|
|
|
|
|
|
|
|
|
|
int InitControlServer(const TCHAR *pUserSvrUrl);
|
|
|
|
|
|
2023-07-17 10:55:01 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 调用 RESTful POST 接口并获取服务端返回数据
|
|
|
|
|
* @param[in] pUrlPath 服务端 URL 路径
|
|
|
|
|
* @param[in] pReq 请求消息
|
|
|
|
|
* @param[in] pRsp 返回消息
|
|
|
|
|
* @param[in] platformServer 访问平台还是访问控制服务
|
|
|
|
|
* @return 0: 成功, 小于0 失败 @see USER_ERRNO
|
|
|
|
|
* - -ERR_INPUT_PARAMS 输入参数错误
|
|
|
|
|
* - -ERR_SYSTEM_UNINITIALIZE 服务端URL未初始化
|
|
|
|
|
* - -ERR_JSON_CREATE 创建 JSON 字符串失败
|
|
|
|
|
* - -ERR_HTTP_POST_DATA 调用 POST 方法失败
|
|
|
|
|
* - -ERR_HTTP_SERVER_RSP 服务端返回失败(非200)
|
|
|
|
|
* - -ERR_READ_FILE 服务端返回空数据
|
|
|
|
|
* - -ERR_JSON_DECODE 解析 JSON 数据失败
|
|
|
|
|
* - ERR_SUCCESS 成功
|
|
|
|
|
*/
|
2023-07-14 09:29:02 +00:00
|
|
|
|
template<class T1, class T2>
|
|
|
|
|
int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<T1> *pReq,
|
|
|
|
|
ProtocolResponse<T2> *pRsp,
|
2023-08-14 01:20:25 +00:00
|
|
|
|
bool platformServer);
|
2023-07-14 09:29:02 +00:00
|
|
|
|
|
|
|
|
|
extern template int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<ReqGetUserCfgParams> *pReq,
|
|
|
|
|
ProtocolResponse<RspUserSevrCfgParams> *pRsp,
|
|
|
|
|
bool platformServer);
|
|
|
|
|
|
|
|
|
|
extern template int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<ReqGetUserCfgParams> *pReq,
|
|
|
|
|
ProtocolResponse<RspUsrCliConfigParams> *pRsp,
|
|
|
|
|
bool platformServer);
|
|
|
|
|
|
2023-07-17 10:55:01 +00:00
|
|
|
|
extern template int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<ReqUserSetCliCfgParams> *pReq,
|
|
|
|
|
ProtocolResponse<RspUserSetCliCfgParams> *pRsp,
|
|
|
|
|
bool platformServer);
|
2023-07-14 09:29:02 +00:00
|
|
|
|
|
|
|
|
|
extern template int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<ReqStartTunnelParams> *pReq,
|
|
|
|
|
ProtocolResponse<ResponseStatus> *pRsp,
|
|
|
|
|
bool platformServer);
|
|
|
|
|
|
|
|
|
|
extern template int ProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
ProtocolRequest<ReqHeartParams> *pReq,
|
|
|
|
|
ProtocolResponse<RspHeartParams> *pRsp,
|
2023-08-15 03:01:31 +00:00
|
|
|
|
bool platformServer);
|
|
|
|
|
|
|
|
|
|
#if !USER_REAL_PLATFORM
|
|
|
|
|
template<class T1, class T2> int PlatformProtolPostMessage(const TCHAR *pUrlPath, T1 *pReq, T2 *pRsp);
|
|
|
|
|
|
|
|
|
|
extern template int PlatformProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
PlatformReqServerCfgParms *pReq,
|
|
|
|
|
PlatformRspServerCfgParams *pRsp);
|
|
|
|
|
|
|
|
|
|
extern template int PlatformProtolPostMessage(const TCHAR *pUrlPath,
|
|
|
|
|
PlatformReqClientCfgParms *pReq,
|
|
|
|
|
PlatformRspClientCfgParams *pRsp);
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
template<class T1> int PlatformProtolGetMessage(const TCHAR *pUrlPath, T1 *pRsp);
|
|
|
|
|
|
|
|
|
|
extern template int PlatformProtolGetMessage(const TCHAR *pUrlPath,
|
|
|
|
|
PlatformRspUserClientCfgParams *pRsp);
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|