Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mingcheng committed Apr 27, 2023
2 parents 064f519 + 4e0f632 commit 638f20d
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ Thumbs.db
.DS*
/.idea
/socks5lb
/*.exe
/.task
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ GO_FLAGS=-ldflags="\
-X 'github.com/mingcheng/socks5lb.BuildCommit=$(COMMIT_HASH)' \
-X 'github.com/mingcheng/socks5lb.BuildDate=$(shell date)'"



# Make is verbose in Linux. Make it silent.
MAKEFLAGS += --silent

Expand Down
45 changes: 45 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: '3'

vars:
BINARY_NAME: socks.5lb{{exeExt}}
PACKAGE_NAME: github.com/mingcheng/socks5lb

tasks:
default:
deps:
- test
- build

build:
deps:
- clean
sources:
- ./cmd/socks5lb/*.go
- ./*.go
generates:
- '{{.BINARY_NAME}}'
cmds:
- >
go build -o {{.BINARY_NAME}} -ldflags="
-X '{{.PACKAGE_NAME}}.BuildCommit={{.GIT_COMMIT}}'
-X '{{.PACKAGE_NAME}}.BuildDate={{now}}'
-X '{{.PACKAGE_NAME}}.Version={{now | date "2006-01-02"}}'"
./cmd/socks5lb
vars:
GIT_COMMIT:
sh: git rev-parse --short HEAD
# silent: true

test:
deps:
- clean
cmds:
- go test -v ./...

clean:
aliases:
- cleanup
- clear
cmds:
- go clean ./...
silent: true
5 changes: 2 additions & 3 deletions cmd/socks5lb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package main

import (
"flag"
"io/ioutil"
"syscall"

"github.com/judwhite/go-svc"
Expand All @@ -35,7 +34,7 @@ func init() {

if socks5lb.DebugMode {
log.SetLevel(log.TraceLevel)
log.Debug("debug mode is On, its makess more noise on terminal")
log.Debug("debug mode is enabled, it will print more logs.")
}

flag.StringVar(&cfgPath, "c", "/etc/"+socks5lb.AppName+".yml", "configure file cfgPath")
Expand All @@ -47,7 +46,7 @@ func NewConfig(path string) (config *socks5lb.Configure, err error) {
data []byte
)

if data, err = ioutil.ReadFile(path); err != nil {
if data, err = os.ReadFile(path); err != nil {
return
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/socks5lb/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type program struct {
}

// Init to initial the program
func (p *program) Init(env svc.Environment) (err error) {
func (p *program) Init(svc.Environment) (err error) {

log.Tracef("new initial backend pools")
pool := socks5lb.NewPool()
Expand Down Expand Up @@ -53,7 +53,7 @@ func (p *program) Start() (err error) {
return
}

// Stop when the program is stop
// Stop when the program is stopped
func (p *program) Stop() (err error) {
log.Infof("stop the program")
return p.Server.Stop()
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/mingcheng/socks5lb

go 1.18
go 1.20

require (
github.com/LiamHaworth/go-tproxy v0.0.0-20190726054950-ef7efd7f24ed
Expand All @@ -10,7 +10,7 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.1
github.com/txthinking/socks5 v0.0.0-20220615051428-39268faee3e6
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9
golang.org/x/net v0.5.0
gopkg.in/yaml.v3 v3.0.0
)

Expand All @@ -32,9 +32,9 @@ require (
github.com/txthinking/runnergroup v0.0.0-20210608031112-152c7c4432bf // indirect
github.com/txthinking/x v0.0.0-20210326105829-476fab902fbe // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
21 changes: 14 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,31 @@ github.com/txthinking/x v0.0.0-20210326105829-476fab902fbe/go.mod h1:WgqbSEmUYSj
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 h1:Yqz/iviulwKwAREEeUd3nbBFn0XuyJqkoft2IlrvOhc=
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
3 changes: 2 additions & 1 deletion redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package socks5lb
import "fmt"

// ListenTProxy is not implemented by default
// Deprecated: this function is not implemented in next version
func (s *Server) ListenTProxy(_ string) error {
return fmt.Errorf("sorry transparent proxy is ONLY supports Linux platform")
return fmt.Errorf("sorry this feature is not implemented on this platform")
}
1 change: 1 addition & 0 deletions redirect_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (s *Server) updateSocks5Client() (client *socks5.Client, err error) {
}

// ListenTProxy is listening the local tcp port on the given address
// Deprecated: this feature will be disabled in the future
func (s *Server) ListenTProxy(addr string) (err error) {
tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ func (s *Server) Start() (err error) {
}
}()

if s.Config.TProxy.Addr != "" {
log.Tracef("start linux transparent proxy on %s", s.Config.TProxy.Addr)
go func() {
if err = s.ListenTProxy(s.Config.TProxy.Addr); err != nil {
log.Error(err)
}
}()
}
//if s.Config.TProxy.Addr != "" {
// log.Tracef("start tproxy address on %s", s.Config.TProxy.Addr)
// go func() {
// if err = s.ListenTProxy(s.Config.TProxy.Addr); err != nil {
// log.Error(err)
// }
// }()
//}

if s.Config.HTTP.Addr != "" {
log.Tracef("start http admin control on %s", s.Config.HTTP.Addr)
Expand Down

0 comments on commit 638f20d

Please sign in to comment.