mirror of
https://github.com/OutlineFoundation/outline-server.git
synced 2026-08-04 14:37:34 +00:00
Update more code
This commit is contained in:
parent
a9ef2b7b09
commit
fdbf5aabce
3 changed files with 11 additions and 11 deletions
|
|
@ -26,8 +26,8 @@ export interface ShadowsocksInstance {
|
|||
encryptionMethod: string;
|
||||
accessUrl: string;
|
||||
// Registers a callback to be invoked when the ShadowsocksInstance has
|
||||
// transferred data (inbound and outbond). bytes is the number of
|
||||
// bytes transferred since the last callback.
|
||||
// inbound data (from the client or the target). bytes is the number of
|
||||
// bytes received since the last callback.
|
||||
onInboundBytes(callback: (bytes: number, ipAddresses: string[]) => void);
|
||||
stop();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ export class LibevShadowsocksServer implements ShadowsocksServer {
|
|||
|
||||
class LibevShadowsocksServerInstance implements ShadowsocksInstance {
|
||||
private eventEmitter = new events.EventEmitter();
|
||||
private BYTES_TRANSFERRED_EVENT = 'bytesTransferred';
|
||||
private INBOUND_BYTES_EVENT = 'inboundBytes';
|
||||
|
||||
constructor(
|
||||
private childProcess: child_process.ChildProcess,
|
||||
|
|
@ -96,7 +96,7 @@ class LibevShadowsocksServerInstance implements ShadowsocksInstance {
|
|||
this.childProcess.kill();
|
||||
}
|
||||
|
||||
// onBytesTransferred only reports inbound bytes, received from the client or from the target.
|
||||
// onInboundBytes only reports inbound bytes, received from the client or from the target.
|
||||
//
|
||||
// This measure under-estimates outbound traffic because:
|
||||
// 1) The traffic to and from the client has overhead from Shadowsocks
|
||||
|
|
@ -106,10 +106,10 @@ class LibevShadowsocksServerInstance implements ShadowsocksInstance {
|
|||
// The measure is calculated here:
|
||||
// https://github.com/shadowsocks/shadowsocks-libev/blob/a16826b83e73af386806d1b51149f8321820835e/src/server.c#L172
|
||||
public onInboundBytes(callback: (bytes: number, ipAddresses: string[]) => void) {
|
||||
if (this.eventEmitter.listenerCount(this.BYTES_TRANSFERRED_EVENT) === 0) {
|
||||
if (this.eventEmitter.listenerCount(this.INBOUND_BYTES_EVENT) === 0) {
|
||||
this.createStatsListener();
|
||||
}
|
||||
this.eventEmitter.on(this.BYTES_TRANSFERRED_EVENT, callback);
|
||||
this.eventEmitter.on(this.INBOUND_BYTES_EVENT, callback);
|
||||
}
|
||||
|
||||
private createStatsListener() {
|
||||
|
|
@ -131,7 +131,7 @@ class LibevShadowsocksServerInstance implements ShadowsocksInstance {
|
|||
this.getConnectedClientIPAddresses()
|
||||
.then((ipAddresses: string[]) => {
|
||||
lastInboundBytes = statsMessage.totalInboundBytes;
|
||||
this.eventEmitter.emit(this.BYTES_TRANSFERRED_EVENT, delta, ipAddresses);
|
||||
this.eventEmitter.emit(this.INBOUND_BYTES_EVENT, delta, ipAddresses);
|
||||
})
|
||||
.catch((err) => {
|
||||
logging.error(`Unable to get client IP addresses ${err}`);
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ class ManagedAccessKeyRepository implements AccessKeyRepository {
|
|||
accessKeyJson.port, accessKeyJson.password, statsSocket,
|
||||
accessKeyJson.encryptionMethod)
|
||||
.then((ssInstance) => {
|
||||
ssInstance.onInboundBytes(this.handleBytesTransferred.bind(
|
||||
ssInstance.onInboundBytes(this.handleInboundBytes.bind(
|
||||
this, accessKeyJson.id, accessKeyJson.metricsId));
|
||||
const accessKey = new ManagedAccessKey(
|
||||
accessKeyJson.id, accessKeyJson.metricsId, accessKeyJson.name, ssInstance);
|
||||
|
|
@ -148,7 +148,7 @@ class ManagedAccessKeyRepository implements AccessKeyRepository {
|
|||
this.reservedPorts.add(port);
|
||||
const id = this.allocateId();
|
||||
const metricsId = uuidv4();
|
||||
ssInstance.onInboundBytes(this.handleBytesTransferred.bind(this, id, metricsId));
|
||||
ssInstance.onInboundBytes(this.handleInboundBytes.bind(this, id, metricsId));
|
||||
const accessKey = new ManagedAccessKey(id, metricsId, '', ssInstance);
|
||||
this.accessKeys.set(accessKey.id, accessKey);
|
||||
this.persistState();
|
||||
|
|
@ -182,8 +182,8 @@ class ManagedAccessKeyRepository implements AccessKeyRepository {
|
|||
return true;
|
||||
}
|
||||
|
||||
private handleBytesTransferred(accessKeyId: AccessKeyId, metricsId: AccessKeyId, bytesTransferred: number, ipAddresses: string[]) {
|
||||
this.stats.recordBytesTransferred(accessKeyId, metricsId, bytesTransferred, ipAddresses);
|
||||
private handleInboundBytes(accessKeyId: AccessKeyId, metricsId: AccessKeyId, inboundBytes: number, ipAddresses: string[]) {
|
||||
this.stats.recordBytesTransferred(accessKeyId, metricsId, inboundBytes, ipAddresses);
|
||||
}
|
||||
|
||||
private allocateId(): AccessKeyId {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue