프로젝트 초기 구성
- Rust 호스트 클라이언트 크레이트와 제어 채널 프레이밍(12바이트 공통 헤더, 메시지 타입, 부분 수신을 처리하는 FrameDecoder) 및 테스트 - Android 동반 앱/데몬 Gradle 프로젝트(AGP 9.5.2, minSdk 35)와 데몬 진입점, 프로토콜 상수 - README, .gitignore, .gitattributes
- 작성자
- LeeJunyoung
- 작성 시각
- 커밋
f1702c24c797574be9d1e454dc44d41544dc5a30- 부모
- 없음 (첫 커밋)
변경된 파일 26개
+1,010-0| @@ -0,0 +1,3 @@ | ||
| 1 | 추가: * text=auto eol=lf | |
| 2 | 추가: *.bat text eol=crlf | |
| 3 | 추가: *.jar binary |
| @@ -0,0 +1,21 @@ | ||
| 1 | 추가: # Rust | |
| 2 | 추가: /target/ | |
| 3 | 추가: | |
| 4 | 추가: # Gradle / Android | |
| 5 | 추가: .gradle/ | |
| 6 | 추가: .kotlin/ | |
| 7 | 추가: build/ | |
| 8 | 추가: local.properties | |
| 9 | 추가: captures/ | |
| 10 | 추가: .externalNativeBuild/ | |
| 11 | 추가: .cxx/ | |
| 12 | 추가: *.apk | |
| 13 | 추가: *.aab | |
| 14 | 추가: *.keystore | |
| 15 | 추가: *.jks | |
| 16 | 추가: | |
| 17 | 추가: # IDE / OS | |
| 18 | 추가: .idea/ | |
| 19 | 추가: *.iml | |
| 20 | 추가: .vscode/ | |
| 21 | 추가: .DS_Store |
| @@ -0,0 +1,16 @@ | ||
| 1 | 추가: # This file is automatically @generated by Cargo. | |
| 2 | 추가: # It is not intended for manual editing. | |
| 3 | 추가: version = 4 | |
| 4 | 추가: | |
| 5 | 추가: [[package]] | |
| 6 | 추가: name = "bytes" | |
| 7 | 추가: version = "1.12.2" | |
| 8 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 9 | 추가: checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c" | |
| 10 | 추가: | |
| 11 | 추가: [[package]] | |
| 12 | 추가: name = "wayland-android-remote" | |
| 13 | 추가: version = "0.1.0" | |
| 14 | 추가: dependencies = [ | |
| 15 | 추가: "bytes", | |
| 16 | 추가: ] |
| @@ -0,0 +1,13 @@ | ||
| 1 | 추가: [package] | |
| 2 | 추가: name = "wayland-android-remote" | |
| 3 | 추가: version = "0.1.0" | |
| 4 | 추가: edition = "2024" | |
| 5 | 추가: description = "Ubuntu(Wayland/X11)에서 Android 기기 화면 미러링 및 원격 제어 호스트 클라이언트" | |
| 6 | 추가: publish = false | |
| 7 | 추가: | |
| 8 | 추가: [[bin]] | |
| 9 | 추가: name = "android-remote" | |
| 10 | 추가: path = "src/main.rs" | |
| 11 | 추가: | |
| 12 | 추가: [dependencies] | |
| 13 | 추가: bytes = "1.12.2" |
| @@ -0,0 +1,41 @@ | ||
| 1 | 추가: # wayland-android-remote | |
| 2 | 추가: | |
| 3 | 추가: Ubuntu(Wayland/X11)에서 Android 기기 화면을 실시간으로 미러링하고, PC의 마우스와 키보드로 원격 제어하는 프로젝트입니다. 호스트 PC와 휴대폰 간 텍스트를 Ctrl+C / Ctrl+V로 주고받는 양방향 클립보드 동기화를 지원합니다. | |
| 4 | 추가: | |
| 5 | 추가: 자세한 설계는 Google Docs의 "Android Remote 기획서"에 있습니다. | |
| 6 | 추가: | |
| 7 | 추가: ## 구성 | |
| 8 | 추가: | |
| 9 | 추가: | 경로 | 내용 | | |
| 10 | 추가: |---|---| | |
| 11 | 추가: | `src/`, `tests/` | 호스트 클라이언트 (Rust). 현재는 제어 채널 프레이밍(`src/protocol`)만 구현되어 있습니다. | | |
| 12 | 추가: | `android/` | Android 동반 앱과 shell 권한 데몬 (Kotlin, Gradle). 데몬은 동반 앱 APK 안에 함께 들어가며 `app_process`로 실행됩니다. | | |
| 13 | 추가: | |
| 14 | 추가: ## 연결 구조 요약 | |
| 15 | 추가: | |
| 16 | 추가: 1. 동반 앱이 기기 자신의 무선 디버깅에 접속해 shell 권한 데몬을 띄웁니다. 호스트 PC에는 ADB가 필요 없습니다. | |
| 17 | 추가: 2. 데몬은 TCP 27200 포트에서 대기하고, 모든 연결은 TLS 1.3으로 암호화합니다. | |
| 18 | 추가: 3. 호스트는 IP를 입력해 접속하고 Ed25519 키로 인증합니다. 처음 접속하는 PC는 휴대폰에서 승인합니다. | |
| 19 | 추가: 4. 제어 채널(입력, 클립보드)과 영상 채널(H.264/H.265/AV1)은 별도 TCP 연결로 나뉩니다. | |
| 20 | 추가: | |
| 21 | 추가: ## 개발 환경 | |
| 22 | 추가: | |
| 23 | 추가: ### 호스트 (Rust) | |
| 24 | 추가: | |
| 25 | 추가: - Rust 1.85 이상 (edition 2024) | |
| 26 | 추가: | |
| 27 | 추가: ```bash | |
| 28 | 추가: cargo test | |
| 29 | 추가: cargo run | |
| 30 | 추가: ``` | |
| 31 | 추가: | |
| 32 | 추가: ### Android | |
| 33 | 추가: | |
| 34 | 추가: - JDK 17 이상 (javac 포함) | |
| 35 | 추가: - Android SDK (compileSdk 36), `android/local.properties`에 `sdk.dir` 지정 또는 `ANDROID_HOME` 설정 | |
| 36 | 추가: - 대상 기기: Android 15(API 35) 이상 | |
| 37 | 추가: | |
| 38 | 추가: ```bash | |
| 39 | 추가: cd android | |
| 40 | 추가: ./gradlew assembleDebug | |
| 41 | 추가: ``` |
| @@ -0,0 +1,33 @@ | ||
| 1 | 추가: plugins { | |
| 2 | 추가: alias(libs.plugins.android.application) | |
| 3 | 추가: } | |
| 4 | 추가: | |
| 5 | 추가: android { | |
| 6 | 추가: namespace = "com.androidremote" | |
| 7 | 추가: compileSdk = 36 | |
| 8 | 추가: | |
| 9 | 추가: defaultConfig { | |
| 10 | 추가: applicationId = "com.androidremote" | |
| 11 | 추가: // 기획서 2절: Android 15(API 35) 이상 | |
| 12 | 추가: minSdk = 35 | |
| 13 | 추가: targetSdk = 36 | |
| 14 | 추가: // 데몬 버전 = APK versionCode (기획서 5.4) | |
| 15 | 추가: versionCode = 1 | |
| 16 | 추가: versionName = "0.1.0" | |
| 17 | 추가: } | |
| 18 | 추가: | |
| 19 | 추가: buildTypes { | |
| 20 | 추가: release { | |
| 21 | 추가: isMinifyEnabled = false | |
| 22 | 추가: proguardFiles( | |
| 23 | 추가: getDefaultProguardFile("proguard-android-optimize.txt"), | |
| 24 | 추가: "proguard-rules.pro", | |
| 25 | 추가: ) | |
| 26 | 추가: } | |
| 27 | 추가: } | |
| 28 | 추가: | |
| 29 | 추가: compileOptions { | |
| 30 | 추가: sourceCompatibility = JavaVersion.VERSION_17 | |
| 31 | 추가: targetCompatibility = JavaVersion.VERSION_17 | |
| 32 | 추가: } | |
| 33 | 추가: } |
| @@ -0,0 +1,4 @@ | ||
| 1 | 추가: # 데몬은 app_process로 직접 실행되므로 앱 코드에서 참조되지 않는다. 축소 시 지워지지 않게 유지한다. | |
| 2 | 추가: -keep class com.androidremote.daemon.DaemonMain { | |
| 3 | 추가: public static void main(java.lang.String[]); | |
| 4 | 추가: } |
| @@ -0,0 +1,30 @@ | ||
| 1 | 추가: <?xml version="1.0" encoding="utf-8"?> | |
| 2 | 추가: <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | 추가: xmlns:tools="http://schemas.android.com/tools"> | |
| 4 | 추가: | |
| 5 | 추가: <!-- 로컬 adbd(무선 디버깅) 접속 및 mDNS 탐색 (기획서 5.4) --> | |
| 6 | 추가: <uses-permission android:name="android.permission.INTERNET" /> | |
| 7 | 추가: <!-- 페어링 코드 입력 알림, 신규 PC 승인 알림 --> | |
| 8 | 추가: <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> | |
| 9 | 추가: <!-- 재부팅 후 데몬 자동 재기동 --> | |
| 10 | 추가: <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | |
| 11 | 추가: <!-- 데몬이 pm grant로 부여한다. adb_wifi_enabled 토글용 --> | |
| 12 | 추가: <uses-permission | |
| 13 | 추가: android:name="android.permission.WRITE_SECURE_SETTINGS" | |
| 14 | 추가: tools:ignore="ProtectedPermissions" /> | |
| 15 | 추가: | |
| 16 | 추가: <application | |
| 17 | 추가: android:allowBackup="false" | |
| 18 | 추가: android:label="@string/app_name" | |
| 19 | 추가: android:theme="@android:style/Theme.DeviceDefault.DayNight"> | |
| 20 | 추가: | |
| 21 | 추가: <activity | |
| 22 | 추가: android:name=".companion.MainActivity" | |
| 23 | 추가: android:exported="true"> | |
| 24 | 추가: <intent-filter> | |
| 25 | 추가: <action android:name="android.intent.action.MAIN" /> | |
| 26 | 추가: <category android:name="android.intent.category.LAUNCHER" /> | |
| 27 | 추가: </intent-filter> | |
| 28 | 추가: </activity> | |
| 29 | 추가: </application> | |
| 30 | 추가: </manifest> |
| @@ -0,0 +1,22 @@ | ||
| 1 | 추가: package com.androidremote.companion | |
| 2 | 추가: | |
| 3 | 추가: import android.app.Activity | |
| 4 | 추가: import android.os.Bundle | |
| 5 | 추가: import android.view.Gravity | |
| 6 | 추가: import android.widget.TextView | |
| 7 | 추가: import com.androidremote.R | |
| 8 | 추가: | |
| 9 | 추가: /** | |
| 10 | 추가: * 동반 앱 진입 화면. 이후 온보딩(무선 디버깅 페어링), 허용 PC 목록, 승인 팝업이 들어간다 (기획서 5.1, 5.2, 5.4). | |
| 11 | 추가: */ | |
| 12 | 추가: class MainActivity : Activity() { | |
| 13 | 추가: override fun onCreate(savedInstanceState: Bundle?) { | |
| 14 | 추가: super.onCreate(savedInstanceState) | |
| 15 | 추가: setContentView( | |
| 16 | 추가: TextView(this).apply { | |
| 17 | 추가: setText(R.string.status_not_implemented) | |
| 18 | 추가: gravity = Gravity.CENTER | |
| 19 | 추가: }, | |
| 20 | 추가: ) | |
| 21 | 추가: } | |
| 22 | 추가: } |
| @@ -0,0 +1,25 @@ | ||
| 1 | 추가: package com.androidremote.daemon | |
| 2 | 추가: | |
| 3 | 추가: /** | |
| 4 | 추가: * shell 권한 데몬 진입점 (기획서 5.4). | |
| 5 | 추가: * | |
| 6 | 추가: * 동반 앱이 로컬 adbd에 접속해 다음처럼 실행한다. | |
| 7 | 추가: * `CLASSPATH=<APK 경로> app_process / com.androidremote.daemon.DaemonMain --port 27200` | |
| 8 | 추가: */ | |
| 9 | 추가: object DaemonMain { | |
| 10 | 추가: const val DEFAULT_PORT = 27200 | |
| 11 | 추가: | |
| 12 | 추가: @JvmStatic | |
| 13 | 추가: fun main(args: Array<String>) { | |
| 14 | 추가: val port = parsePort(args) | |
| 15 | 추가: println("android-remote daemon: port=$port (아직 구현 전)") | |
| 16 | 추가: } | |
| 17 | 추가: | |
| 18 | 추가: internal fun parsePort(args: Array<String>): Int { | |
| 19 | 추가: val i = args.indexOf("--port") | |
| 20 | 추가: if (i < 0) return DEFAULT_PORT | |
| 21 | 추가: val value = args.getOrNull(i + 1)?.toIntOrNull() | |
| 22 | 추가: require(value != null && value in 1..65535) { "--port 값이 올바르지 않습니다: ${args.getOrNull(i + 1)}" } | |
| 23 | 추가: return value | |
| 24 | 추가: } | |
| 25 | 추가: } |
| @@ -0,0 +1,33 @@ | ||
| 1 | 추가: package com.androidremote.daemon | |
| 2 | 추가: | |
| 3 | 추가: /** | |
| 4 | 추가: * 제어 채널 프레이밍 상수 (기획서 7.1, 7.2). 호스트의 Rust `protocol` 모듈과 값이 같아야 한다. | |
| 5 | 추가: * JVM ByteBuffer/DataInputStream 기본 바이트 순서가 Big-Endian이라 별도 변환 없이 읽는다. | |
| 6 | 추가: */ | |
| 7 | 추가: object Protocol { | |
| 8 | 추가: const val MAGIC: Int = 0x4152 | |
| 9 | 추가: const val VERSION: Int = 0x01 | |
| 10 | 추가: const val HEADER_LEN: Int = 12 | |
| 11 | 추가: const val MAX_PAYLOAD_LEN: Int = 4 * 1024 * 1024 | |
| 12 | 추가: | |
| 13 | 추가: object MsgType { | |
| 14 | 추가: const val PING = 0x01 | |
| 15 | 추가: const val PONG = 0x02 | |
| 16 | 추가: const val AUTH_HELLO = 0x03 | |
| 17 | 추가: const val AUTH_CHALLENGE = 0x04 | |
| 18 | 추가: const val AUTH_RESPONSE = 0x05 | |
| 19 | 추가: const val AUTH_RESULT = 0x06 | |
| 20 | 추가: const val CHANNEL_ATTACH = 0x07 | |
| 21 | 추가: const val KEY_EVENT = 0x10 | |
| 22 | 추가: const val TEXT_INPUT = 0x11 | |
| 23 | 추가: const val SYSTEM_ACTION = 0x12 | |
| 24 | 추가: const val CLIPBOARD_SYNC = 0x20 | |
| 25 | 추가: const val TOUCH_EVENT = 0x30 | |
| 26 | 추가: const val SCROLL_EVENT = 0x31 | |
| 27 | 추가: const val VIDEO_CONFIG_REQUEST = 0x40 | |
| 28 | 추가: const val VIDEO_CONFIG = 0x41 | |
| 29 | 추가: const val VIDEO_REQUEST_KEYFRAME = 0x42 | |
| 30 | 추가: const val ACK = 0xF0 | |
| 31 | 추가: const val ERROR = 0xFF | |
| 32 | 추가: } | |
| 33 | 추가: } |
| @@ -0,0 +1,5 @@ | ||
| 1 | 추가: <?xml version="1.0" encoding="utf-8"?> | |
| 2 | 추가: <resources> | |
| 3 | 추가: <string name="app_name">Android Remote</string> | |
| 4 | 추가: <string name="status_not_implemented">동반 앱 준비 중입니다.</string> | |
| 5 | 추가: </resources> |
| @@ -0,0 +1,3 @@ | ||
| 1 | 추가: plugins { | |
| 2 | 추가: alias(libs.plugins.android.application) apply false | |
| 3 | 추가: } |
| @@ -0,0 +1,2 @@ | ||
| 1 | 추가: org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8 | |
| 2 | 추가: org.gradle.configuration-cache=true |
| @@ -0,0 +1,5 @@ | ||
| 1 | 추가: [versions] | |
| 2 | 추가: agp = "9.5.2" | |
| 3 | 추가: | |
| 4 | 추가: [plugins] | |
| 5 | 추가: android-application = { id = "com.android.application", version.ref = "agp" } |
바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기| @@ -0,0 +1,9 @@ | ||
| 1 | 추가: distributionBase=GRADLE_USER_HOME | |
| 2 | 추가: distributionPath=wrapper/dists | |
| 3 | 추가: distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.2-bin.zip | |
| 4 | 추가: networkTimeout=10000 | |
| 5 | 추가: retries=0 | |
| 6 | 추가: retryBackOffMs=500 | |
| 7 | 추가: validateDistributionUrl=true | |
| 8 | 추가: zipStoreBase=GRADLE_USER_HOME | |
| 9 | 추가: zipStorePath=wrapper/dists |
| @@ -0,0 +1,248 @@ | ||
| 1 | 추가: #!/bin/sh | |
| 2 | 추가: | |
| 3 | 추가: # | |
| 4 | 추가: # Copyright © 2015 the original authors. | |
| 5 | 추가: # | |
| 6 | 추가: # Licensed under the Apache License, Version 2.0 (the "License"); | |
| 7 | 추가: # you may not use this file except in compliance with the License. | |
| 8 | 추가: # You may obtain a copy of the License at | |
| 9 | 추가: # | |
| 10 | 추가: # https://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | 추가: # | |
| 12 | 추가: # Unless required by applicable law or agreed to in writing, software | |
| 13 | 추가: # distributed under the License is distributed on an "AS IS" BASIS, | |
| 14 | 추가: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 15 | 추가: # See the License for the specific language governing permissions and | |
| 16 | 추가: # limitations under the License. | |
| 17 | 추가: # | |
| 18 | 추가: # SPDX-License-Identifier: Apache-2.0 | |
| 19 | 추가: # | |
| 20 | 추가: | |
| 21 | 추가: ############################################################################## | |
| 22 | 추가: # | |
| 23 | 추가: # gradlew start up script for POSIX generated by Gradle. | |
| 24 | 추가: # | |
| 25 | 추가: # Important for running: | |
| 26 | 추가: # | |
| 27 | 추가: # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is | |
| 28 | 추가: # noncompliant, but you have some other compliant shell such as ksh or | |
| 29 | 추가: # bash, then to run this script, type that shell name before the whole | |
| 30 | 추가: # command line, like: | |
| 31 | 추가: # | |
| 32 | 추가: # ksh gradlew | |
| 33 | 추가: # | |
| 34 | 추가: # Busybox and similar reduced shells will NOT work, because this script | |
| 35 | 추가: # requires all of these POSIX shell features: | |
| 36 | 추가: # * functions; | |
| 37 | 추가: # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», | |
| 38 | 추가: # «${var#prefix}», «${var%suffix}», and «$( cmd )»; | |
| 39 | 추가: # * compound commands having a testable exit status, especially «case»; | |
| 40 | 추가: # * various built-in commands including «command», «set», and «ulimit». | |
| 41 | 추가: # | |
| 42 | 추가: # Important for patching: | |
| 43 | 추가: # | |
| 44 | 추가: # (2) This script targets any POSIX shell, so it avoids extensions provided | |
| 45 | 추가: # by Bash, Ksh, etc; in particular arrays are avoided. | |
| 46 | 추가: # | |
| 47 | 추가: # The "traditional" practice of packing multiple parameters into a | |
| 48 | 추가: # space-separated string is a well documented source of bugs and security | |
| 49 | 추가: # problems, so this is (mostly) avoided, by progressively accumulating | |
| 50 | 추가: # options in "$@", and eventually passing that to Java. | |
| 51 | 추가: # | |
| 52 | 추가: # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, | |
| 53 | 추가: # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; | |
| 54 | 추가: # see the in-line comments for details. | |
| 55 | 추가: # | |
| 56 | 추가: # There are tweaks for specific operating systems such as AIX, CygWin, | |
| 57 | 추가: # Darwin, MinGW, and NonStop. | |
| 58 | 추가: # | |
| 59 | 추가: # (3) This script is generated from the Groovy template | |
| 60 | 추가: # https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt | |
| 61 | 추가: # within the Gradle project. | |
| 62 | 추가: # | |
| 63 | 추가: # You can find Gradle at https://github.com/gradle/gradle/. | |
| 64 | 추가: # | |
| 65 | 추가: ############################################################################## | |
| 66 | 추가: | |
| 67 | 추가: # Attempt to set APP_HOME | |
| 68 | 추가: | |
| 69 | 추가: # Resolve links: $0 may be a link | |
| 70 | 추가: app_path=$0 | |
| 71 | 추가: | |
| 72 | 추가: # Need this for daisy-chained symlinks. | |
| 73 | 추가: while | |
| 74 | 추가: APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path | |
| 75 | 추가: [ -h "$app_path" ] | |
| 76 | 추가: do | |
| 77 | 추가: ls=$( ls -ld "$app_path" ) | |
| 78 | 추가: link=${ls#*' -> '} | |
| 79 | 추가: case $link in #( | |
| 80 | 추가: /*) app_path=$link ;; #( | |
| 81 | 추가: *) app_path=$APP_HOME$link ;; | |
| 82 | 추가: esac | |
| 83 | 추가: done | |
| 84 | 추가: | |
| 85 | 추가: # This is normally unused | |
| 86 | 추가: # shellcheck disable=SC2034 | |
| 87 | 추가: APP_BASE_NAME=${0##*/} | |
| 88 | 추가: # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) | |
| 89 | 추가: APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit | |
| 90 | 추가: | |
| 91 | 추가: # Use the maximum available, or set MAX_FD != -1 to use that value. | |
| 92 | 추가: MAX_FD=maximum | |
| 93 | 추가: | |
| 94 | 추가: warn () { | |
| 95 | 추가: echo "$*" | |
| 96 | 추가: } >&2 | |
| 97 | 추가: | |
| 98 | 추가: die () { | |
| 99 | 추가: echo | |
| 100 | 추가: echo "$*" | |
| 101 | 추가: echo | |
| 102 | 추가: exit 1 | |
| 103 | 추가: } >&2 | |
| 104 | 추가: | |
| 105 | 추가: # OS specific support (must be 'true' or 'false'). | |
| 106 | 추가: cygwin=false | |
| 107 | 추가: msys=false | |
| 108 | 추가: darwin=false | |
| 109 | 추가: nonstop=false | |
| 110 | 추가: case "$( uname )" in #( | |
| 111 | 추가: CYGWIN* ) cygwin=true ;; #( | |
| 112 | 추가: Darwin* ) darwin=true ;; #( | |
| 113 | 추가: MSYS* | MINGW* ) msys=true ;; #( | |
| 114 | 추가: NONSTOP* ) nonstop=true ;; | |
| 115 | 추가: esac | |
| 116 | 추가: | |
| 117 | 추가: | |
| 118 | 추가: | |
| 119 | 추가: # Determine the Java command to use to start the JVM. | |
| 120 | 추가: if [ -n "$JAVA_HOME" ] ; then | |
| 121 | 추가: if [ -x "$JAVA_HOME/jre/sh/java" ] ; then | |
| 122 | 추가: # IBM's JDK on AIX uses strange locations for the executables | |
| 123 | 추가: JAVACMD=$JAVA_HOME/jre/sh/java | |
| 124 | 추가: else | |
| 125 | 추가: JAVACMD=$JAVA_HOME/bin/java | |
| 126 | 추가: fi | |
| 127 | 추가: if [ ! -x "$JAVACMD" ] ; then | |
| 128 | 추가: die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME | |
| 129 | 추가: | |
| 130 | 추가: Please set the JAVA_HOME variable in your environment to match the | |
| 131 | 추가: location of your Java installation." | |
| 132 | 추가: fi | |
| 133 | 추가: else | |
| 134 | 추가: JAVACMD=java | |
| 135 | 추가: if ! command -v java >/dev/null 2>&1 | |
| 136 | 추가: then | |
| 137 | 추가: die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | |
| 138 | 추가: | |
| 139 | 추가: Please set the JAVA_HOME variable in your environment to match the | |
| 140 | 추가: location of your Java installation." | |
| 141 | 추가: fi | |
| 142 | 추가: fi | |
| 143 | 추가: | |
| 144 | 추가: # Increase the maximum file descriptors if we can. | |
| 145 | 추가: if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then | |
| 146 | 추가: case $MAX_FD in #( | |
| 147 | 추가: max*) | |
| 148 | 추가: # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. | |
| 149 | 추가: # shellcheck disable=SC2039,SC3045 | |
| 150 | 추가: MAX_FD=$( ulimit -H -n ) || | |
| 151 | 추가: warn "Could not query maximum file descriptor limit" | |
| 152 | 추가: esac | |
| 153 | 추가: case $MAX_FD in #( | |
| 154 | 추가: '' | soft) :;; #( | |
| 155 | 추가: *) | |
| 156 | 추가: # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. | |
| 157 | 추가: # shellcheck disable=SC2039,SC3045 | |
| 158 | 추가: ulimit -n "$MAX_FD" || | |
| 159 | 추가: warn "Could not set maximum file descriptor limit to $MAX_FD" | |
| 160 | 추가: esac | |
| 161 | 추가: fi | |
| 162 | 추가: | |
| 163 | 추가: # Collect all arguments for the java command, stacking in reverse order: | |
| 164 | 추가: # * args from the command line | |
| 165 | 추가: # * the main class name | |
| 166 | 추가: # * -classpath | |
| 167 | 추가: # * -D...appname settings | |
| 168 | 추가: # * --module-path (only if needed) | |
| 169 | 추가: # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. | |
| 170 | 추가: | |
| 171 | 추가: # For Cygwin or MSYS, switch paths to Windows format before running java | |
| 172 | 추가: if "$cygwin" || "$msys" ; then | |
| 173 | 추가: APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) | |
| 174 | 추가: | |
| 175 | 추가: JAVACMD=$( cygpath --unix "$JAVACMD" ) | |
| 176 | 추가: | |
| 177 | 추가: # Now convert the arguments - kludge to limit ourselves to /bin/sh | |
| 178 | 추가: for arg do | |
| 179 | 추가: if | |
| 180 | 추가: case $arg in #( | |
| 181 | 추가: -*) false ;; # don't mess with options #( | |
| 182 | 추가: /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath | |
| 183 | 추가: [ -e "$t" ] ;; #( | |
| 184 | 추가: *) false ;; | |
| 185 | 추가: esac | |
| 186 | 추가: then | |
| 187 | 추가: arg=$( cygpath --path --ignore --mixed "$arg" ) | |
| 188 | 추가: fi | |
| 189 | 추가: # Roll the args list around exactly as many times as the number of | |
| 190 | 추가: # args, so each arg winds up back in the position where it started, but | |
| 191 | 추가: # possibly modified. | |
| 192 | 추가: # | |
| 193 | 추가: # NB: a `for` loop captures its iteration list before it begins, so | |
| 194 | 추가: # changing the positional parameters here affects neither the number of | |
| 195 | 추가: # iterations, nor the values presented in `arg`. | |
| 196 | 추가: shift # remove old arg | |
| 197 | 추가: set -- "$@" "$arg" # push replacement arg | |
| 198 | 추가: done | |
| 199 | 추가: fi | |
| 200 | 추가: | |
| 201 | 추가: | |
| 202 | 추가: # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | |
| 203 | 추가: DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' | |
| 204 | 추가: | |
| 205 | 추가: # Collect all arguments for the java command: | |
| 206 | 추가: # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, | |
| 207 | 추가: # and any embedded shellness will be escaped. | |
| 208 | 추가: # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be | |
| 209 | 추가: # treated as '${Hostname}' itself on the command line. | |
| 210 | 추가: | |
| 211 | 추가: set -- \ | |
| 212 | 추가: "-Dorg.gradle.appname=$APP_BASE_NAME" \ | |
| 213 | 추가: -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ | |
| 214 | 추가: "$@" | |
| 215 | 추가: | |
| 216 | 추가: # Stop when "xargs" is not available. | |
| 217 | 추가: if ! command -v xargs >/dev/null 2>&1 | |
| 218 | 추가: then | |
| 219 | 추가: die "xargs is not available" | |
| 220 | 추가: fi | |
| 221 | 추가: | |
| 222 | 추가: # Use "xargs" to parse quoted args. | |
| 223 | 추가: # | |
| 224 | 추가: # With -n1 it outputs one arg per line, with the quotes and backslashes removed. | |
| 225 | 추가: # | |
| 226 | 추가: # In Bash we could simply go: | |
| 227 | 추가: # | |
| 228 | 추가: # readarray ARGS < <( xargs -n1 <<<"$var" ) && | |
| 229 | 추가: # set -- "${ARGS[@]}" "$@" | |
| 230 | 추가: # | |
| 231 | 추가: # but POSIX shell has neither arrays nor command substitution, so instead we | |
| 232 | 추가: # post-process each arg (as a line of input to sed) to backslash-escape any | |
| 233 | 추가: # character that might be a shell metacharacter, then use eval to reverse | |
| 234 | 추가: # that process (while maintaining the separation between arguments), and wrap | |
| 235 | 추가: # the whole thing up as a single "set" statement. | |
| 236 | 추가: # | |
| 237 | 추가: # This will of course break if any of these variables contains a newline or | |
| 238 | 추가: # an unmatched quote. | |
| 239 | 추가: # | |
| 240 | 추가: | |
| 241 | 추가: eval "set -- $( | |
| 242 | 추가: printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | | |
| 243 | 추가: xargs -n1 | | |
| 244 | 추가: sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | | |
| 245 | 추가: tr '\n' ' ' | |
| 246 | 추가: )" '"$@"' | |
| 247 | 추가: | |
| 248 | 추가: exec "$JAVACMD" "$@" |
| @@ -0,0 +1,112 @@ | ||
| 1 | 추가: @rem | |
| 2 | 추가: @rem Copyright 2015 the original author or authors. | |
| 3 | 추가: @rem | |
| 4 | 추가: @rem Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | 추가: @rem you may not use this file except in compliance with the License. | |
| 6 | 추가: @rem You may obtain a copy of the License at | |
| 7 | 추가: @rem | |
| 8 | 추가: @rem https://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | 추가: @rem | |
| 10 | 추가: @rem Unless required by applicable law or agreed to in writing, software | |
| 11 | 추가: @rem distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | 추가: @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | 추가: @rem See the License for the specific language governing permissions and | |
| 14 | 추가: @rem limitations under the License. | |
| 15 | 추가: @rem | |
| 16 | 추가: @rem SPDX-License-Identifier: Apache-2.0 | |
| 17 | 추가: @rem | |
| 18 | 추가: | |
| 19 | 추가: @if "%DEBUG%"=="" @echo off | |
| 20 | 추가: @rem ########################################################################## | |
| 21 | 추가: @rem | |
| 22 | 추가: @rem gradlew startup script for Windows | |
| 23 | 추가: @rem | |
| 24 | 추가: @rem ########################################################################## | |
| 25 | 추가: | |
| 26 | 추가: @rem Set local scope for the variables, and ensure extensions are enabled | |
| 27 | 추가: setlocal EnableExtensions | |
| 28 | 추가: | |
| 29 | 추가: @rem Catch executions from older scripts and ensure they exit cleanly. | |
| 30 | 추가: @rem This can be removed once we can be reasonably confident that few people | |
| 31 | 추가: @rem will be migrating directly to this new wrapper. | |
| 32 | 추가: goto afterSafetyNet | |
| 33 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 34 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 35 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 36 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 37 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 38 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 39 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 40 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 41 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 42 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 43 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 44 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 45 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 46 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 47 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 48 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 49 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 50 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 51 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 52 | 추가: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
| 53 | 추가: goto exitWithErrorLevel | |
| 54 | 추가: :afterSafetyNet | |
| 55 | 추가: | |
| 56 | 추가: set DIRNAME=%~dp0 | |
| 57 | 추가: if "%DIRNAME%"=="" set DIRNAME=. | |
| 58 | 추가: @rem This is normally unused | |
| 59 | 추가: set APP_BASE_NAME=%~n0 | |
| 60 | 추가: set APP_HOME=%DIRNAME% | |
| 61 | 추가: | |
| 62 | 추가: @rem Resolve any "." and ".." in APP_HOME to make it shorter. | |
| 63 | 추가: for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi | |
| 64 | 추가: | |
| 65 | 추가: @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | |
| 66 | 추가: set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" | |
| 67 | 추가: | |
| 68 | 추가: @rem Find java.exe | |
| 69 | 추가: if defined JAVA_HOME goto findJavaFromJavaHome | |
| 70 | 추가: | |
| 71 | 추가: set JAVA_EXE=java.exe | |
| 72 | 추가: %JAVA_EXE% -version >NUL 2>&1 | |
| 73 | 추가: if %ERRORLEVEL% equ 0 goto execute | |
| 74 | 추가: | |
| 75 | 추가: 1>&2 echo. | |
| 76 | 추가: 1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | |
| 77 | 추가: 1>&2 echo. | |
| 78 | 추가: 1>&2 echo Please set the JAVA_HOME variable in your environment to match the | |
| 79 | 추가: 1>&2 echo location of your Java installation. | |
| 80 | 추가: | |
| 81 | 추가: "%COMSPEC%" /c exit 1 | |
| 82 | 추가: goto exitWithErrorLevel | |
| 83 | 추가: | |
| 84 | 추가: :findJavaFromJavaHome | |
| 85 | 추가: set JAVA_HOME=%JAVA_HOME:"=% | |
| 86 | 추가: set JAVA_EXE=%JAVA_HOME%/bin/java.exe | |
| 87 | 추가: | |
| 88 | 추가: if exist "%JAVA_EXE%" goto execute | |
| 89 | 추가: | |
| 90 | 추가: 1>&2 echo. | |
| 91 | 추가: 1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% | |
| 92 | 추가: 1>&2 echo. | |
| 93 | 추가: 1>&2 echo Please set the JAVA_HOME variable in your environment to match the | |
| 94 | 추가: 1>&2 echo location of your Java installation. | |
| 95 | 추가: | |
| 96 | 추가: "%COMSPEC%" /c exit 1 | |
| 97 | 추가: goto exitWithErrorLevel | |
| 98 | 추가: | |
| 99 | 추가: :execute | |
| 100 | 추가: @rem Setup the command line | |
| 101 | 추가: | |
| 102 | 추가: | |
| 103 | 추가: | |
| 104 | 추가: @rem Execute gradlew | |
| 105 | 추가: @rem endlocal doesn't take effect until after the line is parsed and variables are expanded | |
| 106 | 추가: @rem which allows us to clear the local environment before executing the java command | |
| 107 | 추가: endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel | |
| 108 | 추가: | |
| 109 | 추가: @rem This label must not be changed. We rely on old scripts being able to jump to this point. | |
| 110 | 추가: :exitWithErrorLevel | |
| 111 | 추가: @rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts | |
| 112 | 추가: "%COMSPEC%" /c exit %ERRORLEVEL% |
| @@ -0,0 +1,18 @@ | ||
| 1 | 추가: pluginManagement { | |
| 2 | 추가: repositories { | |
| 3 | 추가: google() | |
| 4 | 추가: mavenCentral() | |
| 5 | 추가: gradlePluginPortal() | |
| 6 | 추가: } | |
| 7 | 추가: } | |
| 8 | 추가: | |
| 9 | 추가: dependencyResolutionManagement { | |
| 10 | 추가: repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) | |
| 11 | 추가: repositories { | |
| 12 | 추가: google() | |
| 13 | 추가: mavenCentral() | |
| 14 | 추가: } | |
| 15 | 추가: } | |
| 16 | 추가: | |
| 17 | 추가: rootProject.name = "android-remote" | |
| 18 | 추가: include(":app") |
| @@ -0,0 +1,5 @@ | ||
| 1 | 추가: //! Android Remote 호스트 클라이언트. | |
| 2 | 추가: //! | |
| 3 | 추가: //! Ubuntu(Wayland/X11)에서 Android 기기 화면을 미러링하고 마우스·키보드로 원격 제어한다. | |
| 4 | 추가: | |
| 5 | 추가: pub mod protocol; |
| @@ -0,0 +1,7 @@ | ||
| 1 | 추가: fn main() { | |
| 2 | 추가: println!( | |
| 3 | 추가: "android-remote {} (protocol v{}): 아직 구현 전입니다.", | |
| 4 | 추가: env!("CARGO_PKG_VERSION"), | |
| 5 | 추가: wayland_android_remote::protocol::VERSION | |
| 6 | 추가: ); | |
| 7 | 추가: } |
| @@ -0,0 +1,119 @@ | ||
| 1 | 추가: use bytes::{Buf, BufMut, Bytes, BytesMut}; | |
| 2 | 추가: | |
| 3 | 추가: use super::{HEADER_LEN, MAGIC, MAX_PAYLOAD_LEN, MsgType, ProtocolError, VERSION}; | |
| 4 | 추가: | |
| 5 | 추가: /// 12바이트 공통 프레임 헤더 (기획서 7.1). `payload_len`은 [`Frame`]의 페이로드에서 계산한다. | |
| 6 | 추가: #[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
| 7 | 추가: pub struct FrameHeader { | |
| 8 | 추가: pub msg_type: MsgType, | |
| 9 | 추가: pub flags: u16, | |
| 10 | 추가: pub seq_id: u16, | |
| 11 | 추가: } | |
| 12 | 추가: | |
| 13 | 추가: /// 헤더와 페이로드가 모두 도착한 완성 프레임. | |
| 14 | 추가: #[derive(Debug, Clone, PartialEq, Eq)] | |
| 15 | 추가: pub struct Frame { | |
| 16 | 추가: pub header: FrameHeader, | |
| 17 | 추가: pub payload: Bytes, | |
| 18 | 추가: } | |
| 19 | 추가: | |
| 20 | 추가: impl Frame { | |
| 21 | 추가: pub fn new(msg_type: MsgType, seq_id: u16, payload: impl Into<Bytes>) -> Self { | |
| 22 | 추가: Self { | |
| 23 | 추가: header: FrameHeader { | |
| 24 | 추가: msg_type, | |
| 25 | 추가: flags: 0, | |
| 26 | 추가: seq_id, | |
| 27 | 추가: }, | |
| 28 | 추가: payload: payload.into(), | |
| 29 | 추가: } | |
| 30 | 추가: } | |
| 31 | 추가: } | |
| 32 | 추가: | |
| 33 | 추가: /// 프레임을 직렬화해 `dst` 뒤에 붙인다. | |
| 34 | 추가: /// | |
| 35 | 추가: /// # Panics | |
| 36 | 추가: /// 페이로드가 [`MAX_PAYLOAD_LEN`]을 넘으면 패닉한다. 상한을 넘는 데이터는 호출 측에서 | |
| 37 | 추가: /// 미리 나누거나 거부해야 한다. | |
| 38 | 추가: pub fn encode_frame(frame: &Frame, dst: &mut BytesMut) { | |
| 39 | 추가: let len = u32::try_from(frame.payload.len()) | |
| 40 | 추가: .ok() | |
| 41 | 추가: .filter(|&n| n <= MAX_PAYLOAD_LEN) | |
| 42 | 추가: .expect("payload exceeds MAX_PAYLOAD_LEN"); | |
| 43 | 추가: dst.reserve(HEADER_LEN + frame.payload.len()); | |
| 44 | 추가: dst.put_u16(MAGIC); | |
| 45 | 추가: dst.put_u8(VERSION); | |
| 46 | 추가: dst.put_u8(frame.header.msg_type.into()); | |
| 47 | 추가: dst.put_u16(frame.header.flags); | |
| 48 | 추가: dst.put_u16(frame.header.seq_id); | |
| 49 | 추가: dst.put_u32(len); | |
| 50 | 추가: dst.put_slice(&frame.payload); | |
| 51 | 추가: } | |
| 52 | 추가: | |
| 53 | 추가: /// TCP 스트림에서 읽은 바이트를 쌓아 두고 완성된 프레임만 꺼내는 디코더 (기획서 7.5). | |
| 54 | 추가: #[derive(Debug, Default)] | |
| 55 | 추가: pub struct FrameDecoder { | |
| 56 | 추가: buf: BytesMut, | |
| 57 | 추가: } | |
| 58 | 추가: | |
| 59 | 추가: impl FrameDecoder { | |
| 60 | 추가: pub fn new() -> Self { | |
| 61 | 추가: Self::default() | |
| 62 | 추가: } | |
| 63 | 추가: | |
| 64 | 추가: /// 소켓에서 읽은 바이트를 버퍼에 추가한다. | |
| 65 | 추가: pub fn extend(&mut self, data: &[u8]) { | |
| 66 | 추가: self.buf.extend_from_slice(data); | |
| 67 | 추가: } | |
| 68 | 추가: | |
| 69 | 추가: /// 버퍼에 남아 있는 아직 처리하지 않은 바이트 수. | |
| 70 | 추가: pub fn buffered_len(&self) -> usize { | |
| 71 | 추가: self.buf.len() | |
| 72 | 추가: } | |
| 73 | 추가: | |
| 74 | 추가: /// 완성된 프레임 하나를 꺼낸다. 데이터가 모자라면 버퍼를 건드리지 않고 `Ok(None)`을 돌려준다. | |
| 75 | 추가: /// | |
| 76 | 추가: /// 헤더 검증은 헤더 12바이트가 도착하자마자 하므로, 잘못된 `payload_len`이 오면 | |
| 77 | 추가: /// 페이로드를 기다리지 않고 바로 오류를 낸다. | |
| 78 | 추가: pub fn decode(&mut self) -> Result<Option<Frame>, ProtocolError> { | |
| 79 | 추가: if self.buf.len() < HEADER_LEN { | |
| 80 | 추가: return Ok(None); | |
| 81 | 추가: } | |
| 82 | 추가: | |
| 83 | 추가: let mut h = &self.buf[..HEADER_LEN]; | |
| 84 | 추가: let magic = h.get_u16(); | |
| 85 | 추가: let version = h.get_u8(); | |
| 86 | 추가: let msg_type = h.get_u8(); | |
| 87 | 추가: let flags = h.get_u16(); | |
| 88 | 추가: let seq_id = h.get_u16(); | |
| 89 | 추가: let payload_len = h.get_u32(); | |
| 90 | 추가: | |
| 91 | 추가: if magic != MAGIC { | |
| 92 | 추가: return Err(ProtocolError::BadMagic(magic)); | |
| 93 | 추가: } | |
| 94 | 추가: if version != VERSION { | |
| 95 | 추가: return Err(ProtocolError::UnsupportedVersion(version)); | |
| 96 | 추가: } | |
| 97 | 추가: if payload_len > MAX_PAYLOAD_LEN { | |
| 98 | 추가: return Err(ProtocolError::PayloadTooLarge(payload_len)); | |
| 99 | 추가: } | |
| 100 | 추가: let msg_type = MsgType::try_from(msg_type)?; | |
| 101 | 추가: | |
| 102 | 추가: let total = HEADER_LEN + payload_len as usize; | |
| 103 | 추가: if self.buf.len() < total { | |
| 104 | 추가: self.buf.reserve(total - self.buf.len()); | |
| 105 | 추가: return Ok(None); | |
| 106 | 추가: } | |
| 107 | 추가: | |
| 108 | 추가: self.buf.advance(HEADER_LEN); | |
| 109 | 추가: let payload = self.buf.split_to(payload_len as usize).freeze(); | |
| 110 | 추가: Ok(Some(Frame { | |
| 111 | 추가: header: FrameHeader { | |
| 112 | 추가: msg_type, | |
| 113 | 추가: flags, | |
| 114 | 추가: seq_id, | |
| 115 | 추가: }, | |
| 116 | 추가: payload, | |
| 117 | 추가: })) | |
| 118 | 추가: } | |
| 119 | 추가: } |
| @@ -0,0 +1,52 @@ | ||
| 1 | 추가: //! 제어 채널 바이너리 프레이밍 프로토콜 (기획서 7절). | |
| 2 | 추가: //! | |
| 3 | 추가: //! 모든 제어 패킷은 12바이트 Big-Endian 공통 헤더와 가변 길이 페이로드로 이루어진다. | |
| 4 | 추가: //! TCP(TLS) 스트림은 프레임 경계를 보장하지 않으므로 [`FrameDecoder`]가 부분 수신과 | |
| 5 | 추가: //! 여러 프레임이 한 번에 도착하는 경우를 모두 처리한다. | |
| 6 | 추가: | |
| 7 | 추가: mod frame; | |
| 8 | 추가: mod msg_type; | |
| 9 | 추가: | |
| 10 | 추가: pub use frame::{Frame, FrameDecoder, FrameHeader, encode_frame}; | |
| 11 | 추가: pub use msg_type::MsgType; | |
| 12 | 추가: | |
| 13 | 추가: /// 프로토콜 식별자 (ASCII 'A', 'R'). | |
| 14 | 추가: pub const MAGIC: u16 = 0x4152; | |
| 15 | 추가: /// 현재 프로토콜 버전. | |
| 16 | 추가: pub const VERSION: u8 = 0x01; | |
| 17 | 추가: /// 공통 헤더 길이 (바이트). | |
| 18 | 추가: pub const HEADER_LEN: usize = 12; | |
| 19 | 추가: /// 페이로드 최대 길이. 이보다 큰 `payload_len`은 OOM 방지를 위해 거부한다. | |
| 20 | 추가: pub const MAX_PAYLOAD_LEN: u32 = 4 * 1024 * 1024; | |
| 21 | 추가: | |
| 22 | 추가: /// 헤더 `flags` 비트. | |
| 23 | 추가: pub mod flags { | |
| 24 | 추가: /// 수신 측에 ACK 응답을 요청한다. | |
| 25 | 추가: pub const ACK_REQUESTED: u16 = 0x0001; | |
| 26 | 추가: /// 페이로드가 압축되어 있다. | |
| 27 | 추가: pub const COMPRESSED: u16 = 0x0002; | |
| 28 | 추가: } | |
| 29 | 추가: | |
| 30 | 추가: /// 프레임 디코딩 중 발생하는 오류. 발생하면 스트림 동기가 깨진 것이므로 연결을 끊는다. | |
| 31 | 추가: #[derive(Debug, Clone, PartialEq, Eq)] | |
| 32 | 추가: pub enum ProtocolError { | |
| 33 | 추가: BadMagic(u16), | |
| 34 | 추가: UnsupportedVersion(u8), | |
| 35 | 추가: UnknownMsgType(u8), | |
| 36 | 추가: PayloadTooLarge(u32), | |
| 37 | 추가: } | |
| 38 | 추가: | |
| 39 | 추가: impl std::fmt::Display for ProtocolError { | |
| 40 | 추가: fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
| 41 | 추가: match self { | |
| 42 | 추가: Self::BadMagic(m) => write!(f, "잘못된 magic 값: {m:#06x}"), | |
| 43 | 추가: Self::UnsupportedVersion(v) => write!(f, "지원하지 않는 프로토콜 버전: {v:#04x}"), | |
| 44 | 추가: Self::UnknownMsgType(t) => write!(f, "알 수 없는 msg_type: {t:#04x}"), | |
| 45 | 추가: Self::PayloadTooLarge(n) => { | |
| 46 | 추가: write!(f, "payload_len {n}이 상한 {MAX_PAYLOAD_LEN}을 넘음") | |
| 47 | 추가: } | |
| 48 | 추가: } | |
| 49 | 추가: } | |
| 50 | 추가: } | |
| 51 | 추가: | |
| 52 | 추가: impl std::error::Error for ProtocolError {} |
| @@ -0,0 +1,75 @@ | ||
| 1 | 추가: use super::ProtocolError; | |
| 2 | 추가: | |
| 3 | 추가: /// 제어 메시지 유형 (기획서 7.2). | |
| 4 | 추가: #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | |
| 5 | 추가: #[repr(u8)] | |
| 6 | 추가: pub enum MsgType { | |
| 7 | 추가: Ping = 0x01, | |
| 8 | 추가: Pong = 0x02, | |
| 9 | 추가: AuthHello = 0x03, | |
| 10 | 추가: AuthChallenge = 0x04, | |
| 11 | 추가: AuthResponse = 0x05, | |
| 12 | 추가: AuthResult = 0x06, | |
| 13 | 추가: ChannelAttach = 0x07, | |
| 14 | 추가: KeyEvent = 0x10, | |
| 15 | 추가: TextInput = 0x11, | |
| 16 | 추가: SystemAction = 0x12, | |
| 17 | 추가: ClipboardSync = 0x20, | |
| 18 | 추가: TouchEvent = 0x30, | |
| 19 | 추가: ScrollEvent = 0x31, | |
| 20 | 추가: VideoConfigRequest = 0x40, | |
| 21 | 추가: VideoConfig = 0x41, | |
| 22 | 추가: VideoRequestKeyframe = 0x42, | |
| 23 | 추가: Ack = 0xF0, | |
| 24 | 추가: Error = 0xFF, | |
| 25 | 추가: } | |
| 26 | 추가: | |
| 27 | 추가: impl MsgType { | |
| 28 | 추가: /// 인증 완료(AUTH_RESULT OK) 전에도 처리할 수 있는 메시지인지 여부 (기획서 7.3 6항). | |
| 29 | 추가: pub fn allowed_before_auth(self) -> bool { | |
| 30 | 추가: matches!( | |
| 31 | 추가: self, | |
| 32 | 추가: Self::Ping | |
| 33 | 추가: | Self::Pong | |
| 34 | 추가: | Self::AuthHello | |
| 35 | 추가: | Self::AuthChallenge | |
| 36 | 추가: | Self::AuthResponse | |
| 37 | 추가: | Self::AuthResult | |
| 38 | 추가: | Self::Error | |
| 39 | 추가: ) | |
| 40 | 추가: } | |
| 41 | 추가: } | |
| 42 | 추가: | |
| 43 | 추가: impl TryFrom<u8> for MsgType { | |
| 44 | 추가: type Error = ProtocolError; | |
| 45 | 추가: | |
| 46 | 추가: fn try_from(value: u8) -> Result<Self, ProtocolError> { | |
| 47 | 추가: Ok(match value { | |
| 48 | 추가: 0x01 => Self::Ping, | |
| 49 | 추가: 0x02 => Self::Pong, | |
| 50 | 추가: 0x03 => Self::AuthHello, | |
| 51 | 추가: 0x04 => Self::AuthChallenge, | |
| 52 | 추가: 0x05 => Self::AuthResponse, | |
| 53 | 추가: 0x06 => Self::AuthResult, | |
| 54 | 추가: 0x07 => Self::ChannelAttach, | |
| 55 | 추가: 0x10 => Self::KeyEvent, | |
| 56 | 추가: 0x11 => Self::TextInput, | |
| 57 | 추가: 0x12 => Self::SystemAction, | |
| 58 | 추가: 0x20 => Self::ClipboardSync, | |
| 59 | 추가: 0x30 => Self::TouchEvent, | |
| 60 | 추가: 0x31 => Self::ScrollEvent, | |
| 61 | 추가: 0x40 => Self::VideoConfigRequest, | |
| 62 | 추가: 0x41 => Self::VideoConfig, | |
| 63 | 추가: 0x42 => Self::VideoRequestKeyframe, | |
| 64 | 추가: 0xF0 => Self::Ack, | |
| 65 | 추가: 0xFF => Self::Error, | |
| 66 | 추가: other => return Err(ProtocolError::UnknownMsgType(other)), | |
| 67 | 추가: }) | |
| 68 | 추가: } | |
| 69 | 추가: } | |
| 70 | 추가: | |
| 71 | 추가: impl From<MsgType> for u8 { | |
| 72 | 추가: fn from(value: MsgType) -> Self { | |
| 73 | 추가: value as u8 | |
| 74 | 추가: } | |
| 75 | 추가: } |
| @@ -0,0 +1,109 @@ | ||
| 1 | 추가: use bytes::BytesMut; | |
| 2 | 추가: use wayland_android_remote::protocol::{ | |
| 3 | 추가: Frame, FrameDecoder, HEADER_LEN, MAX_PAYLOAD_LEN, MsgType, ProtocolError, encode_frame, flags, | |
| 4 | 추가: }; | |
| 5 | 추가: | |
| 6 | 추가: fn encode(frame: &Frame) -> Vec<u8> { | |
| 7 | 추가: let mut buf = BytesMut::new(); | |
| 8 | 추가: encode_frame(frame, &mut buf); | |
| 9 | 추가: buf.to_vec() | |
| 10 | 추가: } | |
| 11 | 추가: | |
| 12 | 추가: #[test] | |
| 13 | 추가: fn header_layout_matches_spec() { | |
| 14 | 추가: let mut frame = Frame::new(MsgType::SystemAction, 0x1234, vec![0x01, 0, 0, 0]); | |
| 15 | 추가: frame.header.flags = flags::ACK_REQUESTED; | |
| 16 | 추가: let bytes = encode(&frame); | |
| 17 | 추가: | |
| 18 | 추가: assert_eq!( | |
| 19 | 추가: &bytes[..HEADER_LEN], | |
| 20 | 추가: &[ | |
| 21 | 추가: 0x41, 0x52, 0x01, 0x12, 0x00, 0x01, 0x12, 0x34, 0x00, 0x00, 0x00, 0x04 | |
| 22 | 추가: ] | |
| 23 | 추가: ); | |
| 24 | 추가: assert_eq!(&bytes[HEADER_LEN..], &[0x01, 0, 0, 0]); | |
| 25 | 추가: } | |
| 26 | 추가: | |
| 27 | 추가: #[test] | |
| 28 | 추가: fn roundtrip() { | |
| 29 | 추가: let frame = Frame::new(MsgType::ClipboardSync, 7, "안녕하세요".as_bytes().to_vec()); | |
| 30 | 추가: let mut dec = FrameDecoder::new(); | |
| 31 | 추가: dec.extend(&encode(&frame)); | |
| 32 | 추가: assert_eq!(dec.decode().unwrap(), Some(frame)); | |
| 33 | 추가: assert_eq!(dec.decode().unwrap(), None); | |
| 34 | 추가: assert_eq!(dec.buffered_len(), 0); | |
| 35 | 추가: } | |
| 36 | 추가: | |
| 37 | 추가: #[test] | |
| 38 | 추가: fn partial_reads_wait_without_consuming() { | |
| 39 | 추가: let frame = Frame::new(MsgType::TouchEvent, 1, vec![0xAB; 20]); | |
| 40 | 추가: let bytes = encode(&frame); | |
| 41 | 추가: let mut dec = FrameDecoder::new(); | |
| 42 | 추가: | |
| 43 | 추가: for (i, b) in bytes.iter().enumerate() { | |
| 44 | 추가: if i < bytes.len() - 1 { | |
| 45 | 추가: dec.extend(&[*b]); | |
| 46 | 추가: assert_eq!(dec.decode().unwrap(), None, "byte {i}"); | |
| 47 | 추가: assert_eq!(dec.buffered_len(), i + 1); | |
| 48 | 추가: } else { | |
| 49 | 추가: dec.extend(&[*b]); | |
| 50 | 추가: } | |
| 51 | 추가: } | |
| 52 | 추가: assert_eq!(dec.decode().unwrap(), Some(frame)); | |
| 53 | 추가: } | |
| 54 | 추가: | |
| 55 | 추가: #[test] | |
| 56 | 추가: fn coalesced_frames_decode_in_order() { | |
| 57 | 추가: let a = Frame::new(MsgType::Ping, 1, Vec::new()); | |
| 58 | 추가: let b = Frame::new(MsgType::KeyEvent, 2, vec![0; 12]); | |
| 59 | 추가: let c = Frame::new(MsgType::Pong, 3, Vec::new()); | |
| 60 | 추가: let mut bytes = encode(&a); | |
| 61 | 추가: bytes.extend(encode(&b)); | |
| 62 | 추가: bytes.extend(&encode(&c)[..5]); | |
| 63 | 추가: | |
| 64 | 추가: let mut dec = FrameDecoder::new(); | |
| 65 | 추가: dec.extend(&bytes); | |
| 66 | 추가: assert_eq!(dec.decode().unwrap(), Some(a)); | |
| 67 | 추가: assert_eq!(dec.decode().unwrap(), Some(b)); | |
| 68 | 추가: assert_eq!(dec.decode().unwrap(), None); | |
| 69 | 추가: dec.extend(&encode(&c)[5..]); | |
| 70 | 추가: assert_eq!(dec.decode().unwrap(), Some(c)); | |
| 71 | 추가: } | |
| 72 | 추가: | |
| 73 | 추가: #[test] | |
| 74 | 추가: fn rejects_bad_magic() { | |
| 75 | 추가: let mut bytes = encode(&Frame::new(MsgType::Ping, 0, Vec::new())); | |
| 76 | 추가: bytes[0] = 0x00; | |
| 77 | 추가: let mut dec = FrameDecoder::new(); | |
| 78 | 추가: dec.extend(&bytes); | |
| 79 | 추가: assert_eq!(dec.decode(), Err(ProtocolError::BadMagic(0x0052))); | |
| 80 | 추가: } | |
| 81 | 추가: | |
| 82 | 추가: #[test] | |
| 83 | 추가: fn rejects_oversized_payload_before_buffering_it() { | |
| 84 | 추가: let mut bytes = encode(&Frame::new(MsgType::ClipboardSync, 0, Vec::new())); | |
| 85 | 추가: bytes[8..12].copy_from_slice(&(MAX_PAYLOAD_LEN + 1).to_be_bytes()); | |
| 86 | 추가: let mut dec = FrameDecoder::new(); | |
| 87 | 추가: dec.extend(&bytes); | |
| 88 | 추가: assert_eq!( | |
| 89 | 추가: dec.decode(), | |
| 90 | 추가: Err(ProtocolError::PayloadTooLarge(MAX_PAYLOAD_LEN + 1)) | |
| 91 | 추가: ); | |
| 92 | 추가: } | |
| 93 | 추가: | |
| 94 | 추가: #[test] | |
| 95 | 추가: fn rejects_unknown_msg_type() { | |
| 96 | 추가: let mut bytes = encode(&Frame::new(MsgType::Ping, 0, Vec::new())); | |
| 97 | 추가: bytes[3] = 0x99; | |
| 98 | 추가: let mut dec = FrameDecoder::new(); | |
| 99 | 추가: dec.extend(&bytes); | |
| 100 | 추가: assert_eq!(dec.decode(), Err(ProtocolError::UnknownMsgType(0x99))); | |
| 101 | 추가: } | |
| 102 | 추가: | |
| 103 | 추가: #[test] | |
| 104 | 추가: fn only_auth_messages_allowed_before_auth() { | |
| 105 | 추가: assert!(MsgType::AuthHello.allowed_before_auth()); | |
| 106 | 추가: assert!(MsgType::Ping.allowed_before_auth()); | |
| 107 | 추가: assert!(!MsgType::TouchEvent.allowed_before_auth()); | |
| 108 | 추가: assert!(!MsgType::ChannelAttach.allowed_before_auth()); | |
| 109 | 추가: } |