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

@ -190,7 +190,7 @@ class SecureChannelCredentialsImpl extends ChannelCredentials {
ca: rootCerts || undefined, ca: rootCerts || undefined,
key: privateKey || undefined, key: privateKey || undefined,
cert: certChain || undefined, cert: certChain || undefined,
ciphers: CIPHER_SUITES ciphers: CIPHER_SUITES,
}); });
this.connectionOptions = { secureContext }; this.connectionOptions = { secureContext };
if (verifyOptions && verifyOptions.checkServerIdentity) { 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 global boolean parameter to getSubchannelPool has the inverse meaning to what
* the grpc.use_local_subchannel_pool channel option means. */ * 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 = { const channelControlHelper: ChannelControlHelper = {
createSubchannel: ( createSubchannel: (
subchannelAddress: SubchannelAddress, subchannelAddress: SubchannelAddress,

View File

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

View File

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

View File

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

View File

@ -75,7 +75,7 @@ export abstract class ServerCredentials {
cert, cert,
key, key,
requestCert: checkClientCertificate, 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 options: ListenOptions = { host: url.hostname, port: +url.port };
const serverOptions: http2.ServerOptions = {}; const serverOptions: http2.ServerOptions = {};
if ('grpc.max_concurrent_streams' in this.options) { 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()) { if (creds._isSecure()) {
const secureServerOptions = Object.assign(serverOptions, creds._getSettings()!); const secureServerOptions = Object.assign(
serverOptions,
creds._getSettings()!
);
this.http2Server = http2.createSecureServer(secureServerOptions); this.http2Server = http2.createSecureServer(secureServerOptions);
} else { } else {
this.http2Server = http2.createServer(serverOptions); this.http2Server = http2.createServer(serverOptions);

View File

@ -16,7 +16,11 @@
*/ */
import { ChannelOptions, channelOptionsEqual } from './channel-options'; import { ChannelOptions, channelOptionsEqual } from './channel-options';
import { Subchannel, SubchannelAddress, subchannelAddressEqual } from './subchannel'; import {
Subchannel,
SubchannelAddress,
subchannelAddressEqual,
} from './subchannel';
import { ChannelCredentials } from './channel-credentials'; import { ChannelCredentials } from './channel-credentials';
// 10 seconds in milliseconds. This value is arbitrary. // 10 seconds in milliseconds. This value is arbitrary.
@ -120,7 +124,10 @@ export class SubchannelPool {
const subchannelObjArray = this.pool[channelTarget]; const subchannelObjArray = this.pool[channelTarget];
for (const subchannelObj of subchannelObjArray) { for (const subchannelObj of subchannelObjArray) {
if ( if (
subchannelAddressEqual(subchannelTarget, subchannelObj.subchannelAddress) && subchannelAddressEqual(
subchannelTarget,
subchannelObj.subchannelAddress
) &&
channelOptionsEqual( channelOptionsEqual(
channelArguments, channelArguments,
subchannelObj.channelArguments subchannelObj.channelArguments

View File

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

View File

@ -17,7 +17,8 @@
import * as fs from 'fs'; 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; const DEFAULT_ROOTS_FILE_PATH = process.env.GRPC_DEFAULT_SSL_ROOTS_FILE_PATH;

View File

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