added base NAT traveral using reverse proxy

This commit is contained in:
2022-12-01 02:49:08 +00:00
parent fbfa0e47fa
commit 7c0ddc79c9
5 changed files with 567 additions and 33 deletions

11
go.mod
View File

@@ -8,10 +8,10 @@ require (
github.com/containerd/continuity v0.0.0-20210315143101-93e15499afd5 // indirect
github.com/docker/docker v20.10.0-beta1.0.20201113105859-b6bfff2a628f+incompatible
github.com/docker/go-connections v0.4.0
github.com/fatedier/frp v0.45.0
github.com/gin-gonic/gin v1.6.3
github.com/go-git/go-git/v5 v5.4.2
github.com/google/uuid v1.1.2
github.com/gorilla/mux v1.8.0 // indirect
github.com/google/uuid v1.3.0
github.com/lithammer/shortuuid v3.0.0+incompatible
github.com/moby/sys/mount v0.2.0 // indirect
github.com/moby/term v0.0.0-20201110203204-bea5bbe245bf // indirect
@@ -19,14 +19,11 @@ require (
github.com/otiai10/copy v1.6.0
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/shirou/gopsutil/v3 v3.22.10
github.com/spf13/viper v1.4.0
github.com/spf13/viper v1.7.0
github.com/urfave/cli/v2 v2.3.0
gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40 // indirect
gitlab.com/NebulousLabs/go-upnp v0.0.0-20181011194642-3a71999ed0d3
golang.org/x/mod v0.3.0
golang.org/x/text v0.3.5 // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
google.golang.org/grpc v1.35.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
gopkg.in/yaml.v2 v2.4.0
gotest.tools/v3 v3.0.3 // indirect
)

483
go.sum

File diff suppressed because it is too large Load Diff

40
p2p/frp/client.go Normal file
View File

@@ -0,0 +1,40 @@
package frp
import (
"github.com/fatedier/frp/client"
"github.com/fatedier/frp/pkg/config"
)
// Starts FRP client
func StartFRPClient(address string, port int) error {
cfg := config.GetDefaultClientConf()
//var cfg config.ClientCommonConf
var visitorCfgs map[string]config.VisitorConf
//
cfg.ServerAddr = address
cfg.ServerPort = port
var tcpcnf config.TCPProxyConf
tcpcnf.LocalIP = "0.0.0.0"
tcpcnf.LocalPort = 22
tcpcnf.RemotePort = 3000
proxyConfs := map[string]config.ProxyConf{
tcpcnf.ProxyName: &tcpcnf,
}
//cfg.ClientConfig = auth.GetDefaultClientConf()
//cfg.Protocol = "tcp"
//pxyCfgs, visitorCfgs, _ = config.LoadAllProxyConfsFromIni(cfg.User, nil, cfg.Start)
cli, err := client.NewService(cfg, proxyConfs, visitorCfgs, "")
if err != nil {
return err
}
cli.Run()
return nil
}

35
p2p/frp/server.go Normal file
View File

@@ -0,0 +1,35 @@
package frp
import (
"github.com/fatedier/frp/pkg/config"
"github.com/fatedier/frp/server"
)
type ServerFRPConf struct {
address string
}
// StartFRPServer The initial plan is only support reverse proxy
// for TCP ports
// This function starts a server that can act as a reverse
// proxy for nodes behind NAT.
func StartFRPServer(address string, port int) error {
baseConfig := config.GetDefaultServerConf()
baseConfig.BindAddr = address
//TODO look into later for dashboard
//baseConfig.DashboardAddr = "127.0.0.1"
//baseConfig.DashboardPort = 8754
//baseConfig.DashboardUser = "admin"
//baseConfig.DashboardPwd = "admin"
// todo change to make it a dynamic port
baseConfig.BindPort = port
service, err := server.NewService(baseConfig)
if err != nil {
return err
}
service.Run()
return nil
}

31
p2p/frp/server_test.go Normal file
View File

@@ -0,0 +1,31 @@
package frp
import (
"fmt"
"testing"
"time"
)
func TestStartFRPServer(t *testing.T) {
err := StartFRPServer("127.0.0.1", 8808)
if err != nil {
fmt.Println(err)
t.Fail()
}
}
func TestStartFRPClient(t *testing.T) {
go StartFRPServer("127.0.0.1", 8808)
//if err != nil {
// fmt.Println(err)
// t.Fail()
//}
time.Sleep(3 * time.Second)
err := StartFRPClient("127.0.0.1", 8808)
if err != nil {
fmt.Println(err)
t.Fail()
}
}