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
"use strict";
var _ = require("lodash");
var U = require("glace-utils");
var BaseProxy = function (opts) {
opts = U.defVal(opts, {});
this.isRunning = false;
this.reqSpeed = U.defVal(opts.reqSpeed, opts.speed);
this.resSpeed = U.defVal(opts.resSpeed, opts.speed);
this.responsesData = null;
this.useCache = U.defVal(opts.useCache, false);
this._reconnect = U.defVal(opts.reconnect, 0);
this._timeout = U.defVal(opts.timeout, 60000);
this._port = U.defVal(opts.port, 0);
this._proxy = null;
};
BaseProxy.prototype.getPort = function () {
if (this._port === 0) throw Error(
"Port is not defined and will be chosen randomly on proxy start");
return this._port;
};
BaseProxy.prototype.setSpeed = function (speed) {
if (_.isNumber(speed)) {
this.reqSpeed = this.resSpeed = speed;
} else {
if (speed.req !== undefined) this.reqSpeed = speed.req;
if (speed.res !== undefined) this.resSpeed = speed.res;
};
};
BaseProxy.prototype.resetSpeed = function () {
this.reqSpeed = this.resSpeed = null;
};
BaseProxy.prototype.measureResponses = function () {
this.responsesData = [];
};
BaseProxy.prototype.unmeasureResponses = function () {
this.responsesData = null;
};
BaseProxy.prototype.getResponsesData = function () {
if (this.responsesData === null) return null;
return _.cloneDeep(this.responsesData);
};
BaseProxy.prototype.start = function () {
throw new Error("Should be implemented in derived class");
};
BaseProxy.prototype.stop = function () {
throw new Error("Should be implemented in derived class");
};
module.exports = BaseProxy;