UNPKG

1.61 kBPlain TextView Raw
1/*
2 * Copyright 2019 gRPC authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import { Resolver, ResolverListener, registerResolver } from './resolver';
18import { SubchannelAddress } from './subchannel-address';
19import { GrpcUri } from './uri-parser';
20import { ChannelOptions } from './channel-options';
21
22class UdsResolver implements Resolver {
23 private addresses: SubchannelAddress[] = [];
24 constructor(
25 target: GrpcUri,
26 private listener: ResolverListener,
27 channelOptions: ChannelOptions
28 ) {
29 let path: string;
30 if (target.authority === '') {
31 path = '/' + target.path;
32 } else {
33 path = target.path;
34 }
35 this.addresses = [{ path }];
36 }
37 updateResolution(): void {
38 process.nextTick(
39 this.listener.onSuccessfulResolution,
40 this.addresses,
41 null,
42 null,
43 null,
44 {}
45 );
46 }
47
48 destroy() {
49 // This resolver owns no resources, so we do nothing here.
50 }
51
52 static getDefaultAuthority(target: GrpcUri): string {
53 return 'localhost';
54 }
55}
56
57export function setup() {
58 registerResolver('unix', UdsResolver);
59}