Skip to content

Commit

Permalink
pkg/wrap: move to btwiuse/wsconn
Browse files Browse the repository at this point in the history
  • Loading branch information
navigaid committed Mar 26, 2024
1 parent 5c31510 commit 0f56c6f
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 272 deletions.
1 change: 0 additions & 1 deletion .mods
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ k0s.io/pkg/simple
k0s.io/pkg/tunnel
k0s.io/pkg/ui
k0s.io/pkg/utils
k0s.io/pkg/wrap
k0s.io/third_party
2 changes: 0 additions & 2 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use (
./pkg/tunnel
./pkg/ui
./pkg/utils
./pkg/wrap
./third_party
)

Expand All @@ -42,6 +41,5 @@ replace (
k0s.io/pkg/tunnel v0.1.15 => ./pkg/tunnel/
k0s.io/pkg/ui v0.1.15 => ./pkg/ui/
k0s.io/pkg/utils v0.1.15 => ./pkg/utils/
k0s.io/pkg/wrap v0.1.15 => ./pkg/wrap/
k0s.io/third_party v0.1.15 => ./third_party/
)
16 changes: 16 additions & 0 deletions go_repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,14 @@ def go_repositories():
sum = "h1:MSMG+C1wR+bgG5xB2TRZK+5yxYiOmGwe44c/3gpaGT0=",
version = "v0.0.36",
)
go_repository(
name = "com_github_btwiuse_wsconn",
build_file_generation = "on",
build_file_proto_mode = "disable",
importpath = "github.com/btwiuse/wsconn",
sum = "h1:rg91k9EygX1K5XErlo6mIkyD0cdtaG7FhdPAUKMBKEc=",
version = "v0.0.0",
)
go_repository(
name = "com_github_buger_jsonparser",
build_file_generation = "on",
Expand Down Expand Up @@ -10081,6 +10089,14 @@ def go_repositories():
sum = "h1:cZhhbV8+DE0Y1kotwhr1a3RC3kFO7AtuZ4GLr3qKSc8=",
version = "v1.0.2",
)
go_repository(
name = "io_k0s_pkg_wrap",
build_file_generation = "on",
build_file_proto_mode = "disable",
importpath = "k0s.io/pkg/wrap",
sum = "h1:n6nfxU+72QfHR1COxNts2xaJa0jv5BMO2prrt9wMgNg=",
version = "v0.1.15",
)
go_repository(
name = "io_k8s_api",
build_file_generation = "on",
Expand Down
4 changes: 2 additions & 2 deletions pkg/dial/dial_gorilla.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/url"

"github.com/gorilla/websocket"
"k0s.io/pkg/wrap"
"github.com/btwiuse/wsconn"
)

func Dial(u *url.URL) (conn net.Conn, err error) {
Expand All @@ -26,5 +26,5 @@ func Dial(u *url.URL) (conn net.Conn, err error) {
return nil, err
}

return wrap.NetConn(wsconn), nil
return wsconn.NetConn(wsconn), nil
}
7 changes: 2 additions & 5 deletions pkg/dial/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ module k0s.io/pkg/dial
go 1.22.1

require (
github.com/btwiuse/wsconn v0.0.0
github.com/gorilla/websocket v1.5.1
k0s.io/pkg/wrap v0.1.15
nhooyr.io/websocket v1.8.10
)

require (
golang.org/x/net v0.21.0 // indirect
k0s.io v0.1.15 // indirect
)
require golang.org/x/net v0.21.0 // indirect
3 changes: 2 additions & 1 deletion pkg/hub/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/btwiuse/sse v0.0.1
github.com/btwiuse/version v0.0.0
github.com/btwiuse/wetty v0.0.36
github.com/btwiuse/wsconn v0.0.0
github.com/gorilla/mux v1.8.1
github.com/jpillora/go-echo-server v0.5.0
k0s.io v0.1.15
Expand All @@ -17,7 +18,6 @@ require (
k0s.io/pkg/middleware v0.1.15
k0s.io/pkg/ui v0.1.15
k0s.io/pkg/utils v0.1.15
k0s.io/pkg/wrap v0.1.15
modernc.org/httpfs v1.0.6
nhooyr.io/websocket v1.8.10
)
Expand Down Expand Up @@ -67,5 +67,6 @@ require (
k0s.io/pkg/asciitransport v0.1.15 // indirect
k0s.io/pkg/dial v0.1.15 // indirect
k0s.io/pkg/distro v0.1.15 // indirect
k0s.io/pkg/wrap v0.1.15 // indirect
k8s.io/apimachinery v0.29.1 // indirect
)
2 changes: 1 addition & 1 deletion pkg/hub/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ go_library(
"//pkg/manager:go_default_library",
"//pkg/middleware:go_default_library",
"//pkg/ui:go_default_library",
"//pkg/wrap:go_default_library",
"@com_github_btwiuse_pretty//:go_default_library",
"@com_github_btwiuse_rng//:go_default_library",
"@com_github_btwiuse_sse//:go_default_library",
"@com_github_btwiuse_wetty//pkg/assets:go_default_library",
"@com_github_btwiuse_wsconn//:go_default_library",
"@com_github_gorilla_mux//:go_default_library",
"@com_github_jpillora_go_echo_server//handler:go_default_library",
"@io_nhooyr_websocket//:go_default_library",
Expand Down
10 changes: 5 additions & 5 deletions pkg/hub/server/relays.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"k0s.io"
"k0s.io/pkg/api"
"k0s.io/pkg/hub"
"k0s.io/pkg/wrap"
"github.com/btwiuse/wsconn"
"nhooyr.io/websocket"
)

Expand Down Expand Up @@ -74,7 +74,7 @@ func fsRelay(ag hub.Agent) http.HandlerFunc {
return
}

conn, err := wrap.Hijack(w)
conn, err := wsconn.Hijack(w)
if err != nil {
log.Println(err)
return
Expand Down Expand Up @@ -106,7 +106,7 @@ func versionRelay(ag hub.Agent) http.HandlerFunc {
return
}

conn, err := wrap.Hijack(w)
conn, err := wsconn.Hijack(w)
if err != nil {
log.Println(err)
return
Expand Down Expand Up @@ -138,7 +138,7 @@ func dohRelay(ag hub.Agent) http.HandlerFunc {
return
}

conn, err := wrap.Hijack(w)
conn, err := wsconn.Hijack(w)
if err != nil {
log.Println(err)
return
Expand Down Expand Up @@ -217,7 +217,7 @@ func envRelay(ag hub.Agent) http.HandlerFunc {
return
}

conn, err := wrap.Hijack(w)
conn, err := wsconn.Hijack(w)
if err != nil {
log.Println(err)
return
Expand Down
8 changes: 4 additions & 4 deletions pkg/hub/server/req2conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net"
"net/http"

"k0s.io/pkg/wrap"
"github.com/btwiuse/wsconn"
)

var (
Expand All @@ -21,7 +21,7 @@ type lys struct {

func (l *lys) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// log.Println(r.Header)
conn, err := wrap.Wrconn(w, r)
conn, err := wsconn.Wrconn(w, r)
if err != nil {
log.Println("error ws accept:", err)
return
Expand All @@ -34,8 +34,8 @@ func (l *lys) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
network := conn.RemoteAddr().Network()
hostport := forwardIP + ":" + forwardPort
addr := wrap.NewAddr(network, hostport)
conn = wrap.ConnWithAddr(conn, addr)
addr := wsconn.NewAddr(network, hostport)
conn = wsconn.ConnWithAddr(conn, addr)
}

l.conns <- conn
Expand Down
4 changes: 2 additions & 2 deletions pkg/hub/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"k0s.io/pkg/log"
"k0s.io/pkg/middleware"
"k0s.io/pkg/ui"
"k0s.io/pkg/wrap"
"github.com/btwiuse/wsconn"
"modernc.org/httpfs"
)

Expand Down Expand Up @@ -259,7 +259,7 @@ func (h *hubServer) handleTunnel(tun api.Tunnel) func(w http.ResponseWriter, r *
return
}

conn, err := wrap.Wrconn(w, r)
conn, err := wsconn.Wrconn(w, r)
if err != nil {
log.Printf("error accepting %s: %s\n", tun, err)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/tunnel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ go_library(
],
importpath = "k0s.io/pkg/tunnel",
visibility = ["//visibility:public"],
deps = ["//pkg/wrap:go_default_library"],
deps = ["@com_github_btwiuse_wsconn//:go_default_library"],
)
2 changes: 1 addition & 1 deletion pkg/tunnel/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module k0s.io/pkg/tunnel
go 1.22.1

require (
github.com/btwiuse/wsconn v0.0.0
k0s.io v0.1.15
k0s.io/pkg/middleware v0.1.15
k0s.io/pkg/wrap v0.1.15
nhooyr.io/websocket v1.8.10
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/tunnel/handler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ go_library(
"//pkg/log:go_default_library",
"//pkg/middleware:go_default_library",
"//pkg/tunnel:go_default_library",
"//pkg/wrap:go_default_library",
"@com_github_btwiuse_wsconn//:go_default_library",
],
)
6 changes: 3 additions & 3 deletions pkg/tunnel/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"k0s.io/pkg/log"
"k0s.io/pkg/middleware"
portless "k0s.io/pkg/tunnel"
"k0s.io/pkg/wrap"
"github.com/btwiuse/wsconn"
)

func Handler(prefix string) http.Handler {
Expand Down Expand Up @@ -97,7 +97,7 @@ func setupTunnel(next http.Handler) http.Handler {
pattern := r.URL.Path
from := r.URL.Query().Get("from")
switch _, ok := defaultTunnelMux.Tunnels[fp]; {
// passthrough regular request to wrapped handler
// passthrough regular request to wsconnped handler
case fp == "":
next.ServeHTTP(w, r)
// new stream identifier, create new tunnel
Expand Down Expand Up @@ -205,7 +205,7 @@ func (mux *tunnelMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

connDst, err := wrap.Wrconn(w, r)
connDst, err := wsconn.Wrconn(w, r)
if err != nil {
log.Println(err)
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"sync"

"k0s.io/pkg/wrap"
"github.com/btwiuse/wsconn"
)

func NewTunnel() *Tunnel {
Expand Down Expand Up @@ -59,7 +59,7 @@ func (t *Tunnel) String() string {
var _ http.Handler = (*Tunnel)(nil)

func (t *Tunnel) ServeHTTP(w http.ResponseWriter, r *http.Request) {
conn, err := wrap.Wrconn(w, r)
conn, err := wsconn.Wrconn(w, r)
if err != nil {
log.Println(err)
return
Expand Down
18 changes: 0 additions & 18 deletions pkg/wrap/BUILD.bazel

This file was deleted.

30 changes: 0 additions & 30 deletions pkg/wrap/connaddr.go

This file was deleted.

11 changes: 0 additions & 11 deletions pkg/wrap/go.mod

This file was deleted.

27 changes: 0 additions & 27 deletions pkg/wrap/hijack.go

This file was deleted.

0 comments on commit 0f56c6f

Please sign in to comment.