Commit Graph

1720 Commits

Author SHA1 Message Date
yusing
45eb3eefab docs(stream): update README to correct header size and enhance API documentation
- Corrected the total header size from 273 to 274 bytes.
- Improved documentation for `StreamRequestHeader` and `ConnectionManager` types, including method descriptions.
- Added details on TCP and UDP functions, as well as connection management and ALPN protocol usage.
2026-01-09 00:15:24 +08:00
yusing
b7cd4b51cb docs(stream): enhance documentation 2026-01-08 20:53:38 +08:00
yusing
e1dd84ed16 docs(agent): rename PROTOCOL.md to README.md 2026-01-08 20:35:15 +08:00
yusing
caa71b1bb6 docs(idlewatcher): update README to include loading page and SSE endpoint details
- Added information about the loading page (HTML + JS + CSS) and the SSE endpoint for wake events.
- Clarified the health monitor implementation and readiness tracking in the architecture overview.
- Correct state machine syntax.
2026-01-08 20:32:16 +08:00
yusing
0775ac0b92 feat(docs): add health check and monitor packages README; mermaid styling fix 2026-01-08 20:32:16 +08:00
yusing
b1e3aa382c feat(scriptsi): add script to sync implementation docs with wiki
- Introduced a new `update-wiki` script to automate the synchronization of implementation documentation from the repository to the wiki.
- Added necessary configuration files including `package.json`, `tsconfig.json`, and `.gitignore` for the new script.
- Updated the Makefile to include a target for running the `update-wiki` script.
2026-01-08 20:32:15 +08:00
yusing
1c1e50a35b fix(health): correct context handling, move NewMonitor, and improve docker health check errors
- Correct BaseContext nil check in Context() method
- Move NewMonitor from monitor.go to new.go
- Export ErrDockerHealthCheckFailedTooManyTimes and add ErrDockerHealthCheckNotAvailable
- Return ErrDockerHealthCheckNotAvailable when container has no health check configured
- Only log first docker health check failure and skip logging for ErrDockerHealthCheckNotAvailable
- Use mon.Context() instead of mon.task.Context() to avoid nil panic
2026-01-08 18:14:14 +08:00
yusing
1c78e19a4a refactor: move internal/watcher/health to internal/health 2026-01-08 15:11:04 +08:00
yusing
7c7fabb7a1 refactor(health): restructure health check implementations into dedicated check package
- Move health check implementations from monitor/ to new check/ package
- Add h2c, tcp4/6, udp4/6 scheme support to agent health check API
- Add timeout URL parameter to agent health check endpoint
- Remove unused agent dependencies (dnsproviders, lego, various cloud SDKs)
- Use net.JoinHostPort instead of fmt.Sprintf for port joining
2026-01-08 15:03:00 +08:00
yusing
db2eda49f1 refactor(agent): extract agent pool and HTTP utilities to dedicated package
Moved non-agent-specific logic from agent/pkg/agent/ to internal/agentpool/:
- pool.go: Agent pool management (Get, Add, Remove, List, Iter, etc.)
- http_requests.go: HTTP utilities (health checks, forwarding, websockets, reverse proxy)
- agent.go: Agent struct with HTTP client management

This separates general-purpose pool management from agent-specific configuration,
improving code organization and making the agent package focused on agent config only.
2026-01-08 15:02:27 +08:00
yusing
751d73da7c refactor(agent/stream): remove connQueueListener and simplify the handshaking flow 2026-01-08 00:15:47 +08:00
yusing
d3a8b3c0e6 fix(agent/stream): improve error handling in UDP server connection
- Enhanced error handling in the UDP server to properly manage EOF and closed connection scenarios.
- Ensured that bytes read from the client are forwarded before handling errors.
- Added checks to avoid logging noise for expected shutdown conditions.
2026-01-07 23:42:21 +08:00
yusing
63f96b8d76 refactor(agent/stream): update header size calculation and field types
- Adjusted headerSize calculation to reflect the correct size based on field definitions.
- Changed HostLength and PortLength types from uint8 to byte.
- Updated PROTOCOL.md to reflect the new header size and structure.
2026-01-07 22:33:24 +08:00
yusing
5048326c20 fix(agent/stream): handle EOF error in UDP server connection
- Updated error handling in the UDP server to ignore io.EOF errors when reading from client connections.
- Added a check to return early if no bytes are read from the client connection.
- Ensured proper closure of tcpListener in the main.go file during cancellation.
2026-01-07 21:10:47 +08:00
yusing
d7361c6f52 refactor(agent/config): simplify stream server address handling
- Removed the streamServerAddr field from AgentConfig to streamline configuration.
- Updated StartWithCerts, NewTCPClient, and NewUDPClient methods to use Addr directly for establishing connections.
- Eliminated the getStreamServerAddr method as it is no longer needed.
2026-01-07 21:09:07 +08:00
yusing
c8f617108e refactor(agent/stream): rename payload.go to header.go and update protocol header format
- Rename payload.go to header.go for clarity
- Add HostLength and PortLength fields to avoid NUL-terminated string scanning
- Add padding bytes to make struct size match headerSize
- Remove unused StreamRequestPayload struct and WriteTo method
- Add runtime size validation in init()
- Update PROTOCOL.md documentation
2026-01-07 21:08:04 +08:00
yusing
039ae26696 chore(stream): remove unused StreamRequestPayload test 2026-01-07 21:05:52 +08:00
yusing
a605d56a4c feat(agent/stream): remove STREAM_PORT and use tcp multiplexing on the same port 2026-01-07 18:30:31 +08:00
yusing
cc406921cb refactor: remove NoCopy struct; move RefCounter struct to goutils and update usage; remove internal/utils entirely 2026-01-07 17:19:34 +08:00
yusing
04dd963535 chore: go mod tidy 2026-01-07 17:04:44 +08:00
yusing
5ff6928b13 Cherry-Pick 1ebba20216 2026-01-07 15:29:39 +08:00
yusing
63e69e71c3 fix(stream): nil panic for excluded routes 2026-01-07 15:24:09 +08:00
yusing
0b9553e4af Cherry-Pick 25ceb512b4 2026-01-07 15:09:51 +08:00
yusing
25ceb512b4 feat(route): add bind address support for TCP/UDP routes
- Introduced a new `Bind` field in the route configuration to specify the address to listen on for TCP and UDP routes.
- Defaulted the bind address to "0.0.0.0" if not provided.
- Enhanced validation to ensure the bind address is a valid IP.
- Updated stream initialization to use the correct network type (tcp4/tcp6 or udp4/udp6) based on the bind address.
- Refactored stream creation functions to accept the network type as a parameter.
2026-01-07 15:05:55 +08:00
yusing
682b4330fc feat(agent/stream): log UDP server errors 2026-01-07 14:34:14 +08:00
yusing
56f7841eda test(agent/stream): refactor server flow tests to use testify and real certificate generation
- Use agent.NewAgent() for properly configured certificates matching real usage
- Migrate to testify/require for assertions
- Add tests for UDP server rejecting clients with invalid certificates
- Use t.Context() for lifecycle management
2026-01-07 14:19:58 +08:00
yusing
0a28d026c5 Merge branch 'main' into feat/agent-stream-rebased 2026-01-07 10:54:56 +08:00
yusing
9205af3a4f feat(api/cert): enhance certificate info retrieval
- Introduced a new method `GetCertInfos` to fetch details of all available certificates.
- Updated the `Info` handler to return an array of `CertInfo` instead of a single certificate.
- Improved error handling for cases with no available certificates.
- Refactored related error messages for clarity.
2026-01-07 10:54:33 +08:00
yusing
08f4d9e95f chore: update goutils 2026-01-07 10:24:08 +08:00
yusing
559fea3ab1 chore(swagger): update swagger 2026-01-07 10:21:50 +08:00
yusing
2e2b7246d5 fix(agent): set ServerName in NewTCPClient and NewUDPClient; move CertDNSName to agent/pkg/common 2026-01-07 02:01:59 +08:00
yusing
c039f9f4b5 fix(route): update logging to use Stringer for scheme in StreamRoute 2026-01-07 01:37:20 +08:00
yusing
55a0b722b9 chore(goutils): update submodule 2026-01-07 01:21:44 +08:00
yusing
fc3af0b874 chore(agent): update submodule and add logging for TCP/UDP stream server startup 2026-01-07 01:21:29 +08:00
yusing
68c15536bc fix(agent): add omitempty to stream_port in AgentInfo 2026-01-07 01:06:40 +08:00
yusing
920f5b1a58 feat(agent): add optional StreamPort to agent creation API
- Introduced `StreamPort` field in `NewAgentRequest` for agent configuration.
- Implemented default behavior for `StreamPort` to be `Port + 1` if not specified.
- Added validation to ensure `StreamPort` is within the valid range (1-65535).
2026-01-07 00:58:55 +08:00
yusing
fe619f1dd9 feat(agent): agent stream tunneling with TLS and dTLS (UDP); combined agent APIs
- Add `StreamPort` configuration to agent configuration and environment variables
- Implement TCP and UDP stream client support in agent package
- Update agent verification to test stream connectivity (TCP/UDP)
- Add `/info` endpoint to agent HTTP handler for version, name, runtime, and stream port
- Remove /version, /name, /runtime APIs, replaced by /info
- Update agent compose template to expose stream port for TCP and UDP
- Update agent creation API to optionally specify stream port (defaults to port + 1)
- Modify `StreamRoute` to pass agent configuration to stream implementations
- Update `TCPTCPStream` and `UDPUDPStream` to use agent stream tunneling when agent is configured
- Add support for both direct connections and agent-tunneled connections in stream routes

This enables agents to handle TCP and UDP route tunneling, expanding the proxy capabilities beyond HTTP-only connections.
2026-01-07 00:44:12 +08:00
yusing
a44b9e352c refactor(docker): simplify flow of isLocal check 2026-01-06 16:38:49 +08:00
yusing
424398442b refactor: replace gperr.Builder with gperr.Group for concurrent error handling
- Updated various files to utilize gperr.Group for cleaner concurrency error handling.
- Removed sync.WaitGroup usage, simplifying the code structure.
- Ensured consistent error reporting across different components.
2026-01-06 16:29:35 +08:00
yusing
724617a2b3 chore(go.mod): update goquery comment and add description for x/sync package 2026-01-05 20:58:56 +08:00
yusing
61c8ac04e8 feat(autocert): add back inwx provider v0.23.1 2026-01-05 20:55:04 +08:00
yusing
cc27942c4d chore(deps): update dependencies 2026-01-05 20:47:56 +08:00
yusing
1c2515cb29 chore(docs): add README.md across multiple packages 2026-01-04 22:01:48 +08:00
yusing
45720db754 fix(Makefile): correct test command 2026-01-04 21:57:25 +08:00
yusing
1b9cfa6540 fix(autocert): forceRenewalDoneCh was never closed v0.23.0 2026-01-04 20:40:38 +08:00
yusing
f1d906ac11 fix(test): update test expectations 2026-01-04 20:31:11 +08:00
yusing
2835fd5fb0 fix(autocert): ensure extra certificate registration and renewal scheduling
Extra providers were not being properly initialized during NewProvider(),
causing certificate registration and renewal scheduling to be skipped.

- Add ConfigExtra type with idx field for provider indexing
- Add MergeExtraConfig() for inheriting main provider settings
- Add setupExtraProviders() for recursive extra provider initialization
- Refactor NewProvider to return error and call setupExtraProviders()
- Add provider-scoped logger with "main" or "extra[N]" name
- Add batch operations: ObtainCertIfNotExistsAll(), ObtainCertAll()
- Add ForceExpiryAll() with completion tracking via WaitRenewalDone()
- Add RenewMode (force/ifNeeded) for controlling renewal behavior
- Add PrintCertExpiriesAll() for logging all provider certificate expiries

Summary of staged changes:
- config.go: Added ConfigExtra type, MergeExtraConfig(), recursive validation with path uniqueness checking
- provider.go: Added provider indexing, scoped logger, batch cert operations, force renewal with completion tracking, RenewMode control
- setup.go: New file with setupExtraProviders() for proper extra provider initialization
- setup_test.go: New tests for extra provider setup
- multi_cert_test.go: New tests for multi-certificate functionality
- renew.go: Updated to use new provider API with error handling
- state.go: Updated to handle NewProvider error return
2026-01-04 20:30:58 +08:00
yusing
11d0c61b9c refactor(state): replace Entrypoint method with ShortLinkMatcher interface
- Cleaned up agent go.mod by removing unused indirect dependencies.
2026-01-04 12:43:05 +08:00
Yuzerion
c00854a124 feat(autocert): add multi-certificate support (#185)
Multi-certificate, SNI matching with exact map and suffix tree

Add support for multiple TLS certificates with SNI-based selection. The
root provider maintains a single centralized SNI matcher that uses an
exact match map for O(1) lookups, falling back to a suffix tree for
wildcard matching.

Key features:
- Add `Extra []Config` field to autocert.Config for additional certificates
- Each extra entry must specify unique `cert_path` and `key_path`
- Extra certs inherit main config (except `email` and `extra` fields)
- Extra certs participate in ACME obtain/renew cycles independently
- SNI selection precedence: exact match > wildcard match, main > extra
- Single centralized SNI matcher on root provider rebuilt after cert changes

The SNI matcher structure:
- Exact match map: O(1) lookup for exact domain matches
- Suffix tree: Efficient wildcard matching (e.g., *.example.com)

Implementation details:
- Provider.GetCert() now uses SNI from ClientHelloInfo for selection
- Main cert is returned as fallback when no SNI match is found
- Extra providers are created as child providers with merged configs
- SNI matcher is rebuilt after Setup() and after ObtainCert() completes
2026-01-04 00:37:26 +08:00
yusing
117dbb62f4 refactor(docker): accept unix and ssh scheme for providers 2026-01-03 20:06:31 +08:00