Commit Graph

1713 Commits

Author SHA1 Message Date
yusing
373372ac59 refactor(homepage/icon): check service health before fetching icons and add retry logic
The icon fetching logic now checks if the target service is healthy before
attempting to fetch icons. If the health monitor reports an unhealthy status,
the function returns HTTP 503 Service Unavailable instead of proceeding.

Additionally, the icon cache lookup now includes infinite retry logic with a
15-second backoff interval, improving resilience during transient service
outages. Previously, failed lookups would not be retried.

The `route` interface was extended with a `HealthMonitor()` method to support
the health check functionality.
2026-01-09 22:38:31 +08:00
yusing
6cf31541d9 fix(homepage/icon): set icons provider on init (introduced in 74f97a6621) 2026-01-09 22:38:30 +08:00
yusing
d1448c886d refactor(route): improve References method to handle FQDN alias 2026-01-09 22:38:30 +08:00
yusing
4a6e821732 fix(agent/stream) TCP/UDP server now handle stream headers with read deadlines 2026-01-09 22:38:29 +08:00
yusing
1c84a9b812 refactor(agent): remove goutils/server dependency and use direct HTTP server setup
- Replaced `goutils/server` helper library with manual HTTP server configuration for agent socketproxy
- Removed entire `agent/pkg/server/server.go` package (43 lines) that wrapped TLS/HTTP server functionality
- Added explicit TCP listener and integrated zerolog with server's error logging
- Cleaned up 17 unused indirect agent dependencies
2026-01-09 22:38:24 +08:00
yusing
35c784375d refactor(homepage): reorganize icons into dedicated package structure
Split the monolithic `internal/homepage` icons functionality into a structured package hierarchy:

- `internal/homepage/icons/` - Core types (URL, Key, Meta, Provider, Source, Variant)
- `internal/homepage/icons/fetch/` - Icon fetching logic (content.go, fetch.go, route.go)
- `internal/homepage/icons/list/` - Icon listing and search (list_icons.go, list_icons_test.go)

Moved icon-related code from `internal/homepage/`:
- `icon_url.go` → `icons/url.go` (+ url_test.go)
- `content.go` → `icons/fetch/content.go`
- `route.go` → `icons/fetch/route.go`
- `list_icons.go` → `icons/list/list_icons.go` (+ list_icons_test.go)

Updated all consumers to use the new package structure:
- `cmd/main.go`
- `internal/api/v1/favicon.go`
- `internal/api/v1/icons.go`
- `internal/idlewatcher/handle_http.go`
- `internal/route/route.go`
2026-01-09 22:37:40 +08:00
yusing
656e470c8e chore(deps): update dependencies 2026-01-09 22:37:33 +08:00
Yuzerion
f950630a19 feat(agent): agent stream tunneling with TLS and dTLS (UDP) (#188)
* **New Features**
  * Multiplexed TLS port: HTTP API and a custom stream protocol can share one port via ALPN.
  * Agent-side TCP and DTLS/UDP stream tunneling with health-check support and runtime capability detection.
  * Agents now advertise per-agent stream support (TCP/UDP).

* **Documentation**
  * Added comprehensive stream protocol documentation.

* **Tests**
  * Extended integration and concurrency tests covering multiplexing, TCP/UDP streams, and health checks.

* **Chores**
  * Compose/template updated to expose both TCP and UDP ports.
2026-01-09 22:36:01 +08:00
yusing
6647ff448e docs: enhance package README documentation 2026-01-09 22:36:01 +08:00
yusing
033e9e4f68 docs: simplify agent/pkg/certs README 2026-01-09 22:36:01 +08:00
yusing
c9ed3ed631 fix(route): allow hostname for stream routes; introduced in 3643add8a3 2026-01-09 22:36:00 +08:00
yusing
78c4fb0990 fix(middleware/redirect): use net.JoinHostPort for setting HTTPS host 2026-01-09 22:36:00 +08:00
yusing
1a20a2cda7 fix(stream): properly handle remote stream scheme IPv4/6 2026-01-09 22:35:59 +08:00
yusing
19d6f3757b fix(monitor): remove unnecssary return type 2026-01-09 22:35:59 +08:00
yusing
7e7e885c57 fix(health/http): potential panic when error is tlsErr 2026-01-09 22:35:58 +08:00
yusing
1ca5fc5ac6 fix(health): remove unnecessary containerId parameter 2026-01-09 22:35:58 +08:00
yusing
fc88d588a0 docs: update README for autocert package to reflect changes in renewal scheduling and primary consumers 2026-01-09 22:35:57 +08:00
yusing
86b655be3c docs: add per package README for implementation details (AI generated with human review) 2026-01-09 22:35:27 +08:00
yusing
2f2828ec48 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-09 22:34:59 +08:00
yusing
a5c74d6773 feat(docs): add health check and monitor packages README; mermaid styling fix 2026-01-09 22:34:33 +08:00
yusing
a6af5779f9 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-09 22:34:16 +08:00
yusing
dbd210b665 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-09 22:34:15 +08:00
yusing
02e6e6f86c refactor: move internal/watcher/health to internal/health 2026-01-09 22:34:15 +08:00
yusing
6d9a193fd5 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-09 22:34:12 +08:00
yusing
5aa58e003d 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-09 22:33:07 +08:00
yusing
19f38a6cfc refactor: remove NoCopy struct; move RefCounter struct to goutils and update usage; remove internal/utils entirely 2026-01-09 22:32:34 +08:00
yusing
f3331515ea fix(docker): add TLS check; correct dial handling and reconnection for custom docker provider; modernize pointer arithemetic with unsafe.Add 2026-01-09 22:32:33 +08:00
yusing
95202fd21d fix(stream): nil panic for excluded routes 2026-01-09 22:32:33 +08:00
yusing
c44636f95a 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-09 22:32:32 +08:00
yusing
17bfc96e3d 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-09 22:32:32 +08:00
yusing
f5dcc85b12 chore: update goutils 2026-01-09 22:32:31 +08:00
yusing
1d1b01efd7 refactor(docker): simplify flow of isLocal check 2026-01-09 22:32:31 +08:00
yusing
90948f7443 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-09 22:32:30 +08:00
yusing
be1f7c7ec4 chore(go.mod): update goquery comment and add description for x/sync package 2026-01-09 22:32:30 +08:00
yusing
91317ff319 feat(autocert): add back inwx provider 2026-01-09 22:32:11 +08:00
yusing
6f14a2907b fix(Makefile): correct test command 2026-01-04 22:02:44 +08:00
yusing
73deb682bd fix(autocert): forceRenewalDoneCh was never closed 2026-01-04 22:02:43 +08:00
yusing
08ce58f031 fix(test): update test expectations 2026-01-04 22:02:43 +08:00
yusing
bf6d7b55f1 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 22:02:42 +08:00
yusing
da8e03258d refactor(state): replace Entrypoint method with ShortLinkMatcher interface
- Cleaned up agent go.mod by removing unused indirect dependencies.
2026-01-04 22:02:42 +08:00
Yuzerion
72e53773b0 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 22:02:41 +08:00
yusing
7e9e0c4511 refactor(docker): accept unix and ssh scheme for providers 2026-01-04 22:02:41 +08:00
yusing
f1d2b170e2 fix(h2c_test_server): correct listening on message 2026-01-04 22:02:40 +08:00
yusing
c026a0df7c refactor(benchmark): restart bench server after each run 2026-01-04 22:02:40 +08:00
yusing
b51d280b29 refactor(io,reverseproxy): suppress "client disconnected" error; optimize CopyClose method 2026-01-04 22:02:40 +08:00
yusing
ea030ebd19 refactor(route): modernize code with unsafe.Add 2026-01-04 22:02:39 +08:00
yusing
64ba519f03 refactor(http/transport): increase MaxIdleConnsPerHost to 1000 2026-01-04 22:02:39 +08:00
yusing
02d0a910f6 refactor(benchmark): replace whoami service with bench server
- Updated dev.compose.yml to define a new bench service that serves 4096 bytes of random data.
- Modified configurations for Traefik, Caddy, and Nginx to route traffic to the new bench service.
- Added Dockerfile and Go application for the bench server, including necessary Go modules.
- Updated benchmark script to target the new bench service endpoint.
2026-01-04 22:02:38 +08:00
yusing
5a2e327cce refactor(http/reverseproxy): performance improvement
- Replaced req.Clone with req.WithContext and url/header/trailer cloning.
- Added conditional handling for "Expect" headers to manage 1xx responses with appropriate tracing.
2026-01-04 22:02:38 +08:00
yusing
4001e94d5c refactor(http): performance improvement
- Introduced a sync.Pool for ResponseRecorder to optimize memory usage.
- Updated ServeHTTP method to utilize the new GetResponseRecorder and PutResponseRecorder functions.
- Adjusted NewResponseRecorder to leverage the pooling mechanism.
2026-01-04 22:02:37 +08:00