当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.SendRequest方法代码示例

本文整理汇总了Golang中golang.org/x/crypto/ssh.Client.SendRequest方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.SendRequest方法的具体用法?Golang Client.SendRequest怎么用?Golang Client.SendRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在golang.org/x/crypto/ssh.Client的用法示例。


在下文中一共展示了Client.SendRequest方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: sendSshKeepAlive

// sendSshKeepAlive is a helper which sends a [email protected] request
// on the specified SSH connections and returns true of the request succeeds
// within a specified timeout.
func sendSshKeepAlive(
	sshClient *ssh.Client, conn net.Conn, timeout time.Duration) error {

	errChannel := make(chan error, 2)
	if timeout > 0 {
		time.AfterFunc(timeout, func() {
			errChannel <- TimeoutError{}
		})
	}

	go func() {
		// Random padding to frustrate fingerprinting
		_, _, err := sshClient.SendRequest(
			"[email protected]", true,
			MakeSecureRandomPadding(0, TUNNEL_SSH_KEEP_ALIVE_PAYLOAD_MAX_BYTES))
		errChannel <- err
	}()

	err := <-errChannel
	if err != nil {
		sshClient.Close()
		conn.Close()
	}

	return ContextError(err)
}
开发者ID:yangguangyu,项目名称:psiphon-tunnel-core,代码行数:29,代码来源:tunnel.go

示例2: sendSshKeepAlive

// sendSshKeepAlive is a helper which sends a [email protected] request
// on the specified SSH connections and returns true of the request succeeds
// within a specified timeout.
func sendSshKeepAlive(sshClient *ssh.Client) error {

	errChannel := make(chan error, 2)
	time.AfterFunc(TUNNEL_SSH_KEEP_ALIVE_TIMEOUT, func() {
		errChannel <- TimeoutError{}
	})

	go func() {
		// Random padding to frustrate fingerprinting
		_, _, err := sshClient.SendRequest(
			"[email protected]", true,
			MakeSecureRandomPadding(0, TUNNEL_SSH_KEEP_ALIVE_PAYLOAD_MAX_BYTES))
		errChannel <- err
	}()

	return ContextError(<-errChannel)
}
开发者ID:clonly,项目名称:psiphon-tunnel-core,代码行数:20,代码来源:tunnel.go

示例3: SSHls

func SSHls(client *ssh.Client) ([]string, error) {
	defer trace.End(trace.Begin(""))

	ok, reply, err := client.SendRequest(msgs.ContainersReq, true, nil)
	if !ok || err != nil {
		return nil, fmt.Errorf("failed to get container IDs from remote: %s", err)
	}

	ids := msgs.ContainersMsg{}

	if err = ids.Unmarshal(reply); err != nil {
		log.Debugf("raw IDs response: %+v", reply)
		return nil, fmt.Errorf("failed to unmarshal ids from remote: %s", err)
	}

	return ids.IDs, nil
}
开发者ID:vmware,项目名称:vic,代码行数:17,代码来源:client.go

示例4:

					client.Close()
				})

				Context("when the client sends a global request", func() {
					var globalRequestHandler *fake_handlers.FakeGlobalRequestHandler

					BeforeEach(func() {
						globalRequestHandler = &fake_handlers.FakeGlobalRequestHandler{}
						globalRequestHandler.HandleRequestStub = func(logger lager.Logger, request *ssh.Request) {
							request.Reply(true, []byte("response-payload"))
						}
						daemonGlobalRequestHandlers["test-global-request"] = globalRequestHandler
					})

					It("gets forwarded to the daemon and the response comes back", func() {
						accepted, response, err := client.SendRequest("test-global-request", true, []byte("request-payload"))
						Expect(err).NotTo(HaveOccurred())
						Expect(accepted).To(BeTrue())
						Expect(response).To(Equal([]byte("response-payload")))

						Expect(globalRequestHandler.HandleRequestCallCount()).To(Equal(1))

						_, request := globalRequestHandler.HandleRequestArgsForCall(0)
						Expect(request.Type).To(Equal("test-global-request"))
						Expect(request.WantReply).To(BeTrue())
						Expect(request.Payload).To(Equal([]byte("request-payload")))
					})
				})

				Context("when the client requests a new channel", func() {
					var newChannelHandler *fake_handlers.FakeNewChannelHandler
开发者ID:sykesm,项目名称:diego-ssh,代码行数:31,代码来源:proxy_test.go

示例5:

		AfterEach(func() {
			client.Close()
		})

		Context("when a global request is recevied", func() {
			var (
				accepted   bool
				requestErr error

				name      string
				wantReply bool
			)

			JustBeforeEach(func() {
				accepted, _, requestErr = client.SendRequest(name, wantReply, []byte("payload"))
			})

			Context("and there is an associated handler", func() {
				BeforeEach(func() {
					name = "known-handler"
					wantReply = true

					fakeHandler.HandleRequestStub = func(logger lager.Logger, request *ssh.Request) {
						request.Reply(true, []byte("response"))
					}
				})

				It("calls the handler to handle the request", func() {
					Eventually(fakeHandler.HandleRequestCallCount).Should(Equal(1))
				})
开发者ID:benjaminharnett,项目名称:diego-ssh,代码行数:30,代码来源:daemon_test.go


注:本文中的golang.org/x/crypto/ssh.Client.SendRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。