f21fa5b5e8
Commilitia Drop:自托管的跨设备剪贴板同步与点对点文件传输。 - 后端 Go(chi / SQLite WAL / SSE Hub / WebRTC signaling + 状态机 / Relay ring buffer),编译进单个 distroless 镜像(前端 go:embed)。 - 前端 React + TanStack Router + Zustand,自实现 SSE + WebRTC P2P,NAT 受阻时回退服务端中继;聚珍(Juzhen)CJK 综合排版。 - 桌面端 Wails v2(macOS / Windows),瘦客户端复用 web。 - 鉴权 OIDC PKCE(自建 Casdoor 等),refresh_token 信封加密存系统密钥库;iOS Shortcut 用 HS256 scoped token。 架构文档与变更记录见 docs 分支(PROJECT_BRIEF / FRONTEND_DESIGN / CHANGELOG)。 本次为公开发布初始提交:完整开发历史(含部署细节)留存于私有归档,公开仓库自此干净起步。
55 lines
1.9 KiB
Go
55 lines
1.9 KiB
Go
package transfer
|
|
|
|
const (
|
|
StatePending = "PENDING"
|
|
StateAccepted = "ACCEPTED"
|
|
StateP2PActive = "P2P_ACTIVE"
|
|
StateRelayActive = "RELAY_ACTIVE"
|
|
StateDone = "DONE"
|
|
StateFailed = "FAILED"
|
|
StateCancelled = "CANCELLED"
|
|
)
|
|
|
|
const (
|
|
ModeP2P = "p2p"
|
|
ModeRelay = "relay"
|
|
)
|
|
|
|
// AutoAcceptThreshold is the file size at/under which the receiver may
|
|
// silently auto-accept a transfer. brief §2: "> 100 MB 二次确认".
|
|
const AutoAcceptThreshold = 100 * 1024 * 1024
|
|
|
|
// IsValidTransition reports whether a transfer may move from→to.
|
|
//
|
|
// Forward-only: any state can advance to a "later" state, but never go back.
|
|
// We're permissive because client→server timing races are real:
|
|
// - sender's /p2p can land before receiver's /accept commits → PENDING → P2P_ACTIVE
|
|
// - either side may call /done before /p2p ever fired → ACCEPTED → DONE
|
|
// Strict ordering would surface as 409s the user can't recover from.
|
|
//
|
|
// Terminal states (DONE / FAILED / CANCELLED) accept no further transitions.
|
|
func IsValidTransition(from, to string) bool {
|
|
switch from {
|
|
case StatePending:
|
|
return to == StateAccepted || to == StateP2PActive || to == StateRelayActive ||
|
|
to == StateCancelled || to == StateFailed
|
|
case StateAccepted:
|
|
return to == StateP2PActive || to == StateRelayActive ||
|
|
to == StateDone || to == StateCancelled || to == StateFailed
|
|
case StateP2PActive:
|
|
// P2P 失败自动 fallback 到 Relay (brief §2).
|
|
return to == StateRelayActive || to == StateDone ||
|
|
to == StateFailed || to == StateCancelled
|
|
case StateRelayActive:
|
|
return to == StateDone || to == StateFailed || to == StateCancelled
|
|
case StateDone, StateFailed, StateCancelled:
|
|
return false
|
|
}
|
|
return false
|
|
}
|
|
|
|
// IsTerminal reports whether the state is final (no further transitions).
|
|
func IsTerminal(state string) bool {
|
|
return state == StateDone || state == StateFailed || state == StateCancelled
|
|
}
|