Skip to content

Commit

Permalink
forwarder: Use distinct type for proxies map key
Browse files Browse the repository at this point in the history
This allows the go compiler to catch the bug fixed in the previous
commit:
```
GOARCH=amd64 GOOS=freebsd  go build -ldflags "-s -w -X github.com/containers/gvisor-tap-vsock/pkg/types.gitVersion=v0.8.1-5-g9df1d587" -o bin/gvproxy-freebsd-amd64 ./cmd/gvproxy
 # github.com/containers/gvisor-tap-vsock/pkg/services/forwarder
pkg/services/forwarder/ports.go:73:24: cannot use local (variable of type string) as ProxyKey value in map index
make: *** [Makefile:57: cross] Error 1
```

Signed-off-by: Christophe Fergeau <[email protected]>
  • Loading branch information
cfergeau committed Jan 8, 2025
1 parent 8943ed3 commit 8992370
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/services/forwarder/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/stack"
)

type ProxyKey string

type PortsForwarder struct {
stack *stack.Stack

proxiesLock sync.Mutex
proxies map[string]proxy
proxies map[ProxyKey]proxy
}

type proxy struct {
Expand Down Expand Up @@ -61,7 +63,7 @@ func (w CloseWrapper) Close() error {
func NewPortsForwarder(s *stack.Stack) *PortsForwarder {
return &PortsForwarder{
stack: s,
proxies: make(map[string]proxy),
proxies: make(map[ProxyKey]proxy),
}
}

Expand Down Expand Up @@ -256,8 +258,8 @@ func (f *PortsForwarder) Expose(protocol types.TransportProtocol, local, remote
return nil
}

func key(protocol types.TransportProtocol, local string) string {
return fmt.Sprintf("%s/%s", protocol, local)
func key(protocol types.TransportProtocol, local string) ProxyKey {
return ProxyKey(fmt.Sprintf("%s/%s", protocol, local))
}

func (f *PortsForwarder) Unexpose(protocol types.TransportProtocol, local string) error {
Expand Down

0 comments on commit 8992370

Please sign in to comment.