网络协议总览和记录
翻译: https://www.firezone.dev/blog/how-dns-works-in-firezone
DNS
nslookup github.com
结果如下:
;; Got recursion not available from 172.18.176.1
Server: 172.18.176.1
Address: 172.18.176.1#53
Non-authoritative answer:
Name: github.com
Address: 20.205.243.166
工作原理
从高层次来看,DNS 是一个分层系统,它将解析完全限定域名 (FQDN) 的责任分配给一系列 name servers,每个name s...
阻塞非阻塞、同步异步、IO模型
阻塞、非阻塞、同步、异步
典型的一次 IO 包含两个阶段:
数据准备
数据读写
阻塞和非阻塞:根据系统 IO 的就绪状态判断,也就是数据准备阶段
同步和异步:根据应用程序和内核的交互方式判断,也就是数据读写阶段
在Linux 中,阻塞和非阻塞都是同步 IO,异步 IO 需要特殊的 API
包括 select/poll/epoll 都是同步 IO
Linux 上的 AIO 才是异步 IO,类似于 Windows 上的 IOCP
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
int size = recv(sockfd, buf, 1024, 0);
// s...
生成openssl证书链和公钥pinnings
关于证书的问题: 为什么客户端需要内置 Root 证书?证书链
参考:https://www.kawabangga.com/posts/5330
HTTP Public Key Pinning
HTTP公钥固定是一种防止利用CA机构错发证书,而进行中间人攻击的安全机制,用于预防CA遭受入侵或其他会造成CA签发未授权证书的情况。
工作原理:服务器通过Public-Key-Pins(或Public-Key-Pins-Report-Only用于监测)HTTP头向浏览器传递HTTP公钥固定信息。HTTP公钥固定将网站X.509证书链中的一个SPKI(和至少一个备用密钥)以pin-sha256方式进行哈希,由参数max-age(单位秒)所指定一段时间,可选参数includeSubDomai...
WSL2上安装 Perf
wsl 上安装 perf
参考使用 bcc:https://massoudasadiblog.blogspot.com/2024/07/ebpf-on-wsl2-kernel-version-6x-ubuntu.html?m=1
参考:https://gist.github.com/abel0b/b1881e41b9e1c4b16d84e5e083c38a13
https://gist.github.com/MarioHewardt/5759641727aae880b29c8f715ba4d30f
参考bcc的安装文档:https://github.com/iovisor/bcc/blob/master/INSTALL.md#wslwindows-subsystem-for-li...
Rust性能分析
Rust 性能分析
因为常见的性能瓶颈一般都是两类,CPU 和 I/O 。所以工具也基本面向这两类。
on-cpu 分析
cargo-flamegraph
perf
可以通过 Frame Pointer 和 DWARF 两种方式拿到函数的调用栈,默认是不启用的,通过下列方式启用 Frame Pointer
RUSTFLAGS="-C force-frame-pointers=yes" cargo build --release
因为Frame Pointer的保存和恢复需要引入额外的指令从而带来性能开销,所以Rust编译器,gcc编译器默认都是不会加入Frame Pointer的信息,需要通过编译选项来开启。
Frame Pointer
Frame Point...
Rust中的条件编译
Rust 的条件编译
在 Cargo.toml 中使用 [features] 来加入条件编译 feature。如下定义了一个 rand 的 feature:
[package]
name = "example"
version = "0.1.0"
[features]
rand = []
然后在代码中可以使用该 feature
#[cfg(feature = "rand")]
pub mod rand;
如果作为 crate,则其他人可以像下面一样来启用依赖的feature:
[dependencies]
example = { version = "0.1.0", features = ["rand"]}
还可以开启多个 feature,并且可以有依赖关系:
[featur...
调试libcurl的准备事项、环境配置
Time: 2024-12-17,安装具有时效性,和版本相关
环境:Ubuntu22.04
由于新版本的 nghttp2 依赖 C++ 20 的特性,因此在 Ubuntu22.04 上默认通过 apt install build-essential 安装的 gcc11 版本不匹配,因此需要安装 gcc 13。
gcc13安装
安装 build-essential
sudo apt install build-essential
安装完检查 /usr/bin/ 下是否有 gcc, g++, gcc-11, g++11
添加 ppa 源
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
然后开始安装,并设定不同版...
29 post articles, 4 pages.