Compare commits

...

5 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
96a4338b15 Revert server.go changes - issue is client-side only
The multi-peer issue (#4507) only affects the WireGuard client (outbound).
The server uses a different code path that doesn't have this problem.
Keeping changes focused on the client-side fix only.

Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
2026-01-17 10:04:28 +00:00
copilot-swe-agent[bot]
f2d5e3357d Minimize code changes: keep existing structure, only change data flow direction
Changed from pull-based (ReceiveFunc sends request, goroutine fills) to
push-based (goroutine reads and pushes, ReceiveFunc receives) while
keeping the same channel and data structures.

The core fix: each endpoint's goroutine now owns reading from its own
connection and pushes data with correct endpoint identity, instead of
competing for shared read requests.

Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
2026-01-17 09:49:35 +00:00
copilot-swe-agent[bot]
5bb55adccd Address code review feedback: add buffer pool for memory efficiency
Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
2026-01-16 16:21:47 +00:00
copilot-swe-agent[bot]
e3606dea4c Fix WireGuard multi-peer issue by changing to push-based architecture
In the original implementation, all peer connections shared a single
readQueue channel where ReceiveFunc workers would request buffers.
This caused responses from different peers to be incorrectly associated
with the wrong endpoint when multiple peers were active.

The fix changes to a push-based architecture where:
- Each endpoint's read goroutine pushes responses directly to a shared
  responseRecv channel along with the correct endpoint identity
- The ReceiveFunc workers simply receive from this channel
- This ensures each response is correctly associated with its source endpoint

Fixes issue #4507: multi wg peers outbound only one established

Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
2026-01-16 16:19:38 +00:00
copilot-swe-agent[bot]
055dea63f8 Initial plan 2026-01-16 16:09:46 +00:00

View File

@@ -89,13 +89,14 @@ func (bind *netBind) Open(uport uint16) ([]conn.ReceiveFunc, uint16, error) {
}
}()
r := &netReadInfo{
buff: bufs[0],
r, ok := <-bind.readQueue
if !ok {
return 0, errors.New("channel closed")
}
r.waiter.Add(1)
bind.readQueue <- r
r.waiter.Wait() // wait read goroutine done, or we will miss the result
copy(bufs[0], r.buff[:r.bytes])
sizes[0], eps[0] = r.bytes, r.endpoint
r.waiter.Done()
return 1, r.err
}
workers := bind.workers
@@ -133,24 +134,29 @@ func (bind *netBindClient) connectTo(endpoint *netEndpoint) error {
}
endpoint.conn = c
go func(readQueue <-chan *netReadInfo, endpoint *netEndpoint) {
go func(readQueue chan<- *netReadInfo, endpoint *netEndpoint) {
defer func() {
_ = recover() // handle send on closed channel
}()
for {
v, ok := <-readQueue
if !ok {
return
}
i, err := c.Read(v.buff)
buff := make([]byte, 1700)
i, err := c.Read(buff)
if i > 3 {
v.buff[1] = 0
v.buff[2] = 0
v.buff[3] = 0
buff[1] = 0
buff[2] = 0
buff[3] = 0
}
v.bytes = i
v.endpoint = endpoint
v.err = err
v.waiter.Done()
r := &netReadInfo{
buff: buff,
bytes: i,
endpoint: endpoint,
err: err,
}
r.waiter.Add(1)
readQueue <- r
r.waiter.Wait()
if err != nil {
endpoint.conn = nil
return