-
-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
int7
committed
Oct 12, 2023
1 parent
0a0d25e
commit ea97129
Showing
3 changed files
with
75 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,10 @@ const ( | |
RequestTypeHeartbeat = "[email protected]" | ||
) | ||
|
||
// 当 proxy 失败会返回该错误 | ||
type VProxyError struct { | ||
} | ||
|
||
// parse ssh client cmds input | ||
type forwardedTCPPayload struct { | ||
Addr string | ||
|
@@ -54,7 +58,7 @@ type SSHExtraPayload struct { | |
type SSHService struct { | ||
tcpConn net.Conn | ||
cfg *ssh.ServerConfig | ||
|
||
sshConn *ssh.ServerConn | ||
gChannel <-chan ssh.NewChannel | ||
gReq <-chan *ssh.Request | ||
|
@@ -119,27 +123,25 @@ func (ss *SSHService) wait() { | |
ss.Close() | ||
} | ||
|
||
func (ss *SSHService) Exit() <-chan struct{} { | ||
return ss.closeCh | ||
} | ||
|
||
func (ss *SSHService) Close() { | ||
if atomic.LoadInt32(&ss.exit) == 1 { | ||
return | ||
} | ||
|
||
select { | ||
case _, ok := <-ss.closeCh: | ||
if ok { | ||
close(ss.closeCh) | ||
} | ||
case _, ok := <-ss.addrPayloadCh: | ||
if ok { | ||
close(ss.addrPayloadCh) | ||
} | ||
case _, ok := <-ss.extraPayloadCh: | ||
if ok { | ||
close(ss.extraPayloadCh) | ||
} | ||
case <-ss.closeCh: | ||
return | ||
default: | ||
} | ||
|
||
close(ss.closeCh) | ||
close(ss.addrPayloadCh) | ||
close(ss.extraPayloadCh) | ||
|
||
ss.sshConn.Close() | ||
ss.tcpConn.Close() | ||
|
||
|
@@ -153,10 +155,11 @@ func (ss *SSHService) loopParseCmdPayload() { | |
select { | ||
case req, ok := <-ss.gReq: | ||
if !ok { | ||
log.Warn("global request is close") | ||
log.Info("global request is close") | ||
ss.Close() | ||
return | ||
} | ||
|
||
switch req.Type { | ||
case RequestTypeForward: | ||
var addrPayload SSHCmdPayload | ||
|
@@ -166,10 +169,11 @@ func (ss *SSHService) loopParseCmdPayload() { | |
} | ||
ss.addrPayloadCh <- addrPayload | ||
|
||
// TODO | ||
err := req.Reply(true, nil) | ||
if err != nil { | ||
log.Error("reply to ssh client error: %v", err) | ||
if req.WantReply { | ||
err := req.Reply(true, nil) | ||
if err != nil { | ||
log.Error("reply to ssh client error: %v", err) | ||
} | ||
} | ||
default: | ||
if req.Type == RequestTypeHeartbeat { | ||
|
@@ -201,7 +205,7 @@ func (ss *SSHService) loopSendHeartbeat(ch ssh.Channel) { | |
} | ||
continue | ||
} | ||
log.Info("heartbeat send success, ok: %v", ok) | ||
log.Debug("heartbeat send success, ok: %v", ok) | ||
case <-ss.closeCh: | ||
return | ||
} | ||
|
@@ -252,9 +256,6 @@ func (ss *SSHService) loopParseExtraPayload() { | |
return | ||
} | ||
|
||
type VProxyError struct { | ||
} | ||
|
||
func (ss *SSHService) SSHConn() *ssh.ServerConn { | ||
return ss.sshConn | ||
} | ||
|
@@ -275,7 +276,6 @@ func (ss *SSHService) loopReply() { | |
log.Error("run frp proxy error, close ssh service") | ||
ss.Close() | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
@@ -421,10 +421,6 @@ func ParseHTTPCommand(params []string) (*HTTPCommand, error) { | |
return httpCmd, nil | ||
} | ||
|
||
type nullWriter struct{} | ||
|
||
func (w *nullWriter) Write(p []byte) (n int, err error) { return len(p), nil } | ||
|
||
type TCPCommand struct { | ||
Address string | ||
Port string | ||
|
@@ -467,3 +463,7 @@ func ParseTCPCommand(params []string) (*TCPCommand, error) { | |
} | ||
return tcpCmd, nil | ||
} | ||
|
||
type nullWriter struct{} | ||
|
||
func (w *nullWriter) Write(p []byte) (n int, err error) { return len(p), nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters