From fdbf5aabce54339d403ce2fc97850db200ba8b1a Mon Sep 17 00:00:00 2001 From: fortuna Date: Wed, 16 May 2018 18:18:28 -0400 Subject: [PATCH] Update more code --- src/shadowbox/model/shadowsocks_server.ts | 4 ++-- src/shadowbox/server/libev_shadowsocks_server.ts | 10 +++++----- src/shadowbox/server/managed_user.ts | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/shadowbox/model/shadowsocks_server.ts b/src/shadowbox/model/shadowsocks_server.ts index 5017f100..c30e99e3 100644 --- a/src/shadowbox/model/shadowsocks_server.ts +++ b/src/shadowbox/model/shadowsocks_server.ts @@ -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(); } diff --git a/src/shadowbox/server/libev_shadowsocks_server.ts b/src/shadowbox/server/libev_shadowsocks_server.ts index 10908147..0f953ed8 100644 --- a/src/shadowbox/server/libev_shadowsocks_server.ts +++ b/src/shadowbox/server/libev_shadowsocks_server.ts @@ -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}`); diff --git a/src/shadowbox/server/managed_user.ts b/src/shadowbox/server/managed_user.ts index aedfd151..c9fb8bbe 100644 --- a/src/shadowbox/server/managed_user.ts +++ b/src/shadowbox/server/managed_user.ts @@ -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 {