|
| 1 | +# XrayKit |
| 2 | + |
| 3 | +XrayKit is a robust iOS framework that provides a native integration of Xray-core functionality for iOS applications. This framework serves as a high-performance wrapper around the Xray-core, enabling seamless implementation and management of Xray features in iOS applications. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +XrayKit delivers a comprehensive suite of APIs for interacting with Xray-core, encompassing configuration management, geo data handling, connection testing, and runtime control. The framework is engineered to maintain the full power of Xray-core while providing a developer-friendly interface. |
| 8 | + |
| 9 | +## Professional Services |
| 10 | + |
| 11 | +I offer professional development services for custom iOS VPN and proxy client applications. Whether you need a complete solution from scratch or integration with existing systems, I can help bring your vision to life. My expertise includes: |
| 12 | + |
| 13 | +- Custom VPN client development |
| 14 | +- Proxy client implementation |
| 15 | +- Network security solutions |
| 16 | +- iOS app architecture |
| 17 | +- Performance optimization |
| 18 | +- Security hardening |
| 19 | + |
| 20 | +For professional inquiries, please contact me on Telegram: [@codewithtamim](https://t.me/codewithtamim) |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +### Swift Package Manager |
| 25 | + |
| 26 | +1. In Xcode, select File > Add Packages... |
| 27 | +2. Enter the repository URL: `https://github.com/CodeWithTamim/XrayKit.git` |
| 28 | +3. Select the version you want to use |
| 29 | +4. Click Add Package |
| 30 | + |
| 31 | +### Manual Installation |
| 32 | + |
| 33 | +1. Download the latest release from the [Releases](https://github.com/CodeWithTamim/XrayKit/releases) page |
| 34 | +2. Drag the `XrayKit.xcframework` into your project |
| 35 | +3. Ensure "Copy items if needed" is checked |
| 36 | +4. Add the framework to your target's "Frameworks, Libraries, and Embedded Content" section |
| 37 | + |
| 38 | +## API Documentation |
| 39 | + |
| 40 | +### Core Functionality |
| 41 | + |
| 42 | +#### 1. Xray Instance Management |
| 43 | + |
| 44 | +```swift |
| 45 | +/// Creates a properly formatted base64 request for running Xray |
| 46 | +/// - Parameter configStr: The Xray configuration string |
| 47 | +/// - Returns: A base64 encoded request string |
| 48 | +func NewXrayRunRequest(configStr: String) -> String |
| 49 | + |
| 50 | +/// Starts Xray with the provided configuration |
| 51 | +/// - Parameter xrayRequest: Base64 encoded request string |
| 52 | +/// - Returns: Base64 encoded response string |
| 53 | +func RunXray(xrayRequest: String) -> String |
| 54 | + |
| 55 | +/// Stops the running Xray instance |
| 56 | +/// - Returns: Base64 encoded response string |
| 57 | +func StopXray() -> String |
| 58 | + |
| 59 | +/// Retrieves the current Xray version |
| 60 | +/// - Returns: Base64 encoded version string |
| 61 | +func XrayVersion() -> String |
| 62 | +``` |
| 63 | + |
| 64 | +#### 2. Configuration Testing |
| 65 | + |
| 66 | +```swift |
| 67 | +/// Tests the Xray configuration |
| 68 | +/// - Parameter base64Text: Base64 encoded configuration test request |
| 69 | +/// - Returns: Base64 encoded test results |
| 70 | +func TestXray(base64Text: String) -> String |
| 71 | + |
| 72 | +/// Performs a ping test for outbound connection |
| 73 | +/// - Parameter base64Text: Base64 encoded ping request containing: |
| 74 | +/// - datDir: String |
| 75 | +/// - configPath: String |
| 76 | +/// - timeout: Int |
| 77 | +/// - url: String |
| 78 | +/// - proxy: String |
| 79 | +/// - Returns: Base64 encoded ping results |
| 80 | +func Ping(base64Text: String) -> String |
| 81 | +``` |
| 82 | + |
| 83 | +### Geo Data Management |
| 84 | + |
| 85 | +#### 1. Geo Data Operations |
| 86 | + |
| 87 | +```swift |
| 88 | +/// Counts geo data entries |
| 89 | +/// - Parameter base64Text: Base64 encoded request containing: |
| 90 | +/// - datDir: String |
| 91 | +/// - name: String |
| 92 | +/// - geoType: String |
| 93 | +/// - Returns: Base64 encoded count results |
| 94 | +func CountGeoData(base64Text: String) -> String |
| 95 | + |
| 96 | +/// Thins geo data based on configuration |
| 97 | +/// - Parameter base64Text: Base64 encoded request containing: |
| 98 | +/// - datDir: String |
| 99 | +/// - configPath: String |
| 100 | +/// - dstDir: String |
| 101 | +/// - Returns: Base64 encoded operation results |
| 102 | +func ThinGeoData(base64Text: String) -> String |
| 103 | + |
| 104 | +/// Reads geo files |
| 105 | +/// - Parameter base64Text: Base64 encoded request |
| 106 | +/// - Returns: Base64 encoded JSON containing domain and IP arrays |
| 107 | +func ReadGeoFiles(base64Text: String) -> String |
| 108 | +``` |
| 109 | + |
| 110 | +### Statistics and Monitoring |
| 111 | + |
| 112 | +```swift |
| 113 | +/// Queries inbound and outbound statistics |
| 114 | +/// - Parameter base64Text: Base64 encoded server string |
| 115 | +/// - Returns: Base64 encoded statistics |
| 116 | +func QueryStats(base64Text: String) -> String |
| 117 | +``` |
| 118 | + |
| 119 | +## Usage Examples |
| 120 | + |
| 121 | +### Basic Setup |
| 122 | + |
| 123 | +```swift |
| 124 | +import XrayKit |
| 125 | + |
| 126 | +// Xray configuration |
| 127 | +let config = """ |
| 128 | +{ |
| 129 | + "inbounds": [ |
| 130 | + { |
| 131 | + "port": 1080, |
| 132 | + "protocol": "socks", |
| 133 | + "settings": { |
| 134 | + "auth": "noauth" |
| 135 | + } |
| 136 | + } |
| 137 | + ], |
| 138 | + "outbounds": [ |
| 139 | + { |
| 140 | + "protocol": "freedom" |
| 141 | + } |
| 142 | + ] |
| 143 | +} |
| 144 | +""" |
| 145 | + |
| 146 | +// Create base64 request |
| 147 | +let base64Request = XrayKit.NewXrayRunRequest(configStr: config) |
| 148 | + |
| 149 | +// Initialize Xray |
| 150 | +let response = XrayKit.RunXray(xrayRequest: base64Request) |
| 151 | +``` |
| 152 | + |
| 153 | +### Testing Connection |
| 154 | + |
| 155 | +```swift |
| 156 | +// Ping configuration |
| 157 | +let pingConfig = """ |
| 158 | +{ |
| 159 | + "datDir": "/path/to/dat", |
| 160 | + "configPath": "/path/to/config.json", |
| 161 | + "timeout": 5000, |
| 162 | + "url": "https://www.google.com", |
| 163 | + "proxy": "your-proxy" |
| 164 | +} |
| 165 | +""" |
| 166 | + |
| 167 | +let pingData = pingConfig.data(using: .utf8)! |
| 168 | +let base64Ping = pingData.base64EncodedString() |
| 169 | + |
| 170 | +let response = XrayKit.Ping(base64Text: base64Ping) |
| 171 | +``` |
| 172 | + |
| 173 | +### Working with Geo Data |
| 174 | + |
| 175 | +```swift |
| 176 | +// Geo data configuration |
| 177 | +let geoConfig = """ |
| 178 | +{ |
| 179 | + "datDir": "/path/to/dat", |
| 180 | + "name": "geoip", |
| 181 | + "geoType": "ip" |
| 182 | +} |
| 183 | +""" |
| 184 | + |
| 185 | +let geoData = geoConfig.data(using: .utf8)! |
| 186 | +let base64Geo = geoData.base64EncodedString() |
| 187 | + |
| 188 | +let response = XrayKit.CountGeoData(base64Text: base64Geo) |
| 189 | +``` |
| 190 | + |
| 191 | +## Response Handling |
| 192 | + |
| 193 | +All API responses are returned as base64 encoded strings. The following example demonstrates proper response handling: |
| 194 | + |
| 195 | +```swift |
| 196 | +if let responseData = Data(base64Encoded: response), |
| 197 | + let jsonString = String(data: responseData, encoding: .utf8) { |
| 198 | + if let jsonData = jsonString.data(using: .utf8), |
| 199 | + let json = try? JSONSerialization.jsonObject(with: jsonData) as? [String: Any] { |
| 200 | + // Process the decoded response |
| 201 | + print(json) |
| 202 | + } |
| 203 | +} |
| 204 | +``` |
| 205 | + |
| 206 | +## Directory Structure |
| 207 | + |
| 208 | +The framework maintains the following directory structure: |
| 209 | + |
| 210 | +``` |
| 211 | +. |
| 212 | +├── dat/ # Geo data files directory |
| 213 | +└── config/ # Configuration files directory |
| 214 | + └── config.json # Xray configuration file |
| 215 | +``` |
| 216 | + |
| 217 | +## Requirements |
| 218 | + |
| 219 | +- iOS 15.0+ |
| 220 | +- Latest Xcode version recommended |
| 221 | +- Swift 5.0+ |
| 222 | + |
| 223 | +## Author |
| 224 | + |
| 225 | +CodeWithTamim |
| 226 | + |
| 227 | +## License |
| 228 | + |
| 229 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 230 | + |
| 231 | +## Contributing |
| 232 | + |
| 233 | +We welcome contributions to XrayKit. Please follow these guidelines when contributing: |
| 234 | + |
| 235 | +1. Fork the repository |
| 236 | +2. Create a feature branch (`git checkout -b feature/amazing-feature`) |
| 237 | +3. Commit your changes (`git commit -m 'Add amazing feature'`) |
| 238 | +4. Push to the branch (`git push origin feature/amazing-feature`) |
| 239 | +5. Open a Pull Request |
| 240 | + |
| 241 | +### Development Guidelines |
| 242 | + |
| 243 | +- Follow Swift style guidelines |
| 244 | +- Write unit tests for new features |
| 245 | +- Update documentation for API changes |
| 246 | +- Ensure all tests pass before submitting PR |
| 247 | +- Use meaningful commit messages |
| 248 | + |
| 249 | +### Code of Conduct |
| 250 | + |
| 251 | +- Be respectful and inclusive |
| 252 | +- Be patient and welcoming |
| 253 | +- Be thoughtful |
| 254 | +- Be collaborative |
| 255 | +- When disagreeing, try to understand why |
| 256 | + |
| 257 | +### Reporting Issues |
| 258 | + |
| 259 | +Please report bugs and feature requests using the GitHub issue tracker. Include: |
| 260 | +- Detailed description of the issue |
| 261 | +- Steps to reproduce |
| 262 | +- Expected behavior |
| 263 | +- Actual behavior |
| 264 | +- Environment details |
0 commit comments