mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
chore(ext/node): cleanup net blocklist ops (#24299)
This commit is contained in:
parent
c012c202af
commit
496428b82e
1 changed files with 13 additions and 21 deletions
|
@ -1,6 +1,5 @@
|
||||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
|
@ -18,12 +17,6 @@ use ipnetwork::Ipv4Network;
|
||||||
use ipnetwork::Ipv6Network;
|
use ipnetwork::Ipv6Network;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
pub struct BlockListResource {
|
|
||||||
blocklist: RefCell<BlockList>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl deno_core::GcResource for BlockListResource {}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct SocketAddressSerialization(String, String);
|
struct SocketAddressSerialization(String, String);
|
||||||
|
|
||||||
|
@ -66,52 +59,51 @@ pub fn op_socket_address_get_serialization(
|
||||||
|
|
||||||
#[op2]
|
#[op2]
|
||||||
#[cppgc]
|
#[cppgc]
|
||||||
pub fn op_blocklist_new() -> BlockListResource {
|
pub fn op_blocklist_new() -> BlockList {
|
||||||
let blocklist = BlockList::new();
|
BlockList::new()
|
||||||
BlockListResource {
|
|
||||||
blocklist: RefCell::new(blocklist),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op2(fast)]
|
#[op2(fast)]
|
||||||
pub fn op_blocklist_add_address(
|
pub fn op_blocklist_add_address(
|
||||||
#[cppgc] wrap: &BlockListResource,
|
#[cppgc] blocklist: &mut BlockList,
|
||||||
#[string] addr: &str,
|
#[string] addr: &str,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
wrap.blocklist.borrow_mut().add_address(addr)
|
blocklist.add_address(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op2(fast)]
|
#[op2(fast)]
|
||||||
pub fn op_blocklist_add_range(
|
pub fn op_blocklist_add_range(
|
||||||
#[cppgc] wrap: &BlockListResource,
|
#[cppgc] blocklist: &mut BlockList,
|
||||||
#[string] start: &str,
|
#[string] start: &str,
|
||||||
#[string] end: &str,
|
#[string] end: &str,
|
||||||
) -> Result<bool, AnyError> {
|
) -> Result<bool, AnyError> {
|
||||||
wrap.blocklist.borrow_mut().add_range(start, end)
|
blocklist.add_range(start, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op2(fast)]
|
#[op2(fast)]
|
||||||
pub fn op_blocklist_add_subnet(
|
pub fn op_blocklist_add_subnet(
|
||||||
#[cppgc] wrap: &BlockListResource,
|
#[cppgc] blocklist: &mut BlockList,
|
||||||
#[string] addr: &str,
|
#[string] addr: &str,
|
||||||
#[smi] prefix: u8,
|
#[smi] prefix: u8,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
wrap.blocklist.borrow_mut().add_subnet(addr, prefix)
|
blocklist.add_subnet(addr, prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op2(fast)]
|
#[op2(fast)]
|
||||||
pub fn op_blocklist_check(
|
pub fn op_blocklist_check(
|
||||||
#[cppgc] wrap: &BlockListResource,
|
#[cppgc] blocklist: &BlockList,
|
||||||
#[string] addr: &str,
|
#[string] addr: &str,
|
||||||
#[string] r#type: &str,
|
#[string] type_: &str,
|
||||||
) -> Result<bool, AnyError> {
|
) -> Result<bool, AnyError> {
|
||||||
wrap.blocklist.borrow().check(addr, r#type)
|
blocklist.check(addr, type_)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BlockList {
|
struct BlockList {
|
||||||
rules: HashSet<IpNetwork>,
|
rules: HashSet<IpNetwork>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl deno_core::GcResource for BlockList {}
|
||||||
|
|
||||||
impl BlockList {
|
impl BlockList {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
BlockList {
|
BlockList {
|
||||||
|
|
Loading…
Reference in a new issue