diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a191b74..36510dd 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -14,7 +14,8 @@ before: - go mod tidy builds: - - env: + - id: release + env: - CGO_ENABLED=0 ldflags: - -s -w -X github.com/BaiMeow/wg-quick-op/cmd.version={{.Version}} @@ -28,8 +29,28 @@ builds: - mips - mips64 + - id: debug + env: + - CGO_ENABLED=0 + - GORELEASER_CURRENT_TAG=debug + ldflags: + - -X github.com/BaiMeow/wg-quick-op/cmd.version={{.Version}}-debug + goos: + - linux + goarch: + - amd64 + - "386" + - arm + - arm64 + - mips + - mips64 + archives: - - format: tar.gz + - id: release-archive + format: tar.gz + files: + - none* + builds: ["release"] # this name template makes the OS and Arch compatible with the results of `uname`. name_template: >- {{ .ProjectName }}_ @@ -43,6 +64,26 @@ archives: - goos: windows format: zip + + - id: debug-archive + format: tar.gz + files: + - none* + builds: ["debug"] + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }}_ + debug + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + changelog: sort: asc filters: @@ -57,7 +98,7 @@ upx: enabled: true # Filter by build ID. - ids: [build1, build2] + ids: [release] # Compress argument. # Valid options are from '1' (faster) to '9' (better), and 'best'. diff --git a/cmd/version.go b/cmd/version.go index d8bd2b7..adc13af 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -var version = "dev" +var version = "-dev" // versionCmd represents the version command var versionCmd = &cobra.Command{ diff --git a/daemon/service.go b/daemon/service.go index a250b0e..4a6ab87 100644 --- a/daemon/service.go +++ b/daemon/service.go @@ -50,7 +50,7 @@ func Serve() { for _, iface := range cfgs { peers, err := quick.PeerStatus(iface.name) if err != nil { - logrus.WithError(err).WithField("iface", iface).Error("failed to get device") + logrus.WithError(err).WithField("iface", iface.name).Error("failed to get device") continue } @@ -61,8 +61,8 @@ func Serve() { logrus.WithField("iface", iface.name).WithField("peer", peer.PublicKey).Debugln("peer endpoint is nil, skip it") continue } - status := peers[peer.PublicKey] - if time.Now().Sub(status.LastHandshakeTime) < conf.DDNS.MaxLastHandleShake { + if time.Now().Sub(peer.LastHandshakeTime) < conf.DDNS.MaxLastHandleShake { + logrus.WithField("iface", iface.name).WithField("peer", peer.PublicKey).Debugln("peer ok") continue } logrus.WithField("iface", iface.name).WithField("peer", peer.PublicKey).Debugln("peer handshake timeout, re-resolve endpoint") @@ -75,8 +75,9 @@ func Serve() { logrus.WithField("iface", iface).WithField("peer", peer.PublicKey).WithError(err).Error("failed to resolve endpoint") continue } + for i, v := range iface.cfg.Peers { - if v.PublicKey == peer.PublicKey && addr.AddrPort() != peer.Endpoint.AddrPort() { + if v.PublicKey == peer.PublicKey && !peer.Endpoint.IP.Equal(addr.IP) { iface.cfg.Peers[i].Endpoint = addr sync = true break @@ -85,18 +86,18 @@ func Serve() { } if !sync { - logrus.WithField("iface", iface).Infoln("same addr, skip") + logrus.WithField("iface", iface.name).Debugln("same addr, skip") continue } link, err := netlink.LinkByName(iface.name) if err != nil { - logrus.WithField("iface", iface).WithError(err).Error("get link failed") + logrus.WithField("iface", iface.name).WithError(err).Error("get link failed") continue } - if err := quick.SyncWireguardDevice(iface.cfg, link, logrus.WithField("iface", iface)); err != nil { - logrus.WithField("iface", iface).WithError(err).Error("sync device failed") + if err := quick.SyncWireguardDevice(iface.cfg, link, logrus.WithField("iface", iface.name)); err != nil { + logrus.WithField("iface", iface.name).WithError(err).Error("sync device failed") continue } diff --git a/debug.go b/debug.go new file mode 100644 index 0000000..64033e2 --- /dev/null +++ b/debug.go @@ -0,0 +1,12 @@ +//go:build debug + +package main + +import ( + "net/http" + _ "net/http/pprof" +) + +func init() { + go http.ListenAndServe(":46789", nil) +} diff --git a/go.mod b/go.mod index 360c646..ec7cafc 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/BaiMeow/wg-quick-op -go 1.19 +go 1.21 require ( github.com/sirupsen/logrus v1.9.3