diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-01-18 18:35:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-18 18:35:12 +0100 |
commit | 34b99fec8edcff7d3b667f273afea69df15e4d5e (patch) | |
tree | 108ea1800b83641023baede5bf9bceba8238f203 /cli/js | |
parent | 4f1fa82d1d0458170039d4809c3879993659e560 (diff) |
rename dial to connect and dialTLS to connectTLS (#3710)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/deno.ts | 3 | ||||
-rw-r--r-- | cli/js/dispatch.ts | 4 | ||||
-rw-r--r-- | cli/js/lib.deno_runtime.d.ts | 28 | ||||
-rw-r--r-- | cli/js/net.ts | 25 | ||||
-rw-r--r-- | cli/js/net_test.ts | 14 | ||||
-rw-r--r-- | cli/js/resources_test.ts | 2 | ||||
-rw-r--r-- | cli/js/tls.ts | 12 | ||||
-rw-r--r-- | cli/js/tls_test.ts | 10 |
8 files changed, 42 insertions, 56 deletions
diff --git a/cli/js/deno.ts b/cli/js/deno.ts index a754bc4e2..513d9f284 100644 --- a/cli/js/deno.ts +++ b/cli/js/deno.ts @@ -81,14 +81,13 @@ export { FileInfo } from "./file_info.ts"; export { openPlugin } from "./plugins.ts"; export { connect, - dial, listen, Listener, Conn, ShutdownMode, shutdown } from "./net.ts"; -export { dialTLS, listenTLS } from "./tls.ts"; +export { connectTLS, listenTLS } from "./tls.ts"; export { metrics, Metrics } from "./metrics.ts"; export { resources } from "./resources.ts"; export { diff --git a/cli/js/dispatch.ts b/cli/js/dispatch.ts index 7e6709dc6..f5049cca8 100644 --- a/cli/js/dispatch.ts +++ b/cli/js/dispatch.ts @@ -29,7 +29,7 @@ export let OP_REPL_START: number; export let OP_REPL_READLINE: number; export let OP_ACCEPT: number; export let OP_ACCEPT_TLS: number; -export let OP_DIAL: number; +export let OP_CONNECT: number; export let OP_SHUTDOWN: number; export let OP_LISTEN: number; export let OP_LISTEN_TLS: number; @@ -69,7 +69,7 @@ export let OP_READ_LINK: number; export let OP_TRUNCATE: number; export let OP_MAKE_TEMP_DIR: number; export let OP_CWD: number; -export let OP_DIAL_TLS: number; +export let OP_CONNECT_TLS: number; export let OP_HOSTNAME: number; export let OP_OPEN_PLUGIN: number; export let OP_COMPILE: number; diff --git a/cli/js/lib.deno_runtime.d.ts b/cli/js/lib.deno_runtime.d.ts index 32914dabe..c4055bc35 100644 --- a/cli/js/lib.deno_runtime.d.ts +++ b/cli/js/lib.deno_runtime.d.ts @@ -1307,7 +1307,7 @@ declare namespace Deno { interface Addr { transport: Transport; - /** UNSTABLE: Address is unstable because inconsistent with DialOptions. */ + /** UNSTABLE: Address is unstable because inconsistent with ConnectOptions. */ address: string; } @@ -1419,15 +1419,13 @@ declare namespace Deno { */ export function listenTLS(options: ListenTLSOptions): Listener; - /** UNSTABLE rename to ConnectOptions */ - export interface DialOptions { + export interface ConnectOptions { port: number; hostname?: string; transport?: Transport; } - /** UNSTABLE: Rename to connect. - * + /** * Dial connects to the address on the named transport. * * @param options @@ -1440,25 +1438,23 @@ declare namespace Deno { * * Examples: * - * dial({ port: 80 }) - * dial({ hostname: "192.0.2.1", port: 80 }) - * dial({ hostname: "[2001:db8::1]", port: 80 }); - * dial({ hostname: "golang.org", port: 80, transport: "tcp" }) + * connect({ port: 80 }) + * connect({ hostname: "192.0.2.1", port: 80 }) + * connect({ hostname: "[2001:db8::1]", port: 80 }); + * connect({ hostname: "golang.org", port: 80, transport: "tcp" }) */ - export function dial(options: DialOptions): Promise<Conn>; + export function connect(options: ConnectOptions): Promise<Conn>; - /** UNSTABLE: rename to ConnectTLSOptions */ - export interface DialTLSOptions { + export interface ConnectTLSOptions { port: number; hostname?: string; certFile?: string; } - /** UNSTABLE: rename to connectTLS. - * - * dialTLS establishes a secure connection over TLS (transport layer security). + /** + * Establishes a secure connection over TLS (transport layer security). */ - export function dialTLS(options: DialTLSOptions): Promise<Conn>; + export function connectTLS(options: ConnectTLSOptions): Promise<Conn>; /** UNSTABLE: not sure if broken or not */ export interface Metrics { diff --git a/cli/js/net.ts b/cli/js/net.ts index 8c9fbcb39..374454136 100644 --- a/cli/js/net.ts +++ b/cli/js/net.ts @@ -1,6 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { EOF, Reader, Writer, Closer } from "./io.ts"; -import { notImplemented } from "./util.ts"; import { read, write, close } from "./files.ts"; import * as dispatch from "./dispatch.ts"; import { sendSync, sendAsync } from "./dispatch_json.ts"; @@ -9,7 +8,7 @@ export type Transport = "tcp"; // TODO support other types: // export type Transport = "tcp" | "tcp4" | "tcp6" | "unix" | "unixpacket"; -// TODO(ry) Replace 'address' with 'hostname' and 'port', similar to DialOptions +// TODO(ry) Replace 'address' with 'hostname' and 'port', similar to ConnectOptions // and ListenOptions. export interface Addr { transport: Transport; @@ -184,7 +183,7 @@ export function listen(options: ListenOptions): Listener { return new ListenerImpl(res.rid, transport, res.localAddr); } -export interface DialOptions { +export interface ConnectOptions { port: number; hostname?: string; transport?: Transport; @@ -202,24 +201,16 @@ export interface DialOptions { * * Examples: * - * dial({ port: 80 }) - * dial({ hostname: "192.0.2.1", port: 80 }) - * dial({ hostname: "[2001:db8::1]", port: 80 }); - * dial({ hostname: "golang.org", port: 80, transport: "tcp" }) + * connect({ port: 80 }) + * connect({ hostname: "192.0.2.1", port: 80 }) + * connect({ hostname: "[2001:db8::1]", port: 80 }); + * connect({ hostname: "golang.org", port: 80, transport: "tcp" }) */ -export async function dial(options: DialOptions): Promise<Conn> { - const res = await sendAsync(dispatch.OP_DIAL, { +export async function connect(options: ConnectOptions): Promise<Conn> { + const res = await sendAsync(dispatch.OP_CONNECT, { hostname: options.hostname || "127.0.0.1", port: options.port, transport: options.transport || "tcp" }); return new ConnImpl(res.rid, res.remoteAddr!, res.localAddr!); } - -/** **RESERVED** */ -export async function connect( - _transport: Transport, - _address: string -): Promise<Conn> { - return notImplemented(); -} diff --git a/cli/js/net_test.ts b/cli/js/net_test.ts index 926571c82..ec395bc1d 100644 --- a/cli/js/net_test.ts +++ b/cli/js/net_test.ts @@ -6,7 +6,7 @@ testPerm({ net: true }, function netListenClose(): void { const addr = listener.addr(); assertEquals(addr.transport, "tcp"); // TODO(ry) Replace 'address' with 'hostname' and 'port', similar to - // DialOptions and ListenOptions. + // ConnectOptions and ListenOptions. assertEquals(addr.address, "127.0.0.1:4500"); listener.close(); }); @@ -57,7 +57,7 @@ testPerm({ net: true }, async function netDialListen(): Promise<void> { conn.close(); } ); - const conn = await Deno.dial({ hostname: "127.0.0.1", port: 4500 }); + const conn = await Deno.connect({ hostname: "127.0.0.1", port: 4500 }); assertEquals(conn.remoteAddr, "127.0.0.1:4500"); assert(conn.localAddr != null); const buf = new Uint8Array(1024); @@ -99,7 +99,7 @@ testPerm({ net: true }, async function netListenAsyncIterator(): Promise<void> { } }; runAsyncIterator(); - const conn = await Deno.dial("127.0.0.1:4500"); + const conn = await Deno.connect("127.0.0.1:4500"); const buf = new Uint8Array(1024); const readResult = await conn.read(buf); assertEquals(3, readResult); @@ -136,7 +136,7 @@ testPerm({ net: true }, async function netCloseReadSuccess() { conn.close(); closeDeferred.resolve(); }); - const conn = await Deno.dial(addr); + const conn = await Deno.connect(addr); conn.closeRead(); // closing read closeReadDeferred.resolve(); const buf = new Uint8Array(1024); @@ -160,7 +160,7 @@ testPerm({ net: true }, async function netDoubleCloseRead() { await closeDeferred.promise; conn.close(); }); - const conn = await Deno.dial(addr); + const conn = await Deno.connect(addr); conn.closeRead(); // closing read let err; try { @@ -188,7 +188,7 @@ testPerm({ net: true }, async function netCloseWriteSuccess() { await closeDeferred.promise; conn.close(); }); - const conn = await Deno.dial(addr); + const conn = await Deno.connect(addr); conn.closeWrite(); // closing write const buf = new Uint8Array(1024); // Check read not impacted @@ -222,7 +222,7 @@ testPerm({ net: true }, async function netDoubleCloseWrite() { await closeDeferred.promise; conn.close(); }); - const conn = await Deno.dial(addr); + const conn = await Deno.connect(addr); conn.closeWrite(); // closing write let err; try { diff --git a/cli/js/resources_test.ts b/cli/js/resources_test.ts index f0fec8089..880727027 100644 --- a/cli/js/resources_test.ts +++ b/cli/js/resources_test.ts @@ -11,7 +11,7 @@ test(function resourcesStdio(): void { testPerm({ net: true }, async function resourcesNet(): Promise<void> { const listener = Deno.listen({ port: 4501 }); - const dialerConn = await Deno.dial({ port: 4501 }); + const dialerConn = await Deno.connect({ port: 4501 }); const listenerConn = await listener.accept(); const res = Deno.resources(); diff --git a/cli/js/tls.ts b/cli/js/tls.ts index 1a2c4bdfd..4dfb32e31 100644 --- a/cli/js/tls.ts +++ b/cli/js/tls.ts @@ -5,19 +5,19 @@ import { Listener, Transport, Conn, ConnImpl, ListenerImpl } from "./net.ts"; // TODO(ry) There are many configuration options to add... // https://docs.rs/rustls/0.16.0/rustls/struct.ClientConfig.html -interface DialTLSOptions { +interface ConnectTLSOptions { port: number; hostname?: string; certFile?: string; } -const dialTLSDefaults = { hostname: "127.0.0.1", transport: "tcp" }; +const connectTLSDefaults = { hostname: "127.0.0.1", transport: "tcp" }; /** - * dialTLS establishes a secure connection over TLS (transport layer security). + * Establishes a secure connection over TLS (transport layer security). */ -export async function dialTLS(options: DialTLSOptions): Promise<Conn> { - options = Object.assign(dialTLSDefaults, options); - const res = await sendAsync(dispatch.OP_DIAL_TLS, options); +export async function connectTLS(options: ConnectTLSOptions): Promise<Conn> { + options = Object.assign(connectTLSDefaults, options); + const res = await sendAsync(dispatch.OP_CONNECT_TLS, options); return new ConnImpl(res.rid, res.remoteAddr!, res.localAddr!); } diff --git a/cli/js/tls_test.ts b/cli/js/tls_test.ts index da2c1cec8..de841f5a1 100644 --- a/cli/js/tls_test.ts +++ b/cli/js/tls_test.ts @@ -7,10 +7,10 @@ import { runIfMain } from "../../std/testing/mod.ts"; const encoder = new TextEncoder(); const decoder = new TextDecoder(); -test(async function dialTLSNoPerm(): Promise<void> { +test(async function connectTLSNoPerm(): Promise<void> { let err; try { - await Deno.dialTLS({ hostname: "github.com", port: 443 }); + await Deno.connectTLS({ hostname: "github.com", port: 443 }); } catch (e) { err = e; } @@ -18,10 +18,10 @@ test(async function dialTLSNoPerm(): Promise<void> { assertEquals(err.name, "PermissionDenied"); }); -test(async function dialTLSCertFileNoReadPerm(): Promise<void> { +test(async function connectTLSCertFileNoReadPerm(): Promise<void> { let err; try { - await Deno.dialTLS({ + await Deno.connectTLS({ hostname: "github.com", port: 443, certFile: "cli/tests/tls/RootCA.crt" @@ -173,7 +173,7 @@ testPerm({ read: true, net: true }, async function dialAndListenTLS(): Promise< } ); - const conn = await Deno.dialTLS({ + const conn = await Deno.connectTLS({ hostname, port, certFile: "cli/tests/tls/RootCA.pem" |