fix: remove useless change

This commit is contained in:
int7 2023-11-10 16:22:59 +08:00
parent e68f1ca257
commit 40677ce9c4
6 changed files with 29 additions and 38 deletions

View File

@ -104,7 +104,6 @@ func NewControl(
ctl.msgDispatcher = msg.NewDispatcher(cryptoRW)
ctl.registerMsgHandlers()
ctl.msgTransporter = transport.NewMessageTransporter(ctl.msgDispatcher.SendChannel())
ctl.pm = proxy.NewManager(ctl.ctx, clientCfg, ctl.msgTransporter)
@ -134,12 +133,10 @@ func (ctl *Control) handleReqWorkConn(_ msg.Message) {
m := &msg.NewWorkConn{
RunID: ctl.runID,
}
if err = ctl.authSetter.SetNewWorkConn(m); err != nil {
xl.Warn("error during NewWorkConn authentication: %v", err)
return
}
if err = msg.WriteMsg(workConn, m); err != nil {
xl.Warn("work connection write to server error: %v", err)
workConn.Close()
@ -152,7 +149,6 @@ func (ctl *Control) handleReqWorkConn(_ msg.Message) {
workConn.Close()
return
}
if startMsg.Error != "" {
xl.Error("StartWorkConn contains error: %s", startMsg.Error)
workConn.Close()
@ -165,9 +161,7 @@ func (ctl *Control) handleReqWorkConn(_ msg.Message) {
func (ctl *Control) handleNewProxyResp(m msg.Message) {
xl := ctl.xl
inMsg := m.(*msg.NewProxyResp)
// Server will return NewProxyResp message to each NewProxy message.
// Start a new proxy handler if no error got
err := ctl.pm.StartProxy(inMsg.ProxyName, inMsg.RemoteAddr, inMsg.Error)

View File

@ -199,7 +199,6 @@ func (pw *Wrapper) checkWorker() {
var newProxyMsg msg.NewProxy
pw.Cfg.MarshalToMsg(&newProxyMsg)
pw.lastSendStartMsg = now
_ = pw.handler(&event.StartProxyPayload{
NewProxyMsg: &newProxyMsg,
})

View File

@ -42,7 +42,6 @@ type ServerCommonConf struct {
// BindPort specifies the port that the server listens on. By default, this
// value is 7000.
BindPort int `ini:"bind_port" json:"bind_port"`
// KCPBindPort specifies the KCP port that the server listens on. If this
// value is 0, the server will not listen for KCP connections. By default,
// this value is 0.

View File

@ -49,14 +49,14 @@ type forwardedTCPPayload struct {
// custom define
// parse ssh client cmds input
type SSHCmdPayload struct {
type CmdPayload struct {
Address string
Port uint32
}
// custom define
// with frp control cmds
type SSHExtraPayload struct {
type ExtraPayload struct {
Type string
// TODO port can be set by extra message and priority to ssh raw cmd
@ -64,7 +64,7 @@ type SSHExtraPayload struct {
Port uint32
}
type SSHService struct {
type Service struct {
tcpConn net.Conn
cfg *ssh.ServerConfig
@ -72,8 +72,8 @@ type SSHService struct {
gChannel <-chan ssh.NewChannel
gReq <-chan *ssh.Request
addrPayloadCh chan SSHCmdPayload
extraPayloadCh chan SSHExtraPayload
addrPayloadCh chan CmdPayload
extraPayloadCh chan ExtraPayload
proxyPayloadCh chan v1.ProxyConfigurer
replyCh chan interface{}
@ -87,13 +87,13 @@ func NewSSHService(
cfg *ssh.ServerConfig,
proxyPayloadCh chan v1.ProxyConfigurer,
replyCh chan interface{},
) (ss *SSHService, err error) {
ss = &SSHService{
) (ss *Service, err error) {
ss = &Service{
tcpConn: tcpConn,
cfg: cfg,
addrPayloadCh: make(chan SSHCmdPayload),
extraPayloadCh: make(chan SSHExtraPayload),
addrPayloadCh: make(chan CmdPayload),
extraPayloadCh: make(chan ExtraPayload),
proxyPayloadCh: proxyPayloadCh,
replyCh: replyCh,
@ -113,18 +113,18 @@ func NewSSHService(
return ss, nil
}
func (ss *SSHService) Run() {
func (ss *Service) Run() {
go ss.loopGenerateProxy()
go ss.loopParseCmdPayload()
go ss.loopParseExtraPayload()
go ss.loopReply()
}
func (ss *SSHService) Exit() <-chan struct{} {
func (ss *Service) Exit() <-chan struct{} {
return ss.closeCh
}
func (ss *SSHService) Close() {
func (ss *Service) Close() {
if atomic.LoadInt32(&ss.exit) == 1 {
return
}
@ -149,7 +149,7 @@ func (ss *SSHService) Close() {
log.Info("ssh service close")
}
func (ss *SSHService) loopParseCmdPayload() {
func (ss *Service) loopParseCmdPayload() {
for {
select {
case req, ok := <-ss.gReq:
@ -161,7 +161,7 @@ func (ss *SSHService) loopParseCmdPayload() {
switch req.Type {
case RequestTypeForward:
var addrPayload SSHCmdPayload
var addrPayload CmdPayload
if err := ssh.Unmarshal(req.Payload, &addrPayload); err != nil {
log.Error("ssh unmarshal error: %v", err)
return
@ -189,7 +189,7 @@ func (ss *SSHService) loopParseCmdPayload() {
}
}
func (ss *SSHService) loopSendHeartbeat(ch ssh.Channel) {
func (ss *Service) loopSendHeartbeat(ch ssh.Channel) {
tk := time.NewTicker(time.Second * 60)
defer tk.Stop()
@ -212,7 +212,7 @@ func (ss *SSHService) loopSendHeartbeat(ch ssh.Channel) {
}
}
func (ss *SSHService) loopParseExtraPayload() {
func (ss *Service) loopParseExtraPayload() {
log.Info("loop parse extra payload start")
for newChannel := range ss.gChannel {
@ -256,15 +256,15 @@ func (ss *SSHService) loopParseExtraPayload() {
}
}
func (ss *SSHService) SSHConn() *ssh.ServerConn {
func (ss *Service) SSHConn() *ssh.ServerConn {
return ss.sshConn
}
func (ss *SSHService) TCPConn() net.Conn {
func (ss *Service) TCPConn() net.Conn {
return ss.tcpConn
}
func (ss *SSHService) loopReply() {
func (ss *Service) loopReply() {
for {
select {
case <-ss.closeCh:
@ -282,7 +282,7 @@ func (ss *SSHService) loopReply() {
}
}
func (ss *SSHService) loopGenerateProxy() {
func (ss *Service) loopGenerateProxy() {
log.Info("loop generate proxy start")
for {
@ -293,8 +293,8 @@ func (ss *SSHService) loopGenerateProxy() {
wg := new(sync.WaitGroup)
wg.Add(2)
var p1 SSHCmdPayload
var p2 SSHExtraPayload
var p1 CmdPayload
var p2 ExtraPayload
go func() {
defer wg.Done()
@ -346,7 +346,7 @@ func (ss *SSHService) loopGenerateProxy() {
}
}
func parseSSHExtraMessage(s string) (p SSHExtraPayload, err error) {
func parseSSHExtraMessage(s string) (p ExtraPayload, err error) {
sn := len(s)
log.Info("parse ssh extra message: %v", s)
@ -372,12 +372,12 @@ func parseSSHExtraMessage(s string) (p SSHExtraPayload, err error) {
case "tcp":
tcpCmd, err := ParseTCPCommand(ss)
if err != nil {
return SSHExtraPayload{}, fmt.Errorf("invalid ssh input: %v", err)
return ExtraPayload{}, fmt.Errorf("invalid ssh input: %v", err)
}
port, _ := strconv.Atoi(tcpCmd.Port)
p = SSHExtraPayload{
p = ExtraPayload{
Type: "tcp",
Address: tcpCmd.Address,
Port: uint32(port),
@ -385,12 +385,12 @@ func parseSSHExtraMessage(s string) (p SSHExtraPayload, err error) {
case "http":
httpCmd, err := ParseHTTPCommand(ss)
if err != nil {
return SSHExtraPayload{}, fmt.Errorf("invalid ssh input: %v", err)
return ExtraPayload{}, fmt.Errorf("invalid ssh input: %v", err)
}
_ = httpCmd
p = SSHExtraPayload{
p = ExtraPayload{
Type: "http",
}
}

View File

@ -27,7 +27,7 @@ type VirtualService struct {
pxyCfg v1.ProxyConfigurer
serverCfg v1.ServerConfig
sshSvc *SSHService
sshSvc *Service
// uniq id got from frps, attach it in loginMsg
runID string
@ -53,7 +53,7 @@ func NewVirtualService(
logMsg msg.Login,
rc *controller.ResourceController,
pxyCfg v1.ProxyConfigurer,
sshSvc *SSHService,
sshSvc *Service,
replyCh chan interface{},
) (svr *VirtualService, err error) {
svr = &VirtualService{

View File

@ -73,7 +73,6 @@ func (pxy *TCPProxy) Run() (remoteAddr string, err error) {
pxy.rc.TCPPortManager.Release(pxy.realBindPort)
}
}()
listener, errRet := net.Listen("tcp", net.JoinHostPort(pxy.serverCfg.ProxyBindAddr, strconv.Itoa(pxy.realBindPort)))
if errRet != nil {
err = errRet