-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reverse listener configuration
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package config | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/shoriwe/fullproxy/v3/reverse" | ||
) | ||
|
||
type Reverse struct { | ||
Listener *Listener `yaml:"listener"` | ||
Controller Listener `yaml:"controller"` | ||
} | ||
|
||
func (r *Reverse) Master() (net.Listener, error) { | ||
l, lErr := r.Listener.Listen() | ||
if lErr != nil { | ||
return nil, lErr | ||
} | ||
cl, clErr := r.Listener.Listen() | ||
if clErr != nil { | ||
l.Close() | ||
return nil, clErr | ||
} | ||
return reverse.NewMaster(l, cl) | ||
} | ||
|
||
func (r *Reverse) Slave() (*reverse.Slave, error) { | ||
cl, clErr := r.Controller.Dial() | ||
if clErr != nil { | ||
return nil, clErr | ||
} | ||
return reverse.NewSlave(cl) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestReverse_Master(t *testing.T) { | ||
t.Run("Valid", func(tt *testing.T) { | ||
r := Reverse{ | ||
Listener: &Listener{ | ||
Network: "tcp", | ||
Address: "localhost:0", | ||
}, | ||
Controller: Listener{ | ||
Network: "tcp", | ||
Address: "localhost:0", | ||
}, | ||
} | ||
m, err := r.Master() | ||
assert.Nil(tt, err) | ||
defer m.Close() | ||
}) | ||
t.Run("Invalid User listener", func(tt *testing.T) { | ||
r := Reverse{ | ||
Listener: &Listener{ | ||
Network: "tcp", | ||
Address: "localhost:99999999", | ||
}, | ||
Controller: Listener{ | ||
Network: "tcp", | ||
Address: "localhost:0", | ||
}, | ||
} | ||
_, err := r.Master() | ||
assert.NotNil(tt, err) | ||
}) | ||
t.Run("Invalid Controller listener", func(tt *testing.T) { | ||
r := Reverse{ | ||
Listener: &Listener{ | ||
Network: "tcp", | ||
Address: "localhost:0", | ||
}, | ||
Controller: Listener{ | ||
Network: "tcp", | ||
Address: "localhost:9999999999", | ||
}, | ||
} | ||
_, err := r.Master() | ||
assert.NotNil(tt, err) | ||
}) | ||
} |