Jiri Simsa | 756772c | 2015-03-25 15:40:54 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Vanadium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Todd Wang | 8c4e5cc | 2015-04-09 11:30:52 -0700 | [diff] [blame] | 5 | // Package tunnel defines an interface for creating a network tunnel from client |
| 6 | // to server. |
Jiri Simsa | d5aae83 | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 7 | package tunnel |
| 8 | |
Todd Wang | 387d8a4 | 2015-03-30 17:09:05 -0700 | [diff] [blame] | 9 | import "v.io/v23/security/access" |
Jiri Simsa | d5aae83 | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 10 | |
Jiri Simsa | d5aae83 | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 11 | type Tunnel interface { |
| 12 | // The Forward method is used for network forwarding. All the data sent over |
| 13 | // the byte stream is forwarded to the requested network address and all the |
| 14 | // data received from that network connection is sent back in the reply |
| 15 | // stream. |
Asim Shankar | 4794c93 | 2014-11-24 17:45:56 -0800 | [diff] [blame] | 16 | Forward(network, address string) stream<[]byte, []byte> error {access.Admin} |
Jiri Simsa | d5aae83 | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 17 | |
| 18 | // The Shell method is used to either run shell commands remotely, or to open |
| 19 | // an interactive shell. The data received over the byte stream is sent to the |
| 20 | // shell's stdin, and the data received from the shell's stdout and stderr is |
| 21 | // sent back in the reply stream. It returns the exit status of the shell |
| 22 | // command. |
Todd Wang | 8d1a559 | 2014-12-17 18:13:34 -0800 | [diff] [blame] | 23 | Shell(command string, shellOpts ShellOpts) stream<ClientShellPacket, ServerShellPacket> (int32 | error) {access.Admin} |
Jiri Simsa | d5aae83 | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | type ShellOpts struct { |
Robin Thellend | c14adc9 | 2015-02-11 13:02:19 -0800 | [diff] [blame] | 27 | UsePty bool // Whether to open a pseudo-terminal. |
| 28 | Environment []string // Environment variables to pass to the remote shell. |
| 29 | WinSize WindowSize // The size of the window. |
Jiri Simsa | d5aae83 | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Robin Thellend | c14adc9 | 2015-02-11 13:02:19 -0800 | [diff] [blame] | 32 | type WindowSize struct { |
| 33 | Rows, Cols uint16 |
| 34 | } |
| 35 | |
| 36 | type ClientShellPacket union { |
Robin Thellend | 9faaef3 | 2014-08-01 19:45:40 -0700 | [diff] [blame] | 37 | // Bytes going to the shell's stdin. |
| 38 | Stdin []byte |
Robin Thellend | c14adc9 | 2015-02-11 13:02:19 -0800 | [diff] [blame] | 39 | // Indicates that stdin should be closed. The presence of this field indicates |
| 40 | // EOF. Its actual value is ignored. |
Todd Wang | 53a4e2e | 2015-03-18 10:54:54 -0700 | [diff] [blame] | 41 | EndOfFile unused |
Robin Thellend | c14adc9 | 2015-02-11 13:02:19 -0800 | [diff] [blame] | 42 | // A dynamic update of the window size. |
| 43 | WinSize WindowSize |
Jiri Simsa | d5aae83 | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Robin Thellend | c14adc9 | 2015-02-11 13:02:19 -0800 | [diff] [blame] | 46 | type unused struct {} |
| 47 | |
| 48 | type ServerShellPacket union { |
Robin Thellend | 9faaef3 | 2014-08-01 19:45:40 -0700 | [diff] [blame] | 49 | // Bytes coming from the shell's stdout. |
| 50 | Stdout []byte |
| 51 | // Bytes coming from the shell's stderr. |
| 52 | Stderr []byte |
Jiri Simsa | d5aae83 | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 53 | } |