return error on client.Run

master
Dingjun 8 years ago
parent 7848013c7f
commit bce4a81a51

@ -1,6 +1,7 @@
package obfssh package obfssh
import ( import (
"fmt"
socks "github.com/fangdingjun/socks-go" socks "github.com/fangdingjun/socks-go"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/crypto/ssh/terminal"
@ -18,6 +19,7 @@ type Client struct {
client *ssh.Client client *ssh.Client
listeners []net.Listener listeners []net.Listener
ch chan struct{} ch chan struct{}
err error
} }
// NewClient create a new ssh Client // NewClient create a new ssh Client
@ -63,7 +65,7 @@ func (cc *Client) Client() *ssh.Client {
} }
// Run wait ssh connection to finish // Run wait ssh connection to finish
func (cc *Client) Run() { func (cc *Client) Run() error {
select { select {
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
} }
@ -87,6 +89,7 @@ func (cc *Client) Run() {
} }
Log(DEBUG, "Done") Log(DEBUG, "Done")
cc.Close() cc.Close()
return cc.err
} }
// Close close the ssh connection // Close close the ssh connection
@ -301,6 +304,7 @@ func (cc *Client) keepAlive(interval time.Duration, maxCount int) {
count = 0 count = 0
} }
if count >= maxCount { if count >= maxCount {
cc.err = fmt.Errorf("keep alive detects connection hang up")
Log(ERROR, "keep alive hit max count, exit") Log(ERROR, "keep alive hit max count, exit")
cc.sshConn.Close() cc.sshConn.Close()
// send exit signal // send exit signal
@ -319,6 +323,7 @@ func (cc *Client) registerSignal() {
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM) signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
select { select {
case s1 := <-c: case s1 := <-c:
cc.err = fmt.Errorf("signal %v", s1)
Log(ERROR, "signal %d received, exit", s1) Log(ERROR, "signal %d received, exit", s1)
select { select {
case cc.ch <- struct{}{}: case cc.ch <- struct{}{}:

Loading…
Cancel
Save