Skip to content

Commit

Permalink
fix: wireguard server resolve when only a server in peers
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Jun 12, 2024
1 parent 10f8ba4 commit 5678131
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions adapter/outbound/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,16 @@ func (w *WireGuard) init(ctx context.Context) error {
ipcConf := "private_key=" + w.option.PrivateKey
if len(w.option.Peers) > 0 {
for i, peer := range w.option.Peers {
ipcConf += "\npublic_key=" + peer.PublicKey
destination, err := w.resolve(ctx, peer.Addr())
if err != nil {
// !!! do not set initErr here !!!
// let us can retry domain resolve in next time
return E.Cause(err, "resolve endpoint domain for peer ", i)
}
ipcConf += "\npublic_key=" + peer.PublicKey
if len(w.option.Peers) == 1 { // must call SetConnectAddr if isConnect == true
w.bind.SetConnectAddr(destination)
}
ipcConf += "\nendpoint=" + destination.String()
if peer.PreSharedKey != "" {
ipcConf += "\npreshared_key=" + peer.PreSharedKey
Expand All @@ -332,7 +335,7 @@ func (w *WireGuard) init(ctx context.Context) error {
// let us can retry domain resolve in next time
return E.Cause(err, "resolve endpoint domain")
}
w.bind.SetConnectAddr(destination)
w.bind.SetConnectAddr(destination) // must call SetConnectAddr if isConnect == true
ipcConf += "\nendpoint=" + destination.String()
if w.option.PreSharedKey != "" {
ipcConf += "\npreshared_key=" + w.option.PreSharedKey
Expand Down

0 comments on commit 5678131

Please sign in to comment.