func newSession(ctx context.Context, client *ssh.Client, withTerminal bool) (*Session, error) {
	sshSess, err := client.NewSession()
	if err != nil {
		client.Close()
		return nil, fmt.Errorf("failed to initialise session: %s", err)
	}
	stdin, err := sshSess.StdinPipe()
	if err != nil {
		return nil, fmt.Errorf("failed to get the session stdin pipe: %s", err)
	}
	if withTerminal {
		err = sshSess.RequestPty("xterm", 80, 40,
			ssh.TerminalModes{
				ssh.ECHO:          0,      
				ssh.TTY_OP_ISPEED: 14400,  
				ssh.TTY_OP_OSPEED: 14400,  
			},
		)
		if err != nil {
			return nil, fmt.Errorf("failed to setup the pseudo terminal: %s", err)
		}
	}
	quitChan := make(chan struct{})
	sess := Session{sshSess: sshSess, stdin: stdin, sigintHandlerQuitChan: quitChan}
	go func() {
		select {
		case <-ctx.Done():
			if withTerminal {
				_, err := stdin.Write([]byte("\x03"))
				if err != nil && err != io.EOF {
					log.Warnf("Failed to send SIGINT to the remote process: %s", err)
				}
			}
			err := sess.CloseStdin()
			if err != nil {
				log.Warnf("Failed to close session stdin: %s", err)
			}
			err = ctx.Err()
			if err == context.DeadlineExceeded {
				log.Warnf("Context deadline exceeeded on server: %s", client.RemoteAddr())
			}
		case <-quitChan:
		}
	}()
	return &sess, nil
}
newSession creates a new session
package transport
import (
	"context"
	"fmt"
	"io"
	"sync"
	"time"
	"github.com/mihaitodor/wormhole/inventory"
	log "github.com/sirupsen/logrus"
	"golang.org/x/crypto/ssh"
	"golang.org/x/sync/errgroup"
)
type Session struct {
	sshSess               *ssh.Session
	onceStdinCloser       sync.Once
	stdin                 io.WriteCloser
	sigintHandlerQuitChan chan struct{}
}
func (s *Session) Start(cmd string) error {
	return s.sshSess.Start(cmd)
}
func (s *Session) wait() error {
	return s.sshSess.Wait()
}
func (s *Session) Stdin() io.Writer {
	return s.stdin
}
func (s *Session) CloseStdin() error {
	var err error
	s.onceStdinCloser.Do(func() {
		err = s.stdin.Close()
	})
	return err
}
func (s *Session) close() error {
	if s.sigintHandlerQuitChan != nil {
		close(s.sigintHandlerQuitChan)
	}
	err := s.CloseStdin()
	if err != nil {
		return fmt.Errorf("failed to close stdin: %s", err)
	}
	err = s.sshSess.Close()
	if err != nil {
		return fmt.Errorf("failed to close session: %s", err)
	}
	return nil
}