Skip to content

Commit

Permalink
fix: remove useless change
Browse files Browse the repository at this point in the history
  • Loading branch information
int7 committed Nov 10, 2023
1 parent e68f1ca commit 40677ce
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
6 changes: 0 additions & 6 deletions client/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion client/proxy/proxy_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
1 change: 0 additions & 1 deletion pkg/config/legacy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
54 changes: 27 additions & 27 deletions pkg/ssh/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,31 @@ 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
Address string
Port uint32
}

type SSHService struct {
type Service struct {
tcpConn net.Conn
cfg *ssh.ServerConfig

sshConn *ssh.ServerConn
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{}
Expand All @@ -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,
Expand All @@ -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
}
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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 {
Expand Down Expand Up @@ -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:
Expand All @@ -282,7 +282,7 @@ func (ss *SSHService) loopReply() {
}
}

func (ss *SSHService) loopGenerateProxy() {
func (ss *Service) loopGenerateProxy() {
log.Info("loop generate proxy start")

for {
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -372,25 +372,25 @@ 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),
}
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",
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ssh/vclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand Down
1 change: 0 additions & 1 deletion server/proxy/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 40677ce

Please sign in to comment.