mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
mv folders
This commit is contained in:
parent
aea9f9fbcc
commit
35278ad17f
@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
ini "github.com/vaughan0/go-ini"
|
ini "github.com/vaughan0/go-ini"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/client/proxy"
|
||||||
"github.com/fatedier/frp/g"
|
"github.com/fatedier/frp/g"
|
||||||
"github.com/fatedier/frp/models/config"
|
"github.com/fatedier/frp/models/config"
|
||||||
"github.com/fatedier/frp/utils/log"
|
"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) 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 (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{
|
psr := ProxyStatusResp{
|
||||||
Name: status.Name,
|
Name: status.Name,
|
||||||
Type: status.Type,
|
Type: status.Type,
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/client/proxy"
|
||||||
"github.com/fatedier/frp/g"
|
"github.com/fatedier/frp/g"
|
||||||
"github.com/fatedier/frp/models/config"
|
"github.com/fatedier/frp/models/config"
|
||||||
"github.com/fatedier/frp/models/msg"
|
"github.com/fatedier/frp/models/msg"
|
||||||
@ -38,7 +39,7 @@ type Control struct {
|
|||||||
|
|
||||||
// manage all proxies
|
// manage all proxies
|
||||||
pxyCfgs map[string]config.ProxyConf
|
pxyCfgs map[string]config.ProxyConf
|
||||||
pm *ProxyManager
|
pm *proxy.ProxyManager
|
||||||
|
|
||||||
// manage all visitors
|
// manage all visitors
|
||||||
vm *VisitorManager
|
vm *VisitorManager
|
||||||
@ -87,7 +88,7 @@ func NewControl(runId string, conn frpNet.Conn, session *fmux.Session, pxyCfgs m
|
|||||||
msgHandlerShutdown: shutdown.New(),
|
msgHandlerShutdown: shutdown.New(),
|
||||||
Logger: log.NewPrefixLogger(""),
|
Logger: log.NewPrefixLogger(""),
|
||||||
}
|
}
|
||||||
ctl.pm = NewProxyManager(ctl.sendCh, runId)
|
ctl.pm = proxy.NewProxyManager(ctl.sendCh, runId)
|
||||||
|
|
||||||
ctl.vm = NewVisitorManager(ctl)
|
ctl.vm = NewVisitorManager(ctl)
|
||||||
ctl.vm.Reload(visitorCfgs)
|
ctl.vm.Reload(visitorCfgs)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package client
|
package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package client
|
package health
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package client
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,9 +1,10 @@
|
|||||||
package client
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/client/event"
|
||||||
"github.com/fatedier/frp/models/config"
|
"github.com/fatedier/frp/models/config"
|
||||||
"github.com/fatedier/frp/models/msg"
|
"github.com/fatedier/frp/models/msg"
|
||||||
"github.com/fatedier/frp/utils/log"
|
"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
|
var m msg.Message
|
||||||
switch event := payload.(type) {
|
switch e := payload.(type) {
|
||||||
case *StartProxyPayload:
|
case *event.StartProxyPayload:
|
||||||
m = event.NewProxyMsg
|
m = e.NewProxyMsg
|
||||||
case *CloseProxyPayload:
|
case *event.CloseProxyPayload:
|
||||||
m = event.CloseProxyMsg
|
m = e.CloseProxyMsg
|
||||||
default:
|
default:
|
||||||
return ErrPayloadType
|
return event.ErrPayloadType
|
||||||
}
|
}
|
||||||
|
|
||||||
err := errors.PanicToError(func() {
|
err := errors.PanicToError(func() {
|
@ -1,4 +1,4 @@
|
|||||||
package client
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -6,6 +6,8 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/client/event"
|
||||||
|
"github.com/fatedier/frp/client/health"
|
||||||
"github.com/fatedier/frp/models/config"
|
"github.com/fatedier/frp/models/config"
|
||||||
"github.com/fatedier/frp/models/msg"
|
"github.com/fatedier/frp/models/msg"
|
||||||
"github.com/fatedier/frp/utils/log"
|
"github.com/fatedier/frp/utils/log"
|
||||||
@ -48,10 +50,10 @@ type ProxyWrapper struct {
|
|||||||
|
|
||||||
// if ProxyConf has healcheck config
|
// if ProxyConf has healcheck config
|
||||||
// monitor will watch if it is alive
|
// monitor will watch if it is alive
|
||||||
monitor *HealthCheckMonitor
|
monitor *health.HealthCheckMonitor
|
||||||
|
|
||||||
// event handler
|
// event handler
|
||||||
handler EventHandler
|
handler event.EventHandler
|
||||||
|
|
||||||
health uint32
|
health uint32
|
||||||
lastSendStartMsg time.Time
|
lastSendStartMsg time.Time
|
||||||
@ -63,7 +65,7 @@ type ProxyWrapper struct {
|
|||||||
log.Logger
|
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()
|
baseInfo := cfg.GetBaseInfo()
|
||||||
pw := &ProxyWrapper{
|
pw := &ProxyWrapper{
|
||||||
ProxyStatus: ProxyStatus{
|
ProxyStatus: ProxyStatus{
|
||||||
@ -81,7 +83,7 @@ func NewProxyWrapper(cfg config.ProxyConf, eventHandler EventHandler, logPrefix
|
|||||||
|
|
||||||
if baseInfo.HealthCheckType != "" {
|
if baseInfo.HealthCheckType != "" {
|
||||||
pw.health = 1 // means failed
|
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.HealthCheckTimeoutS, baseInfo.HealthCheckMaxFailed, baseInfo.HealthCheckAddr,
|
||||||
baseInfo.HealthCheckUrl, pw.statusNormalCallback, pw.statusFailedCallback)
|
baseInfo.HealthCheckUrl, pw.statusNormalCallback, pw.statusFailedCallback)
|
||||||
pw.monitor.SetLogger(pw.Logger)
|
pw.monitor.SetLogger(pw.Logger)
|
||||||
@ -137,7 +139,7 @@ func (pw *ProxyWrapper) Stop() {
|
|||||||
}
|
}
|
||||||
pw.Status = ProxyStatusClosed
|
pw.Status = ProxyStatusClosed
|
||||||
|
|
||||||
pw.handler(EvCloseProxy, &CloseProxyPayload{
|
pw.handler(event.EvCloseProxy, &event.CloseProxyPayload{
|
||||||
CloseProxyMsg: &msg.CloseProxy{
|
CloseProxyMsg: &msg.CloseProxy{
|
||||||
ProxyName: pw.Name,
|
ProxyName: pw.Name,
|
||||||
},
|
},
|
||||||
@ -165,7 +167,7 @@ func (pw *ProxyWrapper) checkWorker() {
|
|||||||
var newProxyMsg msg.NewProxy
|
var newProxyMsg msg.NewProxy
|
||||||
pw.Cfg.MarshalToMsg(&newProxyMsg)
|
pw.Cfg.MarshalToMsg(&newProxyMsg)
|
||||||
pw.lastSendStartMsg = now
|
pw.lastSendStartMsg = now
|
||||||
pw.handler(EvStartProxy, &StartProxyPayload{
|
pw.handler(event.EvStartProxy, &event.StartProxyPayload{
|
||||||
NewProxyMsg: &newProxyMsg,
|
NewProxyMsg: &newProxyMsg,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -173,7 +175,7 @@ func (pw *ProxyWrapper) checkWorker() {
|
|||||||
} else {
|
} else {
|
||||||
pw.mu.Lock()
|
pw.mu.Lock()
|
||||||
if pw.Status == ProxyStatusRunning || pw.Status == ProxyStatusWaitStart {
|
if pw.Status == ProxyStatusRunning || pw.Status == ProxyStatusWaitStart {
|
||||||
pw.handler(EvCloseProxy, &CloseProxyPayload{
|
pw.handler(event.EvCloseProxy, &event.CloseProxyPayload{
|
||||||
CloseProxyMsg: &msg.CloseProxy{
|
CloseProxyMsg: &msg.CloseProxy{
|
||||||
ProxyName: pw.Name,
|
ProxyName: pw.Name,
|
||||||
},
|
},
|
@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/stretchr/testify/assert"
|
"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/server/ports"
|
||||||
"github.com/fatedier/frp/tests/consts"
|
"github.com/fatedier/frp/tests/consts"
|
||||||
"github.com/fatedier/frp/tests/mock"
|
"github.com/fatedier/frp/tests/mock"
|
||||||
@ -218,31 +218,31 @@ func TestAllowPorts(t *testing.T) {
|
|||||||
// Port not allowed
|
// Port not allowed
|
||||||
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortNotAllowed)
|
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortNotAllowed)
|
||||||
if assert.NoError(err) {
|
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()))
|
assert.True(strings.Contains(status.Err, ports.ErrPortNotAllowed.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyUdpPortNotAllowed)
|
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyUdpPortNotAllowed)
|
||||||
if assert.NoError(err) {
|
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()))
|
assert.True(strings.Contains(status.Err, ports.ErrPortNotAllowed.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortUnavailable)
|
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortUnavailable)
|
||||||
if assert.NoError(err) {
|
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()))
|
assert.True(strings.Contains(status.Err, ports.ErrPortUnAvailable.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Port normal
|
// Port normal
|
||||||
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortNormal)
|
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyTcpPortNormal)
|
||||||
if assert.NoError(err) {
|
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)
|
status, err = util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyUdpPortNormal)
|
||||||
if assert.NoError(err) {
|
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)
|
assert := assert.New(t)
|
||||||
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyHttpProxy)
|
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, consts.ProxyHttpProxy)
|
||||||
if assert.NoError(err) {
|
if assert.NoError(err) {
|
||||||
assert.Equal(client.ProxyStatusRunning, status.Status)
|
assert.Equal(proxy.ProxyStatusRunning, status.Status)
|
||||||
|
|
||||||
// http proxy
|
// http proxy
|
||||||
addr := status.RemoteAddr
|
addr := status.RemoteAddr
|
||||||
@ -299,7 +299,7 @@ func TestRangePortsMapping(t *testing.T) {
|
|||||||
name := fmt.Sprintf("%s_%d", consts.ProxyRangeTcpPrefix, i)
|
name := fmt.Sprintf("%s_%d", consts.ProxyRangeTcpPrefix, i)
|
||||||
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, name)
|
status, err := util.GetProxyStatus(consts.ADMIN_ADDR, consts.ADMIN_USER, consts.ADMIN_PWD, name)
|
||||||
if assert.NoError(err) {
|
if assert.NoError(err) {
|
||||||
assert.Equal(client.ProxyStatusRunning, status.Status)
|
assert.Equal(proxy.ProxyStatusRunning, status.Status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user