mv folders

This commit is contained in:
fatedier 2018-12-09 22:06:22 +08:00
parent aea9f9fbcc
commit 35278ad17f
8 changed files with 35 additions and 30 deletions

View File

@ -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,

View File

@ -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)

View File

@ -1,4 +1,4 @@
package client
package event
import (
"errors"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package client
package health
import (
"context"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package client
package proxy
import (
"bytes"

View File

@ -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() {

View File

@ -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,
},

View File

@ -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)
}
}
}