Skip to content

Commit

Permalink
Wireguard dial with context
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhan6665 committed May 22, 2024
1 parent 416f2df commit 9b6141b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion proxy/wireguard/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ func (bind *netBind) Close() error {
type netBindClient struct {
netBind

ctx context.Context
dialer internet.Dialer
reserved []byte
}

func (bind *netBindClient) connectTo(endpoint *netEndpoint) error {
c, err := bind.dialer.Dial(context.Background(), endpoint.dst)
c, err := bind.dialer.Dial(bind.ctx, endpoint.dst)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions proxy/wireguard/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func New(ctx context.Context, conf *DeviceConfig) (*Handler, error) {
}, nil
}

func (h *Handler) processWireGuard(dialer internet.Dialer) (err error) {
func (h *Handler) processWireGuard(ctx context.Context, dialer internet.Dialer) (err error) {
h.wgLock.Lock()
defer h.wgLock.Unlock()

Expand Down Expand Up @@ -108,6 +108,7 @@ func (h *Handler) processWireGuard(dialer internet.Dialer) (err error) {
},
workers: int(h.conf.NumWorkers),
},
ctx: ctx,
dialer: dialer,
reserved: h.conf.Reserved,
}
Expand Down Expand Up @@ -135,7 +136,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
ob.Name = "wireguard"
ob.CanSpliceCopy = 3

if err := h.processWireGuard(dialer); err != nil {
if err := h.processWireGuard(ctx, dialer); err != nil {
return err
}

Expand Down

2 comments on commit 9b6141b

@uuonda
Copy link

@uuonda uuonda commented on 9b6141b May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this fix issues with wireguard and dialerProxy?

@us254
Copy link

@us254 us254 commented on 9b6141b May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems the main purpose is to propagate the context (ctx) to the Dial function and the processWireGuard method. This allows for better control over the lifecycle of the WireGuard connections and provides a way to cancel or timeout the operations if needed

Please sign in to comment.