Skip to content

Commit

Permalink
feat: debug build and chore
Browse files Browse the repository at this point in the history
  • Loading branch information
BaiMeow committed Dec 12, 2023
1 parent da2dac7 commit fb533cb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
47 changes: 44 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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
format: tar.gz
files:
- none*
builds: ["release"]
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
Expand All @@ -43,6 +64,26 @@ archives:
- goos: windows
format: zip


- id: debug
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:
Expand All @@ -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'.
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)

var version = "dev"
var version = "-dev"

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Expand Down
17 changes: 9 additions & 8 deletions daemon/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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
}

Expand Down
12 changes: 12 additions & 0 deletions debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build debug

package main

import (
"net/http"
_ "net/http/pprof"
)

func init() {
go http.ListenAndServe(":46789", nil)
}

0 comments on commit fb533cb

Please sign in to comment.