API: client: remove [down/up]Throttle, clarify throttleGlobal[Down/Up]Max unit

This commit is contained in:
Jesse Chan
2020-11-08 01:10:21 +08:00
parent d82ac77ccf
commit d592152967
14 changed files with 59 additions and 92 deletions

View File

@@ -6,15 +6,15 @@ import ModalFormSectionHeader from '../ModalFormSectionHeader';
import SettingStore from '../../../stores/SettingStore';
import SettingsTab from './SettingsTab';
const processSpeedsForDisplay = (speeds: number[]) => {
const processSpeedsForDisplay = (speeds: number[]): string | undefined => {
if (!speeds || speeds.length === 0) {
return undefined;
}
return speeds.map((speed) => Number(speed) / 1024).join(', ');
return speeds.join(', ');
};
const processSpeedsForSave = (speeds = '') => {
const processSpeedsForSave = (speeds = ''): number[] => {
if (speeds === '') {
return [];
}
@@ -22,7 +22,7 @@ const processSpeedsForSave = (speeds = '') => {
return speeds
.replace(/\s/g, '')
.split(',')
.map((speed) => Number(speed) * 1024);
.map((speed) => Number(speed));
};
export default class BandwidthTab extends SettingsTab {

View File

@@ -11,7 +11,6 @@ import LimitsIcon from '../icons/Limits';
import SettingStore from '../../stores/SettingStore';
import Size from '../general/Size';
import Tooltip from '../general/Tooltip';
import TransferDataStore from '../../stores/TransferDataStore';
import type {DropdownItem} from '../general/form-elements/Dropdown';
@@ -33,11 +32,13 @@ const MESSAGES = defineMessages({
@observer
class SpeedLimitDropdown extends React.Component<WrappedComponentProps> {
static handleItemSelect(item: DropdownItem<TransferDirection>) {
if (item.value != null) {
const bytes = item.value;
if (bytes != null) {
const kb = Math.trunc(bytes / 1024);
if (item.property === 'download') {
ClientActions.saveSetting('throttleGlobalDownMax', item.value);
ClientActions.saveSetting('throttleGlobalDownMax', kb);
} else if (item.property === 'upload') {
ClientActions.saveSetting('throttleGlobalUpMax', item.value);
ClientActions.saveSetting('throttleGlobalUpMax', kb);
}
}
}
@@ -82,7 +83,7 @@ class SpeedLimitDropdown extends React.Component<WrappedComponentProps> {
getSpeedList(direction: TransferDirection): Array<DropdownItem<TransferDirection>> {
const {speedLimits} = SettingStore.floodSettings;
const {transferSummary} = TransferDataStore;
const {throttleGlobalDownMax = 0, throttleGlobalUpMax = 0} = SettingStore.clientSettings || {};
const heading = {
className: `dropdown__label dropdown__label--${direction}`,
@@ -93,13 +94,15 @@ class SpeedLimitDropdown extends React.Component<WrappedComponentProps> {
value: null,
};
let insertCurrentThrottle = true;
const currentThrottle: Record<TransferDirection, number> = {
download: transferSummary.downThrottle,
upload: transferSummary.upThrottle,
} || {download: 0, upload: 0};
const speeds: number[] = (speedLimits != null && speedLimits[direction]) || [0];
// Kb/s to B/s
download: throttleGlobalDownMax * 1024,
upload: throttleGlobalUpMax * 1024,
};
const speeds: number[] = speedLimits[direction].map((kb) => kb * 1024);
let insertCurrentThrottle = true;
const items: Array<DropdownItem<TransferDirection>> = speeds.map((bytes) => {
let selected = false;

View File

@@ -9,6 +9,7 @@ import ClientStatusStore from '../../stores/ClientStatusStore';
import Download from '../icons/Download';
import Duration from '../general/Duration';
import InfinityIcon from '../icons/InfinityIcon';
import SettingStore from '../../stores/SettingStore';
import Size from '../general/Size';
import TransferDataStore from '../../stores/TransferDataStore';
import Upload from '../icons/Upload';
@@ -35,21 +36,23 @@ const icons = {
class TransferRateDetails extends Component<TransferRateDetailsProps> {
getCurrentTransferRate(direction: TransferDirection, options: {showHoverDuration?: boolean} = {}) {
const {inspectorPoint, intl} = this.props;
const {throttleGlobalDownMax = 0, throttleGlobalUpMax = 0} = SettingStore.clientSettings || {};
const {transferSummary} = TransferDataStore;
const throttles = {
download: transferSummary != null ? transferSummary.downThrottle : 0,
upload: transferSummary != null ? transferSummary.upThrottle : 0,
// Kb/s to B/s
download: throttleGlobalDownMax * 1024,
upload: throttleGlobalUpMax * 1024,
};
let timestamp = null;
const transferTotals = {
download: transferSummary != null ? transferSummary.downTotal : 0,
upload: transferSummary != null ? transferSummary.upTotal : 0,
download: transferSummary.downTotal,
upload: transferSummary.upTotal,
};
let transferRates = {
download: transferSummary != null ? transferSummary.downRate : 0,
upload: transferSummary != null ? transferSummary.upRate : 0,
download: transferSummary.downRate,
upload: transferSummary.upRate,
};
if (inspectorPoint != null) {
@@ -67,6 +70,7 @@ class TransferRateDetails extends Component<TransferRateDetailsProps> {
'is-visible': inspectorPoint != null && options.showHoverDuration,
});
let timestamp = null;
if (inspectorPoint?.nearestTimestamp != null) {
timestamp = (
<div className={timestampClasses}>

View File

@@ -14,10 +14,8 @@ class TransferDataStore {
transferSummary: TransferSummary = {
downRate: 0,
downThrottle: 0,
downTotal: 0,
upRate: 0,
upThrottle: 0,
upTotal: 0,
};

View File

@@ -360,45 +360,17 @@ class TransmissionClientGatewayService extends ClientGatewayService {
}
async fetchTransferSummary(): Promise<TransferSummary> {
const statsRequest = this.clientRequestManager
return this.clientRequestManager
.getSessionStats()
.then(this.processClientRequestSuccess, this.processClientRequestError)
.catch(() => undefined);
const speedLimitRequest = this.clientRequestManager
.getSessionProperties([
'speed-limit-down',
'speed-limit-down-enabled',
'speed-limit-up',
'speed-limit-up-enabled',
])
.then(this.processClientRequestSuccess, this.processClientRequestError)
.catch(() => undefined);
const stats = await statsRequest;
const properties = await speedLimitRequest;
if (stats == null || properties == null) {
return Promise.reject();
}
const {
'speed-limit-down': speedLimitDown,
'speed-limit-down-enabled': speedLimitDownEnabled,
'speed-limit-up': speedLimitUp,
'speed-limit-up-enabled': speedLimitUpEnabled,
} = properties;
const transferSummary: TransferSummary = {
downRate: stats.downloadSpeed,
downThrottle: speedLimitDownEnabled ? speedLimitDown * 1024 : 0,
downTotal: stats['current-stats'].downloadedBytes,
upRate: stats.uploadSpeed,
upThrottle: speedLimitUpEnabled ? speedLimitUp * 1024 : 0,
upTotal: stats['current-stats'].uploadedBytes,
};
return transferSummary;
.then((stats) => {
return {
downRate: stats.downloadSpeed,
downTotal: stats['current-stats'].downloadedBytes,
upRate: stats.uploadSpeed,
upTotal: stats['current-stats'].uploadedBytes,
};
});
}
async getClientSettings(): Promise<ClientSettings> {
@@ -459,11 +431,9 @@ class TransmissionClientGatewayService extends ClientGatewayService {
'peer-port-random-on-start': settings.networkPortRandom,
'pex-enabled': settings.protocolPex,
'speed-limit-down-enabled': settings.throttleGlobalDownMax !== 0,
'speed-limit-down':
settings.throttleGlobalDownMax != null ? Math.trunc(settings.throttleGlobalDownMax / 1024) : undefined,
'speed-limit-down': settings.throttleGlobalDownMax,
'speed-limit-up-enabled': settings.throttleGlobalUpMax !== 0,
'speed-limit-up':
settings.throttleGlobalUpMax != null ? Math.trunc(settings.throttleGlobalUpMax / 1024) : undefined,
'speed-limit-up': settings.throttleGlobalUpMax,
'seed-queue-enabled': settings.throttleMaxUploadsGlobal !== 0,
'seed-queue-size': settings.throttleMaxUploadsGlobal,
})

View File

@@ -20,10 +20,8 @@ class HistoryService extends BaseService<HistoryServiceEvents> {
transferSummary: TransferSummary = {
downRate: 0,
downThrottle: 0,
downTotal: 0,
upRate: 0,
upThrottle: 0,
upTotal: 0,
};

View File

@@ -315,10 +315,8 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
.then((info) => {
return {
downRate: info.dl_info_speed,
downThrottle: info.dl_rate_limit,
downTotal: info.dl_info_data,
upRate: info.up_info_speed,
upThrottle: info.up_rate_limit,
upTotal: info.up_info_data,
};
});
@@ -342,8 +340,9 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
piecesHashOnCompletion: false,
piecesMemoryMax: 0,
protocolPex: preferences.pex,
throttleGlobalDownMax: preferences.dl_limit,
throttleGlobalUpMax: preferences.up_limit,
// B/s to Kb/s
throttleGlobalDownMax: preferences.dl_limit / 1024,
throttleGlobalUpMax: preferences.up_limit / 1024,
throttleMaxPeersNormal: 0,
throttleMaxPeersSeed: 0,
throttleMaxDownloads: 0,
@@ -367,8 +366,9 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
random_port: settings.networkPortRandom,
listen_port: settings.networkPortRange ? Number(settings.networkPortRange?.split('-')[0]) : undefined,
pex: settings.protocolPex,
dl_limit: settings.throttleGlobalDownMax,
up_limit: settings.throttleGlobalUpMax,
// Kb/s to B/s
dl_limit: settings.throttleGlobalDownMax != null ? settings.throttleGlobalDownMax * 1024 : undefined,
up_limit: settings.throttleGlobalUpMax != null ? settings.throttleGlobalUpMax * 1024 : undefined,
max_uploads_per_torrent: settings.throttleMaxUploads,
max_uploads: settings.throttleMaxUploadsGlobal,
})

View File

@@ -1,3 +1,4 @@
// WRONG API documentation: dl_limit and up_limit are actually in bytes per second
export interface QBittorrentAppPreferences {
dht: boolean;
pex: boolean;

View File

@@ -681,6 +681,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
break;
case 'throttleGlobalDownMax':
case 'throttleGlobalUpMax':
// Kb/s to B/s
methodName = `${configs[property].methodCall}.set`;
param = (param as ClientSettings[typeof property]) * 1024;
break;

View File

@@ -72,13 +72,15 @@ const clientSettingMethodCallConfigs = {
throttleGlobalDownMax: {
methodCall: 'throttle.global_down.max_rate',
transformValue: (value: unknown) => {
return Number(value) / 1024;
// B/s to Kb/s
return Math.trunc(Number(value) / 1024);
},
},
throttleGlobalUpMax: {
methodCall: 'throttle.global_up.max_rate',
transformValue: (value: unknown) => {
return Number(value) / 1024;
// B/s to Kb/s
return Math.trunc(Number(value) / 1024);
},
},
throttleMaxPeersNormal: {

View File

@@ -9,10 +9,6 @@ const transferSummaryMethodCallConfigs = {
methodCall: 'throttle.global_up.total',
transformValue: numberTransformer,
},
upThrottle: {
methodCall: 'throttle.global_up.max_rate',
transformValue: numberTransformer,
},
downRate: {
methodCall: 'throttle.global_down.rate',
transformValue: numberTransformer,
@@ -21,10 +17,6 @@ const transferSummaryMethodCallConfigs = {
methodCall: 'throttle.global_down.total',
transformValue: numberTransformer,
},
downThrottle: {
methodCall: 'throttle.global_down.max_rate',
transformValue: numberTransformer,
},
} as const;
export default transferSummaryMethodCallConfigs;

View File

@@ -62,8 +62,8 @@ const defaultFloodSettings: Readonly<FloodSettings> = {
],
torrentListViewSize: 'condensed',
speedLimits: {
download: [1024, 10240, 102400, 512000, 1048576, 2097152, 5242880, 10485760, 0],
upload: [1024, 10240, 102400, 512000, 1048576, 2097152, 5242880, 10485760, 0],
download: [1, 10, 100, 500, 1024, 2048, 5120, 10240, 0],
upload: [1, 10, 100, 500, 1024, 2048, 5120, 10240, 0],
},
startTorrentsOnLoad: false,
mountPoints: [],

View File

@@ -11,7 +11,9 @@ export interface ClientSettings {
piecesHashOnCompletion: boolean;
piecesMemoryMax: number;
protocolPex: boolean;
// Kb/s
throttleGlobalDownMax: number;
// Kb/s
throttleGlobalUpMax: number;
throttleMaxPeersNormal: number;
throttleMaxPeersSeed: number;

View File

@@ -1,15 +1,11 @@
export interface TransferSummary {
// Global download rate
// Global download rate in B/s
downRate: number;
// Download rate limit
downThrottle: number;
// Data downloaded this session
// Data downloaded this session in bytes
downTotal: number;
// Global upload rate
// Global upload rate in B/s
upRate: number;
// Upload rate limit
upThrottle: number;
// Data uploaded this session
// Data uploaded this session in bytes
upTotal: number;
}