Skip to content

Commit

Permalink
Merge pull request #515 from djs55/fix-build
Browse files Browse the repository at this point in the history
go: use narrower UDPListener interface
  • Loading branch information
djs55 authored Jan 23, 2021
2 parents a5fc5f6 + 5731659 commit 9443069
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion go/pkg/vpnkit/forward/udp_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func listenUDP(port vpnkit.Port) (libproxy.UDPListener, error) {

type wrappedCloser struct {
port vpnkit.Port
l *net.UDPConn
l libproxy.UDPListener
}

func (w *wrappedCloser) ReadFromUDP(b []byte) (int, *net.UDPAddr, error) {
Expand All @@ -41,3 +41,7 @@ func (w *wrappedCloser) WriteToUDP(b []byte, addr *net.UDPAddr) (int, error) {
func (w *wrappedCloser) Close() error {
return closeUDPVmnet(w.port.OutIP, w.port.OutPort, w.l)
}

func (w *wrappedCloser) LocalAddr() net.Addr {
return w.l.LocalAddr()
}
4 changes: 2 additions & 2 deletions go/pkg/vpnkit/forward/vmnet_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ func listenUDPVmnet(IP net.IP, Port uint16) (libproxy.UDPListener, error) {
}

type vmnetdUdpWrapper struct {
*net.UDPConn
libproxy.UDPListener
localAddr *net.UDPAddr
}

func (w vmnetdUdpWrapper) LocalAddr() net.Addr {
return w.localAddr
}

func closeUDPVmnet(IP net.IP, Port uint16, l *net.UDPConn) error {
func closeUDPVmnet(IP net.IP, Port uint16, l libproxy.UDPListener) error {
errCh := make(chan error)
go func() {
errCh <- l.Close()
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/vpnkit/forward/vmnet_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestBindUDPVmnetd(t *testing.T) {
t.FailNow()
}()
result := make([]byte, 1024)
n, err := f.Read(result)
n, _, err := f.ReadFromUDP(result)
assert.Nil(t, err)
assert.Equal(t, string(hello), string(result[0:n]))
done <- struct{}{}
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestBindUDPVmnetdClose(t *testing.T) {
assert.Nil(t, err)
go func() {
buf := make([]byte, 1024)
_, err := f.Read(buf)
_, _, err := f.ReadFromUDP(buf)
assert.Nil(t, err)
}()
time.Sleep(10 * time.Millisecond)
Expand Down

0 comments on commit 9443069

Please sign in to comment.