summaryrefslogtreecommitdiff
path: root/ext/net/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/net/lib.rs')
-rw-r--r--ext/net/lib.rs86
1 files changed, 38 insertions, 48 deletions
diff --git a/ext/net/lib.rs b/ext/net/lib.rs
index 4703b05cc..76ed02706 100644
--- a/ext/net/lib.rs
+++ b/ext/net/lib.rs
@@ -8,9 +8,6 @@ pub mod ops_unix;
pub mod resolve_addr;
use deno_core::error::AnyError;
-use deno_core::include_js_files;
-use deno_core::Extension;
-use deno_core::ExtensionBuilder;
use deno_core::OpState;
use deno_tls::rustls::RootCertStore;
use std::cell::RefCell;
@@ -78,55 +75,48 @@ pub struct DefaultTlsOptions {
/// would override previously used alias.
pub struct UnsafelyIgnoreCertificateErrors(pub Option<Vec<String>>);
-fn ext() -> ExtensionBuilder {
- Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_web"])
-}
+deno_core::extension!(deno_net,
+ deps = [ deno_web ],
+ parameters = [ P: NetPermissions ],
+ ops = [
+ ops::op_net_accept_tcp,
+ ops::op_net_connect_tcp<P>,
+ ops::op_net_listen_tcp<P>,
+ ops::op_net_listen_udp<P>,
+ ops::op_node_unstable_net_listen_udp<P>,
+ ops::op_net_recv_udp,
+ ops::op_net_send_udp<P>,
+ ops::op_dns_resolve<P>,
+ ops::op_set_nodelay,
+ ops::op_set_keepalive,
-fn ops<P: NetPermissions + 'static>(
- ext: &mut ExtensionBuilder,
- root_cert_store: Option<RootCertStore>,
- unstable: bool,
- unsafely_ignore_certificate_errors: Option<Vec<String>>,
-) -> &mut ExtensionBuilder {
- let mut ops = ops::init::<P>();
- ops.extend(ops_tls::init::<P>());
+ ops_tls::op_tls_start<P>,
+ ops_tls::op_net_connect_tls<P>,
+ ops_tls::op_net_listen_tls<P>,
+ ops_tls::op_net_accept_tls,
+ ops_tls::op_tls_handshake,
- ext.ops(ops).state(move |state| {
+ #[cfg(unix)] ops_unix::op_net_accept_unix,
+ #[cfg(unix)] ops_unix::op_net_connect_unix<P>,
+ #[cfg(unix)] ops_unix::op_net_listen_unix<P>,
+ #[cfg(unix)] ops_unix::op_net_listen_unixpacket<P>,
+ #[cfg(unix)] ops_unix::op_node_unstable_net_listen_unixpacket<P>,
+ #[cfg(unix)] ops_unix::op_net_recv_unixpacket,
+ #[cfg(unix)] ops_unix::op_net_send_unixpacket<P>,
+ ],
+ esm = [ "01_net.js", "02_tls.js" ],
+ config = {
+ root_cert_store: Option<RootCertStore>,
+ unstable: bool,
+ unsafely_ignore_certificate_errors: Option<Vec<String>>,
+ },
+ state = |state, root_cert_store, unstable, unsafely_ignore_certificate_errors| {
state.put(DefaultTlsOptions {
- root_cert_store: root_cert_store.clone(),
+ root_cert_store,
});
state.put(UnstableChecker { unstable });
state.put(UnsafelyIgnoreCertificateErrors(
- unsafely_ignore_certificate_errors.clone(),
+ unsafely_ignore_certificate_errors,
));
- })
-}
-
-pub fn init_ops_and_esm<P: NetPermissions + 'static>(
- root_cert_store: Option<RootCertStore>,
- unstable: bool,
- unsafely_ignore_certificate_errors: Option<Vec<String>>,
-) -> Extension {
- ops::<P>(
- &mut ext(),
- root_cert_store,
- unstable,
- unsafely_ignore_certificate_errors,
- )
- .esm(include_js_files!("01_net.js", "02_tls.js",))
- .build()
-}
-
-pub fn init_ops<P: NetPermissions + 'static>(
- root_cert_store: Option<RootCertStore>,
- unstable: bool,
- unsafely_ignore_certificate_errors: Option<Vec<String>>,
-) -> Extension {
- ops::<P>(
- &mut ext(),
- root_cert_store,
- unstable,
- unsafely_ignore_certificate_errors,
- )
- .build()
-}
+ },
+);