Skip to content

Commit

Permalink
code review comment RD3
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Dec 10, 2024
1 parent bf93a3a commit 933d693
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 54 deletions.
5 changes: 1 addition & 4 deletions client/go/outline/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,13 @@ type NewClientResult struct {

// NewClient creates a new Outline client from a configuration string.
func NewClient(transportConfig string) *NewClientResult {
client, err := newClientWithBaseDialers(transportConfig, defaultBaseTCPDialer(), defaultBaseUDPDialer())
client, err := newClientWithBaseDialers(transportConfig, net.Dialer{KeepAlive: -1}, net.Dialer{})
return &NewClientResult{
Client: client,
Error: platerrors.ToPlatformError(err),
}
}

func defaultBaseTCPDialer() net.Dialer { return net.Dialer{KeepAlive: -1} }
func defaultBaseUDPDialer() net.Dialer { return net.Dialer{} }

func newClientWithBaseDialers(transportConfig string, tcpDialer, udpDialer net.Dialer) (*Client, error) {
conf, err := parseConfigFromJSON(transportConfig)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 The Outline Authors
// Copyright 2023 The Outline Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,25 +14,27 @@

package outline

import "syscall"

func createWithOpts(transport string, opts *DeviceOptions) (_ *Device, err error) {
d := &Device{}
import (
"net"
"syscall"
)

// NewClient creates a new Outline client from a configuration string.
func NewClientWithFWMark(transportConfig string, fwmark uint32) (*Client, error) {
control := func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, int(opts.LinuxOpts.FWMark))
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, int(fwmark))
})
}

tcp := defaultBaseTCPDialer()
tcp.Control = control

udp := defaultBaseUDPDialer()
udp.Control = control
tcp := net.Dialer{
Control: control,
KeepAlive: -1,
}

if d.c, err = newClientWithBaseDialers(transport, tcp, udp); err != nil {
return nil, err
udp := net.Dialer{
Control: control,
}
return d, nil

return newClientWithBaseDialers(transportConfig, tcp, udp)
}
10 changes: 3 additions & 7 deletions client/go/outline/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@ type DeviceOptions struct {
LinuxOpts *LinuxOptions
}

func NewDevice(transportConfig string, opts *DeviceOptions) (*Device, error) {
if opts == nil || opts.LinuxOpts == nil {
return nil, perrs.PlatformError{
Code: perrs.InternalError,
Message: "must provide at least one platform specific Option",
}
func NewDevice(c *Client) *Device {
return &Device{
c: c,
}
return createWithOpts(transportConfig, opts)
}

func (d *Device) Connect() (err error) {
Expand Down
23 changes: 0 additions & 23 deletions client/go/outline/device_others.go

This file was deleted.

9 changes: 3 additions & 6 deletions client/go/outline/vpn/vpn_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,11 @@ func newVPNConnection(conf *configJSON) (_ *linuxVPNConn, err error) {
return nil, errIllegalConfig("must provide a transport config")
}

c.proxy, err = outline.NewDevice(conf.TransportConfig, &outline.DeviceOptions{
LinuxOpts: &outline.LinuxOptions{
FWMark: c.nmOpts.FWMark,
},
})
oc, err := outline.NewClientWithFWMark(conf.TransportConfig, c.nmOpts.FWMark)
if err != nil {
return
return nil, err
}
c.proxy = outline.NewDevice(oc)

c.ctx, c.cancel = context.WithCancel(context.Background())
return c, nil
Expand Down

0 comments on commit 933d693

Please sign in to comment.