/
tunnel.vdl.go
1489 lines (1352 loc) · 46.8 KB
/
tunnel.vdl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file was auto-generated by the vanadium vdl tool.
// Package: tunnel
// Package tunnel defines an interface for creating a network tunnel from client
// to server.
//nolint:golint
package tunnel
import (
"fmt"
"io"
v23 "v.io/v23"
"v.io/v23/context"
"v.io/v23/rpc"
"v.io/v23/security/access"
"v.io/v23/vdl"
)
var _ = initializeVDL() // Must be first; see initializeVDL comments for details.
// Type definitions
// ================
type WindowSize struct {
Rows uint16
Cols uint16
}
func (WindowSize) VDLReflect(struct {
Name string `vdl:"v.io/x/ref/examples/tunnel.WindowSize"`
}) {
}
func (x WindowSize) VDLIsZero() bool { //nolint:gocyclo
return x == WindowSize{}
}
func (x WindowSize) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct1); err != nil {
return err
}
if x.Rows != 0 {
if err := enc.NextFieldValueUint(0, vdl.Uint16Type, uint64(x.Rows)); err != nil {
return err
}
}
if x.Cols != 0 {
if err := enc.NextFieldValueUint(1, vdl.Uint16Type, uint64(x.Cols)); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x *WindowSize) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = WindowSize{}
if err := dec.StartValue(vdlTypeStruct1); err != nil {
return err
}
decType := dec.Type()
for {
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return dec.FinishValue()
}
if decType != vdlTypeStruct1 {
index = vdlTypeStruct1.FieldIndexByName(decType.Field(index).Name)
if index == -1 {
if err := dec.SkipValue(); err != nil {
return err
}
continue
}
}
switch index {
case 0:
switch value, err := dec.ReadValueUint(16); {
case err != nil:
return err
default:
x.Rows = uint16(value)
}
case 1:
switch value, err := dec.ReadValueUint(16); {
case err != nil:
return err
default:
x.Cols = uint16(value)
}
}
}
}
type ShellOpts struct {
UsePty bool // Whether to open a pseudo-terminal.
Environment []string // Environment variables to pass to the remote shell.
WinSize WindowSize // The size of the window.
}
func (ShellOpts) VDLReflect(struct {
Name string `vdl:"v.io/x/ref/examples/tunnel.ShellOpts"`
}) {
}
func (x ShellOpts) VDLIsZero() bool { //nolint:gocyclo
if x.UsePty {
return false
}
if len(x.Environment) != 0 {
return false
}
if x.WinSize != (WindowSize{}) {
return false
}
return true
}
func (x ShellOpts) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct2); err != nil {
return err
}
if x.UsePty {
if err := enc.NextFieldValueBool(0, vdl.BoolType, x.UsePty); err != nil {
return err
}
}
if len(x.Environment) != 0 {
if err := enc.NextField(1); err != nil {
return err
}
if err := vdlWriteAnonList1(enc, x.Environment); err != nil {
return err
}
}
if x.WinSize != (WindowSize{}) {
if err := enc.NextField(2); err != nil {
return err
}
if err := x.WinSize.VDLWrite(enc); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func vdlWriteAnonList1(enc vdl.Encoder, x []string) error {
if err := enc.StartValue(vdlTypeList3); err != nil {
return err
}
if err := enc.SetLenHint(len(x)); err != nil {
return err
}
for _, elem := range x {
if err := enc.NextEntryValueString(vdl.StringType, elem); err != nil {
return err
}
}
if err := enc.NextEntry(true); err != nil {
return err
}
return enc.FinishValue()
}
func (x *ShellOpts) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = ShellOpts{}
if err := dec.StartValue(vdlTypeStruct2); err != nil {
return err
}
decType := dec.Type()
for {
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return dec.FinishValue()
}
if decType != vdlTypeStruct2 {
index = vdlTypeStruct2.FieldIndexByName(decType.Field(index).Name)
if index == -1 {
if err := dec.SkipValue(); err != nil {
return err
}
continue
}
}
switch index {
case 0:
switch value, err := dec.ReadValueBool(); {
case err != nil:
return err
default:
x.UsePty = value
}
case 1:
if err := vdlReadAnonList1(dec, &x.Environment); err != nil {
return err
}
case 2:
if err := x.WinSize.VDLRead(dec); err != nil {
return err
}
}
}
}
func vdlReadAnonList1(dec vdl.Decoder, x *[]string) error {
if err := dec.StartValue(vdlTypeList3); err != nil {
return err
}
if len := dec.LenHint(); len > 0 {
*x = make([]string, 0, len)
} else {
*x = nil
}
for {
switch done, elem, err := dec.NextEntryValueString(); {
case err != nil:
return err
case done:
return dec.FinishValue()
default:
*x = append(*x, elem)
}
}
}
// TODO(toddw): Replace Unused with the unnamed empty struct{}.
type Unused struct {
}
func (Unused) VDLReflect(struct {
Name string `vdl:"v.io/x/ref/examples/tunnel.Unused"`
}) {
}
func (x Unused) VDLIsZero() bool { //nolint:gocyclo
return x == Unused{}
}
func (x Unused) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct4); err != nil {
return err
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x *Unused) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = Unused{}
if err := dec.StartValue(vdlTypeStruct4); err != nil {
return err
}
decType := dec.Type()
for {
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return dec.FinishValue()
}
if decType != vdlTypeStruct4 {
index = vdlTypeStruct4.FieldIndexByName(decType.Field(index).Name)
if index == -1 {
if err := dec.SkipValue(); err != nil {
return err
}
continue
}
}
switch index {
}
}
}
type (
// ClientShellPacket represents any single field of the ClientShellPacket union type.
ClientShellPacket interface {
// Index returns the field index.
Index() int
// Interface returns the field value as an interface.
Interface() interface{}
// Name returns the field name.
Name() string
// VDLReflect describes the ClientShellPacket union type.
VDLReflect(vdlClientShellPacketReflect)
VDLIsZero() bool
VDLWrite(vdl.Encoder) error
}
// ClientShellPacketStdin represents field Stdin of the ClientShellPacket union type.
//
// Bytes going to the shell's stdin.
ClientShellPacketStdin struct{ Value []byte }
// ClientShellPacketEndOfFile represents field EndOfFile of the ClientShellPacket union type.
//
// Indicates that stdin should be closed. The presence of this field indicates
// EOF. Its actual value is ignored.
ClientShellPacketEndOfFile struct{ Value Unused }
// ClientShellPacketWinSize represents field WinSize of the ClientShellPacket union type.
//
// A dynamic update of the window size.
ClientShellPacketWinSize struct{ Value WindowSize }
// vdlClientShellPacketReflect describes the ClientShellPacket union type.
vdlClientShellPacketReflect struct {
Name string `vdl:"v.io/x/ref/examples/tunnel.ClientShellPacket"`
Type ClientShellPacket
Union struct {
Stdin ClientShellPacketStdin
EndOfFile ClientShellPacketEndOfFile
WinSize ClientShellPacketWinSize
}
}
)
func (x ClientShellPacketStdin) Index() int { return 0 }
func (x ClientShellPacketStdin) Interface() interface{} { return x.Value }
func (x ClientShellPacketStdin) Name() string { return "Stdin" }
func (x ClientShellPacketStdin) VDLReflect(vdlClientShellPacketReflect) {}
func (x ClientShellPacketEndOfFile) Index() int { return 1 }
func (x ClientShellPacketEndOfFile) Interface() interface{} { return x.Value }
func (x ClientShellPacketEndOfFile) Name() string { return "EndOfFile" }
func (x ClientShellPacketEndOfFile) VDLReflect(vdlClientShellPacketReflect) {}
func (x ClientShellPacketWinSize) Index() int { return 2 }
func (x ClientShellPacketWinSize) Interface() interface{} { return x.Value }
func (x ClientShellPacketWinSize) Name() string { return "WinSize" }
func (x ClientShellPacketWinSize) VDLReflect(vdlClientShellPacketReflect) {}
func (x ClientShellPacketStdin) VDLIsZero() bool { //nolint:gocyclo
return len(x.Value) == 0
}
func (x ClientShellPacketEndOfFile) VDLIsZero() bool {
return false
}
func (x ClientShellPacketWinSize) VDLIsZero() bool {
return false
}
func (x ClientShellPacketStdin) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeUnion6); err != nil {
return err
}
if err := enc.NextFieldValueBytes(0, vdlTypeList5, x.Value); err != nil {
return err
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x ClientShellPacketEndOfFile) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeUnion6); err != nil {
return err
}
if err := enc.NextField(1); err != nil {
return err
}
if err := x.Value.VDLWrite(enc); err != nil {
return err
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x ClientShellPacketWinSize) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeUnion6); err != nil {
return err
}
if err := enc.NextField(2); err != nil {
return err
}
if err := x.Value.VDLWrite(enc); err != nil {
return err
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func VDLReadClientShellPacket(dec vdl.Decoder, x *ClientShellPacket) error { //nolint:gocyclo
if err := dec.StartValue(vdlTypeUnion6); err != nil {
return err
}
decType := dec.Type()
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return fmt.Errorf("missing field in union %T, from %v", x, decType)
}
if decType != vdlTypeUnion6 {
name := decType.Field(index).Name
index = vdlTypeUnion6.FieldIndexByName(name)
if index == -1 {
return fmt.Errorf("field %q not in union %T, from %v", name, x, decType)
}
}
switch index {
case 0:
var field ClientShellPacketStdin
if err := dec.ReadValueBytes(-1, &field.Value); err != nil {
return err
}
*x = field
case 1:
var field ClientShellPacketEndOfFile
if err := field.Value.VDLRead(dec); err != nil {
return err
}
*x = field
case 2:
var field ClientShellPacketWinSize
if err := field.Value.VDLRead(dec); err != nil {
return err
}
*x = field
}
switch index, err := dec.NextField(); {
case err != nil:
return err
case index != -1:
return fmt.Errorf("extra field %d in union %T, from %v", index, x, dec.Type())
}
return dec.FinishValue()
}
type (
// ServerShellPacket represents any single field of the ServerShellPacket union type.
ServerShellPacket interface {
// Index returns the field index.
Index() int
// Interface returns the field value as an interface.
Interface() interface{}
// Name returns the field name.
Name() string
// VDLReflect describes the ServerShellPacket union type.
VDLReflect(vdlServerShellPacketReflect)
VDLIsZero() bool
VDLWrite(vdl.Encoder) error
}
// ServerShellPacketStdout represents field Stdout of the ServerShellPacket union type.
//
// Bytes coming from the shell's stdout.
ServerShellPacketStdout struct{ Value []byte }
// ServerShellPacketStderr represents field Stderr of the ServerShellPacket union type.
//
// Bytes coming from the shell's stderr.
ServerShellPacketStderr struct{ Value []byte }
// vdlServerShellPacketReflect describes the ServerShellPacket union type.
vdlServerShellPacketReflect struct {
Name string `vdl:"v.io/x/ref/examples/tunnel.ServerShellPacket"`
Type ServerShellPacket
Union struct {
Stdout ServerShellPacketStdout
Stderr ServerShellPacketStderr
}
}
)
func (x ServerShellPacketStdout) Index() int { return 0 }
func (x ServerShellPacketStdout) Interface() interface{} { return x.Value }
func (x ServerShellPacketStdout) Name() string { return "Stdout" }
func (x ServerShellPacketStdout) VDLReflect(vdlServerShellPacketReflect) {}
func (x ServerShellPacketStderr) Index() int { return 1 }
func (x ServerShellPacketStderr) Interface() interface{} { return x.Value }
func (x ServerShellPacketStderr) Name() string { return "Stderr" }
func (x ServerShellPacketStderr) VDLReflect(vdlServerShellPacketReflect) {}
func (x ServerShellPacketStdout) VDLIsZero() bool { //nolint:gocyclo
return len(x.Value) == 0
}
func (x ServerShellPacketStderr) VDLIsZero() bool {
return false
}
func (x ServerShellPacketStdout) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeUnion7); err != nil {
return err
}
if err := enc.NextFieldValueBytes(0, vdlTypeList5, x.Value); err != nil {
return err
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x ServerShellPacketStderr) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeUnion7); err != nil {
return err
}
if err := enc.NextFieldValueBytes(1, vdlTypeList5, x.Value); err != nil {
return err
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func VDLReadServerShellPacket(dec vdl.Decoder, x *ServerShellPacket) error { //nolint:gocyclo
if err := dec.StartValue(vdlTypeUnion7); err != nil {
return err
}
decType := dec.Type()
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return fmt.Errorf("missing field in union %T, from %v", x, decType)
}
if decType != vdlTypeUnion7 {
name := decType.Field(index).Name
index = vdlTypeUnion7.FieldIndexByName(name)
if index == -1 {
return fmt.Errorf("field %q not in union %T, from %v", name, x, decType)
}
}
switch index {
case 0:
var field ServerShellPacketStdout
if err := dec.ReadValueBytes(-1, &field.Value); err != nil {
return err
}
*x = field
case 1:
var field ServerShellPacketStderr
if err := dec.ReadValueBytes(-1, &field.Value); err != nil {
return err
}
*x = field
}
switch index, err := dec.NextField(); {
case err != nil:
return err
case index != -1:
return fmt.Errorf("extra field %d in union %T, from %v", index, x, dec.Type())
}
return dec.FinishValue()
}
// Interface definitions
// =====================
// TunnelClientMethods is the client interface
// containing Tunnel methods.
type TunnelClientMethods interface {
// The Forward method is used for network forwarding. All the data sent over
// the byte stream is forwarded to the requested network address and all the
// data received from that network connection is sent back on the reply
// stream.
Forward(_ *context.T, network string, address string, _ ...rpc.CallOpt) (TunnelForwardClientCall, error)
// The ReverseForward method is used for network forwarding from the server
// back to the client. The server process listens on the requested network
// address, forwarding all connections by calling Forwarder.Forward on the
// caller.
ReverseForward(_ *context.T, network string, address string, _ ...rpc.CallOpt) error
// The Shell method is used to either run shell commands remotely, or to open
// an interactive shell. The data received over the byte stream is sent to the
// shell's stdin, and the data received from the shell's stdout and stderr is
// sent back in the reply stream. It returns the exit status of the shell
// command as an integer exit code and a human readable string.
Shell(_ *context.T, command string, shellOpts ShellOpts, _ ...rpc.CallOpt) (TunnelShellClientCall, error)
}
// TunnelClientStub embeds TunnelClientMethods and is a
// placeholder for additional management operations.
type TunnelClientStub interface {
TunnelClientMethods
}
// TunnelClient returns a client stub for Tunnel.
func TunnelClient(name string) TunnelClientStub {
return implTunnelClientStub{name}
}
type implTunnelClientStub struct {
name string
}
func (c implTunnelClientStub) Forward(ctx *context.T, i0 string, i1 string, opts ...rpc.CallOpt) (ocall TunnelForwardClientCall, err error) {
var call rpc.ClientCall
if call, err = v23.GetClient(ctx).StartCall(ctx, c.name, "Forward", []interface{}{i0, i1}, opts...); err != nil {
return
}
ocall = &implTunnelForwardClientCall{ClientCall: call}
return
}
func (c implTunnelClientStub) ReverseForward(ctx *context.T, i0 string, i1 string, opts ...rpc.CallOpt) (err error) {
err = v23.GetClient(ctx).Call(ctx, c.name, "ReverseForward", []interface{}{i0, i1}, nil, opts...)
return
}
func (c implTunnelClientStub) Shell(ctx *context.T, i0 string, i1 ShellOpts, opts ...rpc.CallOpt) (ocall TunnelShellClientCall, err error) {
var call rpc.ClientCall
if call, err = v23.GetClient(ctx).StartCall(ctx, c.name, "Shell", []interface{}{i0, i1}, opts...); err != nil {
return
}
ocall = &implTunnelShellClientCall{ClientCall: call}
return
}
// TunnelForwardClientStream is the client stream for Tunnel.Forward.
type TunnelForwardClientStream interface {
// RecvStream returns the receiver side of the Tunnel.Forward client stream.
RecvStream() interface {
// Advance stages an item so that it may be retrieved via Value. Returns
// true iff there is an item to retrieve. Advance must be called before
// Value is called. May block if an item is not available.
Advance() bool
// Value returns the item that was staged by Advance. May panic if Advance
// returned false or was not called. Never blocks.
Value() []byte
// Err returns any error encountered by Advance. Never blocks.
Err() error
}
// SendStream returns the send side of the Tunnel.Forward client stream.
SendStream() interface {
// Send places the item onto the output stream. Returns errors
// encountered while sending, or if Send is called after Close or
// the stream has been canceled. Blocks if there is no buffer
// space; will unblock when buffer space is available or after
// the stream has been canceled.
Send(item []byte) error
// Close indicates to the server that no more items will be sent;
// server Recv calls will receive io.EOF after all sent items.
// This is an optional call - e.g. a client might call Close if it
// needs to continue receiving items from the server after it's
// done sending. Returns errors encountered while closing, or if
// Close is called after the stream has been canceled. Like Send,
// blocks if there is no buffer space available.
Close() error
}
}
// TunnelForwardClientCall represents the call returned from Tunnel.Forward.
type TunnelForwardClientCall interface {
TunnelForwardClientStream
// Finish performs the equivalent of SendStream().Close, then blocks until
// the server is done, and returns the positional return values for the call.
//
// Finish returns immediately if the call has been canceled; depending on the
// timing the output could either be an error signaling cancelation, or the
// valid positional return values from the server.
//
// Calling Finish is mandatory for releasing stream resources, unless the call
// has been canceled or any of the other methods return an error. Finish should
// be called at most once.
Finish() error
}
type implTunnelForwardClientCall struct {
rpc.ClientCall
valRecv []byte
errRecv error
}
func (c *implTunnelForwardClientCall) RecvStream() interface {
Advance() bool
Value() []byte
Err() error
} {
return implTunnelForwardClientCallRecv{c}
}
type implTunnelForwardClientCallRecv struct {
c *implTunnelForwardClientCall
}
func (c implTunnelForwardClientCallRecv) Advance() bool {
c.c.errRecv = c.c.Recv(&c.c.valRecv)
return c.c.errRecv == nil
}
func (c implTunnelForwardClientCallRecv) Value() []byte {
return c.c.valRecv
}
func (c implTunnelForwardClientCallRecv) Err() error {
if c.c.errRecv == io.EOF {
return nil
}
return c.c.errRecv
}
func (c *implTunnelForwardClientCall) SendStream() interface {
Send(item []byte) error
Close() error
} {
return implTunnelForwardClientCallSend{c}
}
type implTunnelForwardClientCallSend struct {
c *implTunnelForwardClientCall
}
func (c implTunnelForwardClientCallSend) Send(item []byte) error {
return c.c.Send(item)
}
func (c implTunnelForwardClientCallSend) Close() error {
return c.c.CloseSend()
}
func (c *implTunnelForwardClientCall) Finish() (err error) {
err = c.ClientCall.Finish()
return
}
// TunnelShellClientStream is the client stream for Tunnel.Shell.
type TunnelShellClientStream interface {
// RecvStream returns the receiver side of the Tunnel.Shell client stream.
RecvStream() interface {
// Advance stages an item so that it may be retrieved via Value. Returns
// true iff there is an item to retrieve. Advance must be called before
// Value is called. May block if an item is not available.
Advance() bool
// Value returns the item that was staged by Advance. May panic if Advance
// returned false or was not called. Never blocks.
Value() ServerShellPacket
// Err returns any error encountered by Advance. Never blocks.
Err() error
}
// SendStream returns the send side of the Tunnel.Shell client stream.
SendStream() interface {
// Send places the item onto the output stream. Returns errors
// encountered while sending, or if Send is called after Close or
// the stream has been canceled. Blocks if there is no buffer
// space; will unblock when buffer space is available or after
// the stream has been canceled.
Send(item ClientShellPacket) error
// Close indicates to the server that no more items will be sent;
// server Recv calls will receive io.EOF after all sent items.
// This is an optional call - e.g. a client might call Close if it
// needs to continue receiving items from the server after it's
// done sending. Returns errors encountered while closing, or if
// Close is called after the stream has been canceled. Like Send,
// blocks if there is no buffer space available.
Close() error
}
}
// TunnelShellClientCall represents the call returned from Tunnel.Shell.
type TunnelShellClientCall interface {
TunnelShellClientStream
// Finish performs the equivalent of SendStream().Close, then blocks until
// the server is done, and returns the positional return values for the call.
//
// Finish returns immediately if the call has been canceled; depending on the
// timing the output could either be an error signaling cancelation, or the
// valid positional return values from the server.
//
// Calling Finish is mandatory for releasing stream resources, unless the call
// has been canceled or any of the other methods return an error. Finish should
// be called at most once.
Finish() (exitCode int32, exitMsg string, _ error)
}
type implTunnelShellClientCall struct {
rpc.ClientCall
valRecv ServerShellPacket
errRecv error
}
func (c *implTunnelShellClientCall) RecvStream() interface {
Advance() bool
Value() ServerShellPacket
Err() error
} {
return implTunnelShellClientCallRecv{c}
}
type implTunnelShellClientCallRecv struct {
c *implTunnelShellClientCall
}
func (c implTunnelShellClientCallRecv) Advance() bool {
c.c.errRecv = c.c.Recv(&c.c.valRecv)
return c.c.errRecv == nil
}
func (c implTunnelShellClientCallRecv) Value() ServerShellPacket {
return c.c.valRecv
}
func (c implTunnelShellClientCallRecv) Err() error {
if c.c.errRecv == io.EOF {
return nil
}
return c.c.errRecv
}
func (c *implTunnelShellClientCall) SendStream() interface {
Send(item ClientShellPacket) error
Close() error
} {
return implTunnelShellClientCallSend{c}
}
type implTunnelShellClientCallSend struct {
c *implTunnelShellClientCall
}
func (c implTunnelShellClientCallSend) Send(item ClientShellPacket) error {
return c.c.Send(item)
}
func (c implTunnelShellClientCallSend) Close() error {
return c.c.CloseSend()
}
func (c *implTunnelShellClientCall) Finish() (o0 int32, o1 string, err error) {
err = c.ClientCall.Finish(&o0, &o1)
return
}
// TunnelServerMethods is the interface a server writer
// implements for Tunnel.
type TunnelServerMethods interface {
// The Forward method is used for network forwarding. All the data sent over
// the byte stream is forwarded to the requested network address and all the
// data received from that network connection is sent back on the reply
// stream.
Forward(_ *context.T, _ TunnelForwardServerCall, network string, address string) error
// The ReverseForward method is used for network forwarding from the server
// back to the client. The server process listens on the requested network
// address, forwarding all connections by calling Forwarder.Forward on the
// caller.
ReverseForward(_ *context.T, _ rpc.ServerCall, network string, address string) error
// The Shell method is used to either run shell commands remotely, or to open
// an interactive shell. The data received over the byte stream is sent to the
// shell's stdin, and the data received from the shell's stdout and stderr is
// sent back in the reply stream. It returns the exit status of the shell
// command as an integer exit code and a human readable string.
Shell(_ *context.T, _ TunnelShellServerCall, command string, shellOpts ShellOpts) (exitCode int32, exitMsg string, _ error)
}
// TunnelServerStubMethods is the server interface containing
// Tunnel methods, as expected by rpc.Server.
// The only difference between this interface and TunnelServerMethods
// is the streaming methods.
type TunnelServerStubMethods interface {
// The Forward method is used for network forwarding. All the data sent over
// the byte stream is forwarded to the requested network address and all the
// data received from that network connection is sent back on the reply
// stream.
Forward(_ *context.T, _ *TunnelForwardServerCallStub, network string, address string) error
// The ReverseForward method is used for network forwarding from the server
// back to the client. The server process listens on the requested network
// address, forwarding all connections by calling Forwarder.Forward on the
// caller.
ReverseForward(_ *context.T, _ rpc.ServerCall, network string, address string) error
// The Shell method is used to either run shell commands remotely, or to open
// an interactive shell. The data received over the byte stream is sent to the
// shell's stdin, and the data received from the shell's stdout and stderr is
// sent back in the reply stream. It returns the exit status of the shell
// command as an integer exit code and a human readable string.
Shell(_ *context.T, _ *TunnelShellServerCallStub, command string, shellOpts ShellOpts) (exitCode int32, exitMsg string, _ error)
}
// TunnelServerStub adds universal methods to TunnelServerStubMethods.
type TunnelServerStub interface {
TunnelServerStubMethods
// DescribeInterfaces the Tunnel interfaces.
Describe__() []rpc.InterfaceDesc
}
// TunnelServer returns a server stub for Tunnel.
// It converts an implementation of TunnelServerMethods into
// an object that may be used by rpc.Server.
func TunnelServer(impl TunnelServerMethods) TunnelServerStub {
stub := implTunnelServerStub{
impl: impl,
}
// Initialize GlobState; always check the stub itself first, to handle the
// case where the user has the Glob method defined in their VDL source.
if gs := rpc.NewGlobState(stub); gs != nil {
stub.gs = gs
} else if gs := rpc.NewGlobState(impl); gs != nil {
stub.gs = gs
}
return stub
}
type implTunnelServerStub struct {
impl TunnelServerMethods
gs *rpc.GlobState
}
func (s implTunnelServerStub) Forward(ctx *context.T, call *TunnelForwardServerCallStub, i0 string, i1 string) error {
return s.impl.Forward(ctx, call, i0, i1)
}
func (s implTunnelServerStub) ReverseForward(ctx *context.T, call rpc.ServerCall, i0 string, i1 string) error {
return s.impl.ReverseForward(ctx, call, i0, i1)
}
func (s implTunnelServerStub) Shell(ctx *context.T, call *TunnelShellServerCallStub, i0 string, i1 ShellOpts) (int32, string, error) {
return s.impl.Shell(ctx, call, i0, i1)
}
func (s implTunnelServerStub) Globber() *rpc.GlobState {
return s.gs
}
func (s implTunnelServerStub) Describe__() []rpc.InterfaceDesc {
return []rpc.InterfaceDesc{TunnelDesc}
}
// TunnelDesc describes the Tunnel interface.
var TunnelDesc rpc.InterfaceDesc = descTunnel
// descTunnel hides the desc to keep godoc clean.
var descTunnel = rpc.InterfaceDesc{
Name: "Tunnel",
PkgPath: "v.io/x/ref/examples/tunnel",
Methods: []rpc.MethodDesc{
{
Name: "Forward",
Doc: "// The Forward method is used for network forwarding. All the data sent over\n// the byte stream is forwarded to the requested network address and all the\n// data received from that network connection is sent back on the reply\n// stream.",
InArgs: []rpc.ArgDesc{
{Name: "network", Doc: ``}, // string
{Name: "address", Doc: ``}, // string
},
Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Admin"))},
},
{
Name: "ReverseForward",
Doc: "// The ReverseForward method is used for network forwarding from the server\n// back to the client. The server process listens on the requested network\n// address, forwarding all connections by calling Forwarder.Forward on the\n// caller.",
InArgs: []rpc.ArgDesc{
{Name: "network", Doc: ``}, // string
{Name: "address", Doc: ``}, // string
},
Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Admin"))},
},
{
Name: "Shell",
Doc: "// The Shell method is used to either run shell commands remotely, or to open\n// an interactive shell. The data received over the byte stream is sent to the\n// shell's stdin, and the data received from the shell's stdout and stderr is\n// sent back in the reply stream. It returns the exit status of the shell\n// command as an integer exit code and a human readable string.",
InArgs: []rpc.ArgDesc{
{Name: "command", Doc: ``}, // string
{Name: "shellOpts", Doc: ``}, // ShellOpts
},
OutArgs: []rpc.ArgDesc{
{Name: "exitCode", Doc: ``}, // int32
{Name: "exitMsg", Doc: ``}, // string
},
Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Admin"))},
},
},
}
// TunnelForwardServerStream is the server stream for Tunnel.Forward.
type TunnelForwardServerStream interface {
// RecvStream returns the receiver side of the Tunnel.Forward server stream.
RecvStream() interface {
// Advance stages an item so that it may be retrieved via Value. Returns
// true iff there is an item to retrieve. Advance must be called before
// Value is called. May block if an item is not available.
Advance() bool
// Value returns the item that was staged by Advance. May panic if Advance
// returned false or was not called. Never blocks.
Value() []byte
// Err returns any error encountered by Advance. Never blocks.
Err() error
}
// SendStream returns the send side of the Tunnel.Forward server stream.
SendStream() interface {
// Send places the item onto the output stream. Returns errors encountered
// while sending. Blocks if there is no buffer space; will unblock when
// buffer space is available.
Send(item []byte) error
}
}
// TunnelForwardServerCall represents the context passed to Tunnel.Forward.
type TunnelForwardServerCall interface {
rpc.ServerCall
TunnelForwardServerStream
}