Skip to content

Commit

Permalink
feat: update api configures
Browse files Browse the repository at this point in the history
  • Loading branch information
linaaaqi committed May 29, 2022
1 parent 193cd9d commit eb9dce3
Show file tree
Hide file tree
Showing 53 changed files with 643 additions and 334 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:flutter_lints/flutter.yaml
2 changes: 1 addition & 1 deletion android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kanshiyun.sail_app">
package="com.losgif.sail_app">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kanshiyun.sail_app">
package="com.losgif.sail_app">
<application
android:name="${applicationName}"
android:label="sail_app"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kanshiyun.sail_app
package com.losgif.sail_app

import io.flutter.embedding.android.FlutterActivity

Expand Down
2 changes: 1 addition & 1 deletion android/app/src/profile/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kanshiyun.sail_app">
package="com.losgif.sail_app">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
4 changes: 4 additions & 0 deletions ios/PacketTunnel/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSCameraUsageDescription</key>
<string>用于客服消息上传图片</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.networkextension.packet-tunnel</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).PacketTunnelProvider</string>
</dict>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>用于客服消息上传图片</string>
</dict>
</plist>
4 changes: 0 additions & 4 deletions ios/PacketTunnel/PacketTunnel.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@
<array>
<string>packet-tunnel-provider</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.kanshiyun.sail</string>
</array>
</dict>
</plist>
21 changes: 11 additions & 10 deletions ios/PacketTunnel/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import NetworkExtension

let appGroup = "group.com.kanshiyun.sail"
let appGroup = "group.com.losgif.sail"

let leafId: UInt16 = 0

let conf = """
[General]
Expand All @@ -10,12 +12,10 @@ tun-fd = REPLACE-ME-WITH-THE-FD
[Proxy]
Direct = direct
# Shadowsocks
SS = ss, SERVER_HOST, SERVER_PORT, encrypt-method=chacha20-ietf-poly1305, password=b9bd376c-642a-42c3-85ea-afec2bb812d6
[Rule]
EXTERNAL, site:cn, Direct
FINAL, SS
FINAL, Direct
"""

class PacketTunnelProvider: NEPacketTunnelProvider {
Expand All @@ -36,33 +36,34 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
let subpath = path[start..<path.endIndex]
DispatchQueue.global(qos: .userInteractive).async {
signal(SIGPIPE, SIG_IGN)
run_leaf(String(subpath))
leaf_run(leafId, String(subpath))
}
completionHandler(nil)
}
}

override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
leaf_shutdown(leafId)
// Add code here to start the process of stopping the tunnel.
completionHandler()
}

override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)?) {
// Add code here to handle the message.
if let handler = completionHandler {
handler(messageData)
}
}

override func sleep(completionHandler: @escaping () -> Void) {
// Add code here to get ready to sleep.
completionHandler()
}

override func wake() {
// Add code here to wake up.
}

func createTunnelSettings() -> NEPacketTunnelNetworkSettings {
let newSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "240.0.0.10")
newSettings.ipv4Settings = NEIPv4Settings(addresses: ["240.0.0.1"], subnetMasks: ["255.255.255.0"])
Expand Down
115 changes: 114 additions & 1 deletion ios/PacketTunnel/libleaf/leaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,117 @@
#include <stdint.h>
#include <stdlib.h>

void run_leaf(const char *path);
/**
* No error.
*/
#define ERR_OK 0

/**
* Config path error.
*/
#define ERR_CONFIG_PATH 1

/**
* Config parsing error.
*/
#define ERR_CONFIG 2

/**
* IO error.
*/
#define ERR_IO 3

/**
* Config file watcher error.
*/
#define ERR_WATCHER 4

/**
* Async channel send error.
*/
#define ERR_ASYNC_CHANNEL_SEND 5

/**
* Sync channel receive error.
*/
#define ERR_SYNC_CHANNEL_RECV 6

/**
* Runtime manager error.
*/
#define ERR_RUNTIME_MANAGER 7

/**
* No associated config file.
*/
#define ERR_NO_CONFIG_FILE 8

/**
* Starts leaf with options, on a successful start this function blocks the current
* thread.
*
* @note This is not a stable API, parameters will change from time to time.
*
* @param rt_id A unique ID to associate this leaf instance, this is required when
* calling subsequent FFI functions, e.g. reload, shutdown.
* @param config_path The path of the config file, must be a file with suffix .conf
* or .json, according to the enabled features.
* @param auto_reload Enabls auto reloading when config file changes are detected,
* takes effect only when the "auto-reload" feature is enabled.
* @param multi_thread Whether to use a multi-threaded runtime.
* @param auto_threads Sets the number of runtime worker threads automatically,
* takes effect only when multi_thread is true.
* @param threads Sets the number of runtime worker threads, takes effect when
* multi_thread is true, but can be overridden by auto_threads.
* @param stack_size Sets stack size of the runtime worker threads, takes effect when
* multi_thread is true.
* @return ERR_OK on finish running, any other errors means a startup failure.
*/
int32_t leaf_run_with_options(uint16_t rt_id,
const char *config_path,
bool auto_reload,
bool multi_thread,
bool auto_threads,
int32_t threads,
int32_t stack_size);

/**
* Starts leaf with a single-threaded runtime, on a successful start this function
* blocks the current thread.
*
* @param rt_id A unique ID to associate this leaf instance, this is required when
* calling subsequent FFI functions, e.g. reload, shutdown.
* @param config_path The path of the config file, must be a file with suffix .conf
* or .json, according to the enabled features.
* @return ERR_OK on finish running, any other errors means a startup failure.
*/
int32_t leaf_run(uint16_t rt_id, const char *config_path);

int32_t leaf_run_with_config_string(uint16_t rt_id, const char *config);

/**
* Reloads DNS servers, outbounds and routing rules from the config file.
*
* @param rt_id The ID of the leaf instance to reload.
*
* @return Returns ERR_OK on success.
*/
int32_t leaf_reload(uint16_t rt_id);

/**
* Shuts down leaf.
*
* @param rt_id The ID of the leaf instance to reload.
*
* @return Returns true on success, false otherwise.
*/
bool leaf_shutdown(uint16_t rt_id);

/**
* Tests the configuration.
*
* @param config_path The path of the config file, must be a file with suffix .conf
* or .json, according to the enabled features.
* @return Returns ERR_OK on success, i.e no syntax error.
*/
int32_t leaf_test_config(const char *config_path);
Binary file modified ios/PacketTunnel/libleaf/libleaf.a
Binary file not shown.
23 changes: 23 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,32 +1,55 @@
PODS:
- Flutter (1.0.0)
- flutter_inappwebview (0.0.1):
- Flutter
- flutter_inappwebview/Core (= 0.0.1)
- OrderedSet (~> 5.0)
- flutter_inappwebview/Core (0.0.1):
- Flutter
- OrderedSet (~> 5.0)
- OrderedSet (5.0.0)
- path_provider_ios (0.0.1):
- Flutter
- shared_preferences (0.0.1):
- Flutter
- url_launcher_ios (0.0.1):
- Flutter
- webview_flutter (0.0.1):
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_inappwebview (from `.symlinks/plugins/flutter_inappwebview/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
- webview_flutter (from `.symlinks/plugins/webview_flutter/ios`)

SPEC REPOS:
trunk:
- OrderedSet

EXTERNAL SOURCES:
Flutter:
:path: Flutter
flutter_inappwebview:
:path: ".symlinks/plugins/flutter_inappwebview/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"
shared_preferences:
:path: ".symlinks/plugins/shared_preferences/ios"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
webview_flutter:
:path: ".symlinks/plugins/webview_flutter/ios"

SPEC CHECKSUMS:
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
flutter_inappwebview: bfd58618f49dc62f2676de690fc6dcda1d6c3721
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
webview_flutter: d2b4d6c66968ad042ad94cbb791f5b72b4678a96

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
Expand Down
22 changes: 12 additions & 10 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
2F50954B25A36FD0001A32D5 /* VPNManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F50954A25A36FD0001A32D5 /* VPNManager.swift */; };
2FD21F0E25A363E300F556E0 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2FD21EF825A363AA00F556E0 /* NetworkExtension.framework */; };
2FD21F1125A363E300F556E0 /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FD21F1025A363E300F556E0 /* PacketTunnelProvider.swift */; };
2FD21F1625A363E300F556E0 /* PacketTunnel.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 2FD21F0D25A363E300F556E0 /* PacketTunnel.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
2FD21F2425A364B700F556E0 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2FD21EF825A363AA00F556E0 /* NetworkExtension.framework */; };
2FD21F2F25A369DC00F556E0 /* libleaf.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2FD21F2E25A369C800F556E0 /* libleaf.a */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3D20CCEEC65D391313166582 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC0398181A4528DE14110496 /* Pods_Runner.framework */; };
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
7A198E042842118A001511F4 /* libleaf.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2FD21F2E25A369C800F556E0 /* libleaf.a */; };
7A31DD8228420C0B00E82EE1 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2FD21EF825A363AA00F556E0 /* NetworkExtension.framework */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
Expand Down Expand Up @@ -72,6 +72,7 @@
6687DE675C77C0119D704778 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7A198E0828423FC0001511F4 /* Crisp.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Crisp.xcframework; path = Pods/Crisp/Crisp.xcframework; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
82E989E092091738BD8B760F /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
Expand All @@ -90,8 +91,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2FD21F0E25A363E300F556E0 /* NetworkExtension.framework in Frameworks */,
2FD21F2F25A369DC00F556E0 /* libleaf.a in Frameworks */,
7A31DD8228420C0B00E82EE1 /* NetworkExtension.framework in Frameworks */,
7A198E042842118A001511F4 /* libleaf.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -188,6 +189,7 @@
F6BCB37E43B89DAB5A76B9D0 /* Frameworks */ = {
isa = PBXGroup;
children = (
7A198E0828423FC0001511F4 /* Crisp.xcframework */,
2FD21F2E25A369C800F556E0 /* libleaf.a */,
FC0398181A4528DE14110496 /* Pods_Runner.framework */,
2FD21EF825A363AA00F556E0 /* NetworkExtension.framework */,
Expand Down Expand Up @@ -492,7 +494,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.kanshiyun.sail;
PRODUCT_BUNDLE_IDENTIFIER = com.losgif.sail;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -532,7 +534,7 @@
MARKETING_VERSION = 1.0.2;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.kanshiyun.sail.PacketTunnel;
PRODUCT_BUNDLE_IDENTIFIER = com.losgif.sail.PacketTunnel;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
Expand Down Expand Up @@ -573,7 +575,7 @@
);
MARKETING_VERSION = 1.0.2;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.kanshiyun.sail.PacketTunnel;
PRODUCT_BUNDLE_IDENTIFIER = com.losgif.sail.PacketTunnel;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_DIR)/PacketTunnel/BridgingHeader.h";
Expand Down Expand Up @@ -612,7 +614,7 @@
);
MARKETING_VERSION = 1.0.2;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.kanshiyun.sail.PacketTunnel;
PRODUCT_BUNDLE_IDENTIFIER = com.losgif.sail.PacketTunnel;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_DIR)/PacketTunnel/BridgingHeader.h";
Expand Down Expand Up @@ -754,7 +756,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.kanshiyun.sail;
PRODUCT_BUNDLE_IDENTIFIER = com.losgif.sail;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand Down Expand Up @@ -788,7 +790,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.kanshiyun.sail;
PRODUCT_BUNDLE_IDENTIFIER = com.losgif.sail;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
Loading

0 comments on commit eb9dce3

Please sign in to comment.