-
Notifications
You must be signed in to change notification settings - Fork 8
/
Server.js
49 lines (38 loc) · 1.56 KB
/
Server.js
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
const net = require('net'),
util = require('util'),
events = require('events'),
uuid = require('uuid');
const i2putil = require("./i2putil");
const BaseServer = require("./BaseServer");
const SessionManager = require("./SessionManager");
module.exports = function() {
var self = this;
BaseServer.call(this);
self.forward_options = i2putil.copyObj(self.forward_options);
}
util.inherits(module.exports, BaseServer);
module.exports.prototype.forward_options = {
// ID: undefined,
// LOCAL_DESTINATION: undefined,
// PORT: undefined,
// HOST: undefined
}
module.exports.prototype.listen = function (forward_options, sam_options) {
var self = this;
i2putil.copyObj(forward_options, self.forward_options);
var session_options = {};
if (self.forward_options.ID != undefined) session_options.ID = self.forward_options.ID;
if (self.forward_options.LOCAL_DESTINATION != undefined) session_options.DESTINATION = self.forward_options.LOCAL_DESTINATION;
SessionManager.getSession(session_options, function (session) {
self.session = session;
base_forward_options = {ID: self.session.ID};
if (self.forward_options.PORT != undefined) base_forward_options.PORT = self.forward_options.PORT;
if (self.forward_options.HOST != undefined) base_forward_options.HOST = self.forward_options.HOST;
BaseServer.prototype.listen.call(self, base_forward_options, sam_options);
});
}
module.exports.prototype.handleEnd = function () {
var self = this;
BaseServer.prototype.handleEnd.call(this);
SessionManager.releaseSession(self.session);
}