Skip to content

Commit

Permalink
fix(resolveInternetAddress): Only take Awala Internet addresses (#497)
Browse files Browse the repository at this point in the history
Dropping support for custom ports.
  • Loading branch information
gnarea authored Aug 2, 2022
1 parent c3cb820 commit 7048cfe
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 24 deletions.
7 changes: 0 additions & 7 deletions src/integration_tests/internetAddressing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,4 @@ describe('resolveInternetAddress', () => {
test('Non-existing addresses should not be resolved', async () => {
await expect(resolveInternetAddress(NON_EXISTING_ADDRESS, BindingType.PDC)).resolves.toBeNull();
});

test('Non-existing address should resolve if port is contained', async () => {
const port = 1234;
await expect(
resolveInternetAddress(`${NON_EXISTING_ADDRESS}:${port}`, BindingType.PDC),
).resolves.toEqual({ host: NON_EXISTING_ADDRESS, port });
});
});
8 changes: 0 additions & 8 deletions src/lib/internetAddressing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ import {
describe('resolveInternetAddress', () => {
const MALFORMED_ANSWER_ERROR = new InternetAddressingError('DNS answer is malformed');

test('DNS resolution should be skipped if host name contains port', async () => {
const address = await resolveInternetAddress(`${HOST}:${TARGET_PORT}`, BindingType.PDC);

expect(address).toHaveProperty('host', HOST);
expect(address).toHaveProperty('port', TARGET_PORT);
expect(mockGetDNS).not.toBeCalled();
});

test('Specified domain name should be requested', async () => {
await resolveInternetAddress(HOST, BindingType.PDC);

Expand Down
9 changes: 0 additions & 9 deletions src/lib/internetAddressing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,13 @@ export class UnreachableResolverError extends RelaynetError {}
* `null` is returned when `hostName` is an IP address or a non-existing SRV record for the service
* in `bindingType`.
*
* If `hostName` contains the port number (e.g., `example.com:443`), no DNS lookup will be done
* and the resulting address will simply be the result of parsing the input.
*
* DNS resolution is done with DNS-over-HTTPS.
*/
export async function resolveInternetAddress(
hostName: string,
bindingType: BindingType,
resolverURL = CLOUDFLARE_RESOLVER_URL,
): Promise<PublicNodeAddress | null> {
const urlParts = new URL(`scheme://${hostName}`);
if (urlParts.port !== '') {
const port = parseInt(urlParts.port, 10);
return { host: urlParts.hostname, port };
}

const name = `_${bindingType}._tcp.${hostName}`;
const doh = new DNSoverHTTPS({ url: resolverURL });
let result: LookupResult;
Expand Down

0 comments on commit 7048cfe

Please sign in to comment.