Exemplo n.º 1
0
func (beacon *Beacon) keepAlive(conn ssh.Conn) (<-chan error, chan<- struct{}) {
	logger := beacon.Logger.Session("keepalive")

	errs := make(chan error, 1)

	kas := time.NewTicker(5 * time.Second)
	cancel := make(chan struct{})

	go func() {
		for {
			// ignore reply; server may just not have handled it, since there's no
			// standard keepalive request name

			_, _, err := conn.SendRequest("keepalive", true, []byte("sup"))
			if err != nil {
				logger.Error("failed", err)
				errs <- err
				return
			}

			logger.Debug("ok")

			select {
			case <-kas.C:
			case <-cancel:
				errs <- nil
				return
			}
		}
	}()

	return errs, cancel
}
Exemplo n.º 2
0
Arquivo: ssh.go Projeto: Reejoshi/cli
func keepalive(conn ssh.Conn, ticker *time.Ticker, stopCh chan struct{}) {
	for {
		select {
		case <-ticker.C:
			_, _, _ = conn.SendRequest("*****@*****.**", true, nil)
		case <-stopCh:
			ticker.Stop()
			return
		}
	}
}
Exemplo n.º 3
0
/* handleConnRequests handles proxying requests read from reqs to the SSH
connection sc.  info is used for logging */
func handleConnRequests(
	reqs <-chan *ssh.Request,
	c ssh.Conn,
	info string,
) {
	for r := range reqs {
		go handleRequest(
			r,
			func(
				name string,
				wantReply bool,
				payload []byte,
			) (bool, []byte, error) {
				return c.SendRequest(name, wantReply, payload)
			},
			func() error { return c.Close() },
			info,
		)
	}
}
Exemplo n.º 4
0
func ProxyGlobalRequests(logger lager.Logger, conn ssh.Conn, reqs <-chan *ssh.Request) {
	logger = logger.Session("proxy-global-requests")

	logger.Info("started")
	defer logger.Info("completed")

	for req := range reqs {
		logger.Info("request", lager.Data{
			"type":      req.Type,
			"wantReply": req.WantReply,
			"payload":   req.Payload,
		})
		success, reply, err := conn.SendRequest(req.Type, req.WantReply, req.Payload)
		if err != nil {
			logger.Error("send-request-failed", err)
			continue
		}

		if req.WantReply {
			req.Reply(success, reply)
		}
	}
}