Skip to content

Commit

Permalink
fix: updated reverse to manually set the dial func that uses the slave
Browse files Browse the repository at this point in the history
  • Loading branch information
shoriwe committed Jun 11, 2023
1 parent 2b27847 commit d08e213
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions proxies/socks5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func TestSocks5_Reverse(t *testing.T) {
go func() {
s := &reverse.Slave{
Master: master,
Dial: net.Dial,
}
defer s.Close()
go s.Serve()
Expand Down
12 changes: 6 additions & 6 deletions reverse/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestMaster_init(t *testing.T) {
master := network.Dial(control.Addr().String())
defer master.Close()
go func() {
s := &Slave{Master: master}
s := &Slave{Master: master, Dial: net.Dial}
defer s.Close()
assert.Nil(tt, s.init())
}()
Expand All @@ -36,7 +36,7 @@ func TestMaster_init(t *testing.T) {
go func() {
master := network.Dial(control.Addr().String())
defer master.Close()
s := &Slave{Master: master}
s := &Slave{Master: master, Dial: net.Dial}
defer s.Close()
assert.Nil(tt, s.init())
assert.Nil(tt, s.init())
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestMaster_Accept(t *testing.T) {
doneChan := make(chan struct{}, 2)
defer close(doneChan)
go func() {
s := &Slave{Master: master}
s := &Slave{Master: master, Dial: net.Dial}
defer s.Close()
go s.Serve()
<-doneChan
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestMaster_SlaveDial(t *testing.T) {
<-doneChan
}()
go func() {
s := &Slave{Master: master}
s := &Slave{Master: master, Dial: net.Dial}
defer s.Close()
go s.Serve()
<-doneChan
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestMaster_SlaveDial(t *testing.T) {
doneChan := make(chan struct{}, 1)
defer close(doneChan)
go func() {
s := &Slave{Master: master}
s := &Slave{Master: master, Dial: net.Dial}
defer s.Close()
go s.Serve()
<-doneChan
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestMaster_SlaveAccept(t *testing.T) {
doneChan := make(chan struct{}, 2)
defer close(doneChan)
go func() {
s := &Slave{Master: master, Listener: sListener}
s := &Slave{Master: master, Listener: sListener, Dial: net.Dial}
defer s.Close()
go s.Serve()
<-doneChan
Expand Down
6 changes: 4 additions & 2 deletions reverse/slave.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"net"

"github.com/hashicorp/yamux"
"github.com/shoriwe/fullproxy/v3/utils/network"
)

type Slave struct {
initialized bool
Listener net.Listener // Optional listener
Listener net.Listener // Optional listener
Dial network.DialFunc
Master net.Conn // Master connection
Control *yamux.Session // Control channel
}
Expand Down Expand Up @@ -47,7 +49,7 @@ func (s *Slave) HandleAccept(conn net.Conn, req *Request) (err error) {

func (s *Slave) HandleDial(conn net.Conn, req *Request) (err error) {
var target net.Conn
target, err = net.Dial(req.Network, req.Address)
target, err = s.Dial(req.Network, req.Address)
if err == nil {
defer target.Close()
err = gob.NewEncoder(conn).Encode(SucceedResponse)
Expand Down
14 changes: 7 additions & 7 deletions reverse/slave_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestSlave_init(t *testing.T) {
master := network.Dial(control.Addr().String())
defer master.Close()
go func() {
s := &Slave{Master: master}
s := &Slave{Master: master, Dial: net.Dial}
defer s.Close()
assert.Nil(tt, s.init())
}()
Expand All @@ -37,7 +37,7 @@ func TestSlave_init(t *testing.T) {
go func() {
master := network.Dial(control.Addr().String())
defer master.Close()
s := &Slave{Master: master}
s := &Slave{Master: master, Dial: net.Dial}
defer s.Close()
assert.Nil(tt, s.init())
assert.Nil(tt, s.init())
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestSlave_HandleAccept(t *testing.T) {
assert.Nil(tt, wErr)
<-doneChan
}()
s := &Slave{Master: master, Listener: sListener}
s := &Slave{Master: master, Listener: sListener, Dial: net.Dial}
defer s.Close()
assert.Nil(tt, s.init())
go func() {
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestSlave_HandleAccept(t *testing.T) {
assert.NotNil(tt, cErr)
<-doneChan
}()
s := &Slave{Master: master}
s := &Slave{Master: master, Dial: net.Dial}
defer s.Close()
assert.Nil(tt, s.init())
job, aErr := s.Control.Accept()
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestSlave_Handle(t *testing.T) {
assert.Nil(tt, wErr)
<-doneChan
}()
s := &Slave{Master: master, Listener: sListener}
s := &Slave{Master: master, Listener: sListener, Dial: net.Dial}
defer s.Close()
assert.Nil(tt, s.init())
go func() {
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestSlave_Handle(t *testing.T) {
assert.Nil(tt, wErr)
<-doneChan
}()
s := &Slave{Master: master}
s := &Slave{Master: master, Dial: net.Dial}
defer s.Close()
assert.Nil(tt, s.init())
go func() {
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestSlave_Handle(t *testing.T) {
}))
<-doneChan
}()
s := &Slave{Master: master, Listener: sListener}
s := &Slave{Master: master, Listener: sListener, Dial: net.Dial}
defer s.Close()
assert.Nil(tt, s.init())
job, aErr := s.Control.Accept()
Expand Down

0 comments on commit d08e213

Please sign in to comment.