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.msgDispatcher = msg.NewDispatcher(cryptoRW)
ctl.registerMsgHandlers() ctl.registerMsgHandlers()
ctl.msgTransporter = transport.NewMessageTransporter(ctl.msgDispatcher.SendChannel()) ctl.msgTransporter = transport.NewMessageTransporter(ctl.msgDispatcher.SendChannel())
ctl.pm = proxy.NewManager(ctl.ctx, clientCfg, ctl.msgTransporter) ctl.pm = proxy.NewManager(ctl.ctx, clientCfg, ctl.msgTransporter)
@ -134,12 +133,10 @@ func (ctl *Control) handleReqWorkConn(_ msg.Message) {
m := &msg.NewWorkConn{ m := &msg.NewWorkConn{
RunID: ctl.runID, RunID: ctl.runID,
} }
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
} }
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()
@ -152,7 +149,6 @@ func (ctl *Control) handleReqWorkConn(_ msg.Message) {
workConn.Close() workConn.Close()
return return
} }
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()
@ -165,9 +161,7 @@ func (ctl *Control) handleReqWorkConn(_ msg.Message) {
func (ctl *Control) handleNewProxyResp(m msg.Message) { func (ctl *Control) handleNewProxyResp(m msg.Message) {
xl := ctl.xl xl := ctl.xl
inMsg := m.(*msg.NewProxyResp) inMsg := m.(*msg.NewProxyResp)
// Server will return NewProxyResp message to each NewProxy message. // Server will return NewProxyResp message to each NewProxy message.
// Start a new proxy handler if no error got // Start a new proxy handler if no error got
err := ctl.pm.StartProxy(inMsg.ProxyName, inMsg.RemoteAddr, inMsg.Error) err := ctl.pm.StartProxy(inMsg.ProxyName, inMsg.RemoteAddr, inMsg.Error)

View File

@ -199,7 +199,6 @@ func (pw *Wrapper) 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(&event.StartProxyPayload{ _ = pw.handler(&event.StartProxyPayload{
NewProxyMsg: &newProxyMsg, NewProxyMsg: &newProxyMsg,
}) })

View File

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

View File

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

View File

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

View File

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