-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from gofrp/feat_refactor
feat: refactor
- Loading branch information
Showing
24 changed files
with
625 additions
and
176 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,18 @@ | ||
## v0.1.2 (2024-04-15) | ||
|
||
This release introduces a set of code optimizations, improvements to documentation, and an extension of the testing suite. This is a patch release and does not contain any breaking changes or new features. It is backwards compatible with v0.1.1. | ||
|
||
### Improvements | ||
|
||
**Code Optimization**: Refactored some parts of the codebase to enhance performance and readability. | ||
|
||
**Documentation**: Updated and added inline documentation and comments to make the codebase more accessible for new contributors. | ||
|
||
**Unit Testing**: Increased test coverage by adding new unit tests for previously untested functions. | ||
|
||
|
||
## v0.1.1 (2024-04-12) | ||
Init Project. | ||
|
||
## v0.1.0 (2024-04-11) | ||
Init Project. |
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
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
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
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 |
---|---|---|
|
@@ -88,6 +88,9 @@ HTTP 服务: | |
访问到内网的 HTTP 服务。 | ||
|
||
|
||
# 原理 | ||
![how tiny frpc works](doc/pic/architecture.png) | ||
|
||
|
||
# 说明 | ||
|
||
|
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 |
---|---|---|
@@ -1,14 +1 @@ | ||
### Features | ||
|
||
Introducing version of our proxy solution, we enable reverse proxying through standard ssh protocol communicating with frps. | ||
|
||
We offer two binary program options for different user needs: | ||
|
||
The Go standalone mode: This version works independently to communicate with frps. It's built for those who favor self-sufficiency and prefer a simpler deployment process. | ||
|
||
The ssh native mode: This version works in conjunction with the operating system's ssh program. It is intended for those whose systems comprise a preconfigured ssh setup, or who wish to utilize the existing ssh program. | ||
Both versions necessitate the provision of a frpc toml format configuration file to function correctly. | ||
|
||
This release is just the beginning. Stay tuned for more advanced features, improvements and we are always keen to hear user feedback for future developments. | ||
|
||
**This is currently a preview version. Compatibility is not guaranteed. It is presently for testing purposes only and should not be used in production environments!!!** | ||
Please refer to [CHANGELOG.md](https://github.com/gofrp/tiny-frpc/blob/main/CHANGELOG.md) for details. |
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,24 @@ | ||
package main | ||
|
||
import ( | ||
v1 "github.com/gofrp/tiny-frpc/pkg/config/v1" | ||
"github.com/gofrp/tiny-frpc/pkg/model" | ||
"github.com/gofrp/tiny-frpc/pkg/util/log" | ||
) | ||
|
||
var runner model.Runner = defaultRunner{} | ||
|
||
type defaultRunner struct{} | ||
|
||
func (r defaultRunner) New(commonCfg *v1.ClientCommonConfig, pxyCfg []v1.ProxyConfigurer, vCfg []v1.VisitorConfigurer) (err error) { | ||
log.Infof("init default runner") | ||
return | ||
} | ||
|
||
func (r defaultRunner) Run() (err error) { | ||
return | ||
} | ||
|
||
func (r defaultRunner) Close() (err error) { | ||
return | ||
} |
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,96 @@ | ||
//go:build gssh | ||
// +build gssh | ||
|
||
package main | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/gofrp/tiny-frpc/pkg/config" | ||
v1 "github.com/gofrp/tiny-frpc/pkg/config/v1" | ||
"github.com/gofrp/tiny-frpc/pkg/gssh" | ||
"github.com/gofrp/tiny-frpc/pkg/util/log" | ||
) | ||
|
||
type GoSSHRun struct { | ||
commonCfg *v1.ClientCommonConfig | ||
pxyCfg []v1.ProxyConfigurer | ||
vCfg []v1.VisitorConfigurer | ||
|
||
wg *sync.WaitGroup | ||
mu *sync.RWMutex | ||
|
||
tcs map[int]*gssh.TunnelClient | ||
} | ||
|
||
func (gr *GoSSHRun) New(commonCfg *v1.ClientCommonConfig, pxyCfg []v1.ProxyConfigurer, vCfg []v1.VisitorConfigurer) error { | ||
log.Infof("init go ssh runner") | ||
|
||
runner = &GoSSHRun{ | ||
commonCfg: commonCfg, | ||
pxyCfg: pxyCfg, | ||
vCfg: vCfg, | ||
|
||
wg: new(sync.WaitGroup), | ||
mu: &sync.RWMutex{}, | ||
|
||
tcs: make(map[int]*gssh.TunnelClient, 0), | ||
} | ||
return nil | ||
} | ||
|
||
func (gr *GoSSHRun) Run() error { | ||
params := config.ParseFRPCConfigToGoSSHParam(gr.commonCfg, gr.pxyCfg, gr.vCfg) | ||
|
||
log.Infof("proxy total len: %v", len(params)) | ||
|
||
for i, cmd := range params { | ||
gr.wg.Add(1) | ||
|
||
go func(cmd config.GoSSHParam, idx int) { | ||
defer gr.wg.Done() | ||
|
||
log.Infof("start to run: %v", cmd) | ||
|
||
tc, err := gssh.NewTunnelClient(cmd.LocalAddr, cmd.ServerAddr, cmd.SSHExtraCmd) | ||
if err != nil { | ||
log.Errorf("new ssh tunnel client error: %v", err) | ||
return | ||
} | ||
|
||
gr.mu.Lock() | ||
gr.tcs[idx] = tc | ||
gr.mu.Unlock() | ||
|
||
err = tc.Start() | ||
if err != nil { | ||
log.Errorf("cmd: %v run error: %v", cmd, err) | ||
|
||
gr.mu.Lock() | ||
delete(gr.tcs, idx) | ||
gr.mu.Unlock() | ||
|
||
return | ||
} | ||
}(cmd, i) | ||
} | ||
|
||
gr.wg.Wait() | ||
|
||
log.Infof("stopping ssh tunnel to frps") | ||
return nil | ||
} | ||
|
||
func (gr *GoSSHRun) Close() error { | ||
gr.mu.Lock() | ||
defer gr.mu.Unlock() | ||
|
||
for _, tc := range gr.tcs { | ||
tc.Close() | ||
} | ||
return nil | ||
} | ||
|
||
func init() { | ||
runner = &GoSSHRun{} | ||
} |
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
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,87 @@ | ||
//go:build nssh | ||
// +build nssh | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/gofrp/tiny-frpc/pkg/config" | ||
v1 "github.com/gofrp/tiny-frpc/pkg/config/v1" | ||
"github.com/gofrp/tiny-frpc/pkg/nssh" | ||
"github.com/gofrp/tiny-frpc/pkg/util/log" | ||
) | ||
|
||
type NativeSSHRun struct { | ||
commonCfg *v1.ClientCommonConfig | ||
pxyCfg []v1.ProxyConfigurer | ||
vCfg []v1.VisitorConfigurer | ||
|
||
wg *sync.WaitGroup | ||
mu *sync.RWMutex | ||
|
||
cws map[int]*nssh.CmdWrapper | ||
} | ||
|
||
func (nr *NativeSSHRun) New(commonCfg *v1.ClientCommonConfig, pxyCfg []v1.ProxyConfigurer, vCfg []v1.VisitorConfigurer) error { | ||
log.Infof("init native ssh runner") | ||
|
||
runner = &NativeSSHRun{ | ||
commonCfg: commonCfg, | ||
pxyCfg: pxyCfg, | ||
vCfg: vCfg, | ||
|
||
wg: new(sync.WaitGroup), | ||
mu: &sync.RWMutex{}, | ||
|
||
cws: make(map[int]*nssh.CmdWrapper, 0), | ||
} | ||
return nil | ||
} | ||
|
||
func (nr *NativeSSHRun) Run() error { | ||
cmdParams := config.ParseFRPCConfigToSSHCmd(nr.commonCfg, nr.pxyCfg, nr.vCfg) | ||
|
||
log.Infof("proxy total len: %v", len(cmdParams)) | ||
|
||
for i, cmd := range cmdParams { | ||
nr.wg.Add(1) | ||
|
||
go func(cmd string, idx int) { | ||
defer nr.wg.Done() | ||
ctx := context.Background() | ||
|
||
log.Infof("start to run: %v", cmd) | ||
|
||
cmdWrapper := nssh.NewCmdWrapper(ctx, cmd) | ||
|
||
nr.mu.Lock() | ||
nr.cws[idx] = cmdWrapper | ||
nr.mu.Unlock() | ||
|
||
cmdWrapper.ExecuteCommand(ctx) | ||
}(cmd, i) | ||
} | ||
|
||
nr.wg.Wait() | ||
|
||
log.Infof("stopping native ssh tunnel to frps") | ||
|
||
return nil | ||
} | ||
|
||
func (nr *NativeSSHRun) Close() error { | ||
nr.mu.Lock() | ||
defer nr.mu.Unlock() | ||
|
||
for _, c := range nr.cws { | ||
c.Close() | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func init() { | ||
runner = &NativeSSHRun{} | ||
} |
Oops, something went wrong.