Skip to content

Commit

Permalink
Unix socket support
Browse files Browse the repository at this point in the history
The new Brave BAT payments service uses viproxy to expose the service in
the nitro enclave. For local testing outside AWS we plan to simulate
Nitro by using a container that does not have an IP network but rather
uses Unix sockets to communicate to the outside world. To cover that add
support for directing the traffic into a unix socket.

For symmetry also allow to listen on UNIX sockets.

Report an explicit error when net.Addr is unsupported.
  • Loading branch information
ibukanov committed Sep 17, 2024
1 parent 39b3d0a commit cdb323b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions viproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package viproxy

import (
"fmt"
"io"
"log"
"net"
Expand Down Expand Up @@ -56,6 +57,10 @@ func dial(addr net.Addr) (net.Conn, error) {
conn, err = vsock.Dial(a.ContextID, a.Port, nil)
case *net.TCPAddr:
conn, err = net.DialTCP("tcp", nil, a)
case *net.UnixAddr:
conn, err = net.DialUnix(addr.Network(), nil, a)
default:
return nil, fmt.Errorf("unsupported address type %T", addr)
}
if err != nil {
return nil, err
Expand All @@ -73,6 +78,10 @@ func listen(addr net.Addr) (net.Listener, error) {
ln, err = vsock.ListenContextID(a.ContextID, a.Port, nil)
case *net.TCPAddr:
ln, err = net.ListenTCP(a.Network(), a)
case *net.UnixAddr:
ln, err = net.ListenUnix(addr.Network(), a)
default:
return nil, fmt.Errorf("unsupported address type %T", addr)
}
if err != nil {
return nil, err
Expand Down

0 comments on commit cdb323b

Please sign in to comment.