lint and formatting fixes

This commit is contained in:
murgatroid99 2020-01-29 09:56:49 -08:00
parent 57c18382d8
commit c5428c5733
12 changed files with 89 additions and 33 deletions

View File

@ -18,7 +18,7 @@
import { ConnectionOptions, createSecureContext, PeerCertificate } from 'tls';
import { CallCredentials } from './call-credentials';
import {CIPHER_SUITES, getDefaultRootsData} from './tls-helpers';
import { CIPHER_SUITES, getDefaultRootsData } from './tls-helpers';
// tslint:disable-next-line:no-any
function verifyIsBufferOrNull(obj: any, friendlyName: string): void {
@ -190,7 +190,7 @@ class SecureChannelCredentialsImpl extends ChannelCredentials {
ca: rootCerts || undefined,
key: privateKey || undefined,
cert: certChain || undefined,
ciphers: CIPHER_SUITES
ciphers: CIPHER_SUITES,
});
this.connectionOptions = { secureContext };
if (verifyOptions && verifyOptions.checkServerIdentity) {

View File

@ -143,7 +143,9 @@ export class ChannelImplementation implements Channel {
) {
/* The global boolean parameter to getSubchannelPool has the inverse meaning to what
* the grpc.use_local_subchannel_pool channel option means. */
this.subchannelPool = getSubchannelPool((options['grpc.use_local_subchannel_pool'] ?? 0) === 0);
this.subchannelPool = getSubchannelPool(
(options['grpc.use_local_subchannel_pool'] ?? 0) === 0
);
const channelControlHelper: ChannelControlHelper = {
createSubchannel: (
subchannelAddress: SubchannelAddress,

View File

@ -30,7 +30,11 @@ import {
UnavailablePicker,
} from './picker';
import { LoadBalancingConfig } from './load-balancing-config';
import { Subchannel, ConnectivityStateListener, SubchannelAddress } from './subchannel';
import {
Subchannel,
ConnectivityStateListener,
SubchannelAddress,
} from './subchannel';
import * as logging from './logging';
import { LogVerbosity } from './constants';

View File

@ -30,7 +30,11 @@ import {
UnavailablePicker,
} from './picker';
import { LoadBalancingConfig } from './load-balancing-config';
import { Subchannel, ConnectivityStateListener, SubchannelAddress } from './subchannel';
import {
Subchannel,
ConnectivityStateListener,
SubchannelAddress,
} from './subchannel';
const TYPE_NAME = 'round_robin';

View File

@ -131,7 +131,7 @@ function parseIP(target: string): SubchannelAddress[] | null {
} else {
port = DEFAULT_PORT;
}
return [{host: addr, port: +port}];
return [{ host: addr, port: +port }];
}
/**
@ -223,8 +223,9 @@ class DnsResolver implements Resolver {
this.pendingResultPromise.then(
([addressList, txtRecord]) => {
this.pendingResultPromise = null;
const ip4Addresses: dns.LookupAddress[] = addressList
.filter(addr => addr.family === 4);
const ip4Addresses: dns.LookupAddress[] = addressList.filter(
addr => addr.family === 4
);
let ip6Addresses: dns.LookupAddress[];
if (semver.satisfies(process.version, IPV6_SUPPORT_RANGE)) {
ip6Addresses = addressList.filter(addr => addr.family === 6);
@ -234,10 +235,16 @@ class DnsResolver implements Resolver {
const allAddresses: SubchannelAddress[] = mergeArrays(
ip4Addresses,
ip6Addresses
).map(addr => {return {host: addr.address, port: +this.port!};});
const allAddressesString: string = '[' + allAddresses.map(addr => addr.host + ':' + addr.port).join(',') + ']';
).map(addr => ({ host: addr.address, port: +this.port! }));
const allAddressesString: string =
'[' +
allAddresses.map(addr => addr.host + ':' + addr.port).join(',') +
']';
trace(
'Resolved addresses for target ' + this.target + ': ' + allAddressesString
'Resolved addresses for target ' +
this.target +
': ' +
allAddressesString
);
if (allAddresses.length === 0) {
this.listener.onError(this.defaultResolutionError);

View File

@ -37,7 +37,7 @@ function getUdsName(target: string): string {
class UdsResolver implements Resolver {
private addresses: SubchannelAddress[] = [];
constructor(target: string, private listener: ResolverListener) {
this.addresses = [{path: getUdsName(target)}];
this.addresses = [{ path: getUdsName(target) }];
}
updateResolution(): void {
process.nextTick(

View File

@ -16,7 +16,7 @@
*/
import { SecureServerOptions } from 'http2';
import {CIPHER_SUITES, getDefaultRootsData} from './tls-helpers';
import { CIPHER_SUITES, getDefaultRootsData } from './tls-helpers';
export interface KeyCertPair {
private_key: Buffer;
@ -75,7 +75,7 @@ export abstract class ServerCredentials {
cert,
key,
requestCert: checkClientCertificate,
ciphers: CIPHER_SUITES
ciphers: CIPHER_SUITES,
});
}
}

View File

@ -203,11 +203,16 @@ export class Server {
const options: ListenOptions = { host: url.hostname, port: +url.port };
const serverOptions: http2.ServerOptions = {};
if ('grpc.max_concurrent_streams' in this.options) {
serverOptions.settings = {maxConcurrentStreams: this.options['grpc.max_concurrent_streams']};
serverOptions.settings = {
maxConcurrentStreams: this.options['grpc.max_concurrent_streams'],
};
}
if (creds._isSecure()) {
const secureServerOptions = Object.assign(serverOptions, creds._getSettings()!);
const secureServerOptions = Object.assign(
serverOptions,
creds._getSettings()!
);
this.http2Server = http2.createSecureServer(secureServerOptions);
} else {
this.http2Server = http2.createServer(serverOptions);

View File

@ -16,7 +16,11 @@
*/
import { ChannelOptions, channelOptionsEqual } from './channel-options';
import { Subchannel, SubchannelAddress, subchannelAddressEqual } from './subchannel';
import {
Subchannel,
SubchannelAddress,
subchannelAddressEqual,
} from './subchannel';
import { ChannelCredentials } from './channel-credentials';
// 10 seconds in milliseconds. This value is arbitrary.
@ -72,8 +76,8 @@ export class SubchannelPool {
}
/* For each subchannel in the pool, try to unref it if it has
* exactly one ref (which is the ref from the pool itself). If that
* does happen, remove the subchannel from the pool */
* exactly one ref (which is the ref from the pool itself). If that
* does happen, remove the subchannel from the pool */
this.pool[channelTarget] = refedSubchannels;
}
/* Currently we do not delete keys with empty values. If that results
@ -120,7 +124,10 @@ export class SubchannelPool {
const subchannelObjArray = this.pool[channelTarget];
for (const subchannelObj of subchannelObjArray) {
if (
subchannelAddressEqual(subchannelTarget, subchannelObj.subchannelAddress) &&
subchannelAddressEqual(
subchannelTarget,
subchannelObj.subchannelAddress
) &&
channelOptionsEqual(
channelArguments,
subchannelObj.channelArguments

View File

@ -86,8 +86,15 @@ export interface SubchannelAddress {
path?: string;
}
export function subchannelAddressEqual(address1: SubchannelAddress, address2: SubchannelAddress) : boolean {
return address1.port === address2.port && address1.host === address2.host && address1.path === address2.path;
export function subchannelAddressEqual(
address1: SubchannelAddress,
address2: SubchannelAddress
): boolean {
return (
address1.port === address2.port &&
address1.host === address2.host &&
address1.path === address2.path
);
}
export class Subchannel {
@ -194,7 +201,7 @@ export class Subchannel {
clearTimeout(this.keepaliveTimeoutId);
const backoffOptions: BackoffOptions = {
initialDelay: options['grpc.initial_reconnect_backoff_ms'],
maxDelay: options['grpc.max_reconnect_backoff_ms']
maxDelay: options['grpc.max_reconnect_backoff_ms'],
};
this.backoffTimeout = new BackoffTimeout(() => {
if (this.continueConnecting) {
@ -276,7 +283,10 @@ export class Subchannel {
connectionOptions.servername = getDefaultAuthority(this.channelTarget);
}
}
connectionOptions = Object.assign(connectionOptions, this.subchannelAddress);
connectionOptions = Object.assign(
connectionOptions,
this.subchannelAddress
);
/* http2.connect uses the options here:
* https://github.com/nodejs/node/blob/70c32a6d190e2b5d7b9ff9d5b6a459d14e8b7d59/lib/internal/http2/core.js#L3028-L3036
* The spread operator overides earlier values with later ones, so any port

View File

@ -17,7 +17,8 @@
import * as fs from 'fs';
export const CIPHER_SUITES: string | undefined = process.env.GRPC_SSL_CIPHER_SUITES;
export const CIPHER_SUITES: string | undefined =
process.env.GRPC_SSL_CIPHER_SUITES;
const DEFAULT_ROOTS_FILE_PATH = process.env.GRPC_DEFAULT_SSL_ROOTS_FILE_PATH;
@ -31,4 +32,4 @@ export function getDefaultRootsData(): Buffer | null {
return defaultRootsData;
}
return null;
}
}

View File

@ -38,7 +38,11 @@ describe('Name Resolver', () => {
serviceConfig: ServiceConfig | null,
serviceConfigError: StatusObject | null
) => {
assert(addressList.some(addr => addr.host === '127.0.0.1' && addr.port === 50051));
assert(
addressList.some(
addr => addr.host === '127.0.0.1' && addr.port === 50051
)
);
// We would check for the IPv6 address but it needs to be omitted on some Node versions
done();
},
@ -57,7 +61,11 @@ describe('Name Resolver', () => {
serviceConfig: ServiceConfig | null,
serviceConfigError: StatusObject | null
) => {
assert(addressList.some(addr => addr.host === '127.0.0.1' && addr.port === 443));
assert(
addressList.some(
addr => addr.host === '127.0.0.1' && addr.port === 443
)
);
// We would check for the IPv6 address but it needs to be omitted on some Node versions
done();
},
@ -76,7 +84,11 @@ describe('Name Resolver', () => {
serviceConfig: ServiceConfig | null,
serviceConfigError: StatusObject | null
) => {
assert(addressList.some(addr => addr.host === '1.2.3.4' && addr.port === 443));
assert(
addressList.some(
addr => addr.host === '1.2.3.4' && addr.port === 443
)
);
// We would check for the IPv6 address but it needs to be omitted on some Node versions
done();
},
@ -95,7 +107,9 @@ describe('Name Resolver', () => {
serviceConfig: ServiceConfig | null,
serviceConfigError: StatusObject | null
) => {
assert(addressList.some(addr => addr.host === '::1' && addr.port === 443));
assert(
addressList.some(addr => addr.host === '::1' && addr.port === 443)
);
// We would check for the IPv6 address but it needs to be omitted on some Node versions
done();
},
@ -114,7 +128,9 @@ describe('Name Resolver', () => {
serviceConfig: ServiceConfig | null,
serviceConfigError: StatusObject | null
) => {
assert(addressList.some(addr => addr.host === '::1' && addr.port === 50051));
assert(
addressList.some(addr => addr.host === '::1' && addr.port === 50051)
);
// We would check for the IPv6 address but it needs to be omitted on some Node versions
done();
},
@ -223,7 +239,7 @@ describe('Name Resolver', () => {
serviceConfig: ServiceConfig | null,
serviceConfigError: StatusObject | null
) => {
assert(addressList.some(addr => addr.path = 'socket'));
assert(addressList.some(addr => (addr.path = 'socket')));
done();
},
onError: (error: StatusObject) => {
@ -241,7 +257,7 @@ describe('Name Resolver', () => {
serviceConfig: ServiceConfig | null,
serviceConfigError: StatusObject | null
) => {
assert(addressList.some(addr => addr.path = '/tmp/socket'));
assert(addressList.some(addr => (addr.path = '/tmp/socket')));
done();
},
onError: (error: StatusObject) => {