Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/hanwen/go-fuse/v2 v2.10.1
github.com/miekg/dns v1.1.72
github.com/prometheus/client_golang v1.23.2
github.com/puzpuzpuz/xsync/v3 v3.5.1
github.com/puzpuzpuz/xsync/v4 v4.5.0
github.com/segmentio/ksuid v1.0.4
github.com/stretchr/testify v1.11.1
github.com/testcontainers/testcontainers-go v0.40.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ github.com/prometheus/otlptranslator v1.0.0 h1:s0LJW/iN9dkIH+EnhiD3BlkkP5QVIUVEo
github.com/prometheus/otlptranslator v1.0.0/go.mod h1:vRYWnXvI6aWGpsdY/mOT/cbeVRBlPWtBNDb7kGR3uKM=
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
github.com/puzpuzpuz/xsync/v3 v3.5.1 h1:GJYJZwO6IdxN/IKbneznS6yPkVC+c3zyY/j19c++5Fg=
github.com/puzpuzpuz/xsync/v3 v3.5.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
github.com/puzpuzpuz/xsync/v4 v4.5.0 h1:vOSWu6b57/emh+L/Cw0BeQfvxa/cogFywXHeGUxQxAg=
github.com/puzpuzpuz/xsync/v4 v4.5.0/go.mod h1:VJDmTCJMBt8igNxnkQd86r+8KUeN1quSfNKu5bLYFQo=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rodaine/protogofakeit v0.1.1 h1:ZKouljuRM3A+TArppfBqnH8tGZHOwM/pjvtXe9DaXH8=
Expand Down
9 changes: 5 additions & 4 deletions pkg/conntrack/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/vercel/bridge/pkg/ippool"

"github.com/puzpuzpuz/xsync/v3"
"github.com/puzpuzpuz/xsync/v4"
)

const (
Expand All @@ -32,7 +32,7 @@ type Entry struct {
// Registry tracks mappings between allocated proxy IPs and their real destinations.
type Registry struct {
pool *ippool.Pool
entries *xsync.MapOf[string, *Entry] // keyed by proxy IP string
entries *xsync.Map[string, *Entry] // keyed by proxy IP string
stopCh chan struct{}
stopOnce sync.Once
}
Expand All @@ -42,7 +42,7 @@ type Registry struct {
func New(pool *ippool.Pool) *Registry {
r := &Registry{
pool: pool,
entries: xsync.NewMapOf[string, *Entry](),
entries: xsync.NewMap[string, *Entry](),
stopCh: make(chan struct{}),
}
go r.cleanupLoop()
Expand Down Expand Up @@ -139,7 +139,8 @@ func (r *Registry) cleanupUnused() {

// Release stale entries
for _, ip := range toRelease {
slog.Debug("Releasing unused DNS allocation",
slog.Debug(
"Releasing unused DNS allocation",
"proxy_ip", ip,
"reason", "timeout without connection",
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/ippool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"net"
"sync/atomic"

"github.com/puzpuzpuz/xsync/v3"
"github.com/puzpuzpuz/xsync/v4"
)

// Pool manages a pool of IP addresses from a CIDR block.
type Pool struct {
network *net.IPNet
baseIP uint32
size uint32
allocated *xsync.MapOf[uint32, bool]
allocated *xsync.Map[uint32, bool]
nextIndex atomic.Uint32
}

Expand All @@ -39,7 +39,7 @@ func New(cidr string) (*Pool, error) {
network: network,
baseIP: baseIP,
size: size,
allocated: xsync.NewMapOf[uint32, bool](),
allocated: xsync.NewMap[uint32, bool](),
}
p.nextIndex.Store(1) // Start from 1 to skip the network address

Expand Down
6 changes: 3 additions & 3 deletions pkg/k8s/k8spf/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package k8spf
import (
"fmt"

"github.com/puzpuzpuz/xsync/v3"
"github.com/puzpuzpuz/xsync/v4"
"github.com/vercel/bridge/pkg/k8s/portforward"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand All @@ -12,12 +12,12 @@ import (
// dialerPool caches SPDY portforward.Dialer instances by target key so
// multiple gRPC streams to the same pod share one SPDY connection.
type dialerPool struct {
dialers *xsync.MapOf[string, *portforward.Dialer] // key: "pod.namespace:port"
dialers *xsync.Map[string, *portforward.Dialer] // key: "pod.namespace:port"
}

func newDialerPool() *dialerPool {
return &dialerPool{
dialers: xsync.NewMapOf[string, *portforward.Dialer](),
dialers: xsync.NewMap[string, *portforward.Dialer](),
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
"sync"

"github.com/puzpuzpuz/xsync/v3"
"github.com/puzpuzpuz/xsync/v4"
bridgev1 "github.com/vercel/bridge/api/go/bridge/v1"
"github.com/vercel/bridge/pkg/mitm"
"github.com/vercel/bridge/pkg/plumbing"
Expand Down Expand Up @@ -53,7 +53,7 @@ func New(dialer plumbing.ContextDialer, stream Stream, opts ...Option) Tunnel {
dialer: dialer,
stream: stream,
sendCh: make(chan *bridgev1.TunnelNetworkMessage, 64),
conns: xsync.NewMapOf[string, net.Conn](),
conns: xsync.NewMap[string, net.Conn](),
done: make(chan struct{}),
}
for _, o := range opts {
Expand All @@ -67,7 +67,7 @@ type tunnelImpl struct {
hijacker mitm.Hijacker
stream Stream
sendCh chan *bridgev1.TunnelNetworkMessage
conns *xsync.MapOf[string, net.Conn]
conns *xsync.Map[string, net.Conn]
done chan struct{}
ctx context.Context
cancel context.CancelFunc
Expand Down