parent
1dd2cbbfa1
commit
2258e3e315
|
@ -1,10 +1,25 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ArrayIndexOutOfBounds" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="ConstantConditionsOC" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="ConstantFunctionResult" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="ConstantParameter" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="DanglingPointer" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="EndlessLoop" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="InfiniteRecursion" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="LocalValueEscapesScope" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="LoopDoesntUseConditionVariable" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="NullDereference" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||
<option name="processCode" value="true" />
|
||||
<option name="processLiterals" value="true" />
|
||||
<option name="processComments" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="UnreachableCallsOfFunction" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="UnreachableCode" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="UnusedLocalVariable" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="UnusedParameter" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="UnusedValue" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
|
@ -14,6 +14,10 @@ android {
|
|||
versionName = "1.0"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
ndk {
|
||||
//abiFilters.add("armeabi-v7a")
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
# Sets the minimum CMake version required for this project.
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
|
||||
OPTION(SCG_ENABLE "Enable SCG Proxy Service" OFF)
|
||||
|
||||
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
|
||||
# Since this is the top level CMakeLists.txt, the project name is also accessible
|
||||
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
|
||||
|
@ -13,6 +15,7 @@ project("sccproxy")
|
|||
|
||||
INCLUDE_DIRECTORIES(include ./)
|
||||
FILE(GLOB C_HEADS ./include/*.h ./cJSON/cJSON.h)
|
||||
ADD_DEFINITIONS(-D_LINUX)
|
||||
|
||||
# Creates and names a library, sets it as either STATIC
|
||||
# or SHARED, and provides the relative paths to its source code.
|
||||
|
@ -27,14 +30,25 @@ FILE(GLOB C_HEADS ./include/*.h ./cJSON/cJSON.h)
|
|||
# System.loadLibrary() and pass the name of the library defined here;
|
||||
# for GameActivity/NativeActivity derived applications, the same library name must be
|
||||
# used in the AndroidManifest.xml file.
|
||||
add_library(${CMAKE_PROJECT_NAME} SHARED
|
||||
ADD_LIBRARY(${CMAKE_PROJECT_NAME} SHARED
|
||||
# List C/C++ source files with relative paths to this CMakeLists.txt.
|
||||
native-lib.cpp srcs/ipcalc.cpp srcs/scc-service.cpp srcs/tunnel-proxy.cpp cJSON/cJSON.c ${C_HEADS})
|
||||
native-lib.cpp http/http-client.cpp srcs/ipcalc.cpp srcs/scc-service.cpp srcs/tunnel-proxy.cpp cJSON/cJSON.c ${C_HEADS})
|
||||
|
||||
|
||||
MESSAGE(STATUS "SRC DIRECTORY: ${CMAKE_SOURCE_DIR}")
|
||||
# Specifies libraries CMake should link to your target library. You
|
||||
# can link libraries from various origins, such as libraries defined in this
|
||||
# build script, prebuilt third-party libraries, or Android system libraries.
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
# List libraries link to the target library
|
||||
android
|
||||
log)
|
||||
IF (SCG_ENABLE)
|
||||
ADD_DEFINITIONS(-DSCG_ON)
|
||||
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME}
|
||||
# List libraries link to the target library
|
||||
android
|
||||
log
|
||||
${CMAKE_SOURCE_DIR}/scg/libjwae.a)
|
||||
ELSE()
|
||||
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME}
|
||||
# List libraries link to the target library
|
||||
android
|
||||
log)
|
||||
ENDIF ()
|
||||
|
|
|
@ -0,0 +1,267 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <cstring>
|
||||
#include "log.h"
|
||||
#include "http-client.h"
|
||||
#include "sccproxy.h"
|
||||
#include "scg-service.h"
|
||||
|
||||
#define MY_HTTP_DEFAULT_PORT 80
|
||||
|
||||
#define BUFFER_SIZE 1024
|
||||
#define HTTP_POST "POST /%s HTTP/1.1\r\nHOST: %s:%d\r\nAccept: */*\r\n"\
|
||||
"Content-Type:application/json\r\nContent-Length: %d\r\n\r\n%s"
|
||||
#define HTTP_GET "GET /%s HTTP/1.1\r\nHOST: %s:%d\r\nAccept: */*\r\n\r\n"
|
||||
|
||||
static void send_scg_head(int sock, int vmId) {
|
||||
int ret;
|
||||
unsigned char vmid[4];
|
||||
unsigned char *p;
|
||||
const unsigned int id = htonl(vmId);
|
||||
const auto svrId = static_cast<unsigned char>(WG_CTRL_SCG_ID);
|
||||
unsigned char scgProxy[] = {0x01, // VERSION
|
||||
0x09, // Length
|
||||
0xF0, // ++++++ INFO[0] TYPE
|
||||
0x04, // INFO[0] LENGTH
|
||||
0, // INFO[0] VMID[0]
|
||||
0, // INFO[0] VMID[1]
|
||||
0, // INFO[0] VMID[2]
|
||||
0, // INFO[0] VMID[3]
|
||||
0xF1, // INFO[1] TYPE
|
||||
0x01, // INFO[1] LENGTH
|
||||
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];
|
||||
|
||||
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",
|
||||
vmId, WG_CTRL_SCG_ID, ret);
|
||||
}
|
||||
|
||||
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "Service Connected To SCG Server:vmid = %d, SCGAppId = %d: %d\n",
|
||||
vmId, WG_CTRL_SCG_ID, sock);
|
||||
}
|
||||
|
||||
static int http_tcpclient_create(const char *host, int port) {
|
||||
struct hostent *he;
|
||||
struct sockaddr_in server_addr {};
|
||||
int socket_fd;
|
||||
|
||||
if ((he = gethostbyname(host)) == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_port = htons(port);
|
||||
server_addr.sin_addr = *((struct in_addr *) he->h_addr);
|
||||
|
||||
if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (connect(socket_fd, (struct sockaddr *) &server_addr, sizeof(struct sockaddr)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//if(get_scg_cur_vmid() > 0) {
|
||||
send_scg_head(socket_fd, get_scg_cur_vmid());
|
||||
//}
|
||||
|
||||
return socket_fd;
|
||||
}
|
||||
|
||||
static void http_tcpclient_close(int socket) {
|
||||
close(socket);
|
||||
}
|
||||
|
||||
static int http_parse_url(const char *url, char *host, char *file, int *port) {
|
||||
char *ptr1, *ptr2;
|
||||
int len = 0;
|
||||
if (!url || !host || !file || !port) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ptr1 = (char *) url;
|
||||
|
||||
if (!strncmp(ptr1, "http://", strlen("http://"))) {
|
||||
ptr1 += strlen("http://");
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ptr2 = strchr(ptr1, '/');
|
||||
if (ptr2) {
|
||||
len = strlen(ptr1) - strlen(ptr2);
|
||||
memcpy(host, ptr1, len);
|
||||
host[len] = '\0';
|
||||
if (*(ptr2 + 1)) {
|
||||
memcpy(file, ptr2 + 1, strlen(ptr2) - 1);
|
||||
file[strlen(ptr2) - 1] = '\0';
|
||||
}
|
||||
} else {
|
||||
memcpy(host, ptr1, strlen(ptr1));
|
||||
host[strlen(ptr1)] = '\0';
|
||||
}
|
||||
//get host and ip
|
||||
ptr1 = strchr(host, ':');
|
||||
if (ptr1) {
|
||||
*ptr1++ = '\0';
|
||||
*port = atoi(ptr1);
|
||||
} else {
|
||||
*port = MY_HTTP_DEFAULT_PORT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int http_tcpclient_recv(int socket, char *lpbuff) {
|
||||
int recvnum = 0;
|
||||
|
||||
recvnum = recv(socket, lpbuff, BUFFER_SIZE * 4, 0);
|
||||
|
||||
return recvnum;
|
||||
}
|
||||
|
||||
static int http_tcpclient_send(int socket, char *buff, int size) {
|
||||
int sent = 0, tmpres = 0;
|
||||
|
||||
while (sent < size) {
|
||||
tmpres = send(socket, buff + sent, size - sent, 0);
|
||||
if (tmpres == -1) {
|
||||
return -1;
|
||||
}
|
||||
sent += tmpres;
|
||||
}
|
||||
return sent;
|
||||
}
|
||||
|
||||
static char *http_parse_result(const char *lpbuf) {
|
||||
char *ptmp = nullptr;
|
||||
char *response = nullptr;
|
||||
ptmp = (char *) strstr(lpbuf, "HTTP/1.1");
|
||||
if (!ptmp) {
|
||||
printf("http/1.1 not faind\n");
|
||||
return nullptr;
|
||||
}
|
||||
if (atoi(ptmp + 9) != 200) {
|
||||
printf("result:\n%s\n", lpbuf);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ptmp = (char *) strstr(lpbuf, "\r\n\r\n");
|
||||
if (!ptmp) {
|
||||
printf("ptmp is nullptr\n");
|
||||
return nullptr;
|
||||
}
|
||||
response = (char *) malloc(strlen(ptmp) + 1);
|
||||
if (!response) {
|
||||
printf("malloc failed \n");
|
||||
return nullptr;
|
||||
}
|
||||
strcpy(response, ptmp + 4);
|
||||
return response;
|
||||
}
|
||||
|
||||
char *http_post(const char *url, const char *post_str) {
|
||||
|
||||
char post[BUFFER_SIZE] = {'\0'};
|
||||
int socket_fd = -1;
|
||||
char lpbuf[BUFFER_SIZE * 4] = {'\0'};
|
||||
char *ptmp;
|
||||
char host_addr[BUFFER_SIZE] = {'\0'};
|
||||
char file[BUFFER_SIZE] = {'\0'};
|
||||
int port = 0;
|
||||
int len = 0;
|
||||
char *response = nullptr;
|
||||
|
||||
if (!url || !post_str) {
|
||||
printf(" failed!\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (http_parse_url(url, host_addr, file, &port)) {
|
||||
printf("http_parse_url failed!\n");
|
||||
return nullptr;
|
||||
}
|
||||
//printf("host_addr : %s\tfile:%s\t,%d\n",host_addr,file,port);
|
||||
|
||||
socket_fd = http_tcpclient_create(host_addr, port);
|
||||
if (socket_fd < 0) {
|
||||
printf("http_tcpclient_create failed\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sprintf(lpbuf, HTTP_POST, file, host_addr, port, static_cast<int>(strlen(post_str)), post_str);
|
||||
|
||||
if (http_tcpclient_send(socket_fd, lpbuf, static_cast<int>(strlen(lpbuf))) < 0) {
|
||||
printf("http_tcpclient_send failed..\n");
|
||||
return nullptr;
|
||||
}
|
||||
//printf("发送请求:\n%s\n",lpbuf);
|
||||
|
||||
/*it's time to recv from server*/
|
||||
if (http_tcpclient_recv(socket_fd, lpbuf) <= 0) {
|
||||
printf("http_tcpclient_recv failed\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
http_tcpclient_close(socket_fd);
|
||||
|
||||
return http_parse_result(lpbuf);
|
||||
}
|
||||
|
||||
char *http_get(const char *url) {
|
||||
|
||||
char post[BUFFER_SIZE] = {'\0'};
|
||||
int socket_fd = -1;
|
||||
char lpbuf[BUFFER_SIZE * 4] = {'\0'};
|
||||
char *ptmp;
|
||||
char host_addr[BUFFER_SIZE] = {'\0'};
|
||||
char file[BUFFER_SIZE] = {'\0'};
|
||||
int port = 0;
|
||||
int len = 0;
|
||||
|
||||
if (!url) {
|
||||
printf(" failed!\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (http_parse_url(url, host_addr, file, &port)) {
|
||||
printf("http_parse_url failed!\n");
|
||||
return nullptr;
|
||||
}
|
||||
//printf("host_addr : %s\tfile:%s\t,%d\n",host_addr,file,port);
|
||||
|
||||
socket_fd = http_tcpclient_create(host_addr, port);
|
||||
if (socket_fd < 0) {
|
||||
printf("http_tcpclient_create failed\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sprintf(lpbuf, HTTP_GET, file, host_addr, port);
|
||||
|
||||
if (http_tcpclient_send(socket_fd, lpbuf, static_cast<int>(strlen(lpbuf))) < 0) {
|
||||
printf("http_tcpclient_send failed..\n");
|
||||
return nullptr;
|
||||
}
|
||||
// printf("发送请求:\n%s\n",lpbuf);
|
||||
|
||||
if (http_tcpclient_recv(socket_fd, lpbuf) <= 0) {
|
||||
printf("http_tcpclient_recv failed\n");
|
||||
return nullptr;
|
||||
}
|
||||
http_tcpclient_close(socket_fd);
|
||||
|
||||
return http_parse_result(lpbuf);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
char * http_get(const char *url);
|
||||
char * http_post(const char *url,const char * post_str);
|
File diff suppressed because it is too large
Load Diff
|
@ -38,11 +38,16 @@ extern "C" {
|
|||
int init_scgproxy_service(const char *pSCGIpAddr, int scgPort);
|
||||
|
||||
/**
|
||||
* @brief 启动远程隧道服务端
|
||||
* @brief 连接到远程虚拟机
|
||||
* @param[in] vmId 云电脑虚拟机 VMID
|
||||
*/
|
||||
void remote_connect_vm_service(int vmId);
|
||||
|
||||
/**
|
||||
* @brief 启动远程隧道服务端
|
||||
* @return 函数执行结果 0: 成功, 小于0 失败 @see USER_ERRNO
|
||||
*/
|
||||
int remote_tunnel_service_start(int vmId);
|
||||
int remote_tunnel_service_start();
|
||||
|
||||
/**
|
||||
* @brief 停止远程隧道服务端
|
||||
|
|
|
@ -4,17 +4,51 @@
|
|||
#include "sccproxy.h"
|
||||
#include "log.h"
|
||||
#include "usrerr.h"
|
||||
#include "./scg/jwae.h"
|
||||
|
||||
#ifdef SCG_ON
|
||||
static void connect_scg_server() {
|
||||
|
||||
//1、设置token
|
||||
jwae_set_token("token1234");
|
||||
|
||||
//2、init scg服务
|
||||
StartConfig start_config;
|
||||
start_config.mode = 2; //0:tcp 1:udp 2:tcp and udp
|
||||
|
||||
start_config.server_ip = "112.17.28.215";
|
||||
start_config.client_ip = "127.0.0.1";
|
||||
start_config.path = "/sdcard/";
|
||||
|
||||
start_config.auth_type = 2;
|
||||
start_config.server_port = 10800;
|
||||
start_config.client_port = 10800;
|
||||
start_config.encrypt = 0;
|
||||
int ret = jwae_start(&start_config);
|
||||
|
||||
ANDROID_LOG(ANDROID_LOG_INFO, "SCGPROXY", "connect_scg_server: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
extern "C" JNIEXPORT jstring JNICALL
|
||||
Java_com_example_sccproxy_MainActivity_stringFromJNI(
|
||||
JNIEnv *env,
|
||||
jobject /* this */) {
|
||||
int ret;
|
||||
int vmId = 123;
|
||||
int vmId = 61;
|
||||
char svrTunnelNetwork[256];
|
||||
unsigned short tunnelProxyPort = 0;
|
||||
|
||||
std::string hello = "Hello from C++";
|
||||
|
||||
#ifdef SCG_ON
|
||||
connect_scg_server();
|
||||
#endif
|
||||
|
||||
// struct http_response *hresp = http_get("http://xajhuang.com:32400", "User-agent:MyUserAgent\r\n");
|
||||
//
|
||||
// if(hresp == nullptr) {
|
||||
// ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "http_get error\n");
|
||||
// }
|
||||
//-----------------------------------------------------------------------
|
||||
// 系统初始化, 程序启动时调用一次
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -38,9 +72,13 @@ Java_com_example_sccproxy_MainActivity_stringFromJNI(
|
|||
goto error;
|
||||
}
|
||||
|
||||
#if 1
|
||||
//-----------------------------------------------------------------------
|
||||
// 隧道控制,每次启动/停止 SCC 服务时调用
|
||||
//-----------------------------------------------------------------------
|
||||
// SCC Service Step 0. 设置客户端 SCC 服务需要连接虚拟机
|
||||
remote_connect_vm_service(vmId);
|
||||
|
||||
// SCC Service Step 1. 客户端获取隧道配置并连接到虚拟机后,首先要对虚拟机里面的隧道进行配置
|
||||
/**
|
||||
{
|
||||
|
@ -90,7 +128,7 @@ Java_com_example_sccproxy_MainActivity_stringFromJNI(
|
|||
*/
|
||||
|
||||
// SCC Service Step 3. 启动虚拟机内服务端隧道
|
||||
ret = remote_tunnel_service_start(vmId);
|
||||
ret = remote_tunnel_service_start();
|
||||
if (ret == ERR_SUCCESS) {
|
||||
ANDROID_LOG(ANDROID_LOG_INFO, "SCGPROXY", "remote_tunnel_service_start: SUCCESSED, Current Connect VMID: %d\n", vmId);
|
||||
} else {
|
||||
|
@ -134,7 +172,7 @@ Java_com_example_sccproxy_MainActivity_stringFromJNI(
|
|||
|
||||
// UnInit step 4. 停止客户端 Wireguard 隧道 UDP 代理服务
|
||||
stop_wireguard_proxy_server();
|
||||
|
||||
error:
|
||||
#endif
|
||||
error:
|
||||
return env->NewStringUTF(hello.c_str());
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
{
|
||||
"ver": "0.3.2",
|
||||
"log": {
|
||||
"level": "info"
|
||||
},
|
||||
"monitor_server": {
|
||||
"addr": "127.0.0.1",
|
||||
"port": 12000
|
||||
},
|
||||
"local_setting": {
|
||||
"spec": {
|
||||
"max_rule_cache_size": 10000,
|
||||
"max_tcp_session_size": 10000,
|
||||
"max_udp_session_size": 10000
|
||||
},
|
||||
"connection_pool": {
|
||||
"connection_pool_size": 1,
|
||||
"new_connection_period": 10,
|
||||
"choose_connection_method": "random"
|
||||
},
|
||||
"session": {
|
||||
"tcp_session_timeout": 259200,
|
||||
"udp_session_timeout": 259200
|
||||
},
|
||||
"xe_init": {
|
||||
"mtu": 1450,
|
||||
"sender_slidwnd_size": 40000,
|
||||
"receiver_slidwnd_size": 40000,
|
||||
"syn_queue_size": 512,
|
||||
"nodelay": false,
|
||||
"handshake_timeout": 5,
|
||||
"retry_handshake_num": 5,
|
||||
"ack_loop_period": 5000,
|
||||
"conn_info_loop_period":200000,
|
||||
"encrypt": false
|
||||
},
|
||||
"keepalive": {
|
||||
"keepalive_timeout": 30,
|
||||
"heartbeat_period": 6
|
||||
},
|
||||
"drc": {
|
||||
"drc_enable": false,
|
||||
"drc_time_wnd": 100,
|
||||
"drc_count_max": 10,
|
||||
"drc_loss_rate": 0.0001
|
||||
},
|
||||
"rate": {
|
||||
"cycle": 500,
|
||||
"loop_period": 200,
|
||||
"sin_a": 0.96,
|
||||
"sin_b": 0.53
|
||||
},
|
||||
"stream_options": [
|
||||
{
|
||||
"port": 0,
|
||||
"protocol": "tcp",
|
||||
"ordering": true,
|
||||
"retransmit": true,
|
||||
"congestion_ctl": true
|
||||
},
|
||||
{
|
||||
"port": 0,
|
||||
"protocol": "udp",
|
||||
"ordering": false,
|
||||
"retransmit": true,
|
||||
"retransmit_timeout": 300,
|
||||
"congestion_ctl": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"inbounds": [
|
||||
{
|
||||
"tag": "redirect_socket1",
|
||||
"listening_address": "0.0.0.0",
|
||||
"listening_port": 10800,
|
||||
"role": "redirect_socket",
|
||||
"next": "aac1"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct StartConfig {
|
||||
unsigned int mode;
|
||||
unsigned int auth_type;
|
||||
const char *server_ip;
|
||||
unsigned int server_port;
|
||||
const char *client_ip;
|
||||
unsigned int client_port;
|
||||
const char *path;
|
||||
unsigned int encrypt;
|
||||
} StartConfig;
|
||||
|
||||
typedef struct ConnInfo {
|
||||
unsigned long long send_rate;
|
||||
unsigned long long recv_rate;
|
||||
unsigned long long rtt_mean;
|
||||
float loss_rate;
|
||||
} ConnInfo;
|
||||
|
||||
int jwae_start(struct StartConfig *config);
|
||||
|
||||
int jwae_stop(void);
|
||||
|
||||
void jwae_set_user_passwd(const char *username, const char *password);
|
||||
|
||||
void jwae_set_token(const char *token);
|
||||
|
||||
int jwae_set_log(bool log_conf_flag,
|
||||
const char *level,
|
||||
const char *path,
|
||||
uint64_t size,
|
||||
uint32_t count);
|
||||
|
||||
int32_t jwae_get_errno(int32_t *errno, char *err_buff, uint32_t buff_len);
|
||||
|
||||
int jwae_get_connection_info(struct ConnInfo *conn_info);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Binary file not shown.
|
@ -1,20 +1,25 @@
|
|||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include "usrerr.h"
|
||||
#include "httplib.h"
|
||||
#include "log.h"
|
||||
#include "sccproxy.h"
|
||||
#include "ipcalc.h"
|
||||
#include "scg-service.h"
|
||||
#include "../cJSON/cJSON.h"
|
||||
#include "../http/http-client.h"
|
||||
|
||||
#define SET_CLIENTCFG_PATH ("/tunnel/setconfig")
|
||||
#define SET_CLIENTSTART_TUNNEL ("/tunnel/start")
|
||||
|
||||
typedef struct {
|
||||
char scgProxyIpAddr[MAX_PATH];
|
||||
int scgProxyPort;
|
||||
int curConnVmId;
|
||||
int isEnable;
|
||||
httplib::Client *g_tunCtrlCtx;
|
||||
char scgProxyUrl[MAX_PATH];
|
||||
char scgProxyIpAddr[MAX_PATH];
|
||||
int scgProxyPort;
|
||||
int curConnVmId;
|
||||
int isEnable;
|
||||
//httplib::Client *g_tunCtrlCtx;
|
||||
} SCGPROXY_CONFIG, *PSCGPROXY_CONFIG;
|
||||
|
||||
static SCGPROXY_CONFIG g_scgProxyCfg;
|
||||
|
@ -40,7 +45,6 @@ unsigned short get_scg_proxy_port() {
|
|||
int init_scgproxy_service(const char *pSCGIpAddr, int scgPort) {
|
||||
IP_INFO ipInfo;
|
||||
int ret;
|
||||
char scgProxyUrl[MAX_PATH * 4];
|
||||
|
||||
memset(&g_scgProxyCfg, 0, sizeof(SCGPROXY_CONFIG));
|
||||
|
||||
|
@ -54,29 +58,36 @@ int init_scgproxy_service(const char *pSCGIpAddr, int scgPort) {
|
|||
return -ERR_INPUT_PARAMS;
|
||||
}
|
||||
|
||||
ANDROID_LOG(ANDROID_LOG_INFO, "SCGPROXY", "Enable SCG Proxy: %s:%d, Tunnel Control VMID = %d, Tunnel Data VMID = %d \n",
|
||||
ANDROID_LOG(ANDROID_LOG_INFO, "SCGPROXY", "Enable SCG Proxy: %s:%d, Tunnel Control APPID = %d, Tunnel Data APPID = %d \n",
|
||||
pSCGIpAddr, scgPort, WG_CTRL_SCG_ID, WG_TUNNEL_SCG_ID);
|
||||
|
||||
if ((ret = get_ipv4_info_from_hostname(pSCGIpAddr, &ipInfo)) != ERR_SUCCESS) {
|
||||
ANDROID_LOG(ANDROID_LOG_WARN, "SCGPROXY", "get_ipv4_info_from_hostname error: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
httplib::Client* cli = new httplib::Client("http://xajhuang.com:32400");
|
||||
auto res = cli->Get("/");
|
||||
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "GET: %d\n", res->status);
|
||||
#endif
|
||||
strncpy(g_scgProxyCfg.scgProxyIpAddr, ipInfo.hostip, MAX_PATH);
|
||||
g_scgProxyCfg.scgProxyPort = scgPort;
|
||||
|
||||
memset(scgProxyUrl, 0, MAX_PATH * 4);
|
||||
snprintf(scgProxyUrl, MAX_PATH * 4 - 1, "http://%s:%d", g_scgProxyCfg.scgProxyIpAddr, g_scgProxyCfg.scgProxyPort);
|
||||
g_scgProxyCfg.g_tunCtrlCtx = new httplib::Client(scgProxyUrl);
|
||||
memset(g_scgProxyCfg.scgProxyUrl, 0, MAX_PATH);
|
||||
snprintf(g_scgProxyCfg.scgProxyUrl, MAX_PATH, "http://%s:%d", g_scgProxyCfg.scgProxyIpAddr, g_scgProxyCfg.scgProxyPort);
|
||||
|
||||
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "SCC Service Redirect To SCG Proxy Service: %s\n", g_scgProxyCfg.scgProxyUrl);
|
||||
|
||||
#if 0
|
||||
g_scgProxyCfg.g_tunCtrlCtx = new httplib::Client(scgProxyUrl);
|
||||
if (g_scgProxyCfg.g_tunCtrlCtx == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_WARN, "SCGPROXY", "Create HTTP Proxy error: %s\n", scgProxyUrl);
|
||||
return -ERR_SYSTEM_UNINITIALIZE;
|
||||
} else {
|
||||
g_scgProxyCfg.g_tunCtrlCtx->set_connection_timeout(0, 1000000); // 1 second
|
||||
g_scgProxyCfg.g_tunCtrlCtx->set_connection_timeout(5, 1000000); // 1 second
|
||||
g_scgProxyCfg.g_tunCtrlCtx->set_read_timeout(5, 0); // 5 seconds
|
||||
g_scgProxyCfg.g_tunCtrlCtx->set_write_timeout(5, 0); // 5 seconds
|
||||
g_scgProxyCfg.g_tunCtrlCtx->set_keep_alive(true);
|
||||
//g_scgProxyCfg.g_tunCtrlCtx->set_keep_alive(false);
|
||||
g_scgProxyCfg.g_tunCtrlCtx->set_post_connect_cb([](socket_t sock) {
|
||||
int ret;
|
||||
unsigned char vmid[4];
|
||||
|
@ -113,13 +124,20 @@ int init_scgproxy_service(const char *pSCGIpAddr, int scgPort) {
|
|||
g_scgProxyCfg.curConnVmId, WG_CTRL_SCG_ID, sock);
|
||||
});
|
||||
}
|
||||
|
||||
#endif
|
||||
g_scgProxyCfg.isEnable = true;
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
static int remote_tunnel_service_control(int vmId, bool start) {
|
||||
char *pJsonString;
|
||||
cJSON *pRoot;
|
||||
cJSON *pMsgContent;
|
||||
cJSON *rspCode;
|
||||
char url[1024];
|
||||
char *pSvrResp;
|
||||
|
||||
if (vmId < 0) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Input pSCGIpAddr params error: %d\n", vmId);
|
||||
return -ERR_INPUT_PARAMS;
|
||||
|
@ -130,95 +148,79 @@ static int remote_tunnel_service_control(int vmId, bool start) {
|
|||
return -ERR_SYSTEM_UNINITIALIZE;
|
||||
}
|
||||
|
||||
if (g_scgProxyCfg.g_tunCtrlCtx == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_WARN, "SCGPROXY", "Server Control Service don't connected(g_tunnelHttpCtx is not initialize).");
|
||||
return -ERR_SYSTEM_UNINITIALIZE;
|
||||
} else {
|
||||
char *pJsonString;
|
||||
cJSON *pRoot;
|
||||
cJSON *pMsgContent;
|
||||
cJSON *rspCode;
|
||||
httplib::Result res;
|
||||
g_scgProxyCfg.curConnVmId = vmId;
|
||||
|
||||
g_scgProxyCfg.curConnVmId = vmId;
|
||||
pRoot = cJSON_CreateObject();
|
||||
|
||||
pRoot = cJSON_CreateObject();
|
||||
|
||||
if (pRoot == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Create JSON Error.\n");
|
||||
return -ERR_JSON_CREATE;
|
||||
}
|
||||
|
||||
cJSON_AddNumberToObject(pRoot, "ver", 1);
|
||||
cJSON_AddNumberToObject(pRoot, "cryptoType", 0);
|
||||
cJSON_AddNumberToObject(pRoot, "timeStamp", time(nullptr));
|
||||
|
||||
pMsgContent = cJSON_CreateObject();
|
||||
if (pMsgContent == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Create JSON Error.\n");
|
||||
cJSON_Delete(pRoot);
|
||||
return -ERR_JSON_CREATE;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(pRoot, "msgContent", pMsgContent);
|
||||
cJSON_AddBoolToObject(pMsgContent, "isStart", start);
|
||||
|
||||
pJsonString = cJSON_PrintUnformatted(pRoot);
|
||||
cJSON_Delete(pRoot);
|
||||
|
||||
res = g_scgProxyCfg.g_tunCtrlCtx->Post(SET_CLIENTSTART_TUNNEL, pJsonString, "application/json");
|
||||
|
||||
if (res.error() != httplib::Error::Success) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s error: %s\n", SET_CLIENTSTART_TUNNEL, pJsonString,
|
||||
httplib::to_string(res.error()).c_str());
|
||||
free(pJsonString);
|
||||
return -ERR_HTTP_POST_DATA;
|
||||
}
|
||||
|
||||
if (res->status != 200) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s server return HTTP error: %d\n", SET_CLIENTSTART_TUNNEL,
|
||||
pJsonString,
|
||||
res->status);
|
||||
free(pJsonString);
|
||||
return -ERR_HTTP_SERVER_RSP;
|
||||
}
|
||||
|
||||
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "+++++ Http Request %s\n---- Http Response %s\n", pJsonString, res->body.c_str());
|
||||
|
||||
free(pJsonString);
|
||||
|
||||
if (strlen(res->body.c_str()) == 0) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Server response empty message.\n");
|
||||
return -ERR_READ_FILE;
|
||||
}
|
||||
|
||||
pRoot = cJSON_Parse(res->body.c_str());
|
||||
|
||||
if (pRoot == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode JSON %s Error.\n", res->body.c_str());
|
||||
return -ERR_JSON_DECODE;
|
||||
}
|
||||
|
||||
pMsgContent = cJSON_GetObjectItem(pRoot, "msgContent");
|
||||
|
||||
if (pMsgContent == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent) JSON %s Error.\n", res->body.c_str());
|
||||
cJSON_Delete(pRoot);
|
||||
return -ERR_JSON_DECODE;
|
||||
}
|
||||
|
||||
rspCode = cJSON_GetObjectItem(pMsgContent, "errCode");
|
||||
|
||||
if (rspCode == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.rspCode) JSON %s Error.\n", res->body.c_str());
|
||||
cJSON_Delete(pRoot);
|
||||
return -ERR_JSON_DECODE;
|
||||
}
|
||||
|
||||
cJSON_Delete(pRoot);
|
||||
|
||||
return rspCode->valueint;
|
||||
if (pRoot == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Create JSON Error.\n");
|
||||
return -ERR_JSON_CREATE;
|
||||
}
|
||||
|
||||
cJSON_AddNumberToObject(pRoot, "ver", 1);
|
||||
cJSON_AddNumberToObject(pRoot, "cryptoType", 0);
|
||||
cJSON_AddNumberToObject(pRoot, "timeStamp", time(nullptr));
|
||||
|
||||
pMsgContent = cJSON_CreateObject();
|
||||
if (pMsgContent == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Create JSON Error.\n");
|
||||
cJSON_Delete(pRoot);
|
||||
return -ERR_JSON_CREATE;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(pRoot, "msgContent", pMsgContent);
|
||||
cJSON_AddBoolToObject(pMsgContent, "isStart", start);
|
||||
|
||||
pJsonString = cJSON_PrintUnformatted(pRoot);
|
||||
cJSON_Delete(pRoot);
|
||||
|
||||
memset(url, 0, 1024);
|
||||
snprintf(url, 1024, "%s%s", g_scgProxyCfg.scgProxyUrl, SET_CLIENTSTART_TUNNEL);
|
||||
pSvrResp = http_post(url, pJsonString);
|
||||
|
||||
// res = g_scgProxyCfg.g_tunCtrlCtx->Post(SET_CLIENTSTART_TUNNEL, pJsonString, "application/json");
|
||||
|
||||
if (pSvrResp == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s error\n", SET_CLIENTSTART_TUNNEL, pJsonString);
|
||||
free(pJsonString);
|
||||
return -ERR_HTTP_POST_DATA;
|
||||
}
|
||||
|
||||
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "+++++ Http Request %s\n---- Http Response %s\n", pJsonString, pSvrResp);
|
||||
|
||||
free(pJsonString);
|
||||
|
||||
if (strlen(pSvrResp) == 0) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Server response empty message.\n");
|
||||
return -ERR_READ_FILE;
|
||||
}
|
||||
|
||||
pRoot = cJSON_Parse(pSvrResp);
|
||||
|
||||
if (pRoot == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode JSON %s Error.\n", pSvrResp);
|
||||
return -ERR_JSON_DECODE;
|
||||
}
|
||||
|
||||
pMsgContent = cJSON_GetObjectItem(pRoot, "msgContent");
|
||||
|
||||
if (pMsgContent == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent) JSON %s Error.\n", pSvrResp);
|
||||
cJSON_Delete(pRoot);
|
||||
return -ERR_JSON_DECODE;
|
||||
}
|
||||
|
||||
rspCode = cJSON_GetObjectItem(pMsgContent, "errCode");
|
||||
|
||||
if (rspCode == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.rspCode) JSON %s Error.\n", pSvrResp);
|
||||
cJSON_Delete(pRoot);
|
||||
return -ERR_JSON_DECODE;
|
||||
}
|
||||
|
||||
cJSON_Delete(pRoot);
|
||||
|
||||
return rspCode->valueint;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,11 +233,19 @@ int remote_tunnel_service_stop() {
|
|||
|
||||
/**
|
||||
* @brief 启动远程隧道服务端
|
||||
* @param[in] vmId 云电脑虚拟机 VMID
|
||||
* @return 函数执行结果 0: 成功, 小于0 失败 @see USER_ERRNO
|
||||
*/
|
||||
int remote_tunnel_service_start(int vmId) {
|
||||
return remote_tunnel_service_control(vmId, true);
|
||||
int remote_tunnel_service_start() {
|
||||
return remote_tunnel_service_control(g_scgProxyCfg.curConnVmId, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 连接到远程虚拟机
|
||||
* @param[in] vmId 云电脑虚拟机 VMID
|
||||
*/
|
||||
void remote_connect_vm_service(int vmId) {
|
||||
g_scgProxyCfg.curConnVmId = vmId;
|
||||
ANDROID_LOG(ANDROID_LOG_INFO, "SCGPROXY", "Current Connect VM Id: %d\n", vmId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -252,7 +262,8 @@ int remote_tunnel_set_params(const char *pCliPubKey, const char *pCliNetwork, co
|
|||
cJSON *pMsgContent;
|
||||
cJSON *pRspCode;
|
||||
cJSON *pSvrNet;
|
||||
httplib::Result res;
|
||||
char url[1024];
|
||||
char *pSvrResp;
|
||||
|
||||
if (pCliPubKey == nullptr || strlen(pCliPubKey) == 0) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Input pCliPubKey params error: %s\n", pCliPubKey ? pCliPubKey : "NULL String");
|
||||
|
@ -265,7 +276,8 @@ int remote_tunnel_set_params(const char *pCliPubKey, const char *pCliNetwork, co
|
|||
}
|
||||
|
||||
if (pCliTunNetwork == nullptr || strlen(pCliTunNetwork) == 0) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Input pCliTunNetwork params error: %s\n", pCliTunNetwork ? pCliTunNetwork : "NULL String");
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Input pCliTunNetwork params error: %s\n",
|
||||
pCliTunNetwork ? pCliTunNetwork : "NULL String");
|
||||
return -ERR_INPUT_PARAMS;
|
||||
}
|
||||
|
||||
|
@ -309,42 +321,50 @@ int remote_tunnel_set_params(const char *pCliPubKey, const char *pCliNetwork, co
|
|||
pJsonString = cJSON_PrintUnformatted(pRoot);
|
||||
cJSON_Delete(pRoot);
|
||||
|
||||
res = g_scgProxyCfg.g_tunCtrlCtx->Post(SET_CLIENTCFG_PATH, pJsonString, "application/json");
|
||||
memset(url, 0, 1024);
|
||||
snprintf(url, 1024, "%s%s", g_scgProxyCfg.scgProxyUrl, SET_CLIENTCFG_PATH);
|
||||
pSvrResp = http_post(url, pJsonString);
|
||||
|
||||
if (res.error() != httplib::Error::Success) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s error: %s\n", SET_CLIENTCFG_PATH, pJsonString,
|
||||
httplib::to_string(res.error()).c_str());
|
||||
#if 0
|
||||
memset(url, 0, 1024);
|
||||
//sprintf(url, "%s", g_scgProxyCfg.)
|
||||
snprintf(url, 1024, "http://%s:%d%s", g_scgProxyCfg.scgProxyIpAddr, g_scgProxyCfg.scgProxyPort, SET_CLIENTCFG_PATH);
|
||||
char *resp = http_post(url, pJsonString);
|
||||
|
||||
if (resp == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s recv NULL\n", SET_CLIENTCFG_PATH, pJsonString);
|
||||
return ERR_HTTP_POST_DATA;
|
||||
} else {
|
||||
ANDROID_LOG(ANDROID_LOG_INFO, "SCGPROXY", "[%s]:Post Data %s recv: %s\n", SET_CLIENTCFG_PATH, pJsonString, resp);
|
||||
return ERR_HTTP_POST_DATA;
|
||||
}
|
||||
res = g_scgProxyCfg.g_tunCtrlCtx->Post(SET_CLIENTCFG_PATH, pJsonString, "application/json");
|
||||
#endif
|
||||
if (pSvrResp == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s error", SET_CLIENTCFG_PATH, pJsonString);
|
||||
free(pJsonString);
|
||||
return -ERR_HTTP_POST_DATA;
|
||||
}
|
||||
|
||||
if (res->status != 200) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s server return HTTP error: %d\n", SET_CLIENTCFG_PATH,
|
||||
pJsonString,
|
||||
res->status);
|
||||
free(pJsonString);
|
||||
return -ERR_HTTP_SERVER_RSP;
|
||||
}
|
||||
|
||||
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "+++++ Http Request %s\n---- Http Response %s\n", pJsonString, res->body.c_str());
|
||||
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "+++++ Http Request %s\n---- Http Response %s\n", pJsonString, pSvrResp);
|
||||
free(pJsonString);
|
||||
|
||||
if (strlen(res->body.c_str()) == 0) {
|
||||
if (strlen(pSvrResp) == 0) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Server response empty message.\n");
|
||||
return -ERR_READ_FILE;
|
||||
}
|
||||
|
||||
pRoot = cJSON_Parse(res->body.c_str());
|
||||
pRoot = cJSON_Parse(pSvrResp);
|
||||
|
||||
if (pRoot == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode JSON %s Error.\n", res->body.c_str());
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode JSON %s Error.\n", pSvrResp);
|
||||
return -ERR_JSON_DECODE;
|
||||
}
|
||||
|
||||
pMsgContent = cJSON_GetObjectItem(pRoot, "msgContent");
|
||||
|
||||
if (pMsgContent == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent) JSON %s Error.\n", res->body.c_str());
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent) JSON %s Error.\n", pSvrResp);
|
||||
cJSON_Delete(pRoot);
|
||||
return -ERR_JSON_DECODE;
|
||||
}
|
||||
|
@ -352,7 +372,7 @@ int remote_tunnel_set_params(const char *pCliPubKey, const char *pCliNetwork, co
|
|||
pRspCode = cJSON_GetObjectItem(pMsgContent, "errCode");
|
||||
|
||||
if (pRspCode == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.pRspCode) JSON %s Error.\n", res->body.c_str());
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.pRspCode) JSON %s Error.\n", pSvrResp);
|
||||
cJSON_Delete(pRoot);
|
||||
return -ERR_JSON_DECODE;
|
||||
}
|
||||
|
@ -365,7 +385,7 @@ int remote_tunnel_set_params(const char *pCliPubKey, const char *pCliNetwork, co
|
|||
|
||||
pSvrNet = cJSON_GetObjectItem(pMsgContent, "svrNetwork");
|
||||
if (pSvrNet == nullptr) {
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.pSvrNet) JSON %s Error.\n", res->body.c_str());
|
||||
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.pSvrNet) JSON %s Error.\n", pSvrResp);
|
||||
cJSON_Delete(pRoot);
|
||||
return -ERR_JSON_DECODE;
|
||||
}
|
||||
|
|
|
@ -34,13 +34,11 @@ static SCG_PROXY_INFO g_scgProxyInfo;
|
|||
|
||||
static int pthread_setcancelstate() {
|
||||
sigset_t newState, old;
|
||||
int ret;
|
||||
|
||||
sigemptyset(&newState);
|
||||
sigaddset(&newState, SIG_CANCEL_SIGNAL);
|
||||
|
||||
ret = pthread_sigmask(SIG_BLOCK, &newState, &old);
|
||||
|
||||
return ret;
|
||||
return pthread_sigmask(SIG_BLOCK, &newState, &old);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,14 +1,26 @@
|
|||
package com.example.sccproxy;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.Settings;
|
||||
import android.widget.TextView;
|
||||
|
||||
import android.Manifest;
|
||||
import com.example.sccproxy.databinding.ActivityMainBinding;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private static final int REQUEST_CODE = 1024;
|
||||
|
||||
// Used to load the 'sccproxy' library on application startup.
|
||||
static {
|
||||
System.loadLibrary("sccproxy");
|
||||
|
@ -23,11 +35,68 @@ public class MainActivity extends AppCompatActivity {
|
|||
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
requestPermission();
|
||||
|
||||
// Example of a call to a native method
|
||||
TextView tv = binding.sampleText;
|
||||
tv.setText(stringFromJNI());
|
||||
}
|
||||
|
||||
private void requestPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
// 先判断有没有权限
|
||||
if (Environment.isExternalStorageManager()) {
|
||||
writeFile();
|
||||
} else {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
|
||||
intent.setData(Uri.parse("package:" + this.getPackageName()));
|
||||
startActivityForResult(intent, REQUEST_CODE);
|
||||
}
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
// 先判断有没有权限
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
|
||||
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||
writeFile();
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
|
||||
}
|
||||
} else {
|
||||
writeFile();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (requestCode == REQUEST_CODE) {
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
|
||||
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||
writeFile();
|
||||
} else {
|
||||
//ToastUtils.show("存储权限获取失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_CODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
if (Environment.isExternalStorageManager()) {
|
||||
writeFile();
|
||||
} else {
|
||||
//ToastUtils.show("存储权限获取失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟文件写入
|
||||
*/
|
||||
private void writeFile() {
|
||||
//ToastUtils.show("写入文件成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* A native method that is implemented by the 'sccproxy' native library,
|
||||
* which is packaged with this application.
|
||||
|
|
Loading…
Reference in New Issue