From 35278ad17fe9d658d9a5463ee94315c8cef7bd81 Mon Sep 17 00:00:00 2001 From: fatedier Date: Sun, 9 Dec 2018 22:06:22 +0800 Subject: [PATCH] mv folders --- client/admin_api.go | 3 ++- client/control.go | 5 +++-- client/{ => event}/event.go | 2 +- client/{ => health}/health.go | 2 +- client/{ => proxy}/proxy.go | 2 +- client/{ => proxy}/proxy_manager.go | 17 +++++++++-------- client/{ => proxy}/proxy_wrapper.go | 18 ++++++++++-------- tests/ci/normal_test.go | 16 ++++++++-------- 8 files changed, 35 insertions(+), 30 deletions(-) rename client/{ => event}/event.go (96%) rename client/{ => health}/health.go (99%) rename client/{ => proxy}/proxy.go (99%) rename client/{ => proxy}/proxy_manager.go (88%) rename client/{ => proxy}/proxy_wrapper.go (90%) diff --git a/client/admin_api.go b/client/admin_api.go index 5074540..893d127 100644 --- a/client/admin_api.go +++ b/client/admin_api.go @@ -24,6 +24,7 @@ import ( ini "github.com/vaughan0/go-ini" + "github.com/fatedier/frp/client/proxy" "github.com/fatedier/frp/g" "github.com/fatedier/frp/models/config" "github.com/fatedier/frp/utils/log" @@ -121,7 +122,7 @@ func (a ByProxyStatusResp) Len() int { return len(a) } func (a ByProxyStatusResp) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByProxyStatusResp) Less(i, j int) bool { return strings.Compare(a[i].Name, a[j].Name) < 0 } -func NewProxyStatusResp(status *ProxyStatus) ProxyStatusResp { +func NewProxyStatusResp(status *proxy.ProxyStatus) ProxyStatusResp { psr := ProxyStatusResp{ Name: status.Name, Type: status.Type, diff --git a/client/control.go b/client/control.go index 4a588c5..376893f 100644 --- a/client/control.go +++ b/client/control.go @@ -21,6 +21,7 @@ import ( "sync" "time" + "github.com/fatedier/frp/client/proxy" "github.com/fatedier/frp/g" "github.com/fatedier/frp/models/config" "github.com/fatedier/frp/models/msg" @@ -38,7 +39,7 @@ type Control struct { // manage all proxies pxyCfgs map[string]config.ProxyConf - pm *ProxyManager + pm *proxy.ProxyManager // manage all visitors vm *VisitorManager @@ -87,7 +88,7 @@ func NewControl(runId string, conn frpNet.Conn, session *fmux.Session, pxyCfgs m msgHandlerShutdown: shutdown.New(), Logger: log.NewPrefixLogger(""), } - ctl.pm = NewProxyManager(ctl.sendCh, runId) + ctl.pm = proxy.NewProxyManager(ctl.sendCh, runId) ctl.vm = NewVisitorManager(ctl) ctl.vm.Reload(visitorCfgs) diff --git a/client/event.go b/client/event/event.go similarity index 96% rename from client/event.go rename to client/event/event.go index b10b1e4..e8ea2e2 100644 --- a/client/event.go +++ b/client/event/event.go @@ -1,4 +1,4 @@ -package client +package event import ( "errors" diff --git a/client/health.go b/client/health/health.go similarity index 99% rename from client/health.go rename to client/health/health.go index 7002ade..16c1a59 100644 --- a/client/health.go +++ b/client/health/health.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package client +package health import ( "context" diff --git a/client/proxy.go b/client/proxy/proxy.go similarity index 99% rename from client/proxy.go rename to client/proxy/proxy.go index a89921d..610a6f8 100644 --- a/client/proxy.go +++ b/client/proxy/proxy.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package client +package proxy import ( "bytes" diff --git a/client/proxy_manager.go b/client/proxy/proxy_manager.go similarity index 88% rename from client/proxy_manager.go rename to client/proxy/proxy_manager.go index 42fa9a7..b65f37a 100644 --- a/client/proxy_manager.go +++ b/client/proxy/proxy_manager.go @@ -1,9 +1,10 @@ -package client +package proxy import ( "fmt" "sync" + "github.com/fatedier/frp/client/event" "github.com/fatedier/frp/models/config" "github.com/fatedier/frp/models/msg" "github.com/fatedier/frp/utils/log" @@ -67,15 +68,15 @@ func (pm *ProxyManager) HandleWorkConn(name string, workConn frpNet.Conn) { } } -func (pm *ProxyManager) HandleEvent(evType EventType, payload interface{}) error { +func (pm *ProxyManager) HandleEvent(evType event.EventType, payload interface{}) error { var m msg.Message - switch event := payload.(type) { - case *StartProxyPayload: - m = event.NewProxyMsg - case *CloseProxyPayload: - m = event.CloseProxyMsg + switch e := payload.(type) { + case *event.StartProxyPayload: + m = e.NewProxyMsg + case *event.CloseProxyPayload: + m = e.CloseProxyMsg default: - return ErrPayloadType + return event.ErrPayloadType } err := errors.PanicToError(func() { diff --git a/client/proxy_wrapper.go b/client/proxy/proxy_wrapper.go similarity index 90% rename from client/proxy_wrapper.go rename to client/proxy/proxy_wrapper.go index 059d182..f95144c 100644 --- a/client/proxy_wrapper.go +++ b/client/proxy/proxy_wrapper.go @@ -1,4 +1,4 @@ -package client +package proxy import ( "fmt" @@ -6,6 +6,8 @@ import ( "sync/atomic" "time" + "github.com/fatedier/frp/client/event" + "github.com/fatedier/frp/client/health" "github.com/fatedier/frp/models/config" "github.com/fatedier/frp/models/msg" "github.com/fatedier/frp/utils/log" @@ -48,10 +50,10 @@ type ProxyWrapper struct { // if ProxyConf has healcheck config // monitor will watch if it is alive - monitor *HealthCheckMonitor + monitor *health.HealthCheckMonitor // event handler - handler EventHandler + handler event.EventHandler health uint32 lastSendStartMsg time.Time @@ -63,7 +65,7 @@ type ProxyWrapper struct { log.Logger } -func NewProxyWrapper(cfg config.ProxyConf, eventHandler EventHandler, logPrefix string) *ProxyWrapper { +func NewProxyWrapper(cfg config.ProxyConf, eventHandler event.EventHandler, logPrefix string) *ProxyWrapper { baseInfo := cfg.GetBaseInfo() pw := &ProxyWrapper{ ProxyStatus: ProxyStatus{ @@ -81,7 +83,7 @@ func NewProxyWrapper(cfg config.ProxyConf, eventHandler EventHandler, logPrefix if baseInfo.HealthCheckType != "" { pw.health = 1 // means failed - pw.monitor = NewHealthCheckMonitor(baseInfo.HealthCheckType, baseInfo.HealthCheckIntervalS, + pw.monitor = health.NewHealthCheckMonitor(baseInfo.HealthCheckType, baseInfo.HealthCheckIntervalS, baseInfo.HealthCheckTimeoutS, baseInfo.HealthCheckMaxFailed, baseInfo.HealthCheckAddr, baseInfo.HealthCheckUrl, pw.statusNormalCallback, pw.statusFailedCallback) pw.monitor.SetLogger(pw.Logger) @@ -137,7 +139,7 @@ func (pw *ProxyWrapper) Stop() { } pw.Status = ProxyStatusClosed - pw.handler(EvCloseProxy, &CloseProxyPayload{ + pw.handler(event.EvCloseProxy, &event.CloseProxyPayload{ CloseProxyMsg: &msg.CloseProxy{ ProxyName: pw.Name, }, @@ -165,7 +167,7 @@ func (pw *ProxyWrapper) checkWorker() { var newProxyMsg msg.NewProxy pw.Cfg.MarshalToMsg(&newProxyMsg) pw.lastSendStartMsg = now - pw.handler(EvStartProxy, &StartProxyPayload{ + pw.handler(event.EvStartProxy, &event.StartProxyPayload{ NewProxyMsg: &newProxyMsg, }) } @@ -173,7 +175,7 @@ func (pw *ProxyWrapper) checkWorker() { } else { pw.mu.Lock() if pw.Status == ProxyStatusRunning || pw.Status == ProxyStatusWaitStart { - pw.handler(EvCloseProxy, &CloseProxyPayload{ + pw.handler(event.EvCloseProxy, &event.CloseProxyPayload{ CloseProxyMsg: &msg.CloseProxy{ ProxyName: pw.Name, }, diff --git a/tests/ci/normal_test.go b/tests/ci/normal_test.go index d76cc2d..24f5795 100644 --- a/tests/ci/normal_test.go +++ b/tests/ci/normal_test.go @@ -12,7 +12,7 @@ import ( "github.com/gorilla/websocket" "github.com/stretchr/testify/assert" - "github.com/fatedier/frp/client" + "github.com/fatedier/frp/client/proxy" "github.com/fatedier/frp/server/ports" "github.com/fatedier/frp/tests/consts" "github.com/fatedier/frp/tests/mock" @@ -218,31 +218,31 @@ func TestAllowPorts(t *testing.T) { // Port not allowed status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortNotAllowed) if assert.NoError(err) { - assert.Equal(client.ProxyStatusStartErr, status.Status) + assert.Equal(proxy.ProxyStatusStartErr, status.Status) assert.True(strings.Contains(status.Err, ports.ErrPortNotAllowed.Error())) } status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyUdpPortNotAllowed) if assert.NoError(err) { - assert.Equal(client.ProxyStatusStartErr, status.Status) + assert.Equal(proxy.ProxyStatusStartErr, status.Status) assert.True(strings.Contains(status.Err, ports.ErrPortNotAllowed.Error())) } status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortUnavailable) if assert.NoError(err) { - assert.Equal(client.ProxyStatusStartErr, status.Status) + assert.Equal(proxy.ProxyStatusStartErr, status.Status) assert.True(strings.Contains(status.Err, ports.ErrPortUnAvailable.Error())) } // Port normal status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortNormal) if assert.NoError(err) { - assert.Equal(client.ProxyStatusRunning, status.Status) + assert.Equal(proxy.ProxyStatusRunning, status.Status) } status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyUdpPortNormal) if assert.NoError(err) { - assert.Equal(client.ProxyStatusRunning, status.Status) + assert.Equal(proxy.ProxyStatusRunning, status.Status) } } @@ -271,7 +271,7 @@ func TestPluginHttpProxy(t *testing.T) { assert := assert.New(t) status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyHttpProxy) if assert.NoError(err) { - assert.Equal(client.ProxyStatusRunning, status.Status) + assert.Equal(proxy.ProxyStatusRunning, status.Status) // http proxy addr := status.RemoteAddr @@ -299,7 +299,7 @@ func TestRangePortsMapping(t *testing.T) { name := fmt.Sprintf("%s_%d", consts.ProxyRangeTcpPrefix, i) status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, name) if assert.NoError(err) { - assert.Equal(client.ProxyStatusRunning, status.Status) + assert.Equal(proxy.ProxyStatusRunning, status.Status) } } }