parent
fe1e2b7740
commit
a5d0c64e86
|
@ -549,7 +549,8 @@ namespace sion {
|
|||
bool enable_proxy_ = false;
|
||||
int port_ = 80;
|
||||
|
||||
POSTSOCKETCONNECTCB _postConnCb = nullptr;
|
||||
POSTSOCKETCONNECTCB _postConnCb = nullptr;
|
||||
POSTSOCKETCONNECTCB _postCloseCb = nullptr;
|
||||
|
||||
public:
|
||||
Request() {};
|
||||
|
@ -589,6 +590,11 @@ namespace sion {
|
|||
return *this;
|
||||
}
|
||||
|
||||
Request &SetClosedCb(POSTSOCKETCONNECTCB cb) {
|
||||
_postCloseCb = cb;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Request &SetBody(String body) {
|
||||
request_body_.clear();
|
||||
PushStr2Vec(body, request_body_);
|
||||
|
@ -821,6 +827,9 @@ namespace sion {
|
|||
closesocket(socket);
|
||||
WSACleanup();
|
||||
#else
|
||||
if (_postCloseCb != nullptr) {
|
||||
_postCloseCb(socket);
|
||||
}
|
||||
close(socket);
|
||||
#endif
|
||||
resp.ParseBody();
|
||||
|
|
|
@ -24,6 +24,11 @@ typedef struct {
|
|||
|
||||
static SCGPROXY_CONFIG g_scgProxyCfg;
|
||||
|
||||
static void http_closed_cb(sion::Socket sock) {
|
||||
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "---Service Close To SCG Server:vmid = %d, SCGAppId = %d: %d\n",
|
||||
g_scgProxyCfg.curConnVmId, WG_CTRL_SCG_ID, sock);
|
||||
}
|
||||
|
||||
static void http_connected_cb(sion::Socket sock) {
|
||||
int ret;
|
||||
unsigned char vmid[4];
|
||||
|
@ -31,7 +36,8 @@ static void http_connected_cb(sion::Socket sock) {
|
|||
const unsigned int id = htonl(g_scgProxyCfg.curConnVmId);
|
||||
const auto svrId = static_cast<unsigned char>(WG_CTRL_SCG_ID);
|
||||
unsigned char scgProxy[] = {0x01, // VERSION
|
||||
0x09, // Length
|
||||
0x00, // Length 0
|
||||
0x0A, // Length 1
|
||||
0xF0, // ++++++ INFO[0] TYPE
|
||||
0x04, // INFO[0] LENGTH
|
||||
0, // INFO[0] VMID[0]
|
||||
|
@ -39,24 +45,25 @@ static void http_connected_cb(sion::Socket sock) {
|
|||
0, // INFO[0] VMID[2]
|
||||
0, // INFO[0] VMID[3]
|
||||
0xF1, // INFO[1] TYPE
|
||||
0x01, // INFO[1] LENGTH
|
||||
0x00, // INFO[1] LENGTH 0
|
||||
0x01, // INFO[1] LENGTH 1
|
||||
svrId}; // ------ INFO[1] SCG Service ID
|
||||
|
||||
p = scgProxy;
|
||||
memcpy(vmid, &id, 4);
|
||||
scgProxy[4] = vmid[0];
|
||||
scgProxy[5] = vmid[1];
|
||||
scgProxy[6] = vmid[2];
|
||||
scgProxy[7] = vmid[3];
|
||||
scgProxy[5] = vmid[0];
|
||||
scgProxy[6] = vmid[1];
|
||||
scgProxy[7] = vmid[2];
|
||||
scgProxy[8] = vmid[3];
|
||||
|
||||
ret = send(sock, reinterpret_cast<const char *>(p), sizeof(scgProxy), 0);
|
||||
|
||||
if (ret != sizeof(scgProxy)) {
|
||||
ANDROID_LOG(ANDROID_LOG_WARN, "SCGPROXY", "Service Connected To SCG Server(vmid = %d, SCGAppId = %d) error: %d\n",
|
||||
ANDROID_LOG(ANDROID_LOG_WARN, "SCGPROXY", "+++Service Connected To SCG Server(vmid = %d, SCGAppId = %d) error: %d\n",
|
||||
g_scgProxyCfg.curConnVmId, WG_CTRL_SCG_ID, ret);
|
||||
}
|
||||
|
||||
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "Service Connected To SCG Server:vmid = %d, SCGAppId = %d: %d\n",
|
||||
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "+++Service Connected To SCG Server:vmid = %d, SCGAppId = %d: %d\n",
|
||||
g_scgProxyCfg.curConnVmId, WG_CTRL_SCG_ID, sock);
|
||||
}
|
||||
|
||||
|
@ -223,6 +230,7 @@ static int remote_tunnel_service_control(int vmId, bool start) {
|
|||
.SetHeader("Content-type", "application/json")
|
||||
.SetBody(pJsonString)
|
||||
.SetConnectedCb(http_connected_cb)
|
||||
.SetClosedCb(http_closed_cb)
|
||||
.Send();
|
||||
} catch (std::exception &e) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s Exception: %s\n", SET_CLIENTCFG_PATH, pJsonString, e.what());
|
||||
|
@ -387,6 +395,7 @@ int remote_tunnel_set_params(const char *pCliPubKey, const char *pCliNetwork, co
|
|||
.SetHeader("Content-type", "application/json")
|
||||
.SetBody(pJsonString)
|
||||
.SetConnectedCb(http_connected_cb)
|
||||
.SetClosedCb(http_closed_cb)
|
||||
.Send();
|
||||
} catch (std::exception &e) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s Exception: %s\n", SET_CLIENTCFG_PATH, pJsonString, e.what());
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#define UNUSED(x) UNUSED_##x __attribute__((__unused__))
|
||||
#endif
|
||||
|
||||
#define SCG_UDP_HEAD_SIZE (11)
|
||||
#define SCG_UDP_HEAD_SIZE (13)
|
||||
#define SIG_CANCEL_SIGNAL SIGUSR1
|
||||
|
||||
typedef struct {
|
||||
|
@ -152,24 +152,26 @@ static void *UDPProxyRecvThread(void *UNUSED(lpParameter)) {
|
|||
|
||||
// 构建 SCG UDP 包头
|
||||
recvBuf[0] = 0x01; // VERSION
|
||||
recvBuf[1] = 0x09; // Length
|
||||
recvBuf[2] = 0xF0; // ++++++ INFO[0] TYPE
|
||||
recvBuf[3] = 0x04; // INFO[0] LENGTH
|
||||
recvBuf[4] = 0; // INFO[0] VMID[0]
|
||||
recvBuf[5] = 0; // INFO[0] VMID[1]
|
||||
recvBuf[6] = 0; // INFO[0] VMID[2]
|
||||
recvBuf[7] = 0; // INFO[0] VMID[3]
|
||||
recvBuf[8] = 0xF1; // INFO[1] TYPE
|
||||
recvBuf[9] = 0x01; // INFO[1] LENGTH
|
||||
recvBuf[10] = WG_TUNNEL_SCG_ID; // ------ INFO[1] SCG Service ID
|
||||
recvBuf[1] = 0x0A; // Length 0
|
||||
recvBuf[2] = 0x09; // Length 1
|
||||
recvBuf[3] = 0xF0; // ++++++ INFO[0] TYPE
|
||||
recvBuf[4] = 0x04; // INFO[0] LENGTH
|
||||
recvBuf[5] = 0; // INFO[0] VMID[0]
|
||||
recvBuf[6] = 0; // INFO[0] VMID[1]
|
||||
recvBuf[7] = 0; // INFO[0] VMID[2]
|
||||
recvBuf[8] = 0; // INFO[0] VMID[3]
|
||||
recvBuf[9] = 0xF1; // INFO[1] TYPE
|
||||
recvBuf[10] = 0x00; // INFO[1] LENGTH 0
|
||||
recvBuf[11] = 0x01; // INFO[1] LENGTH 1
|
||||
recvBuf[12] = WG_TUNNEL_SCG_ID; // ------ INFO[1] SCG Service ID
|
||||
|
||||
pProxy->exitNow = false;
|
||||
while (!pProxy->exitNow) {
|
||||
#if ENABLE_UDP_PROXY_DEBUG
|
||||
char ipAddr[MAX_IPV4_LEN];
|
||||
#endif
|
||||
int addrSize = sizeof(struct sockaddr);
|
||||
int iRecvBytes;
|
||||
int addrSize = sizeof(struct sockaddr);
|
||||
int iRecvBytes;
|
||||
|
||||
// 代理服务 Out
|
||||
iRecvBytes = recvfrom(pProxy->udpProxySock,
|
||||
|
@ -206,14 +208,14 @@ static void *UDPProxyRecvThread(void *UNUSED(lpParameter)) {
|
|||
}
|
||||
}
|
||||
|
||||
recvBuf[4] = vmid[0]; // INFO[0] VMID[0]
|
||||
recvBuf[5] = vmid[1]; // INFO[0] VMID[1]
|
||||
recvBuf[6] = vmid[2]; // INFO[0] VMID[2]
|
||||
recvBuf[7] = vmid[3]; // INFO[0] VMID[3]
|
||||
recvBuf[5] = vmid[0]; // INFO[0] VMID[0]
|
||||
recvBuf[6] = vmid[1]; // INFO[0] VMID[1]
|
||||
recvBuf[7] = vmid[2]; // INFO[0] VMID[2]
|
||||
recvBuf[8] = vmid[3]; // INFO[0] VMID[3]
|
||||
|
||||
// 增加SCG包头数据长度
|
||||
#if !USED_DIRECT_PROXY
|
||||
iRecvBytes += 11;
|
||||
iRecvBytes += SCG_UDP_HEAD_SIZE;
|
||||
#else
|
||||
ANDROID_LOG(ANDROID_LOG_WARN, "SCGPROXY", "Porxy Send Data Not Add SCG UDP HEAD\n");
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue