This repository was archived by the owner on Apr 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathsession.js
More file actions
67 lines (53 loc) · 1.92 KB
/
session.js
File metadata and controls
67 lines (53 loc) · 1.92 KB
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
const EventEmitter = require('events').EventEmitter
, util = require('util')
, Channel = require('./channel')
function Session (server, session) {
this._session = session
this._server = server
session.onMessage = function (message) {
if (this._server._options.debug)
console.log('session message', message)
if (message.type == 'auth')
return this.emit('auth', message)
// else handle default.. probably should pass this on
message.replyDefault()
}.bind(this)
session.onNewChannel = function (channel) {
this.emit('channel', new Channel(this._server, channel))
setImmediate(function () {
// why setImmediate?? WHO KNOWS! something to do with the
// timing of starting polling vs setting up the callbacks
channel.start()
})
}.bind(this)
session.onGlobalRequest = function (message) {
if (this._server._options.debug)
console.log('global request', message)
// if no "tcpipforward" listeners exist return failure
// otherwise assume success unless listener explicitly sends "replyDefault"
if (this.listeners('tcpipforward').length === 0)
message.replyDefault()
// tcpipforward, canceltcpipforward, etc
return this.emit(message.subtype, message)
}.bind(this)
session.onClose = function () {
if (this._server._options.debug)
console.log('onClose')
return this.emit('close')
}.bind(this)
EventEmitter.call(this)
}
util.inherits(Session, EventEmitter)
Session.prototype.close = function () {
this._session.close()
return this
}
Session.prototype.setAuthMethods = function (methods) {
this._session.setAuthMethods(methods)
return this
}
Session.prototype.openReverseForward = function (remotehost, remoteport, sourcehost, localport) {
var channel = this._session.openReverseForward(remotehost, remoteport, sourcehost, localport)
return new Channel(this._server, channel)
}
module.exports = Session