Skip to content

Commit eb1e19a

Browse files
authored
Merge pull request fatedier#2906 from fatedier/dev
bump version
2 parents 10f2620 + 6c65858 commit eb1e19a

File tree

16 files changed

+95
-50
lines changed

16 files changed

+95
-50
lines changed

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
builds:
22
- skip: true
33
checksum:
4-
name_template: '{{ .ProjectName }}_{{ .Version }}_sha256_checksums.txt'
4+
name_template: '{{ .ProjectName }}_sha256_checksums.txt'
55
algorithm: sha256
66
extra_files:
77
- glob: ./release/packages/*

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ file:
1616
fmt:
1717
go fmt ./...
1818

19+
vet:
20+
go vet ./...
21+
1922
frps:
2023
env CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/frps ./cmd/frps
2124

@@ -37,7 +40,7 @@ e2e:
3740
e2e-trace:
3841
DEBUG=true LOG_LEVEL=trace ./hack/run-e2e.sh
3942

40-
alltest: gotest e2e
43+
alltest: vet gotest e2e
4144

4245
clean:
4346
rm -f ./bin/frpc

Release.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
### New
22

3-
* Support go http pprof.
3+
* Added new parameter `config_dir` in frpc to run multiple client instances in one process.
44

5-
### Improve
5+
### Fix
66

7-
* Change underlying TCP connection keepalive interval to 2 hours.
8-
* Create new connection to server for `sudp` visitor when needed, to avoid frequent reconnections.
7+
* Equal sign in environment variables causes parsing error.

client/proxy/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
366366
// Listen for clientConn's address and wait for visitor connection
367367
lConn, err := net.ListenUDP("udp", laddr)
368368
if err != nil {
369-
xl.Error("listen on visitorConn's local adress error: %v", err)
369+
xl.Error("listen on visitorConn's local address error: %v", err)
370370
return
371371
}
372372
defer lConn.Close()

client/service.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import (
1919
"crypto/tls"
2020
"fmt"
2121
"io"
22+
"math/rand"
2223
"net"
2324
"runtime"
2425
"strconv"
26+
"strings"
2527
"sync"
2628
"sync/atomic"
2729
"time"
@@ -36,11 +38,17 @@ import (
3638
"github.com/fatedier/frp/pkg/util/util"
3739
"github.com/fatedier/frp/pkg/util/version"
3840
"github.com/fatedier/frp/pkg/util/xlog"
41+
"github.com/fatedier/golib/crypto"
3942
libdial "github.com/fatedier/golib/net/dial"
4043

4144
fmux "github.com/hashicorp/yamux"
4245
)
4346

47+
func init() {
48+
crypto.DefaultSalt = "frp"
49+
rand.Seed(time.Now().UnixNano())
50+
}
51+
4452
// Service is a client service.
4553
type Service struct {
4654
// uniq id got from frps, attach it in loginMsg
@@ -98,6 +106,21 @@ func (svr *Service) GetController() *Control {
98106
func (svr *Service) Run() error {
99107
xl := xlog.FromContextSafe(svr.ctx)
100108

109+
// set custom DNSServer
110+
if svr.cfg.DNSServer != "" {
111+
dnsAddr := svr.cfg.DNSServer
112+
if !strings.Contains(dnsAddr, ":") {
113+
dnsAddr += ":53"
114+
}
115+
// Change default dns server for frpc
116+
net.DefaultResolver = &net.Resolver{
117+
PreferGo: true,
118+
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
119+
return net.Dial("udp", dnsAddr)
120+
},
121+
}
122+
}
123+
101124
// login to frps
102125
for {
103126
conn, session, err := svr.login()
@@ -333,7 +356,14 @@ func (svr *Service) ReloadConf(pxyCfgs map[string]config.ProxyConf, visitorCfgs
333356
svr.visitorCfgs = visitorCfgs
334357
svr.cfgMu.Unlock()
335358

336-
return svr.ctl.ReloadConf(pxyCfgs, visitorCfgs)
359+
svr.ctlMu.RLock()
360+
ctl := svr.ctl
361+
svr.ctlMu.RUnlock()
362+
363+
if ctl != nil {
364+
return svr.ctl.ReloadConf(pxyCfgs, visitorCfgs)
365+
}
366+
return nil
337367
}
338368

339369
func (svr *Service) Close() {
@@ -342,8 +372,12 @@ func (svr *Service) Close() {
342372

343373
func (svr *Service) GracefulClose(d time.Duration) {
344374
atomic.StoreUint32(&svr.exit, 1)
375+
376+
svr.ctlMu.RLock()
345377
if svr.ctl != nil {
346378
svr.ctl.GracefulClose(d)
347379
}
380+
svr.ctlMu.RUnlock()
381+
348382
svr.cancel()
349383
}

cmd/frpc/main.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,10 @@
1515
package main
1616

1717
import (
18-
"math/rand"
19-
"time"
20-
2118
_ "github.com/fatedier/frp/assets/frpc"
2219
"github.com/fatedier/frp/cmd/frpc/sub"
23-
24-
"github.com/fatedier/golib/crypto"
2520
)
2621

2722
func main() {
28-
crypto.DefaultSalt = "frp"
29-
rand.Seed(time.Now().UnixNano())
30-
3123
sub.Execute()
3224
}

cmd/frpc/sub/root.go

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
package sub
1616

1717
import (
18-
"context"
1918
"fmt"
19+
"io/fs"
2020
"net"
2121
"os"
2222
"os/signal"
23+
"path/filepath"
2324
"strconv"
24-
"strings"
25+
"sync"
2526
"syscall"
2627
"time"
2728

@@ -41,6 +42,7 @@ const (
4142

4243
var (
4344
cfgFile string
45+
cfgDir string
4446
showVersion bool
4547

4648
serverAddr string
@@ -72,15 +74,12 @@ var (
7274
bindPort int
7375

7476
tlsEnable bool
75-
76-
kcpDoneCh chan struct{}
7777
)
7878

7979
func init() {
8080
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "./frpc.ini", "config file of frpc")
81+
rootCmd.PersistentFlags().StringVarP(&cfgDir, "config_dir", "", "", "config directory, run one frpc service for each file in config directory")
8182
rootCmd.PersistentFlags().BoolVarP(&showVersion, "version", "v", false, "version of frpc")
82-
83-
kcpDoneCh = make(chan struct{})
8483
}
8584

8685
func RegisterCommonFlags(cmd *cobra.Command) {
@@ -104,6 +103,32 @@ var rootCmd = &cobra.Command{
104103
return nil
105104
}
106105

106+
// If cfgDir is not empty, run multiple frpc service for each config file in cfgDir.
107+
// Note that it's only designed for testing. It's not guaranteed to be stable.
108+
if cfgDir != "" {
109+
var wg sync.WaitGroup
110+
filepath.WalkDir(cfgDir, func(path string, d fs.DirEntry, err error) error {
111+
if err != nil {
112+
return nil
113+
}
114+
if d.IsDir() {
115+
return nil
116+
}
117+
wg.Add(1)
118+
time.Sleep(time.Millisecond)
119+
go func() {
120+
defer wg.Done()
121+
err := runClient(path)
122+
if err != nil {
123+
fmt.Printf("frpc service error for config file [%s]\n", path)
124+
}
125+
}()
126+
return nil
127+
})
128+
wg.Wait()
129+
return nil
130+
}
131+
107132
// Do not show command usage here.
108133
err := runClient(cfgFile)
109134
if err != nil {
@@ -120,12 +145,12 @@ func Execute() {
120145
}
121146
}
122147

123-
func handleSignal(svr *client.Service) {
124-
ch := make(chan os.Signal)
148+
func handleSignal(svr *client.Service, doneCh chan struct{}) {
149+
ch := make(chan os.Signal, 1)
125150
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
126151
<-ch
127152
svr.GracefulClose(500 * time.Millisecond)
128-
close(kcpDoneCh)
153+
close(doneCh)
129154
}
130155

131156
func parseClientCommonCfgFromCmd() (cfg config.ClientCommonConf, err error) {
@@ -182,28 +207,20 @@ func startService(
182207
log.InitLog(cfg.LogWay, cfg.LogFile, cfg.LogLevel,
183208
cfg.LogMaxDays, cfg.DisableLogColor)
184209

185-
if cfg.DNSServer != "" {
186-
s := cfg.DNSServer
187-
if !strings.Contains(s, ":") {
188-
s += ":53"
189-
}
190-
// Change default dns server for frpc
191-
net.DefaultResolver = &net.Resolver{
192-
PreferGo: true,
193-
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
194-
return net.Dial("udp", s)
195-
},
196-
}
210+
if cfgFile != "" {
211+
log.Trace("start frpc service for config file [%s]", cfgFile)
212+
defer log.Trace("frpc service for config file [%s] stopped", cfgFile)
197213
}
198214
svr, errRet := client.NewService(cfg, pxyCfgs, visitorCfgs, cfgFile)
199215
if errRet != nil {
200216
err = errRet
201217
return
202218
}
203219

220+
kcpDoneCh := make(chan struct{})
204221
// Capture the exit signal if we use kcp.
205222
if cfg.Protocol == "kcp" {
206-
go handleSignal(svr)
223+
go handleSignal(svr, kcpDoneCh)
207224
}
208225

209226
err = svr.Run()

conf/frpc_full.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ tls_enable = true
105105
# specify a dns server, so frpc will use this instead of default one
106106
# dns_server = 8.8.8.8
107107

108-
# proxy names you want to start seperated by ','
108+
# proxy names you want to start separated by ','
109109
# default is empty, means all proxies
110110
# start = ssh,dns
111111

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/leodido/go-urn v1.2.1 // indirect
1717
github.com/onsi/ginkgo v1.16.4
1818
github.com/onsi/gomega v1.13.0
19-
github.com/pires/go-proxyproto v0.5.0
19+
github.com/pires/go-proxyproto v0.6.2
2020
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
2121
github.com/prometheus/client_golang v1.11.0
2222
github.com/rodaine/table v1.0.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je4
300300
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
301301
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
302302
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
303-
github.com/pires/go-proxyproto v0.5.0 h1:A4Jv4ZCaV3AFJeGh5mGwkz4iuWUYMlQ7IoO/GTuSuLo=
304-
github.com/pires/go-proxyproto v0.5.0/go.mod h1:Odh9VFOZJCf9G8cLW5o435Xf1J95Jw9Gw5rnCjcwzAY=
303+
github.com/pires/go-proxyproto v0.6.2 h1:KAZ7UteSOt6urjme6ZldyFm4wDe/z0ZUP0Yv0Dos0d8=
304+
github.com/pires/go-proxyproto v0.6.2/go.mod h1:Odh9VFOZJCf9G8cLW5o435Xf1J95Jw9Gw5rnCjcwzAY=
305305
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
306306
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
307307
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

0 commit comments

Comments
 (0)