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 | |
parent | 4f1fa82d1d0458170039d4809c3879993659e560 (diff) |
rename dial to connect and dialTLS to connectTLS (#3710)
-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 | ||||
-rw-r--r-- | cli/ops/net.rs | 8 | ||||
-rw-r--r-- | cli/ops/tls.rs | 11 | ||||
-rw-r--r-- | std/http/racing_server_test.ts | 4 | ||||
-rw-r--r-- | std/http/server_test.ts | 6 | ||||
-rw-r--r-- | std/ws/mod.ts | 4 | ||||
-rw-r--r-- | tools/deno_tcp_proxy.ts | 2 |
14 files changed, 61 insertions, 72 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" diff --git a/cli/ops/net.rs b/cli/ops/net.rs index 06905f0d2..f337a28d8 100644 --- a/cli/ops/net.rs +++ b/cli/ops/net.rs @@ -22,7 +22,7 @@ use tokio::net::TcpStream; pub fn init(i: &mut Isolate, s: &ThreadSafeState) { i.register_op("accept", s.core_op(json_op(s.stateful_op(op_accept)))); - i.register_op("dial", s.core_op(json_op(s.stateful_op(op_dial)))); + i.register_op("connect", s.core_op(json_op(s.stateful_op(op_connect)))); i.register_op("shutdown", s.core_op(json_op(s.stateful_op(op_shutdown)))); i.register_op("listen", s.core_op(json_op(s.stateful_op(op_listen)))); } @@ -126,18 +126,18 @@ fn op_accept( } #[derive(Deserialize)] -struct DialArgs { +struct ConnectArgs { transport: String, hostname: String, port: u16, } -fn op_dial( +fn op_connect( state: &ThreadSafeState, args: Value, _zero_copy: Option<PinnedBuf>, ) -> Result<JsonOp, ErrBox> { - let args: DialArgs = serde_json::from_value(args)?; + let args: ConnectArgs = serde_json::from_value(args)?; assert_eq!(args.transport, "tcp"); // TODO Support others. let state_ = state.clone(); state.check_net(&args.hostname, args.port)?; diff --git a/cli/ops/tls.rs b/cli/ops/tls.rs index 4bbab3f4e..fc2dec0d1 100644 --- a/cli/ops/tls.rs +++ b/cli/ops/tls.rs @@ -36,7 +36,10 @@ use webpki::DNSNameRef; use webpki_roots; pub fn init(i: &mut Isolate, s: &ThreadSafeState) { - i.register_op("dial_tls", s.core_op(json_op(s.stateful_op(op_dial_tls)))); + i.register_op( + "connect_tls", + s.core_op(json_op(s.stateful_op(op_connect_tls))), + ); i.register_op( "listen_tls", s.core_op(json_op(s.stateful_op(op_listen_tls))), @@ -49,18 +52,18 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -struct DialTLSArgs { +struct ConnectTLSArgs { hostname: String, port: u16, cert_file: Option<String>, } -pub fn op_dial_tls( +pub fn op_connect_tls( state: &ThreadSafeState, args: Value, _zero_copy: Option<PinnedBuf>, ) -> Result<JsonOp, ErrBox> { - let args: DialTLSArgs = serde_json::from_value(args)?; + let args: ConnectTLSArgs = serde_json::from_value(args)?; let cert_file = args.cert_file.clone(); let state_ = state.clone(); state.check_net(&args.hostname, args.port)?; diff --git a/std/http/racing_server_test.ts b/std/http/racing_server_test.ts index b66986247..8b7ff9829 100644 --- a/std/http/racing_server_test.ts +++ b/std/http/racing_server_test.ts @@ -1,4 +1,4 @@ -const { dial, run } = Deno; +const { connect, run } = Deno; import { test, runIfMain } from "../testing/mod.ts"; import { assert, assertEquals } from "../testing/asserts.ts"; @@ -50,7 +50,7 @@ World 4 test(async function serverPipelineRace(): Promise<void> { await startServer(); - const conn = await dial({ port: 4501 }); + const conn = await connect({ port: 4501 }); const r = new TextProtoReader(new BufReader(conn)); await conn.write(new TextEncoder().encode(input)); const outLines = output.split("\n"); diff --git a/std/http/server_test.ts b/std/http/server_test.ts index 5fe06f357..aee9db0ff 100644 --- a/std/http/server_test.ts +++ b/std/http/server_test.ts @@ -595,7 +595,7 @@ test({ await delay(100); // Reqeusts to the server and immediately closes the connection - const conn = await Deno.dial({ port: 4502 }); + const conn = await Deno.connect({ port: 4502 }); await conn.write(new TextEncoder().encode("GET / HTTP/1.0\n\n")); conn.close(); @@ -637,7 +637,7 @@ test({ .catch((_): void => {}); // Ignores the error when closing the process. // Requests to the server and immediately closes the connection - const conn = await Deno.dialTLS({ + const conn = await Deno.connectTLS({ hostname: "localhost", port: 4503, certFile: "http/testdata/tls/RootCA.pem" @@ -721,7 +721,7 @@ if (Deno.build.os !== "win") { assert(!(connRid in resources)); }; const p = serverRoutine(); - const conn = await Deno.dial({ + const conn = await Deno.connect({ hostname: "127.0.0.1", port: 8124 }); diff --git a/std/ws/mod.ts b/std/ws/mod.ts index c256f58ad..96ba4df62 100644 --- a/std/ws/mod.ts +++ b/std/ws/mod.ts @@ -484,10 +484,10 @@ export async function connectWebSocket( let conn: Conn; if (url.protocol === "http:" || url.protocol === "ws:") { const port = parseInt(url.port || "80"); - conn = await Deno.dial({ hostname, port }); + conn = await Deno.connect({ hostname, port }); } else if (url.protocol === "https:" || url.protocol === "wss:") { const port = parseInt(url.port || "443"); - conn = await Deno.dialTLS({ hostname, port }); + conn = await Deno.connectTLS({ hostname, port }); } else { throw new Error("ws: unsupported protocol: " + url.protocol); } diff --git a/tools/deno_tcp_proxy.ts b/tools/deno_tcp_proxy.ts index bf54ad1c0..cd1bad247 100644 --- a/tools/deno_tcp_proxy.ts +++ b/tools/deno_tcp_proxy.ts @@ -8,7 +8,7 @@ const [originHostname, originPort] = originAddr.split(":"); const listener = Deno.listen({ hostname, port: Number(port) }); async function handle(conn: Deno.Conn): Promise<void> { - const origin = await Deno.dial({ + const origin = await Deno.connect({ hostname: originHostname, port: Number(originPort) }); |