OCT 1. 获取网卡接口增加网卡状态字段
2. 隧道支持端口映射配置,以及配置协议字段需求 3. 日志支持按天分割文件
This commit is contained in:
parent
83d7cf638e
commit
2d9da7b215
|
@ -104,6 +104,8 @@ public struct NetCard
|
||||||
{
|
{
|
||||||
public int IfIndex;
|
public int IfIndex;
|
||||||
|
|
||||||
|
public int netConnStatus;
|
||||||
|
|
||||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
||||||
public string UUID;
|
public string UUID;
|
||||||
|
|
||||||
|
|
|
@ -598,7 +598,7 @@ int GetUserClientConfigure(const TCHAR *pUserName, const TCHAR *pToken, PUSER_CL
|
||||||
//StringCbCopy(pVm->scgGateWay, MAX_PATH, vm.scgGateway.c_str());
|
//StringCbCopy(pVm->scgGateWay, MAX_PATH, vm.scgGateway.c_str());
|
||||||
StringCbPrintf(pVm->scgGateWay, MAX_PATH, TEXT("http://%s:%d"), vm.scgIp.c_str(), vm.scgPort);
|
StringCbPrintf(pVm->scgGateWay, MAX_PATH, TEXT("http://%s:%d"), vm.scgIp.c_str(), vm.scgPort);
|
||||||
#if USED_PORTMAP_TUNNEL
|
#if USED_PORTMAP_TUNNEL
|
||||||
StringCbPrintf(pVm->scgTunnelGw, MAX_PATH, TEXT("%s:%d"), vm.portMapIp.c_str(), vm.portMapPort - 1);
|
StringCbPrintf(pVm->scgTunnelGw, MAX_PATH, TEXT("%s:%d"), vm.portMapIp.c_str(), vm.portMapPort);
|
||||||
#else
|
#else
|
||||||
StringCbPrintf(pVm->scgTunnelGw, MAX_PATH, TEXT("%s:%d"), vm.scgIp.c_str(), vm.scgPort - 1);
|
StringCbPrintf(pVm->scgTunnelGw, MAX_PATH, TEXT("%s:%d"), vm.scgIp.c_str(), vm.scgPort - 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,31 +1,30 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define USED_PORTMAP_TUNNEL (1)
|
#define USED_PORTMAP_TUNNEL (1)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief WireGuard key 最大长度
|
* @brief WireGuard key 最大长度
|
||||||
*/
|
*/
|
||||||
#define WG_KEY_MAX (64)
|
#define WG_KEY_MAX (64)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 操作系统最大网卡数
|
* @brief 操作系统最大网卡数
|
||||||
*/
|
*/
|
||||||
#define NET_CARD_MAX (32)
|
#define NET_CARD_MAX (32)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief IP 字符串最大长度(支持IPv6)
|
* @brief IP 字符串最大长度(支持IPv6)
|
||||||
*/
|
*/
|
||||||
#define MAX_IP_LEN (48)
|
#define MAX_IP_LEN (48)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief IP 字符串最小长度
|
* @brief IP 字符串最小长度
|
||||||
*/
|
*/
|
||||||
#define MIN_IP_LEN (7)
|
#define MIN_IP_LEN (7)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 网卡名称字符串最大长度(支持IPv6)
|
* @brief 网卡名称字符串最大长度(支持IPv6)
|
||||||
*/
|
*/
|
||||||
#define MAX_NETCARD_NAME (64)
|
#define MAX_NETCARD_NAME (64)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SCG 服务 ID
|
* @brief SCG 服务 ID
|
||||||
|
@ -49,6 +48,29 @@ typedef enum {
|
||||||
CRYPTO_MAX,
|
CRYPTO_MAX,
|
||||||
} PROTO_CRYPTO_TYPE;
|
} PROTO_CRYPTO_TYPE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 网络连接状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
STATUS_DISCONNECTED = 0, ///< 连接已断开连接
|
||||||
|
STATUS_CONNECTING, ///< 连接正在进行连接
|
||||||
|
STATUS_CONNECTED, ///< 连接处于连接状态
|
||||||
|
STATUS_DISCONNECTING, ///< 连接正在断开连接
|
||||||
|
STATUS_HARDWARE_NOT_PRESENT, ///< 连接的硬件(例如网络接口卡 (NIC) )不存在
|
||||||
|
STATUS_HARDWARE_DISABLED, ///< 连接的硬件存在,但未启用
|
||||||
|
STATUS_HARDWARE_MALFUNCTION, ///< 连接的硬件中发生了故障
|
||||||
|
STATUS_MEDIA_DISCONNECTED, ///< 媒体(例如网络电缆)断开连接
|
||||||
|
STATUS_AUTHENTICATING, ///< 连接正在等待身份验证发生
|
||||||
|
STATUS_AUTHENTICATION_SUCCEEDED, ///< 身份验证在此连接上成功
|
||||||
|
STATUS_AUTHENTICATION_FAILED, ///< 此连接上身份验证失败
|
||||||
|
STATUS_INVALID_ADDRESS, ///< 地址无效
|
||||||
|
STATUS_CREDENTIALS_REQUIRED, ///< 需要安全凭据
|
||||||
|
STATUS_ACTION_REQUIRED, ///< 连接需要其它动作
|
||||||
|
STATUS_ACTION_REQUIRED_RETRY, ///< 重试连接其它动作
|
||||||
|
STATUS_CONNECT_FAILED, ///< 连接失败
|
||||||
|
} NET_CONNECT_STATUS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 日志等级
|
* @brief 日志等级
|
||||||
*
|
*
|
||||||
|
|
|
@ -24,6 +24,7 @@ int GetInterfaceIfIndexByIpAddr(const TCHAR *pIpAddr, ULONG *pIfIndex);
|
||||||
* @brief 根据网卡 GUDI 获取网卡名称
|
* @brief 根据网卡 GUDI 获取网卡名称
|
||||||
* @param[in] pGUID 网卡 GUID
|
* @param[in] pGUID 网卡 GUID
|
||||||
* @param[out] ifName 网卡名称
|
* @param[out] ifName 网卡名称
|
||||||
|
* @param[out] pConnStatus 网卡连接状态
|
||||||
* @return 函数执行结果 0: 成功, 小于0 失败 @see USER_ERRNO
|
* @return 函数执行结果 0: 成功, 小于0 失败 @see USER_ERRNO
|
||||||
* - -ERR_INPUT_PARAMS 输入参数错误
|
* - -ERR_INPUT_PARAMS 输入参数错误
|
||||||
* - -ERR_MALLOC_MEMORY 分配内存失败
|
* - -ERR_MALLOC_MEMORY 分配内存失败
|
||||||
|
@ -32,7 +33,7 @@ int GetInterfaceIfIndexByIpAddr(const TCHAR *pIpAddr, ULONG *pIfIndex);
|
||||||
* - -ERR_ITEM_UNEXISTS GUID 不存在
|
* - -ERR_ITEM_UNEXISTS GUID 不存在
|
||||||
* - ERR_SUCCESS 成功
|
* - ERR_SUCCESS 成功
|
||||||
*/
|
*/
|
||||||
int GetInterfaceNameByGUID(const TCHAR *pGUID, TCHAR ifName[MAX_NETCARD_NAME]);
|
int GetInterfaceNameByGUID(const TCHAR *pGUID, TCHAR ifName[MAX_NETCARD_NAME], int* pConnStatus);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 根据网卡名获取网卡索引
|
* @brief 根据网卡名获取网卡索引
|
||||||
|
|
|
@ -17,14 +17,15 @@ typedef PTUNNEL_HEART_ROUTINE LPTUNNEL_HEART_ROUTINE;
|
||||||
* @brief 本地计算机网卡信息
|
* @brief 本地计算机网卡信息
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int InterfaceIndex; ///< 网卡索引
|
int InterfaceIndex; ///< 网卡索引
|
||||||
TCHAR NetCardUUID[260]; ///< 网卡名称, Windows标识为 UUID
|
NET_CONNECT_STATUS netConnStatus; ///< 网卡状态 @see NET_CONNECT_STATUS
|
||||||
TCHAR NetCardName[MAX_NETCARD_NAME]; ///< 网卡名称
|
TCHAR NetCardUUID[260]; ///< 网卡名称, Windows标识为 UUID
|
||||||
TCHAR NetCardDescription[132]; ///< 网卡描述
|
TCHAR NetCardName[MAX_NETCARD_NAME]; ///< 网卡名称
|
||||||
TCHAR NetCardIpaddr[MAX_IP_LEN]; ///< 网卡 IP 地址
|
TCHAR NetCardDescription[132]; ///< 网卡描述
|
||||||
TCHAR NetCardNetmask[MAX_IP_LEN]; ///< 网卡子网掩码
|
TCHAR NetCardIpaddr[MAX_IP_LEN]; ///< 网卡 IP 地址
|
||||||
TCHAR NetCardGateway[MAX_IP_LEN]; ///< 网卡网关
|
TCHAR NetCardNetmask[MAX_IP_LEN]; ///< 网卡子网掩码
|
||||||
TCHAR NetCardMacAddr[20]; ///< 网卡 MAC 地址
|
TCHAR NetCardGateway[MAX_IP_LEN]; ///< 网卡网关
|
||||||
|
TCHAR NetCardMacAddr[20]; ///< 网卡 MAC 地址
|
||||||
} NIC_CONTENT, *PNIC_CONTENT;
|
} NIC_CONTENT, *PNIC_CONTENT;
|
||||||
|
|
||||||
#ifdef __cplusplus // If used by C++ code,
|
#ifdef __cplusplus // If used by C++ code,
|
||||||
|
|
|
@ -2,17 +2,22 @@
|
||||||
|
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include "globalcfg.h"
|
|
||||||
#include "usrerr.h"
|
#include "usrerr.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
#if !USED_PORTMAP_TUNNEL
|
||||||
|
#include "globalcfg.h"
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include <spdlog/fmt/bin_to_hex.h>
|
#include <spdlog/fmt/bin_to_hex.h>
|
||||||
|
|
||||||
#define SCG_UDP_HEAD_SIZE (11)
|
#define SCG_UDP_HEAD_SIZE (11)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void StopUDPProxyServer() {
|
void StopUDPProxyServer() {
|
||||||
|
#if !USED_PORTMAP_TUNNEL
|
||||||
const PSCG_PROXY_INFO pProxy = &GetGlobalCfgInfo()->scgProxy;
|
const PSCG_PROXY_INFO pProxy = &GetGlobalCfgInfo()->scgProxy;
|
||||||
pProxy->exitNow = true;
|
pProxy->exitNow = true;
|
||||||
|
|
||||||
|
@ -31,8 +36,10 @@ void StopUDPProxyServer() {
|
||||||
|
|
||||||
closesocket(pProxy->scgGwSock);
|
closesocket(pProxy->scgGwSock);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !USED_PORTMAP_TUNNEL
|
||||||
static DWORD UDPProxvRemoteThread(LPVOID lpParameter) {
|
static DWORD UDPProxvRemoteThread(LPVOID lpParameter) {
|
||||||
const auto pPeerSock = static_cast<sockaddr_in *>(lpParameter);
|
const auto pPeerSock = static_cast<sockaddr_in *>(lpParameter);
|
||||||
const PSCG_PROXY_INFO pProxy = &GetGlobalCfgInfo()->scgProxy;
|
const PSCG_PROXY_INFO pProxy = &GetGlobalCfgInfo()->scgProxy;
|
||||||
|
@ -207,8 +214,9 @@ static DWORD UDPProxyRecvThread(LPVOID lpParameter) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
int CreateUDPProxyServer() {
|
int CreateUDPProxyServer() {
|
||||||
|
#if !USED_PORTMAP_TUNNEL
|
||||||
HANDLE handle;
|
HANDLE handle;
|
||||||
int ret;
|
int ret;
|
||||||
int addrSize = sizeof(sockaddr_in);
|
int addrSize = sizeof(sockaddr_in);
|
||||||
|
@ -272,6 +280,6 @@ int CreateUDPProxyServer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pProxy->hProxyTunnelThread = handle;
|
pProxy->hProxyTunnelThread = handle;
|
||||||
|
#endif
|
||||||
return ERR_SUCCESS;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
|
@ -140,7 +140,7 @@ int GetInterfaceIfIndexByGUID(const TCHAR *pGUID, int *pIfIndex) {
|
||||||
return -ERR_ITEM_UNEXISTS;
|
return -ERR_ITEM_UNEXISTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetInterfaceNameByGUID(const TCHAR *pGUID, TCHAR ifName[MAX_NETCARD_NAME]) {
|
int GetInterfaceNameByGUID(const TCHAR *pGUID, TCHAR ifName[MAX_NETCARD_NAME], int *pConnStatus) {
|
||||||
VARIANT v;
|
VARIANT v;
|
||||||
INetConnection *pNC = nullptr;
|
INetConnection *pNC = nullptr;
|
||||||
IEnumVARIANT *pEV = nullptr;
|
IEnumVARIANT *pEV = nullptr;
|
||||||
|
@ -245,6 +245,9 @@ int GetInterfaceNameByGUID(const TCHAR *pGUID, TCHAR ifName[MAX_NETCARD_NAME]) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pConnStatus) {
|
||||||
|
*pConnStatus = pNP->Status;
|
||||||
|
}
|
||||||
return ERR_SUCCESS;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -425,7 +428,7 @@ int GetInterfaceIfIndexByName(const TCHAR *pInterfaceName, int *pIfIndex) {
|
||||||
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
|
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
|
||||||
while (pAdapter) {
|
while (pAdapter) {
|
||||||
TCHAR NetCardName[MAX_NETCARD_NAME] = {};
|
TCHAR NetCardName[MAX_NETCARD_NAME] = {};
|
||||||
GetInterfaceNameByGUID(pAdapter->AdapterName, NetCardName);
|
GetInterfaceNameByGUID(pAdapter->AdapterName, NetCardName, nullptr);
|
||||||
|
|
||||||
if (StrCmp(pInterfaceName, NetCardName) == 0) {
|
if (StrCmp(pInterfaceName, NetCardName) == 0) {
|
||||||
*pIfIndex = static_cast<int>(pAdapter->Index);
|
*pIfIndex = static_cast<int>(pAdapter->Index);
|
||||||
|
@ -485,7 +488,7 @@ int GetInterfaceGUIDByName(const TCHAR *pInterfaceName, GUID *pGuid) {
|
||||||
while (pAdapter) {
|
while (pAdapter) {
|
||||||
int ret;
|
int ret;
|
||||||
TCHAR NetCardName[MAX_NETCARD_NAME] = {};
|
TCHAR NetCardName[MAX_NETCARD_NAME] = {};
|
||||||
GetInterfaceNameByGUID(pAdapter->AdapterName, NetCardName);
|
GetInterfaceNameByGUID(pAdapter->AdapterName, NetCardName, nullptr);
|
||||||
|
|
||||||
if (StrCmp(pInterfaceName, NetCardName) == 0) {
|
if (StrCmp(pInterfaceName, NetCardName) == 0) {
|
||||||
WCHAR strGuid[MAX_PATH];
|
WCHAR strGuid[MAX_PATH];
|
||||||
|
@ -632,7 +635,8 @@ int GetAllNICInfo(PNIC_CONTENT *pInfo, int *pItemCounts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
|
if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
int ncStatus;
|
||||||
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
|
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
|
||||||
while (pAdapter && id < NET_CARD_MAX) {
|
while (pAdapter && id < NET_CARD_MAX) {
|
||||||
// Íø¿¨Ë÷Òý
|
// Íø¿¨Ë÷Òý
|
||||||
|
@ -660,7 +664,10 @@ int GetAllNICInfo(PNIC_CONTENT *pInfo, int *pItemCounts) {
|
||||||
pAdapter->Address[4],
|
pAdapter->Address[4],
|
||||||
pAdapter->Address[5]);
|
pAdapter->Address[5]);
|
||||||
|
|
||||||
GetInterfaceNameByGUID(pAdapter->AdapterName, g_NetAdapterInfo[id].NetCardName);
|
if (GetInterfaceNameByGUID(pAdapter->AdapterName, g_NetAdapterInfo[id].NetCardName, &ncStatus) ==
|
||||||
|
ERR_SUCCESS) {
|
||||||
|
g_NetAdapterInfo[id].netConnStatus = static_cast<NET_CONNECT_STATUS>(ncStatus);
|
||||||
|
}
|
||||||
|
|
||||||
id++;
|
id++;
|
||||||
pAdapter = pAdapter->Next;
|
pAdapter = pAdapter->Next;
|
||||||
|
|
|
@ -38,6 +38,7 @@ int InitControlServer(const TCHAR *pUserSvrUrl) {
|
||||||
g_tunnelHttpCtx->set_connection_timeout(0, 1000000); // 1 second
|
g_tunnelHttpCtx->set_connection_timeout(0, 1000000); // 1 second
|
||||||
g_tunnelHttpCtx->set_read_timeout(5, 0); // 5 seconds
|
g_tunnelHttpCtx->set_read_timeout(5, 0); // 5 seconds
|
||||||
g_tunnelHttpCtx->set_write_timeout(5, 0); // 5 seconds
|
g_tunnelHttpCtx->set_write_timeout(5, 0); // 5 seconds
|
||||||
|
g_tunnelHttpCtx->set_keep_alive(true);
|
||||||
g_tunnelHttpCtx->set_post_connect_cb([](socket_t sock) {
|
g_tunnelHttpCtx->set_post_connect_cb([](socket_t sock) {
|
||||||
if (UsedSCGProxy()) {
|
if (UsedSCGProxy()) {
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -96,10 +97,11 @@ template<class T> int CreateProtocolRequest(T *pReqParams, TCHAR **pOutJson) {
|
||||||
if (!g_httpCtx && lstrlen(GetGlobalCfgInfo()->platformServerUrl) > 0) {
|
if (!g_httpCtx && lstrlen(GetGlobalCfgInfo()->platformServerUrl) > 0) {
|
||||||
g_httpCtx = new httplib::Client(GetGlobalCfgInfo()->platformServerUrl);
|
g_httpCtx = new httplib::Client(GetGlobalCfgInfo()->platformServerUrl);
|
||||||
if (g_httpCtx) {
|
if (g_httpCtx) {
|
||||||
g_httpCtx->enable_server_certificate_verification(false);
|
|
||||||
g_httpCtx->set_connection_timeout(0, 300000); // 300 milliseconds
|
g_httpCtx->set_connection_timeout(0, 300000); // 300 milliseconds
|
||||||
g_httpCtx->set_read_timeout(5, 0); // 5 seconds
|
g_httpCtx->set_read_timeout(5, 0); // 5 seconds
|
||||||
g_httpCtx->set_write_timeout(5, 0); // 5 seconds
|
g_httpCtx->set_write_timeout(5, 0); // 5 seconds
|
||||||
|
g_httpCtx->set_keep_alive(true);
|
||||||
|
g_httpCtx->enable_server_certificate_verification(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,30 +346,30 @@ template<class T1, class T2> int PlatformProtolPostMessage(const TCHAR *pUrlPath
|
||||||
lstrlen(GetGlobalCfgInfo()->clientSecret),
|
lstrlen(GetGlobalCfgInfo()->clientSecret),
|
||||||
hashValeu,
|
hashValeu,
|
||||||
true) == ERR_SUCCESS) {
|
true) == ERR_SUCCESS) {
|
||||||
if (lstrcmp(typeid(T1).name(), TEXT("class PlatformReqClientCfgParms")) == 0) {
|
if (typeid(T1) == typeid(PlatformReqClientCfgParms)) {
|
||||||
const auto *p = reinterpret_cast<PlatformReqClientCfgParms *>(pReq);
|
const auto *p = reinterpret_cast<PlatformReqClientCfgParms *>(pReq);
|
||||||
const httplib::Headers headers = {
|
const httplib::Headers headers = {
|
||||||
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
|
{"gzs-client-id", GetGlobalCfgInfo()->clientId },
|
||||||
{"gzs-sign", hashValeu },
|
{"gzs-sign", hashValeu },
|
||||||
{"gzs-timestamp", timestamp },
|
{"gzs-timestamp", timestamp },
|
||||||
{"gzs-userid", p->token.c_str() },
|
{"Authorization", ("Bearer " + p->token).c_str()},
|
||||||
};
|
};
|
||||||
|
|
||||||
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
|
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
|
||||||
} else {
|
} else {
|
||||||
const httplib::Headers headers = {
|
const httplib::Headers headers = {
|
||||||
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
|
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
|
||||||
{"gzs-sign", hashValeu },
|
{"gzs-sign", hashValeu },
|
||||||
{"gzs-timestamp", timestamp },
|
{"gzs-timestamp", timestamp },
|
||||||
};
|
};
|
||||||
|
|
||||||
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
|
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (lstrcmp(typeid(T1).name(), TEXT("class PlatformReqClientCfgParms")) == 0) {
|
if (typeid(T1) == typeid(PlatformReqClientCfgParms)) {
|
||||||
const auto *p = reinterpret_cast<PlatformReqClientCfgParms *>(pReq);
|
const auto *p = reinterpret_cast<PlatformReqClientCfgParms *>(pReq);
|
||||||
const httplib::Headers headers = {
|
const httplib::Headers headers = {
|
||||||
{"gzs-userid", p->token.c_str()},
|
{"Authorization", ("Bearer " + p->token).c_str()},
|
||||||
};
|
};
|
||||||
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
|
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
|
||||||
} else {
|
} else {
|
||||||
|
@ -375,6 +377,8 @@ template<class T1, class T2> int PlatformProtolPostMessage(const TCHAR *pUrlPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SPDLOG_DEBUG(TEXT("+++++ Http Request {0}\n---- Http Response {1}"), pJson, res->body.c_str());
|
||||||
|
|
||||||
if (res.error() != httplib::Error::Success) {
|
if (res.error() != httplib::Error::Success) {
|
||||||
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} error: {2}"), pUrlPath, pJson, httplib::to_string(res.error()));
|
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} error: {2}"), pUrlPath, pJson, httplib::to_string(res.error()));
|
||||||
free(pJson);
|
free(pJson);
|
||||||
|
@ -387,8 +391,6 @@ template<class T1, class T2> int PlatformProtolPostMessage(const TCHAR *pUrlPath
|
||||||
return -ERR_HTTP_SERVER_RSP;
|
return -ERR_HTTP_SERVER_RSP;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_DEBUG(TEXT("+++++ Http Request {0}\n---- Http Response {1}"), pJson, res->body.c_str());
|
|
||||||
|
|
||||||
free(pJson);
|
free(pJson);
|
||||||
|
|
||||||
if (lstrlen(res->body.c_str()) == 0) {
|
if (lstrlen(res->body.c_str()) == 0) {
|
||||||
|
|
|
@ -1,31 +1,30 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define USED_PORTMAP_TUNNEL (1)
|
#define USED_PORTMAP_TUNNEL (0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief WireGuard key 最大长度
|
* @brief WireGuard key 最大长度
|
||||||
*/
|
*/
|
||||||
#define WG_KEY_MAX (64)
|
#define WG_KEY_MAX (64)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 操作系统最大网卡数
|
* @brief 操作系统最大网卡数
|
||||||
*/
|
*/
|
||||||
#define NET_CARD_MAX (32)
|
#define NET_CARD_MAX (32)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief IP 字符串最大长度(支持IPv6)
|
* @brief IP 字符串最大长度(支持IPv6)
|
||||||
*/
|
*/
|
||||||
#define MAX_IP_LEN (48)
|
#define MAX_IP_LEN (48)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief IP 字符串最小长度
|
* @brief IP 字符串最小长度
|
||||||
*/
|
*/
|
||||||
#define MIN_IP_LEN (7)
|
#define MIN_IP_LEN (7)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 网卡名称字符串最大长度(支持IPv6)
|
* @brief 网卡名称字符串最大长度(支持IPv6)
|
||||||
*/
|
*/
|
||||||
#define MAX_NETCARD_NAME (64)
|
#define MAX_NETCARD_NAME (64)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SCG 服务 ID
|
* @brief SCG 服务 ID
|
||||||
|
@ -49,6 +48,29 @@ typedef enum {
|
||||||
CRYPTO_MAX,
|
CRYPTO_MAX,
|
||||||
} PROTO_CRYPTO_TYPE;
|
} PROTO_CRYPTO_TYPE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 网络连接状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
STATUS_DISCONNECTED = 0, ///< 连接已断开连接
|
||||||
|
STATUS_CONNECTING, ///< 连接正在进行连接
|
||||||
|
STATUS_CONNECTED, ///< 连接处于连接状态
|
||||||
|
STATUS_DISCONNECTING, ///< 连接正在断开连接
|
||||||
|
STATUS_HARDWARE_NOT_PRESENT, ///< 连接的硬件(例如网络接口卡 (NIC) )不存在
|
||||||
|
STATUS_HARDWARE_DISABLED, ///< 连接的硬件存在,但未启用
|
||||||
|
STATUS_HARDWARE_MALFUNCTION, ///< 连接的硬件中发生了故障
|
||||||
|
STATUS_MEDIA_DISCONNECTED, ///< 媒体(例如网络电缆)断开连接
|
||||||
|
STATUS_AUTHENTICATING, ///< 连接正在等待身份验证发生
|
||||||
|
STATUS_AUTHENTICATION_SUCCEEDED, ///< 身份验证在此连接上成功
|
||||||
|
STATUS_AUTHENTICATION_FAILED, ///< 此连接上身份验证失败
|
||||||
|
STATUS_INVALID_ADDRESS, ///< 地址无效
|
||||||
|
STATUS_CREDENTIALS_REQUIRED, ///< 需要安全凭据
|
||||||
|
STATUS_ACTION_REQUIRED, ///< 连接需要其它动作
|
||||||
|
STATUS_ACTION_REQUIRED_RETRY, ///< 重试连接其它动作
|
||||||
|
STATUS_CONNECT_FAILED, ///< 连接失败
|
||||||
|
} NET_CONNECT_STATUS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 日志等级
|
* @brief 日志等级
|
||||||
*
|
*
|
||||||
|
|
|
@ -17,14 +17,15 @@ typedef PTUNNEL_HEART_ROUTINE LPTUNNEL_HEART_ROUTINE;
|
||||||
* @brief 本地计算机网卡信息
|
* @brief 本地计算机网卡信息
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int InterfaceIndex; ///< 网卡索引
|
int InterfaceIndex; ///< 网卡索引
|
||||||
CHAR NetCardUUID[260]; ///< 网卡名称, Windows标识为 UUID
|
NET_CONNECT_STATUS netConnStatus; ///< 网卡状态 @see NET_CONNECT_STATUS
|
||||||
CHAR NetCardName[MAX_NETCARD_NAME]; ///< 网卡名称
|
CHAR NetCardUUID[260]; ///< 网卡名称, Windows标识为 UUID
|
||||||
CHAR NetCardDescription[132]; ///< 网卡描述
|
CHAR NetCardName[MAX_NETCARD_NAME]; ///< 网卡名称
|
||||||
CHAR NetCardIpaddr[MAX_IP_LEN]; ///< 网卡 IP 地址
|
CHAR NetCardDescription[132]; ///< 网卡描述
|
||||||
CHAR NetCardNetmask[MAX_IP_LEN]; ///< 网卡子网掩码
|
CHAR NetCardIpaddr[MAX_IP_LEN]; ///< 网卡 IP 地址
|
||||||
CHAR NetCardGateway[MAX_IP_LEN]; ///< 网卡网关
|
CHAR NetCardNetmask[MAX_IP_LEN]; ///< 网卡子网掩码
|
||||||
CHAR NetCardMacAddr[20]; ///< 网卡 MAC 地址
|
CHAR NetCardGateway[MAX_IP_LEN]; ///< 网卡网关
|
||||||
|
CHAR NetCardMacAddr[20]; ///< 网卡 MAC 地址
|
||||||
} NIC_CONTENT, *PNIC_CONTENT;
|
} NIC_CONTENT, *PNIC_CONTENT;
|
||||||
|
|
||||||
#ifdef __cplusplus // If used by C++ code,
|
#ifdef __cplusplus // If used by C++ code,
|
||||||
|
|
|
@ -67,6 +67,7 @@ static void InitTunnelSDKLog(const TCHAR *pLogFile, LOG_LEVEL level) {
|
||||||
const auto dupFileFilter = std::make_shared<spdlog::sinks::dup_filter_sink_st>(std::chrono::seconds(5));
|
const auto dupFileFilter = std::make_shared<spdlog::sinks::dup_filter_sink_st>(std::chrono::seconds(5));
|
||||||
const auto dupStdFilter = std::make_shared<spdlog::sinks::dup_filter_sink_st>(std::chrono::seconds(5));
|
const auto dupStdFilter = std::make_shared<spdlog::sinks::dup_filter_sink_st>(std::chrono::seconds(5));
|
||||||
|
|
||||||
|
//std::make_shared<spdlog::sinks::rotating_file_sink_mt>(buf, 1024 * 1024 * 5, 10)->
|
||||||
dupFileFilter->add_sink(std::make_shared<spdlog::sinks::daily_file_sink_mt>(buf, 2, 30));
|
dupFileFilter->add_sink(std::make_shared<spdlog::sinks::daily_file_sink_mt>(buf, 2, 30));
|
||||||
//dupFileFilter->add_sink(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(buf, 1024 * 1024 * 5, 10));
|
//dupFileFilter->add_sink(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(buf, 1024 * 1024 * 5, 10));
|
||||||
dupStdFilter->add_sink(std::make_shared<spdlog::sinks::wincolor_stdout_sink_mt>());
|
dupStdFilter->add_sink(std::make_shared<spdlog::sinks::wincolor_stdout_sink_mt>());
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#include "CppUnitTest.h"
|
#include "CppUnitTest.h"
|
||||||
|
|
||||||
#include "sccsdk.h"
|
#include "sccsdk.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
#include <cppcodec/base64_url_unpadded.hpp>
|
#include <cppcodec/base64_url_unpadded.hpp>
|
||||||
|
@ -16,10 +15,10 @@ TEST_MODULE_INITIALIZE(ModuleInitialize) {
|
||||||
const TCHAR *path = TEXT(
|
const TCHAR *path = TEXT(
|
||||||
"C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_windows\\NetTunnelApp\\bin\\Debug");
|
"C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_windows\\NetTunnelApp\\bin\\Debug");
|
||||||
|
|
||||||
Logger::WriteMessage("In Module Initialize\n");
|
Logger::WriteMessage("In Module Initialize:\n");
|
||||||
Assert::AreEqual(0,
|
Assert::AreEqual(0,
|
||||||
TunnelSDKInitEnv(path,
|
TunnelSDKInitEnv(path,
|
||||||
"http://172.21.40.39:32549",
|
"https://112.17.28.201:1443",
|
||||||
TEXT("C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_"
|
TEXT("C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_"
|
||||||
"windows\\NetTunnelApp\\bin\\Debug\\utest.log"),
|
"windows\\NetTunnelApp\\bin\\Debug\\utest.log"),
|
||||||
LOG_TRACE,
|
LOG_TRACE,
|
||||||
|
@ -199,18 +198,17 @@ public:
|
||||||
|
|
||||||
TEST_METHOD(TestBase64UrlEncode) {
|
TEST_METHOD(TestBase64UrlEncode) {
|
||||||
const std::string src = "iTeBvsuhkSOIoLB/t8qC/dBOu1lhLWwIZ675nF37MwM=";
|
const std::string src = "iTeBvsuhkSOIoLB/t8qC/dBOu1lhLWwIZ675nF37MwM=";
|
||||||
using base64urlunPad = cppcodec::base64_url_unpadded;
|
using base64urlunPad = cppcodec::base64_url_unpadded;
|
||||||
using base64url = cppcodec::base64_url;
|
using base64url = cppcodec::base64_url;
|
||||||
using base64 = cppcodec::base64_rfc4648;
|
using base64 = cppcodec::base64_rfc4648;
|
||||||
|
|
||||||
std::string base = base64::encode(src);
|
std::string base = base64::encode(src);
|
||||||
std::string baseurl = base64url::encode(src);
|
std::string baseurl = base64url::encode(src);
|
||||||
std::string baseunpad = base64urlunPad::encode(src);
|
std::string baseunpad = base64urlunPad::encode(src);
|
||||||
|
|
||||||
//std::string dbase = base64::decode(base);
|
//std::string dbase = base64::decode(base);
|
||||||
|
|
||||||
|
//std::cout << base64::encode(pSrc, lstrlen(pSrc)) << std::endl;
|
||||||
//std::cout << base64::encode(pSrc, lstrlen(pSrc)) << std::endl;
|
|
||||||
//std::string encode = ::encode(pSrc);
|
//std::string encode = ::encode(pSrc);
|
||||||
Logger::WriteMessage("[");
|
Logger::WriteMessage("[");
|
||||||
Logger::WriteMessage(base64::encode(src).c_str());
|
Logger::WriteMessage(base64::encode(src).c_str());
|
||||||
|
@ -219,7 +217,20 @@ public:
|
||||||
|
|
||||||
TEST_METHOD(TestUserLogin) {
|
TEST_METHOD(TestUserLogin) {
|
||||||
PUSER_CLIENT_CONFIG pCfg;
|
PUSER_CLIENT_CONFIG pCfg;
|
||||||
Assert::AreEqual(RET_OK, GetUserClientConfigure(TEXT("admin"), TEXT("1689189114026041344"), &pCfg));
|
Assert::AreEqual(
|
||||||
|
RET_OK,
|
||||||
|
GetUserClientConfigure(
|
||||||
|
TEXT("admin"),
|
||||||
|
TEXT("eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9."
|
||||||
|
"eyJ1c2VyX25hbWUiOiIxNjg5MTAyMjczNzEzMTg0NzY4Iiwic2NvcGUiOlsiYWxsIl0sInVzZXJUeXBlIjoidXNlciIsImV4c"
|
||||||
|
"CI6MTY5NDg1NDM0MSwiYXV0aG9yaXRpZXMiOlsiUk9MRV9SRVRBSU58MCJdLCJqdGkiOiJDOG5HNFdFSWRIdGRDWDJ3X084a2"
|
||||||
|
"xORlpYNVUiLCJhY2NvdW50IjoiY2hlbnhpYW5nIiwiY2xpZW50X2lkIjoic2Mtd2ludmRpc2RrLWVmYTl2MTJ4d3R6NWVwcHI"
|
||||||
|
"ifQ.cPJaSruDAc1BAuDnSqyvYaswGhS0jNB7MIw6pWqEwgdCBVK2JZy42t9t8MQ2xlsS41nsE0ddm-"
|
||||||
|
"qzZPPS51T5cx7SYhp8eOJva_"
|
||||||
|
"HNfWbH0H2yfYYzwe6CzjrHIT0S7wegK75tT38ZUEGQJVdVliauDO1cfj7FjKKddauBZoycLuZf7QC4O1_"
|
||||||
|
"omRkhN7r4eHvh1ZmPXarONumc0BuR7eMEu9qfbEX9IkIWzBXX-7qyAeMEdsDjROohKn9g9M1xs1_"
|
||||||
|
"uPGVclhUxhwp24038EMeMkHT9WYinZokbKIaIfFF1MCioWNSJc3BnxMXLdOKzeegt8EqYOBbmjn0SkWwnHeAevQ"),
|
||||||
|
&pCfg));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(TestClientProgress) {
|
TEST_METHOD(TestClientProgress) {
|
||||||
|
|
Loading…
Reference in New Issue