From f5d5a7f647245d9e447d130e5ee9cc1776a9da93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 16 May 2026 11:32:24 +0800 Subject: [PATCH] usbip: gate serverImportLease so unsupported-target builds compile control_protocol.go was ungated but referenced ExportLeaseIdentity from host.go (linux || (darwin && cgo)), breaking the stub-register contract on Windows and darwin && !cgo. Move serverImportLease and importLeaseTTL into export_ledger.go alongside their only consumers. --- service/usbip/control_protocol.go | 13 ------------- service/usbip/export_ledger.go | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/service/usbip/control_protocol.go b/service/usbip/control_protocol.go index bd0e9559b..49bfbce12 100644 --- a/service/usbip/control_protocol.go +++ b/service/usbip/control_protocol.go @@ -6,7 +6,6 @@ import ( "io" "slices" "strings" - "time" E "github.com/sagernet/sing/common/exceptions" ) @@ -47,8 +46,6 @@ const ( leaseErrorBadRequest = "bad_request" leaseErrorUnavailable = "unavailable" leaseErrorBusy = "busy" - - importLeaseTTL = 10 * time.Second ) var controlPreface = [controlPrefaceSize]byte{'S', 'B', 'U', 'S', 'B', 'I', 'P', '1'} @@ -121,16 +118,6 @@ type controlLeaseResponse struct { ErrorMessage string `json:"error_message,omitempty"` } -type serverImportLease struct { - ID uint64 - SubscriberID uint64 - BusID string - ClientNonce uint64 - Generation uint64 - Identity ExportLeaseIdentity - Expires time.Time -} - // controlReader reuses its payload scratch across successive reads on a // single connection. The returned payload is only valid until the next call. type controlReader struct { diff --git a/service/usbip/export_ledger.go b/service/usbip/export_ledger.go index 2739701e3..2dd9b65b2 100644 --- a/service/usbip/export_ledger.go +++ b/service/usbip/export_ledger.go @@ -45,7 +45,20 @@ type exportSubscriber struct { send chan controlMessage } -const controlSubscriberSendBuffer = 16 +type serverImportLease struct { + ID uint64 + SubscriberID uint64 + BusID string + ClientNonce uint64 + Generation uint64 + Identity ExportLeaseIdentity + Expires time.Time +} + +const ( + controlSubscriberSendBuffer = 16 + importLeaseTTL = 10 * time.Second +) func newExportLedger(logger log.ContextLogger, ttl time.Duration, now func() time.Time) *exportLedger { if now == nil {