feat: 完成 M2 mosh(LAN + tsnet 端到端验证)

- mosh(blinksh/ios C++)+protobuf-lite 交叉编译为 MoshCore.xcframework
  (CommonCrypto 后端、含 arm64 模拟器 slice;绕 autotools 用 CMake 直编 + 手写 config.h)
- tsnet 桥新增 UDP relay(StartMoshRelay:loopback↔tsnet.Dial 逐包搬运)
- MoshSession(pipe↔FILE*/pthread/SIGWINCH)+ MoshConnectScanner(TXCore,+4 单测=39)
- SSHTerminalModel 编排:SSH 引导 mosh-server→解析 MOSH CONNECT→relay→mosh 接管
- LAN 直连 + mosh-over-tsnet 均端到端验证通过,R1(tsnet UDP 数据报语义) 证伪

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
kid
2026-07-24 16:14:40 +08:00
parent aa92d0e676
commit 32520f09e0
1232 changed files with 728138 additions and 37 deletions

76
vendor/build/build-mosh.sh vendored Executable file
View File

@@ -0,0 +1,76 @@
#!/bin/bash
# 交叉编译 mosh(blinksh/ios 分支) + protobuf-lite → MoshCore.xcframeworkiOS device/simulator/macOS
# crypto 后端 = Apple CommonCrypto系统内建特性宏由 build/mosh/config.h 手写提供(绕过 autotools
# 产出 library-only xcframework头文件与 modulemap 由包内 C target 提供,避免 modulemap 撞车,同 CSSHCore 教训)。
set -euo pipefail
BUILD="$(cd "$(dirname "$0")" && pwd)" # vendor/build
VENDOR="$(cd "$BUILD/.." && pwd)" # vendor
MOSH_SRC="$VENDOR/mosh/src"
PROTOBUF="$VENDOR/protobuf"
PROTOBUF_SRC="$PROTOBUF/src"
MOSH_CMAKE="$BUILD/mosh"
OUT="$BUILD/mosh-out"
ARTIFACTS="$VENDOR/../artifacts"
IOS_DEPLOY=17.0
MAC_DEPLOY=14.0
build_slice() {
local name="$1" sysname="$2" sysroot="$3" archs="$4" deploy="$5"
echo "==================== slice: $name ($archs @ $sysroot) ===================="
rm -rf "$OUT/$name"; mkdir -p "$OUT/$name"
local common=(
-G Ninja
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_SYSTEM_NAME="$sysname"
-DCMAKE_OSX_SYSROOT="$sysroot"
-DCMAKE_OSX_ARCHITECTURES="$archs"
-DCMAKE_OSX_DEPLOYMENT_TARGET="$deploy"
)
# --- protobuf-lite仅 lite runtimemosh 的 .proto 是 proto2 + LITE_RUNTIME ---
cmake -S "$PROTOBUF" -B "$OUT/$name/protobuf" "${common[@]}" \
-Dprotobuf_BUILD_TESTS=OFF \
-Dprotobuf_BUILD_PROTOC_BINARIES=OFF \
-Dprotobuf_BUILD_LIBPROTOC=OFF \
-Dprotobuf_BUILD_SHARED_LIBS=OFF \
-DCMAKE_CXX_STANDARD=14
cmake --build "$OUT/$name/protobuf" --target libprotobuf-lite -j8
# --- moshios我们的 CMakeLists编 src/*.cc ---
cmake -S "$MOSH_CMAKE" -B "$OUT/$name/mosh" "${common[@]}" \
-DMOSH_SRC="$MOSH_SRC" \
-DPROTOBUF_SRC="$PROTOBUF_SRC"
cmake --build "$OUT/$name/mosh" -j8
# --- 合并静态库 → 单一 libMoshCore.a ---
libtool -static -o "$OUT/$name/libMoshCore.a" \
"$OUT/$name/mosh/libmoshios.a" \
"$OUT/$name/protobuf/libprotobuf-lite.a"
echo "[+] $name$(lipo -archs "$OUT/$name/libMoshCore.a")"
}
pack_xcframework() {
echo "==================== packing MoshCore.xcframework (library-only) ===================="
rm -rf "$ARTIFACTS/MoshCore.xcframework"; mkdir -p "$ARTIFACTS"
local args=()
for s in "$@"; do
args+=(-library "$OUT/$s/libMoshCore.a")
done
xcodebuild -create-xcframework "${args[@]}" -output "$ARTIFACTS/MoshCore.xcframework"
echo "[+] MoshCore.xcframework:"; ls "$ARTIFACTS/MoshCore.xcframework"
}
case "${1:-all}" in
iossim) build_slice iossim iOS iphonesimulator "arm64;x86_64" "$IOS_DEPLOY" ;;
device) build_slice ios-arm64 iOS iphoneos "arm64" "$IOS_DEPLOY" ;;
macos) build_slice macos Darwin macosx "arm64" "$MAC_DEPLOY" ;;
all)
build_slice iossim iOS iphonesimulator "arm64;x86_64" "$IOS_DEPLOY"
build_slice ios-arm64 iOS iphoneos "arm64" "$IOS_DEPLOY"
build_slice macos Darwin macosx "arm64" "$MAC_DEPLOY"
pack_xcframework iossim ios-arm64 macos
;;
pack) shift; pack_xcframework "$@" ;;
esac

83
vendor/build/mosh/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,83 @@
cmake_minimum_required(VERSION 3.20)
project(moshios CXX)
# 直接编译 blinksh/mosh(ios 分支) 的 src/*.cc 为静态库,绕过 autotools。
# 特性宏由同目录手写 config.h 提供(-I 本目录,且优先于 src 树内任何 config.h
# 变量入参:
# MOSH_SRC —— vendor/mosh/src 绝对路径
# PROTOBUF_SRC —— vendor/protobuf/src 绝对路径(提供 protobuf-lite 头)
if(NOT DEFINED MOSH_SRC)
message(FATAL_ERROR "MOSH_SRC 未设置")
endif()
if(NOT DEFINED PROTOBUF_SRC)
message(FATAL_ERROR "PROTOBUF_SRC 未设置")
endif()
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON) # gnu++14mosh 用到 GNU 扩展)
# 依据 src/*/Makefile.am 的 BUILD_IOS_CONTROLLER 分支精确选取源文件。
# 关键terminal 用 terminaldisplayinit_ios.cc非 terminaldisplayinit.cc后者需 ncurses
# frontend 仅取 moshiosbridge/iosclient/terminaloverlay排除 mosh-client/server/mosh/stmclient
set(MOSH_SOURCES
${MOSH_SRC}/crypto/base64.cc
${MOSH_SRC}/crypto/crypto.cc
${MOSH_SRC}/crypto/ocb.cc
${MOSH_SRC}/network/compressor.cc
${MOSH_SRC}/network/network.cc
${MOSH_SRC}/network/networktransport.cc
${MOSH_SRC}/network/transportfragment.cc
${MOSH_SRC}/network/transportsender.cc
${MOSH_SRC}/statesync/completeterminal.cc
${MOSH_SRC}/statesync/user.cc
${MOSH_SRC}/terminal/parseraction.cc
${MOSH_SRC}/terminal/parser.cc
${MOSH_SRC}/terminal/parserstate.cc
${MOSH_SRC}/terminal/terminal.cc
${MOSH_SRC}/terminal/terminaldispatcher.cc
${MOSH_SRC}/terminal/terminaldisplay.cc
${MOSH_SRC}/terminal/terminaldisplayinit_ios.cc
${MOSH_SRC}/terminal/terminalframebuffer.cc
${MOSH_SRC}/terminal/terminalfunctions.cc
${MOSH_SRC}/terminal/terminaluserinput.cc
${MOSH_SRC}/util/locale_utils.cc
${MOSH_SRC}/util/pty_compat.cc
${MOSH_SRC}/util/select.cc
${MOSH_SRC}/util/swrite.cc
${MOSH_SRC}/util/timestamp.cc
${MOSH_SRC}/protobufs/hostinput.pb.cc
${MOSH_SRC}/protobufs/transportinstruction.pb.cc
${MOSH_SRC}/protobufs/userinput.pb.cc
${MOSH_SRC}/frontend/moshiosbridge.cc
${MOSH_SRC}/frontend/iosclient.cc
${MOSH_SRC}/frontend/terminaloverlay.cc
)
add_library(moshios STATIC ${MOSH_SOURCES})
target_include_directories(moshios PRIVATE
${CMAKE_CURRENT_SOURCE_DIR} # 手写 config.h必须最先
${MOSH_SRC}
${MOSH_SRC}/crypto
${MOSH_SRC}/network
${MOSH_SRC}/statesync
${MOSH_SRC}/terminal
${MOSH_SRC}/util
${MOSH_SRC}/protobufs
${MOSH_SRC}/frontend
${PROTOBUF_SRC}
)
# 1.3.2 老代码在 Xcode 26/新 clang 下告警多;关掉噪声,绝不开 -Werror。
# 强制前置 <cstdint>protobuf 3.21.12 的 stubs/port.h 用了 int8_t 却未自带 stdint 包含,
# iOS SDK 头链比 host macOS 严格,会报 "unknown type name 'int8_t'"。全 TU 注入即修复。
target_compile_options(moshios PRIVATE
"SHELL:-include cstdint"
-Wno-deprecated-declarations
-Wno-deprecated-register
-Wno-register
-Wno-unused-parameter
-Wno-writable-strings
-fno-strict-aliasing
)

56
vendor/build/mosh/config.h vendored Normal file
View File

@@ -0,0 +1,56 @@
/* config.h — 手写替代 mosh autotools 的 configure 产物iOS/macOS/Apple Silicon
* 本环境缺 autoconf/automake故不跑 ./autogen.sh改由 CMake 直接编 src/*.cc
* 用本文件提供全部特性宏。仅面向 Darwin(iOS device/simulator, macOS arm64)。
* 依据configure.ac 的 AC_CHECK 系列 + 各 .cc 里实际引用的 HAVE / USE 宏收敛而来。 */
#ifndef MOSH_TX_CONFIG_H
#define MOSH_TX_CONFIG_H
/* --- 包标识(仅用于版本串打印) --- */
#define PACKAGE_NAME "mosh"
#define PACKAGE_STRING "mosh 1.3.2"
#define PACKAGE_VERSION "1.3.2"
#define VERSION "1.3.2"
/* --- iOS controller 模式:只编 client 库(对应 --enable-ios-controller --- */
#define IOS_CONTROLLER 1
/* --- crypto 后端Apple CommonCryptoiOS/macOS 系统内建,无需 OpenSSL/mbedTLS ---
* ocb.cc 用 `#elif USE_APPLE_COMMON_CRYPTO_AES` 选择 <CommonCrypto/CommonCryptor.h>。 */
#define USE_APPLE_COMMON_CRYPTO_AES 1
#define USE_OPENSSL_AES 0
#define USE_NETTLE_AES 0
#define USE_REFERENCE_AES 0
#define USE_AES_NI 0
/* --- 时间源iOS/macOS 均有 clock_gettime(CLOCK_MONOTONIC) --- */
#define HAVE_CLOCK_GETTIME 1
#define HAVE_GETTIMEOFDAY 1
#define HAVE_MACH_ABSOLUTE_TIME 1
/* --- 字节序Darwin 用 <libkern/OSByteOrder.h>byteorder.h 的 HAVE_OSX_SWAP 分支) --- */
#define HAVE_OSX_SWAP 1
#define HAVE_DECL_BE64TOH 0
#define HAVE_DECL_BETOH64 0
/* --- 编译器内建clang 全支持) --- */
#define HAVE_DECL___BUILTIN_CTZ 1
#define HAVE_DECL___BUILTIN_BSWAP64 1
/* --- Darwin/iOS 存在的头文件 --- */
#define HAVE_LANGINFO_H 1
#define HAVE_SYS_UIO_H 1
#define HAVE_PATHS_H 1
#define HAVE_UTIL_H 1
#define HAVE_UTMPX_H 1
/* --- Darwin/iOS 存在的函数 --- */
#define HAVE_POSIX_MEMALIGN 1
#define HAVE_PSELECT 1
#define HAVE_CFMAKERAW 1
#define HAVE_FORKPTY 1
/* 说明IP_MTU_DISCOVER / IP_RECVTOS(Linux only) 与 HAVE_IUTF8 均以 #ifdef 判定,
* 此处不定义即自动跳过network.cc 相关分支只在 Linux 生效HAVE_IUTF8 仅被
* 已排除的 mosh-server.cc/stmclient.cc 使用)。 */
#endif /* MOSH_TX_CONFIG_H */