Compare commits

...

1 Commits

Author SHA1 Message Date
eball
f53c09e34a fix: update dependencies and improve WebSocket handling in proxy server 2025-10-22 14:59:03 +08:00
4 changed files with 88 additions and 7 deletions

View File

@@ -8,11 +8,13 @@ replace (
bytetrade.io/web3os/app-service => github.com/beclab/app-service v0.4.23
bytetrade.io/web3os/backups-sdk => github.com/Above-Os/backups-sdk v0.1.17
bytetrade.io/web3os/bfl => github.com/beclab/bfl v0.3.36
github.com/labstack/echo/v4 => github.com/eball/echo/v4 v4.13.4-patch
k8s.io/api => k8s.io/api v0.34.0
k8s.io/apimachinery => k8s.io/apimachinery v0.34.0
k8s.io/client-go => k8s.io/client-go v0.34.0
kubesphere.io/api => ../../kubesphere-ext/staging/src/kubesphere.io/api/
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.19.6
)
require (
@@ -32,7 +34,7 @@ require (
github.com/jochenvg/go-udev v0.0.0-20171110120927-d6b62d56d37b
github.com/joho/godotenv v1.5.1
github.com/klauspost/cpuid/v2 v2.2.8
github.com/labstack/echo/v4 v4.13.4
github.com/labstack/echo/v4 v4.0.0-00010101000000-000000000000
github.com/libp2p/go-netroute v0.2.2
github.com/mackerelio/go-osstat v0.2.5
github.com/muka/network_manager v0.0.0-20200903202308-ae5ede816e07

View File

@@ -83,6 +83,8 @@ github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/eball/echo/v4 v4.13.4-patch h1:5w83KQrEqrxhc1BO0BpRBHssC37vFrWualUM27Rt2sg=
github.com/eball/echo/v4 v4.13.4-patch/go.mod h1:ORgy8LWTq8knpwgaz538rAJMri7WgpoAD6H3zYccn84=
github.com/eball/zeroconf v0.2.1 h1:PZ89f6J2k2Z7q3oSzcZGFXJf97S7NPmj7H04ACw9v8c=
github.com/eball/zeroconf v0.2.1/go.mod h1:eIbIjGYo9sSMaKWLcveHEPRWdyblz7q9ih2R1HnNw5M=
github.com/ebitengine/purego v0.8.4 h1:CF7LEKg5FFOsASUj0+QwaXf8Ht6TlFxg09+S9wz0omw=
@@ -210,8 +212,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA=
github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/libp2p/go-netroute v0.2.2 h1:Dejd8cQ47Qx2kRABg6lPwknU7+nBnFRpko45/fFPuZ8=

View File

@@ -1,6 +1,8 @@
package handlers
import (
"net/http"
"github.com/beclab/Olares/cli/pkg/web5/jws"
"github.com/gofiber/fiber/v2"
"k8s.io/klog/v2"
@@ -18,7 +20,8 @@ func (h *Handlers) ResolveOlaresName(c *fiber.Ctx) error {
klog.Errorf("Failed to resolve DID for %s: %v", olaresName, err)
return h.ErrJSON(c, fiber.StatusInternalServerError, "Failed to resolve DID")
}
return h.OkJSON(c, "success", result)
// return DID protocol resolution result
return c.Status(http.StatusOK).JSON(result)
}
func (h *Handlers) CheckJWS(c *fiber.Ctx) error {

View File

@@ -3,6 +3,7 @@ package intranet
import (
"context"
"crypto/tls"
"fmt"
"net"
"net/http"
"net/url"
@@ -16,6 +17,10 @@ import (
var _ middleware.ProxyBalancer = (*proxyServer)(nil)
type key struct{}
var WSKey = key{}
type proxyServer struct {
proxy *echo.Echo
dnsServer string
@@ -53,6 +58,12 @@ func (p *proxyServer) Start() error {
func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if strings.HasSuffix(c.Request().Host, ".olares.local") {
if c.IsWebSocket() {
ctx := c.Request().Context()
ctx = context.WithValue(ctx, WSKey, true)
r := c.Request().WithContext(ctx)
c.SetRequest(r)
}
return next(c)
}
@@ -126,11 +137,76 @@ func (p *proxyServer) customDialContext(d *net.Dialer) func(ctx context.Context,
return func(ctx context.Context, network, addr string) (net.Conn, error) {
_, port, _ := net.SplitHostPort(addr)
// Force proxying to localhost
klog.Info("addr: ", addr, "port: ", port)
klog.Info("addr: ", addr, " port: ", port, " network: ", network)
if port == "" {
port = "443"
}
addr = net.JoinHostPort("127.0.0.1", port)
return d.DialContext(ctx, network, addr)
newAddr := net.JoinHostPort("127.0.0.1", port)
isWs := false
if v := ctx.Value(WSKey); v != nil {
isWs = v.(bool)
}
if isWs {
klog.Info("WebSocket connection detected, using upgraded dialer")
return tlsDial(ctx, d, func(ctx context.Context, network, addr string) (net.Conn, error) {
return d.DialContext(ctx, network, newAddr)
}, network, addr, &tls.Config{InsecureSkipVerify: true})
}
return d.DialContext(ctx, network, newAddr)
}
}
func tlsDial(ctx context.Context, netDialer *net.Dialer, dialFunc func(ctx context.Context, network, addr string) (net.Conn, error), network, addr string, config *tls.Config) (*tls.Conn, error) {
if netDialer.Timeout != 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, netDialer.Timeout)
defer cancel()
}
if !netDialer.Deadline.IsZero() {
var cancel context.CancelFunc
ctx, cancel = context.WithDeadline(ctx, netDialer.Deadline)
defer cancel()
}
var (
rawConn net.Conn
err error
)
if dialFunc != nil {
rawConn, err = dialFunc(ctx, network, addr)
} else {
rawConn, err = netDialer.DialContext(ctx, network, addr)
}
if err != nil {
return nil, err
}
colonPos := strings.LastIndex(addr, ":")
if colonPos == -1 {
colonPos = len(addr)
}
hostname := addr[:colonPos]
if config == nil {
return nil, fmt.Errorf("tls: config is nil")
}
// If no ServerName is set, infer the ServerName
// from the hostname we're connecting to.
if config.ServerName == "" {
// Make a copy to avoid polluting argument or default.
c := config.Clone()
c.ServerName = hostname
config = c
}
conn := tls.Client(rawConn, config)
if err := conn.HandshakeContext(ctx); err != nil {
rawConn.Close()
return nil, err
}
return conn, nil
}