init
This commit is contained in:
parent
cd8adaea06
commit
43aa894030
@ -145,13 +145,10 @@ func (ctl *Control) HandleReqWorkConn(inMsg *msg.ReqWorkConn) {
|
|||||||
m := &msg.NewWorkConn{
|
m := &msg.NewWorkConn{
|
||||||
RunID: ctl.runID,
|
RunID: ctl.runID,
|
||||||
}
|
}
|
||||||
xl.Info("SetNewWorkConn")
|
|
||||||
if err = ctl.authSetter.SetNewWorkConn(m); err != nil {
|
if err = ctl.authSetter.SetNewWorkConn(m); err != nil {
|
||||||
xl.Warn("error during NewWorkConn authentication: %v", err)
|
xl.Warn("error during NewWorkConn authentication: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
xl.Info("WriteMsg - NewWorkConn")
|
|
||||||
|
|
||||||
if err = msg.WriteMsg(workConn, m); err != nil {
|
if err = msg.WriteMsg(workConn, m); err != nil {
|
||||||
xl.Warn("work connection write to server error: %v", err)
|
xl.Warn("work connection write to server error: %v", err)
|
||||||
workConn.Close()
|
workConn.Close()
|
||||||
@ -159,20 +156,17 @@ func (ctl *Control) HandleReqWorkConn(inMsg *msg.ReqWorkConn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var startMsg msg.StartWorkConn
|
var startMsg msg.StartWorkConn
|
||||||
xl.Info("Starting to read - NewWorkConn")
|
|
||||||
if err = msg.ReadMsgInto(workConn, &startMsg); err != nil {
|
if err = msg.ReadMsgInto(workConn, &startMsg); err != nil {
|
||||||
xl.Error("work connection closed before response StartWorkConn message: %v", err)
|
xl.Error("work connection closed before response StartWorkConn message: %v", err)
|
||||||
workConn.Close()
|
workConn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
xl.Info("Finished to read - NewWorkConn")
|
|
||||||
if startMsg.Error != "" {
|
if startMsg.Error != "" {
|
||||||
xl.Error("StartWorkConn contains error: %s", startMsg.Error)
|
xl.Error("StartWorkConn contains error: %s", startMsg.Error)
|
||||||
workConn.Close()
|
workConn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
xl.Info("Call to HandleWorkConn")
|
|
||||||
// dispatch this work connection to related proxy
|
// dispatch this work connection to related proxy
|
||||||
ctl.pm.HandleWorkConn(startMsg.ProxyName, workConn, &startMsg)
|
ctl.pm.HandleWorkConn(startMsg.ProxyName, workConn, &startMsg)
|
||||||
}
|
}
|
||||||
@ -404,7 +398,6 @@ func (ctl *Control) msgHandler() {
|
|||||||
|
|
||||||
switch m := rawMsg.(type) {
|
switch m := rawMsg.(type) {
|
||||||
case *msg.ReqWorkConn:
|
case *msg.ReqWorkConn:
|
||||||
xl.Info("ReqWorkConn msg")
|
|
||||||
go ctl.HandleReqWorkConn(m)
|
go ctl.HandleReqWorkConn(m)
|
||||||
case *msg.NewProxyResp:
|
case *msg.NewProxyResp:
|
||||||
ctl.HandleNewProxyResp(m)
|
ctl.HandleNewProxyResp(m)
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
[common]
|
[common]
|
||||||
server_addr = tunnel.io
|
server_addr = 127.0.0.1
|
||||||
server_port = 7005
|
server_port = 7000
|
||||||
protocol = websocket
|
|
||||||
log_level = debug
|
|
||||||
|
|
||||||
[web]
|
[ssh]
|
||||||
type = http
|
type = tcp
|
||||||
local_port = 3002
|
local_ip = 127.0.0.1
|
||||||
meta_Authorization = {{ .Envs.AUTHORIZATION }}
|
local_port = 22
|
||||||
subdomain = ziv
|
remote_port = 6000
|
||||||
;ips_allow_list = "127.0.0.2/32,192.198.100.10"
|
|
||||||
;http_user = abc
|
|
||||||
;http_pwd = abc
|
|
||||||
|
@ -1,15 +1,2 @@
|
|||||||
[common]
|
[common]
|
||||||
bind_port = 7005
|
bind_port = 7000
|
||||||
vhost_http_port=82
|
|
||||||
subdomain_host=tunnel.io
|
|
||||||
log_level = trace
|
|
||||||
|
|
||||||
;[plugin.codefresh]
|
|
||||||
;addr = 127.0.0.1:7200
|
|
||||||
;path = /newProxy
|
|
||||||
;ops = NewProxy
|
|
||||||
|
|
||||||
;[plugin.codefresh]
|
|
||||||
;addr = 127.0.0.1:7200
|
|
||||||
;path = /newWorkConn
|
|
||||||
;ops = Ping
|
|
||||||
|
2
go.mod
2
go.mod
@ -22,7 +22,7 @@ require (
|
|||||||
github.com/prometheus/client_golang v1.11.0
|
github.com/prometheus/client_golang v1.11.0
|
||||||
github.com/rodaine/table v1.0.1
|
github.com/rodaine/table v1.0.1
|
||||||
github.com/spf13/cobra v1.1.3
|
github.com/spf13/cobra v1.1.3
|
||||||
github.com/stretchr/testify v1.8.0
|
github.com/stretchr/testify v1.7.0
|
||||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781
|
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781
|
||||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
|
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
|
||||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
|
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
|
||||||
|
@ -61,7 +61,6 @@ func NewHTTPReverseProxy(option HTTPReverseProxyOptions, vhostRouter *Routers) *
|
|||||||
proxy := &ReverseProxy{
|
proxy := &ReverseProxy{
|
||||||
// Modify incoming requests by route policies.
|
// Modify incoming requests by route policies.
|
||||||
Director: func(req *http.Request) {
|
Director: func(req *http.Request) {
|
||||||
frpLog.Info("Director *********************")
|
|
||||||
req.URL.Scheme = "http"
|
req.URL.Scheme = "http"
|
||||||
url := req.Context().Value(RouteInfoURL).(string)
|
url := req.Context().Value(RouteInfoURL).(string)
|
||||||
routeByHTTPUser := req.Context().Value(RouteInfoHTTPUser).(string)
|
routeByHTTPUser := req.Context().Value(RouteInfoHTTPUser).(string)
|
||||||
@ -90,7 +89,6 @@ func NewHTTPReverseProxy(option HTTPReverseProxyOptions, vhostRouter *Routers) *
|
|||||||
ResponseHeaderTimeout: rp.responseHeaderTimeout,
|
ResponseHeaderTimeout: rp.responseHeaderTimeout,
|
||||||
IdleConnTimeout: 60 * time.Second,
|
IdleConnTimeout: 60 * time.Second,
|
||||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
frpLog.Info("DialContext *********************")
|
|
||||||
url := ctx.Value(RouteInfoURL).(string)
|
url := ctx.Value(RouteInfoURL).(string)
|
||||||
host, _ := util.CanonicalHost(ctx.Value(RouteInfoHost).(string))
|
host, _ := util.CanonicalHost(ctx.Value(RouteInfoHost).(string))
|
||||||
routerByHTTPUser := ctx.Value(RouteInfoHTTPUser).(string)
|
routerByHTTPUser := ctx.Value(RouteInfoHTTPUser).(string)
|
||||||
@ -105,7 +103,6 @@ func NewHTTPReverseProxy(option HTTPReverseProxyOptions, vhostRouter *Routers) *
|
|||||||
// Normal:
|
// Normal:
|
||||||
// GET / HTTP/1.1
|
// GET / HTTP/1.1
|
||||||
// Host: example.com
|
// Host: example.com
|
||||||
frpLog.Info("Proxy *********************")
|
|
||||||
urlHost := req.Context().Value(RouteInfoURLHost).(string)
|
urlHost := req.Context().Value(RouteInfoURLHost).(string)
|
||||||
if urlHost != "" {
|
if urlHost != "" {
|
||||||
return req.URL, nil
|
return req.URL, nil
|
||||||
@ -167,8 +164,6 @@ func (rp *HTTPReverseProxy) GetHeaders(domain, location, routeByHTTPUser string)
|
|||||||
|
|
||||||
// CreateConnection create a new connection by route config
|
// CreateConnection create a new connection by route config
|
||||||
func (rp *HTTPReverseProxy) CreateConnection(domain, location, routeByHTTPUser string, remoteAddr string) (net.Conn, error) {
|
func (rp *HTTPReverseProxy) CreateConnection(domain, location, routeByHTTPUser string, remoteAddr string) (net.Conn, error) {
|
||||||
frpLog.Info("CreateConnection *********************")
|
|
||||||
|
|
||||||
vr, ok := rp.getVhost(domain, location, routeByHTTPUser)
|
vr, ok := rp.getVhost(domain, location, routeByHTTPUser)
|
||||||
if ok {
|
if ok {
|
||||||
fn := vr.payload.(*RouteConfig).CreateConnFn
|
fn := vr.payload.(*RouteConfig).CreateConnFn
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
frpLog "github.com/fatedier/frp/pkg/util/log"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@ -230,7 +229,6 @@ func parseBasicAuth(auth string) (username, password string, ok bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
frpLog.Info("ServeHTTP *********************")
|
|
||||||
transport := p.Transport
|
transport := p.Transport
|
||||||
if transport == nil {
|
if transport == nil {
|
||||||
transport = http.DefaultTransport
|
transport = http.DefaultTransport
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
frpLog "github.com/fatedier/frp/pkg/util/log"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
@ -138,7 +137,6 @@ func (pxy *HTTPProxy) GetConf() config.ProxyConf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *HTTPProxy) GetRealConn(remoteAddr string) (workConn net.Conn, err error) {
|
func (pxy *HTTPProxy) GetRealConn(remoteAddr string) (workConn net.Conn, err error) {
|
||||||
frpLog.Info("GetRealConn *********************")
|
|
||||||
xl := pxy.xl
|
xl := pxy.xl
|
||||||
rAddr, errRet := net.ResolveTCPAddr("tcp", remoteAddr)
|
rAddr, errRet := net.ResolveTCPAddr("tcp", remoteAddr)
|
||||||
if errRet != nil {
|
if errRet != nil {
|
||||||
|
@ -317,7 +317,6 @@ func (svr *Service) Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (svr *Service) handleConnection(ctx context.Context, conn net.Conn) {
|
func (svr *Service) handleConnection(ctx context.Context, conn net.Conn) {
|
||||||
log.Info("handleConnection! ")
|
|
||||||
xl := xlog.FromContextSafe(ctx)
|
xl := xlog.FromContextSafe(ctx)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -407,7 +406,6 @@ func (svr *Service) HandleListener(l net.Listener) {
|
|||||||
|
|
||||||
// Start a new goroutine to handle connection.
|
// Start a new goroutine to handle connection.
|
||||||
go func(ctx context.Context, frpConn net.Conn) {
|
go func(ctx context.Context, frpConn net.Conn) {
|
||||||
log.Info("server - handle connection goroutine ")
|
|
||||||
if svr.cfg.TCPMux {
|
if svr.cfg.TCPMux {
|
||||||
fmuxCfg := fmux.DefaultConfig()
|
fmuxCfg := fmux.DefaultConfig()
|
||||||
fmuxCfg.KeepAliveInterval = time.Duration(svr.cfg.TCPMuxKeepaliveInterval) * time.Second
|
fmuxCfg.KeepAliveInterval = time.Duration(svr.cfg.TCPMuxKeepaliveInterval) * time.Second
|
||||||
|
Loading…
Reference in New Issue
Block a user