File: Driver.html

package info (click to toggle)
libnet-ssh-ruby 1.0.10-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,180 kB
  • ctags: 2,327
  • sloc: ruby: 10,321; makefile: 52
file content (667 lines) | stat: -rw-r--r-- 43,300 bytes parent folder | download
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
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Net::SSH::Service::Forward::Driver</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Net::SSH::Service::Forward::Driver</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../../files/lib/net/ssh/service/forward/driver_rb.html">
                lib/net/ssh/service/forward/driver.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
The <a href="Driver.html">Forward::Driver</a> class manages ports that have
been forwarded. It will open a socket on each local port and listen for
local connections, forwarding those connections over an <a
href="../../../SSH.html">SSH</a> channel to the other end.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000298">active_locals</a>&nbsp;&nbsp;
      <a href="#M000299">active_remotes</a>&nbsp;&nbsp;
      <a href="#M000300">cancel_local</a>&nbsp;&nbsp;
      <a href="#M000301">cancel_remote</a>&nbsp;&nbsp;
      <a href="#M000294">direct_channel</a>&nbsp;&nbsp;
      <a href="#M000302">do_open_channel</a>&nbsp;&nbsp;
      <a href="#M000295">local</a>&nbsp;&nbsp;
      <a href="#M000293">new</a>&nbsp;&nbsp;
      <a href="#M000296">remote</a>&nbsp;&nbsp;
      <a href="#M000297">remote_to</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">direct_channel_count</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The number of direct (local-to-remote) channels that have been opened.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">open_direct_channel_count</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The number of direct (local-to-remote) channels that are currently open.

</td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000293" class="method-detail">
        <a name="M000293"></a>

        <div class="method-heading">
          <a href="#M000293" class="method-signature">
          <span class="method-name">new</span><span class="method-args">( connection, buffers, log, handlers )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create a new <a href="Driver.html">Driver</a> instance.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000293-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000293-source">
<pre>
    <span class="ruby-comment cmt"># File lib/net/ssh/service/forward/driver.rb, line 39</span>
39:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>( <span class="ruby-identifier">connection</span>, <span class="ruby-identifier">buffers</span>, <span class="ruby-identifier">log</span>, <span class="ruby-identifier">handlers</span> )
40:             <span class="ruby-ivar">@connection</span> = <span class="ruby-identifier">connection</span>
41:             <span class="ruby-ivar">@buffers</span> = <span class="ruby-identifier">buffers</span>
42:             <span class="ruby-ivar">@log</span> = <span class="ruby-identifier">log</span>
43:             <span class="ruby-ivar">@handlers</span> = <span class="ruby-identifier">handlers</span>
44: 
45:             <span class="ruby-ivar">@local_forwards</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
46:             <span class="ruby-ivar">@remote_forwards</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
47:             <span class="ruby-ivar">@direct_channel_count</span> = <span class="ruby-value">0</span>
48:             <span class="ruby-ivar">@open_direct_channel_count</span> = <span class="ruby-value">0</span>
49: 
50:             <span class="ruby-ivar">@connection</span>.<span class="ruby-identifier">add_channel_open_handler</span>(
51:               <span class="ruby-value str">&quot;forwarded-tcpip&quot;</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">method</span>(<span class="ruby-identifier">:do_open_channel</span>) )
52:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000298" class="method-detail">
        <a name="M000298"></a>

        <div class="method-heading">
          <a href="#M000298" class="method-signature">
          <span class="method-name">active_locals</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Return an array of the active forwarded local connections. Each element of
the array is another array containing the local port, and the remote host
and port of the connection.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000298-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000298-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/service/forward/driver.rb, line 229</span>
229:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">active_locals</span>
230:             <span class="ruby-ivar">@local_forwards</span>.<span class="ruby-identifier">keys</span>
231:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000299" class="method-detail">
        <a name="M000299"></a>

        <div class="method-heading">
          <a href="#M000299" class="method-signature">
          <span class="method-name">active_remotes</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Return an array of the active forwarded remote connections. Each element of
the array is an integer representing the port number of the remote host
that is being forwarded to the local client.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000299-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000299-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/service/forward/driver.rb, line 236</span>
236:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">active_remotes</span>
237:             <span class="ruby-ivar">@remote_forwards</span>.<span class="ruby-identifier">keys</span>
238:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000300" class="method-detail">
        <a name="M000300"></a>

        <div class="method-heading">
          <a href="#M000300" class="method-signature">
          <span class="method-name">cancel_local</span><span class="method-args">( local_port, bind_address=&quot;127.0.0.1&quot; )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Cease forwarding connections from the given local port (and interface). The
parameters must match those given to a prior call to <a
href="Driver.html#M000295">local</a>. Existing forwarded connections are
not affected by this call, but no more connections will be accepted on the
local port.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000300-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000300-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/service/forward/driver.rb, line 245</span>
245:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cancel_local</span>( <span class="ruby-identifier">local_port</span>, <span class="ruby-identifier">bind_address</span>=<span class="ruby-value str">&quot;127.0.0.1&quot;</span> )
246:             <span class="ruby-identifier">key</span> = [ <span class="ruby-identifier">local_port</span>.<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">bind_address</span> ]
247: 
248:             <span class="ruby-identifier">forward</span> = <span class="ruby-ivar">@local_forwards</span>[ <span class="ruby-identifier">key</span> ]
249:             <span class="ruby-ivar">@local_forwards</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">key</span>
250: 
251:             <span class="ruby-identifier">forward</span>[ <span class="ruby-identifier">:socket</span> ].<span class="ruby-identifier">shutdown</span>
252:             <span class="ruby-identifier">forward</span>[ <span class="ruby-identifier">:thread</span> ].<span class="ruby-identifier">terminate</span>
253: 
254:             <span class="ruby-keyword kw">true</span>
255:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000301" class="method-detail">
        <a name="M000301"></a>

        <div class="method-heading">
          <a href="#M000301" class="method-signature">
          <span class="method-name">cancel_remote</span><span class="method-args">( remote_port, remote_host=&quot;127.0.0.1&quot; )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Cease forwarding connections from the given remote port. The
<tt>remote_host</tt> parameter must match the corresponding parameter that
was passed to <a href="Driver.html#M000296">remote</a>. Existing forwarded
connections are not affected by this call, but no more connections will be
forwarded from the remote host to the local host via that port.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000301-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000301-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/service/forward/driver.rb, line 262</span>
262:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cancel_remote</span>( <span class="ruby-identifier">remote_port</span>, <span class="ruby-identifier">remote_host</span>=<span class="ruby-value str">&quot;127.0.0.1&quot;</span> )
263:             <span class="ruby-identifier">writer</span> = <span class="ruby-ivar">@buffers</span>.<span class="ruby-identifier">writer</span>
264:             <span class="ruby-identifier">writer</span>.<span class="ruby-identifier">write_string</span> <span class="ruby-identifier">remote_host</span>
265:             <span class="ruby-identifier">writer</span>.<span class="ruby-identifier">write_long</span> <span class="ruby-identifier">remote_port</span>.<span class="ruby-identifier">to_i</span>
266: 
267:             <span class="ruby-ivar">@connection</span>.<span class="ruby-identifier">global_request</span>( <span class="ruby-value str">&quot;cancel-tcpip-forward&quot;</span>, <span class="ruby-identifier">writer</span>
268:             ) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">success</span>, <span class="ruby-identifier">response</span><span class="ruby-operator">|</span>
269:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">success</span>
270:                 <span class="ruby-ivar">@remote_forwards</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">remote_port</span>
271:               <span class="ruby-keyword kw">else</span>
272:                 <span class="ruby-identifier">raise</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span><span class="ruby-operator">::</span><span class="ruby-constant">Exception</span>,
273:                   <span class="ruby-value str">&quot;could not cancel remote forward request on &quot;</span> <span class="ruby-operator">+</span>
274:                   <span class="ruby-node">&quot;(#{remote_port},#{remote_host})&quot;</span>
275:               <span class="ruby-keyword kw">end</span>
276:             <span class="ruby-keyword kw">end</span>
277:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000294" class="method-detail">
        <a name="M000294"></a>

        <div class="method-heading">
          <a href="#M000294" class="method-signature">
          <span class="method-name">direct_channel</span><span class="method-args">( local_port, remote_host, remote_port, handler, *data )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Open a direct &quot;tcpip&quot; channel to the remote machine, which will
then forward the connection to the given remote-host and remote-port. The
connection will appear to have come from the given port on the local
machine.
</p>
<p>
The handler object may respond to the following messages, in order to
respond to requests over the channel:
</p>
<ul>
<li>on_receive( channel, data ): when data is received over the channel (from
the remote machine), this method will be invoked.

</li>
<li>on_eof( channel ): when the remote machine will no longer send data, this
method will be invoked. The client may continue to send data over the
channel, however.

</li>
<li>on_close( channel ): when the channel has been closed and is no longer
valid for passing data, this method will be invoked.

</li>
<li>confirm( channel, local_port, remote_host, remote_port, *data ): when the
channel has been opened and the remote machine has confirmed it, this
method will be invoked. The <tt>data</tt> parameters are the same
parameters as were passed to the <a
href="Driver.html#M000294">direct_channel</a> method.

</li>
<li>process( channel ): invoked after the channel is confirmed, to process the
channel. It is invoked in a new Thread.

</li>
</ul>
<p>
Only the <tt>process</tt> method is required&#8212;the others will only be
invoked if the handler responds to them.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000294-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000294-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/service/forward/driver.rb, line 79</span>
 79:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">direct_channel</span>( <span class="ruby-identifier">local_port</span>, <span class="ruby-identifier">remote_host</span>, <span class="ruby-identifier">remote_port</span>,
 80:             <span class="ruby-identifier">handler</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">data</span> )
 81:           <span class="ruby-comment cmt"># begin</span>
 82:             <span class="ruby-identifier">writer</span> = <span class="ruby-ivar">@buffers</span>.<span class="ruby-identifier">writer</span>
 83:             <span class="ruby-identifier">writer</span>.<span class="ruby-identifier">write_string</span> <span class="ruby-identifier">remote_host</span>
 84:             <span class="ruby-identifier">writer</span>.<span class="ruby-identifier">write_long</span> <span class="ruby-identifier">remote_port</span>.<span class="ruby-identifier">to_i</span>
 85:             <span class="ruby-identifier">writer</span>.<span class="ruby-identifier">write_string</span> <span class="ruby-value str">&quot;127.0.0.1&quot;</span>
 86:             <span class="ruby-identifier">writer</span>.<span class="ruby-identifier">write_long</span> <span class="ruby-identifier">local_port</span>.<span class="ruby-identifier">to_i</span>
 87: 
 88:             <span class="ruby-ivar">@direct_channel_count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
 89:             <span class="ruby-ivar">@open_direct_channel_count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
 90: 
 91:             <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">debug?</span>
 92:               <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-value str">&quot;opening direct channel for &quot;</span> <span class="ruby-operator">+</span>
 93:                 <span class="ruby-node">&quot;#{local_port}:#{remote_host}:#{remote_port}&quot;</span>
 94:             <span class="ruby-keyword kw">end</span>
 95: 
 96:             <span class="ruby-identifier">c</span> = <span class="ruby-ivar">@connection</span>.<span class="ruby-identifier">open_channel</span>( <span class="ruby-value str">'direct-tcpip'</span>, <span class="ruby-identifier">writer</span> ) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">channel</span><span class="ruby-operator">|</span>
 97:               <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">debug?</span>
 98:                 <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-value str">&quot;direct channel confirmed for &quot;</span> <span class="ruby-operator">+</span>
 99:                   <span class="ruby-node">&quot;#{local_port}:#{remote_host}:#{remote_port}&quot;</span>
100:               <span class="ruby-keyword kw">end</span>
101: 
102:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:on_receive</span> )
103:                 <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">on_data</span>( <span class="ruby-operator">&amp;</span><span class="ruby-identifier">handler</span>.<span class="ruby-identifier">method</span>(<span class="ruby-identifier">:on_receive</span>) )
104:               <span class="ruby-keyword kw">end</span>
105: 
106:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:on_eof</span> )
107:                 <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">on_eof</span>( <span class="ruby-operator">&amp;</span><span class="ruby-identifier">handler</span>.<span class="ruby-identifier">method</span>(<span class="ruby-identifier">:on_eof</span>) )
108:               <span class="ruby-keyword kw">end</span>
109: 
110:               <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">on_close</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ch</span><span class="ruby-operator">|</span>
111:                 <span class="ruby-ivar">@open_direct_channel_count</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
112:                 <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">on_close</span>( <span class="ruby-identifier">ch</span> ) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:on_close</span> )
113:               <span class="ruby-keyword kw">end</span>
114: 
115:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:confirm</span> )
116:                 <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">confirm</span>( <span class="ruby-identifier">channel</span>, <span class="ruby-identifier">local_port</span>, <span class="ruby-identifier">remote_host</span>,
117:                   <span class="ruby-identifier">remote_port</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">data</span> )
118:               <span class="ruby-keyword kw">end</span>
119: 
120:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:process</span> )
121:                 <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> { <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">process</span>( <span class="ruby-identifier">channel</span> ) }
122:               <span class="ruby-keyword kw">end</span>
123:             <span class="ruby-keyword kw">end</span>
124: 
125:             <span class="ruby-identifier">c</span>.<span class="ruby-identifier">on_confirm_failed</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">channel</span>, <span class="ruby-identifier">code</span>,<span class="ruby-identifier">desc</span>,<span class="ruby-identifier">lang</span><span class="ruby-operator">|</span>
126:               <span class="ruby-identifier">raise</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span><span class="ruby-operator">::</span><span class="ruby-constant">Exception</span>, <span class="ruby-value str">&quot;could not open direct channel for &quot;</span> <span class="ruby-operator">+</span>
127:                 <span class="ruby-node">&quot;#{local_port}:#{remote_host}:#{remote_port} (#{code}, #{desc})&quot;</span>
128:             <span class="ruby-keyword kw">end</span>
129: 
130:             <span class="ruby-keyword kw">nil</span>
131:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000302" class="method-detail">
        <a name="M000302"></a>

        <div class="method-heading">
          <a href="#M000302" class="method-signature">
          <span class="method-name">do_open_channel</span><span class="method-args">( connection, channel, data )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
open a new channel as requested by the server
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000302-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000302-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/service/forward/driver.rb, line 280</span>
280:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">do_open_channel</span>( <span class="ruby-identifier">connection</span>, <span class="ruby-identifier">channel</span>, <span class="ruby-identifier">data</span> )
281:             <span class="ruby-identifier">connected_address</span> = <span class="ruby-identifier">data</span>.<span class="ruby-identifier">read_string</span>
282:             <span class="ruby-identifier">connected_port</span> = <span class="ruby-identifier">data</span>.<span class="ruby-identifier">read_long</span>
283:             <span class="ruby-identifier">originator_address</span> = <span class="ruby-identifier">data</span>.<span class="ruby-identifier">read_string</span>
284:             <span class="ruby-identifier">originator_port</span> = <span class="ruby-identifier">data</span>.<span class="ruby-identifier">read_long</span>
285: 
286:             <span class="ruby-identifier">forward_data</span> = <span class="ruby-ivar">@remote_forwards</span>[ <span class="ruby-identifier">connected_port</span> ]
287:             <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">forward_data</span>
288:               <span class="ruby-identifier">raise</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span><span class="ruby-operator">::</span><span class="ruby-constant">Exception</span>,
289:                 <span class="ruby-value str">&quot;recieved invalid channel-open command for a port forward &quot;</span> <span class="ruby-operator">+</span>
290:                 <span class="ruby-value str">&quot;that was never requested&quot;</span>
291:             <span class="ruby-keyword kw">end</span>
292: 
293:             <span class="ruby-identifier">handler</span> = <span class="ruby-identifier">forward_data</span>[<span class="ruby-identifier">:handler</span>]
294: 
295:             <span class="ruby-identifier">forward_data</span>[<span class="ruby-identifier">:channel</span>] = <span class="ruby-identifier">channel</span>
296: 
297:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:on_open</span> )
298:               <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">on_open</span>( <span class="ruby-identifier">channel</span>,
299:                                <span class="ruby-identifier">connected_address</span>, <span class="ruby-identifier">connected_port</span>,
300:                                <span class="ruby-identifier">originator_address</span>, <span class="ruby-identifier">originator_port</span> )
301:             <span class="ruby-keyword kw">end</span>
302: 
303:             <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">on_data</span>( <span class="ruby-operator">&amp;</span><span class="ruby-identifier">handler</span>.<span class="ruby-identifier">method</span>(<span class="ruby-identifier">:on_receive</span>) )
304: 
305:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:on_close</span> )
306:               <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">on_close</span>( <span class="ruby-operator">&amp;</span><span class="ruby-identifier">handler</span>.<span class="ruby-identifier">method</span>(<span class="ruby-identifier">:on_close</span>) )
307:             <span class="ruby-keyword kw">end</span>
308: 
309:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:on_eof</span> )
310:               <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">on_eof</span>( <span class="ruby-operator">&amp;</span><span class="ruby-identifier">handler</span>.<span class="ruby-identifier">method</span>(<span class="ruby-identifier">:on_eof</span>) )
311:             <span class="ruby-keyword kw">end</span>
312:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000295" class="method-detail">
        <a name="M000295"></a>

        <div class="method-heading">
          <a href="#M000295" class="method-signature">
          <span class="method-name">local</span><span class="method-args">( *args )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="../Forward.html">Forward</a> connections on the given local port,
to the given remote host and remote port.
</p>
<p>
This method will return immediately, forwarding the connections
asynchronously.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000295-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000295-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/service/forward/driver.rb, line 138</span>
138:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">local</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">args</span> )
139:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">3</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">4</span>
140:               <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>,
141:                 <span class="ruby-node">&quot;expected 3 or 4 parameters, got #{args.length+1}&quot;</span>
142:             <span class="ruby-keyword kw">end</span>
143: 
144:             <span class="ruby-identifier">bind_address</span> = <span class="ruby-value str">&quot;127.0.0.1&quot;</span>
145:             <span class="ruby-identifier">bind_address</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">shift</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
146: 
147:             <span class="ruby-identifier">local_port</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">shift</span>.<span class="ruby-identifier">to_i</span>
148:             <span class="ruby-identifier">remote_host</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">shift</span>
149:             <span class="ruby-identifier">remote_port</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">shift</span>
150: 
151:             <span class="ruby-identifier">key</span> = [ <span class="ruby-identifier">local_port</span>.<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">bind_address</span> ]
152: 
153:             <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">debug?</span>
154:               <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-value str">&quot;starting local forwarding server on &quot;</span> <span class="ruby-operator">+</span>
155:                 <span class="ruby-identifier">key</span>.<span class="ruby-identifier">inspect</span>
156:             <span class="ruby-keyword kw">end</span>
157: 
158:             <span class="ruby-identifier">socket</span> = <span class="ruby-constant">TCPServer</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">bind_address</span>, <span class="ruby-identifier">local_port</span> )
159: 
160:             <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
161:               <span class="ruby-keyword kw">begin</span>
162:                 <span class="ruby-ivar">@local_forwards</span>[ <span class="ruby-identifier">key</span> ] = { <span class="ruby-identifier">:thread</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>,
163:                                            <span class="ruby-identifier">:socket</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">socket</span> }
164: 
165:                 <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">debug?</span>
166:                   <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;listening for connections on #{key.inspect}&quot;</span>
167:                 <span class="ruby-keyword kw">end</span>
168: 
169:                 <span class="ruby-keyword kw">while</span> ( <span class="ruby-identifier">client</span> = <span class="ruby-identifier">socket</span>.<span class="ruby-identifier">accept</span> )
170:                   <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;#{key.inspect} received connection&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">debug?</span>
171: 
172:                   <span class="ruby-identifier">direct_channel</span>( <span class="ruby-identifier">local_port</span>,
173:                                   <span class="ruby-identifier">remote_host</span>,
174:                                   <span class="ruby-identifier">remote_port</span>,
175:                                   <span class="ruby-ivar">@handlers</span>[<span class="ruby-identifier">:local</span>].<span class="ruby-identifier">call</span>( <span class="ruby-identifier">client</span> ) )
176:                 <span class="ruby-keyword kw">end</span>
177: 
178:               <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
179:                 <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">error</span> <span class="ruby-value str">&quot;error forwarding local connection: &quot;</span> <span class="ruby-operator">+</span>
180:                   <span class="ruby-node">&quot;#{e.class} (#{e.message})\n   &quot;</span> <span class="ruby-operator">+</span>
181:                   <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>( <span class="ruby-value str">&quot;\n  &quot;</span> )
182:               <span class="ruby-keyword kw">end</span>
183:             <span class="ruby-keyword kw">end</span>
184:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000296" class="method-detail">
        <a name="M000296"></a>

        <div class="method-heading">
          <a href="#M000296" class="method-signature">
          <span class="method-name">remote</span><span class="method-args">( handler, remote_port, remote_host=&quot;127.0.0.1&quot; )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Initiate forwarding of the given remote port on the connected host.
Forwarded packets will be passed to the given block as they are recieved.
The remote-host represents the address that should be bound on the remote
host, and defaults to &#8216;127.0.0.1&#8217;.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000296-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000296-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/service/forward/driver.rb, line 190</span>
190:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remote</span>( <span class="ruby-identifier">handler</span>, <span class="ruby-identifier">remote_port</span>, <span class="ruby-identifier">remote_host</span>=<span class="ruby-value str">&quot;127.0.0.1&quot;</span> )
191:             <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@remote_forwards</span>[ <span class="ruby-identifier">remote_port</span> ]
192:               <span class="ruby-identifier">raise</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span><span class="ruby-operator">::</span><span class="ruby-constant">Exception</span>, <span class="ruby-node">&quot;#{remote_port} is already forwarded&quot;</span>
193:             <span class="ruby-keyword kw">end</span>
194: 
195:             <span class="ruby-identifier">writer</span> = <span class="ruby-ivar">@buffers</span>.<span class="ruby-identifier">writer</span>
196:             <span class="ruby-identifier">writer</span>.<span class="ruby-identifier">write_string</span> <span class="ruby-identifier">remote_host</span>
197:             <span class="ruby-identifier">writer</span>.<span class="ruby-identifier">write_long</span> <span class="ruby-identifier">remote_port</span>.<span class="ruby-identifier">to_i</span>
198: 
199:             <span class="ruby-ivar">@connection</span>.<span class="ruby-identifier">global_request</span>( <span class="ruby-value str">&quot;tcpip-forward&quot;</span>, <span class="ruby-identifier">writer</span>
200:             ) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">success</span>, <span class="ruby-identifier">response</span><span class="ruby-operator">|</span>
201:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">success</span>
202:                 <span class="ruby-identifier">remote_port</span> = <span class="ruby-identifier">response</span>.<span class="ruby-identifier">read_long</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">remote_port</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
203:                 <span class="ruby-ivar">@remote_forwards</span>[ <span class="ruby-identifier">remote_port</span> ] = { <span class="ruby-identifier">:port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">remote_port</span>,
204:                                                     <span class="ruby-identifier">:handler</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">handler</span> }
205:                 <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">setup</span>( <span class="ruby-identifier">remote_port</span> ) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:setup</span> )
206:               <span class="ruby-keyword kw">else</span>
207:                 <span class="ruby-identifier">msg</span> = <span class="ruby-node">&quot;remote port #{remote_port} could not be forwarded &quot;</span> <span class="ruby-operator">+</span>
208:                       <span class="ruby-value str">&quot;to local host&quot;</span>
209:                 <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">respond_to?</span>( <span class="ruby-identifier">:error</span> )
210:                   <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">error</span>( <span class="ruby-identifier">msg</span> )
211:                 <span class="ruby-keyword kw">else</span>
212:                   <span class="ruby-identifier">raise</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span><span class="ruby-operator">::</span><span class="ruby-constant">Exception</span>, <span class="ruby-identifier">msg</span>
213:                 <span class="ruby-keyword kw">end</span>
214:               <span class="ruby-keyword kw">end</span>
215:             <span class="ruby-keyword kw">end</span>
216:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000297" class="method-detail">
        <a name="M000297"></a>

        <div class="method-heading">
          <a href="#M000297" class="method-signature">
          <span class="method-name">remote_to</span><span class="method-args">( port, host, remote_port, remote_host=&quot;127.0.0.1&quot; )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A convenience method for setting up a forwarded connection from the given
port on the remote host, to the given host and port (local).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000297-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000297-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/service/forward/driver.rb, line 220</span>
220:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remote_to</span>( <span class="ruby-identifier">port</span>, <span class="ruby-identifier">host</span>, <span class="ruby-identifier">remote_port</span>, <span class="ruby-identifier">remote_host</span>=<span class="ruby-value str">&quot;127.0.0.1&quot;</span> )
221:           <span class="ruby-comment cmt"># begin</span>
222:             <span class="ruby-identifier">remote</span>( <span class="ruby-ivar">@handlers</span>[<span class="ruby-identifier">:remote</span>].<span class="ruby-identifier">call</span>( <span class="ruby-identifier">port</span>, <span class="ruby-identifier">host</span> ), <span class="ruby-identifier">remote_port</span>,
223:               <span class="ruby-identifier">remote_host</span> )
224:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>