UNPKG

1.74 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 { Endpoint } from './subchannel-address';
19import { GrpcUri } from './uri-parser';
20import { ChannelOptions } from './channel-options';
21
22class UdsResolver implements Resolver {
23 private hasReturnedResult = false;
24 private endpoints: Endpoint[] = [];
25 constructor(
26 target: GrpcUri,
27 private listener: ResolverListener,
28 channelOptions: ChannelOptions
29 ) {
30 let path: string;
31 if (target.authority === '') {
32 path = '/' + target.path;
33 } else {
34 path = target.path;
35 }
36 this.endpoints = [{ addresses: [{ path }] }];
37 }
38 updateResolution(): void {
39 if (!this.hasReturnedResult) {
40 this.hasReturnedResult = true;
41 process.nextTick(
42 this.listener.onSuccessfulResolution,
43 this.endpoints,
44 null,
45 null,
46 null,
47 {}
48 );
49 }
50 }
51
52 destroy() {
53 // This resolver owns no resources, so we do nothing here.
54 }
55
56 static getDefaultAuthority(target: GrpcUri): string {
57 return 'localhost';
58 }
59}
60
61export function setup() {
62 registerResolver('unix', UdsResolver);
63}