[{"data":1,"prerenderedAt":1013},["ShallowReactive",2],{"content:\u002Fen\u002Ffiddling\u002Ffake-ip-based-transparent-proxy":3,"series:content_en":303},{"id":4,"title":5,"authorship":6,"body":7,"categories":271,"date":273,"description":274,"draft":275,"extension":276,"image":277,"meta":278,"navigation":280,"path":281,"permalink":282,"published":282,"readingTime":283,"recommend":282,"references":282,"seo":288,"seoDescription":289,"seoTitle":282,"sitemap":290,"stem":294,"tags":295,"type":301,"__hash__":302},"content_en\u002Fposts\u002Ffiddling\u002Ffake-ip-based-transparent-proxy.md","Routing Transparent Proxy Traffic with FakeIP","human-only",{"type":8,"value":9,"toc":260},"minimark",[10,15,24,37,47,50,56,60,74,82,89,99,102,113,117,122,125,131,134,138,145,153,162,169,175,186,197,203,209,212,215,218,226,229,232,238,241,247,250,254,257],[11,12,14],"h3",{"id":13},"introduction","Introduction",[16,17,18,23],"p",{},[19,20,22],"a",{"href":21},"\u002Fen\u002Ffiddling\u002Fdebian-as-bypass-router","The previous post"," introduced a side router for transparent proxying on a LAN. It is usable for most people, but its drawbacks are fairly clear:",[25,26,27,31,34],"ol",{},[28,29,30],"li",{},"A possible single point of failure: DHCP points the gateway directly to the side router, so if Clash stops working, even sites that need no circumvention become unreachable.",[28,32,33],{},"Clash’s packet-forwarding performance is weak compared with hardware forwarding. With the gateway set to the side router, the iptables setup sends all traffic through Clash, whether it needs circumvention or not.",[28,35,36],{},"Having the side router as a gateway means configuring port forwarding on both the main router and the side router.",[16,38,39,40,46],{},"I recently came across a newer proxy core, sing-box. Perhaps not that new—it only really took off after Clash was archived. Its ",[19,41,45],{"href":42,"rel":43},"https:\u002F\u002Fsing-box.sagernet.org\u002Fconfiguration",[44],"nofollow","wiki"," shows comprehensive protocol and feature support, and better performance optimization than Clash. I decided to use sing-box as the core of the new design.",[16,48,49],{},"Of course, Clash can implement this design too.",[16,51,52],{},[53,54,55],"del",{},"Bad news: you need censorship circumvention to read the sing-box wiki.",[11,57,59],{"id":58},"the-idea","The Idea",[16,61,62,63,67,68,73],{},"Both sing-box and Clash have built-in DNS server modules and support FakeIP. Think of FakeIP this way: ",[64,65,66],"mark",{},"when a client makes a DNS query, the DNS module immediately returns a fake IP, performs the actual lookup in the background, and keeps a mapping between the fake and real addresses. When the client later connects and sends data to the FakeIP, the gateway uses that mapping to contact the real address."," See ",[19,69,72],{"href":70,"rel":71},"https:\u002F\u002Fdatatracker.ietf.org\u002Fdoc\u002Fhtml\u002Frfc3089",[44],"RFC3089"," for a more detailed description. Routing later depends on the fake-to-real mapping saved when answering DNS, so a standalone DNS server cannot implement the entire FakeIP mechanism by itself.",[16,75,76,77,81],{},"FakeIP usually comes from a reserved subnet, most often ",[78,79,80],"code",{"code":80},"198.18.0.0\u002F15",", making it extremely easy to identify and route. Have the software router’s proxy DNS module return FakeIP only for domains that require proxying, then configure the main router’s next hop so that only FakeIP destinations go through the software-router proxy. All other traffic forwards normally. In detail:",[16,83,84],{},[85,86],"img",{"alt":87,"src":88},"FakeIP traffic routing","https:\u002F\u002Fblog-img.774352199.xyz\u002F2025\u002Fe078ffe1fe41b2cbcb04b40a55cbbc56.png",[90,91,96],"pre",{"className":92,"code":94,"language":95},[93],"language-text","1. 无须科学的域名\n  1. 客户端发起 DNS 解析\n  2. DNS 模块判断为无须科学，向国内 DNS 请求，返回 RealIP\n  3. 客户端使用 RealIP 发起请求\n  4. 主路由判断不是 FakeIP，走默认路由（直连）\n  \n2. 需要科学的域名\n  1. 客户端发起 DNS 解析\n  2. DNS 模块判断为需要科学，返回 FakeIP，并向国外 DNS 请求\n  3. 客户端使用 FakeIP 发起请求\n  4. 主路由判断是 FakeIP，路由流量到代理软件\n  5. 代理软件根据 FakeIP 映射，通过出口节点向国外 IP 发起请求\n","text",[78,97,94],{"__ignoreMap":98},"",[16,100,101],{},"This solves the three drawbacks from the previous post:",[25,103,104,107,110],{},[28,105,106],{},"The single point of failure: sing-box going down no longer cuts off Internet access. Following the previous design, sing-box DNS sits behind AdGuard Home. When AdGuard detects its upstream failing, it uses fallback DNS within China. That returns no FakeIP, so all traffic follows the main router’s default route.",[28,108,109],{},"Traffic that does not require circumvention is forwarded directly by the router, bypassing proxy software.",[28,111,112],{},"Forwarding is handled by the main router’s routing table, and all clients use the main router as their gateway. There is no second NAT layer, so the main router’s port forwarding continues to work.",[11,114,116],{"id":115},"implementation","Implementation",[118,119,121],"h4",{"id":120},"main-router-configuration","Main Router Configuration",[16,123,124],{},"First, configure a next-hop gateway on the main router. In iKuai, go to Traffic Control & Routing → Routing Settings → Port Routing and add a rule. Choose Next-Hop Gateway as the routing method and enter your software router’s IP, 192.168.7.2 in my case. Add 198.18.0.0\u002F15 as the destination address, leaving everything else at its default.",[16,126,127],{},[85,128],{"alt":129,"src":130},"Next-hop gateway","https:\u002F\u002Fblog-img.774352199.xyz\u002F2025\u002F37f3bc2ebbd0f4f79e218c2a949a84c4.png",[16,132,133],{},"All traffic destined for 198.18.0.0\u002F15 will now be forwarded to 192.168.7.2 when it reaches the main router.",[118,135,137],{"id":136},"install-and-configure-sing-box","Install and Configure sing-box",[16,139,140,141,144],{},"Set up AdGuard Home using ",[19,142,143],{"href":21},"the previous post",", keeping upstream DNS at 127.0.0.1:1053. Then install sing-box. On Debian, one command is enough:",[90,146,151],{"className":147,"code":149,"language":150,"meta":98},[148],"language-shell","bash \u003C(curl -fsSL https:\u002F\u002Fsing-box.app\u002Fdeb-install.sh)\n","shell",[78,152,149],{"__ignoreMap":98},[16,154,155,156,161],{},"Installation instructions for other distributions are at ",[19,157,160],{"href":158,"rel":159},"https:\u002F\u002Fsing-box.sagernet.org\u002Finstallation\u002Fpackage-manager\u002F#__tabbed_2_1",[44],"https:\u002F\u002Fsing-box.sagernet.org\u002Finstallation\u002Fpackage-manager",".",[16,163,164,165,168],{},"The installer creates a systemd service automatically. Unusually, its definition is in ",[78,166,167],{"code":167},"\u002Flib\u002Fsystemd\u002Fsystem\u002Fsing-box.service",". Edit that file and add these three lines before ExecStart:",[90,170,173],{"className":171,"code":172,"language":150,"meta":98},[148],"ExecStartPre  = +\u002Fusr\u002Fbin\u002Fbash \u002Fetc\u002Fsing-box\u002Fclean.sh\nExecStartPost = +\u002Fusr\u002Fbin\u002Fbash \u002Fetc\u002Fsing-box\u002Fiptables.sh\nExecStopPost  = +\u002Fusr\u002Fbin\u002Fbash \u002Fetc\u002Fsing-box\u002Fclean.sh\n",[78,174,172],{"__ignoreMap":98},[16,176,177,178,181,182,185],{},"As in the previous setup, this configures routing at startup and clears it when sing-box stops. All sing-box configuration lives in ",[78,179,180],{"code":180},"\u002Fetc\u002Fsing-box",", and its default config file is ",[78,183,184],{"code":184},"\u002Fetc\u002Fsing-box\u002Fconfig.json",", so we will keep the scripts there too.",[16,187,188,189,192,193,196],{},"Create ",[78,190,191],{"code":191},"\u002Fetc\u002Fsing-box\u002Fiptables.sh"," and ",[78,194,195],{"code":195},"\u002Fetc\u002Fsing-box\u002Fclean.sh"," as follows:",[90,198,201],{"className":199,"code":200,"language":150,"meta":98},[148],"#!\u002Fusr\u002Fbin\u002Fenv bash\n\nset -ex\n\n# ENABLE ipv4 forward\nsysctl -w net.ipv4.ip_forward=1\n# ENABLE ipv6 forward\nsysctl -w net.ipv6.conf.all.forwarding=1\n\n### IPv4 Routing Rules ###\n# ROUTE RULES\nip rule add fwmark 666 lookup 666\nip route add local 0.0.0.0\u002F0 dev lo table 666\n\n# clash 链负责处理转发流量\niptables -t mangle -N clash\n\n# 跳过内网流量\niptables -t mangle -A clash -d 0.0.0.0\u002F8 -j RETURN\niptables -t mangle -A clash -d 127.0.0.0\u002F8 -j RETURN\niptables -t mangle -A clash -d 10.0.0.0\u002F8 -j RETURN\niptables -t mangle -A clash -d 172.16.0.0\u002F12 -j RETURN\niptables -t mangle -A clash -d 192.168.0.0\u002F16 -j RETURN\niptables -t mangle -A clash -d 169.254.0.0\u002F16 -j RETURN\niptables -t mangle -A clash -d 224.0.0.0\u002F4 -j RETURN\niptables -t mangle -A clash -d 240.0.0.0\u002F4 -j RETURN\n\n# 需代理的 IP 转向到 7893 端口，并打上 mark\niptables -t mangle -A clash -d 198.18.0.0\u002F15 -p tcp -j TPROXY --on-port 7893 --tproxy-mark 666\niptables -t mangle -A clash -d 198.18.0.0\u002F15 -p udp -j TPROXY --on-port 7893 --tproxy-mark 666\n\n# 剩余流量正常处理\niptables -t mangle -A clash -j RETURN\n\n# 最后让所有流量通过 clash 链进行处理\niptables -t mangle -A PREROUTING -j clash\n\n# clash_local 链负责处理网关本身发出的流量\niptables -t mangle -N clash_local\n\n# 跳过内网流量\niptables -t mangle -A clash_local -d 0.0.0.0\u002F8 -j RETURN\niptables -t mangle -A clash_local -d 127.0.0.0\u002F8 -j RETURN\niptables -t mangle -A clash_local -d 10.0.0.0\u002F8 -j RETURN\niptables -t mangle -A clash_local -d 172.16.0.0\u002F12 -j RETURN\niptables -t mangle -A clash_local -d 192.168.0.0\u002F16 -j RETURN\niptables -t mangle -A clash_local -d 169.254.0.0\u002F16 -j RETURN\niptables -t mangle -A clash_local -d 224.0.0.0\u002F4 -j RETURN\niptables -t mangle -A clash_local -d 240.0.0.0\u002F4 -j RETURN\n\n# 为本机发出的流量打 mark\niptables -t mangle -A clash_local -p tcp -j MARK --set-mark 666\niptables -t mangle -A clash_local -p udp -j MARK --set-mark 666\n\n# 让本机发出的流量跳转到 clash_local\n# clash_local 链会为本机流量打 mark, 打过 mark 的流量会重新回到 PREROUTING 上\niptables -t mangle -A OUTPUT -j clash_local\n\n# 修复 ICMP(ping)\n# 这并不能保证 ping 结果有效 (clash 等不支持转发 ICMP), 只是让它有返回结果而已\n# --to-destination 设置为一个可达的地址即可\nsysctl -w net.ipv4.conf.all.route_localnet=1\niptables -t nat -A PREROUTING -p icmp -d 198.18.0.0\u002F16 -j DNAT --to-destination 127.0.0.1\n",[78,202,200],{"__ignoreMap":98},[90,204,207],{"className":205,"code":206,"language":150,"meta":98},[148],"#!\u002Fusr\u002Fbin\u002Fenv bash\n\nset -ex\n\nip rule del fwmark 666 table 666 || true\nip route del local 0.0.0.0\u002F0 dev lo table 666 || true\n\niptables -t nat -F\niptables -t nat -X\niptables -t mangle -F\niptables -t mangle -X clash || true\niptables -t mangle -X clash_local || true\n",[78,208,206],{"__ignoreMap":98},[16,210,211],{},"iptables.sh is nearly identical to the previous post’s version. Only the final action in the clash chain changes: traffic to 198.18.0.0\u002F15 goes to TPROXY port 7893, and other traffic follows the default rules. In effect, FakeIP traffic forwarded by the main router is handed to sing-box. clean.sh is completely unchanged.",[16,213,214],{},"I kept the two chains named clash and clash_local because this is just a small modification of the Clash setup. Laziness wins.",[16,216,217],{},"Next is the sing-box configuration. Here is a template:",[90,219,224],{"className":220,"code":222,"language":223,"meta":98},[221],"language-json","{\n  \"log\": {\n    \"level\": \"info\",\n    \"output\": \"box.log\",\n    \"timestamp\": true\n  },\n  \"dns\": {\n    \"servers\": [\n      {\n        \"tag\": \"cloudflare\",\n        \"address\": \"tls:\u002F\u002F1.1.1.1\",\n        \"detour\": \"🌍 外网\" \u002F\u002F 改为你的代理节点 tag\n      },\n      {\n        \"tag\": \"local\",\n        \"address\": \"223.5.5.5\",\n        \"detour\": \"DIRECT\"\n      },\n      {\n        \"tag\": \"dns-fakeip\",\n        \"address\": \"fakeip\"\n      },\n      {\n        \"tag\": \"block\",\n        \"address\": \"rcode:\u002F\u002Fsuccess\"\n      }\n    ],\n    \"rules\": [\n      {\n        \"server\": \"block\",\n        \"query_type\": [\n          \"HTTPS\",\n          \"SVCB\"\n        ]\n      },\n      {\n        \"server\": \"local\",\n        \"outbound\": \"any\"\n      },\n      {\n        \"server\": \"local\",\n        \"rewrite_ttl\": 10,\n        \"type\": \"logical\",\n        \"mode\": \"and\",\n        \"rules\": [\n          {\n            \"rule_set\": [\n              \"geosite-geolocation-!cn\"\n            ],\n            \"invert\": true\n          },\n          {\n            \"rule_set\": [\n              \"geosite-cn\",\n              \"geosite-category-companies@cn\",\n              \"geoip-cn\"\n            ]\n          }\n        ]\n      },\n      {\n        \"server\": \"dns-fakeip\",\n        \"rewrite_ttl\": 1,\n        \"query_type\": [\n          \"A\",\n          \"AAAA\"\n        ]\n      }\n    ],\n    \"strategy\": \"ipv4_only\",\n    \"fakeip\": {\n      \"enabled\": true,\n      \"inet4_range\": \"198.18.0.0\u002F15\"\n    }\n  },\n  \"inbounds\": [\n    {\n      \"type\": \"tproxy\",\n      \"tag\": \"tproxy-in\",\n      \"listen\": \"::\",\n      \"listen_port\": 7893,\n      \"tcp_fast_open\": true,\n      \"udp_fragment\": true,\n      \"sniff\": true\n    },\n    {\n      \"type\": \"mixed\",\n      \"tag\": \"mixed-in\",\n      \"listen\": \"::\",\n      \"listen_port\": 7890,\n      \"tcp_fast_open\": true,\n      \"udp_fragment\": true,\n      \"sniff\": true\n    },\n    {\n      \"type\": \"direct\",\n      \"tag\": \"dns-in\",\n      \"listen\": \"::\",\n      \"listen_port\": 1053\n    }\n  ],\n  \"outbounds\": [\n    {\n      \"type\": \"direct\",\n      \"tag\": \"DIRECT\"\n    },\n    {\n      \"type\": \"block\",\n      \"tag\": \"REJECT\"\n    },\n    {\n      \"type\": \"dns\",\n      \"tag\": \"dns-out\"\n    },\n    \u002F\u002F 此处填写你的代理节点\n  ],\n  \"route\": {\n    \"rules\": [\n      {\n        \"inbound\": \"dns-in\",\n        \"outbound\": \"dns-out\"\n      },\n      {\n        \"protocol\": \"dns\",\n        \"outbound\": \"dns-out\"\n      },\n      {\n        \"outbound\": \"DIRECT\",\n        \"type\": \"logical\",\n        \"mode\": \"and\",\n        \"rules\": [\n          {\n            \"rule_set\": [\n              \"geosite-geolocation-!cn\"\n            ],\n            \"invert\": true\n          },\n          {\n            \"rule_set\": [\n              \"geosite-cn\",\n              \"geosite-category-companies@cn\",\n              \"geoip-cn\"\n            ]\n          }\n        ]\n      }\n    ],\n    \"rule_set\": [\n      {\n        \"type\": \"remote\",\n        \"tag\": \"geoip-cn\",\n        \"format\": \"binary\",\n        \"url\": \"https:\u002F\u002Fcdn.jsdelivr.net\u002Fgh\u002FSagerNet\u002Fsing-geoip@rule-set\u002Fgeoip-cn.srs\",\n        \"download_detour\": \"DIRECT\"\n      },\n      {\n        \"type\": \"remote\",\n        \"tag\": \"geosite-cn\",\n        \"format\": \"binary\",\n        \"url\": \"https:\u002F\u002Fcdn.jsdelivr.net\u002Fgh\u002FSagerNet\u002Fsing-geosite@rule-set\u002Fgeosite-cn.srs\",\n        \"download_detour\": \"DIRECT\"\n      },\n      {\n        \"type\": \"remote\",\n        \"tag\": \"geosite-geolocation-!cn\",\n        \"format\": \"binary\",\n        \"url\": \"https:\u002F\u002Fcdn.jsdelivr.net\u002Fgh\u002FSagerNet\u002Fsing-geosite@rule-set\u002Fgeosite-geolocation-!cn.srs\",\n        \"download_detour\": \"DIRECT\"\n      },\n      {\n        \"type\": \"remote\",\n        \"tag\": \"geosite-category-companies@cn\",\n        \"format\": \"binary\",\n        \"url\": \"https:\u002F\u002Fcdn.jsdelivr.net\u002Fgh\u002FSagerNet\u002Fsing-geosite@rule-set\u002Fgeosite-category-companies@cn.srs\",\n        \"download_detour\": \"DIRECT\"\n      }\n    ],\n    \"final\": \"🌍 外网\", \u002F\u002F 改为你的代理节点 tag\n    \"auto_detect_interface\": true\n  },\n  \"experimental\": {\n    \"clash_api\": {\n      \"external_controller\": \"0.0.0.0:9090\",\n      \"external_ui\": \"yacd\",\n      \"external_ui_download_url\": \"https:\u002F\u002Fgithub.com\u002FMetaCubeX\u002FYacd-meta\u002Farchive\u002Fgh-pages.zip\",\n      \"external_ui_download_detour\": \"🌍 外网\", \u002F\u002F 改为你的代理节点 tag\n      \"default_mode\": \"Rule\"\n    }\n  }\n}\n","json",[78,225,222],{"__ignoreMap":98},[16,227,228],{},"Edit the places marked by comments. By default, Chinese domains are resolved directly through 223.5.5.5 into RealIP (DNS-rules[2]); other domains get FakeIP (DNS-rules[3]). Traffic routing sends Chinese IPs and domains through DIRECT (route-rules[2]), with everything else using the proxy (route-final).",[16,230,231],{},"Once everything is configured, enable sing-box at boot and start it immediately.",[90,233,236],{"className":234,"code":235,"language":150,"meta":98},[148],"systemctl enable --now sing-box\n",[78,237,235],{"__ignoreMap":98},[16,239,240],{},"To view logs later, use Debian’s built-in tools:",[90,242,245],{"className":243,"code":244,"language":150,"meta":98},[148],"journalctl -efu sing-box\n",[78,246,244],{"__ignoreMap":98},[16,248,249],{},"sing-box provides a Clash-compatible API, so you can manage it with Clash’s web UI. Wait a little after startup while sing-box downloads the UI, then open yacd on port 9090.",[118,251,253],{"id":252},"the-telegram-problem","The Telegram Problem",[16,255,256],{},"The drawback is obvious too: routing depends on DNS, so direct IP traffic that does not use DNS goes straight out through the main router. Apps such as Telegram that use IPs directly therefore are not routed correctly. The fix is simple: add those IPs to the main router’s next-hop IP list, the forwarding list in iptables.sh, and the sing-box rules, specifying that they use the proxy.",[16,258,259],{},"I currently have a script that processes IPs in rule sets and generates the corresponding IP list, iptables.sh, and a ready-to-use sing-box config.json. I will polish it up, remove private details, and release it as open source. Stay tuned.",{"title":98,"searchDepth":261,"depth":261,"links":262},4,[263,265,266],{"id":13,"depth":264,"text":14},3,{"id":58,"depth":264,"text":59},{"id":115,"depth":264,"text":116,"children":267},[268,269,270],{"id":120,"depth":261,"text":121},{"id":136,"depth":261,"text":137},{"id":252,"depth":261,"text":253},[272],"fiddling","2024-08-16 23:53:00","This FakeIP-based transparent proxy design addresses the single point of failure, poor performance, and awkward port forwarding of a traditional side router. Switching to the sing-box proxy core improves forwarding performance and simplifies configuration, with broader protocol support and better optimization than the previous Clash setup. Clash can implement the same design, but sing-box provides a flexible alternative.",false,"md","https:\u002F\u002Fblog-img.774352199.xyz\u002FS2HHD5.webp",{"slots":279},{},true,"\u002Ffiddling\u002Ffake-ip-based-transparent-proxy",null,{"text":284,"minutes":285,"time":286,"words":287},"10 min read",9.395,563700,1879,{"title":5,"description":274},"Use sing-box FakeIP DNS and next-hop routing to send selected traffic through a side router, with AdGuard fallback and extra rules for IP-based clients.",{"loc":281,"images":291},[292,293],{"loc":88},{"loc":130},"posts\u002Ffiddling\u002Ffake-ip-based-transparent-proxy",[296,297,298,299,300],"FakeIP","sing-box","Transparent proxy","Policy-based routing","Traffic routing","tech","tHsaBvwoS7Pu7-vg08YZfc6ziLJoPC8rsXLyijPles0",[304,322,339,357,373,391,409,426,444,460,464,479,495,511,528,546,561,578,592,608,625,642,658,675,691,710,726,743,761,775,793,810,826,842,856,873,887,902,917,931,945,959,974,988,999],{"categories":305,"date":307,"description":308,"image":309,"path":310,"readingTime":311,"recommend":282,"tags":316,"title":321,"type":301},[306],"daily","2024-09-01 22:03:10","Chronic gastritis has been a long, uneven journey: stomach trouble throughout childhood, a surprising reprieve at university, then a return of symptoms after years of late nights and drinking. Frequent nausea and reflux eventually became too much to live with. After repeated examinations and some reflection, I finally began taking the recovery process seriously.","https:\u002F\u002Fblog-img.774352199.xyz\u002F0Hr9l5.webp","\u002Fdaily\u002Fanti-chronic-gastritis",{"text":312,"minutes":313,"time":314,"words":315},"4 min read",3.08,184800,616,[317,318,319,320],"Chronic gastritis","Medical care experiences","Gastroscopy","Health journal","My Journey with Chronic Gastritis",{"categories":323,"date":324,"description":325,"image":326,"path":327,"readingTime":328,"recommend":282,"tags":333,"title":338,"type":301},[306],"2022-04-11 00:13:13","In The Three-Body Problem, Liu Cixin uses an immense historical canvas to explore the relationship between individuals and the collective. His doubts about Western democracy and the majority’s ability to determine its own fate run through the trilogy. Heroes struggle and sacrifice, only to see their work swept aside by history. Beginning with the Cultural Revolution, the story sets up a conflict between exceptional individuals and the ordinary masses, raising uncomfortable questions about humanity and society.","https:\u002F\u002Fblog-img.774352199.xyz\u002FLTzbFP.webp","\u002Fdaily\u002Fpeople-in-three-body",{"text":329,"minutes":330,"time":331,"words":332},"9 min read",8.635,518100,1727,[334,335,336,337],"The Three-Body Problem","Liu Cixin","Science fiction","Reading notes","The “Majority” in The Three-Body Problem",{"categories":340,"date":341,"description":342,"image":343,"path":344,"readingTime":345,"recommend":282,"tags":350,"title":356,"type":301},[306],"2024-01-04 02:06:51","My learning goals for 2024: reach N2 in Japanese, finish SICP and TAPL, build a kernel with full POSIX support, and update the blog theme. A challenging list, but a clear direction for the year.","https:\u002F\u002Fblog-img.774352199.xyz\u002FV3rSQC.webp","\u002Fdaily\u002Fplan2024",{"text":346,"minutes":347,"time":348,"words":349},"1 min read",0.15,9000,30,[351,352,353,354,355],"Annual planning","Learning Japanese","SICP","TAPL","Operating systems","My Learning Plan for 2024",{"categories":358,"date":359,"description":360,"image":361,"path":362,"readingTime":363,"recommend":282,"tags":367,"title":372,"type":301},[306],"2024-09-28 16:26:00","Three years at ByteDance have made time feel strangely accelerated. Amid the changes, I have still managed to hold on to some mental balance. Looking back at the new graduate gazing at distant mountains from the balcony of our Hangzhou office, I can trace how curiosity, workplace challenges, and shifting expectations taught me to find a rhythm of my own.","https:\u002F\u002Fblog-img.774352199.xyz\u002FhnCaht.webp","\u002Fdaily\u002Fwork-for-3-years",{"text":284,"minutes":364,"time":365,"words":366},9.74,584400,1948,[368,369,370,371],"ByteDance","Software engineering careers","Career retrospective","Mental health","Working at ByteDance for Three Years and Staying Somewhat Sane Is Not Entirely Impossible",{"categories":374,"date":375,"description":376,"image":377,"path":378,"readingTime":379,"recommend":282,"tags":384,"title":390,"type":301},[272],"2025-05-28 22:09:00","After moving my blog to Astro, the usual Google Analytics integration no longer fit its performance goals. Adding event-reporting JavaScript directly to the head works, but hurts page performance. I used partytown to move the scripts off the main thread so they would not interfere with loading. With a few adjustments to the example code, Google Analytics finally worked, balancing performance with analytics.","https:\u002F\u002Fblog-img.774352199.xyz\u002FQ0w4RN.webp","\u002Ffiddling\u002Fastro-google-tag-manager",{"text":380,"minutes":381,"time":382,"words":383},"2 min read",1.785,107100,357,[385,386,387,388,389],"Astro","Google Analytics","Google Tag Manager","Partytown","Web analytics","Adding Google Analytics to Astro with Tag Manager",{"categories":392,"date":393,"description":394,"image":395,"path":396,"readingTime":397,"recommend":402,"tags":403,"title":408,"type":301},[272],"2023-04-08 13:16:36","Designing a new programming language is challenging and fun. Setting aside complicated compiler theory and implementation details to focus on where code runs helps clarify how languages are built. Starting from the RISC-VI instruction set, this discussion explores the underlying architecture, layered computer systems, and virtual-machine model, reflecting on the nature of programming languages as well as their implementation.","https:\u002F\u002Fblog-img.774352199.xyz\u002FuO420B.webp","\u002Ffiddling\u002Fchitchat-about-programming-language",{"text":398,"minutes":399,"time":400,"words":401},"15 min read",14.275,856500,2855,2,[404,405,406,407],"Programming language design","Type systems","Compiler design","RISC-V","Some Thoughts on Programming Languages",{"categories":410,"date":411,"description":412,"image":413,"path":414,"readingTime":415,"recommend":261,"tags":420,"title":425,"type":301},[272],"2025-04-18 16:43:12","My girlfriend moved from Beijing to Shanghai for work, and I helped arrange broadband too. Shanghai Telecom’s 500M connection costs more than a 1000M line in Hangzhou, frustratingly. I set out to connect the two cities’ networks: transparent proxying in Shanghai, selected traffic exiting through Hangzhou, and access between both LANs. Hangzhou already had a simple setup with a software router and an AP, configured to route my everyday traffic home and ready for the next networking adventure.","https:\u002F\u002Fblog-img.774352199.xyz\u002FO6cAGh.webp","\u002Ffiddling\u002Fcross-city-network-setup",{"text":416,"minutes":417,"time":418,"words":419},"5 min read",4.865,291900,973,[421,422,423,298,424],"Tailscale","mihomo","Site-to-site networking","Home networking","Connecting My Shanghai and Hangzhou Networks",{"categories":427,"date":428,"description":429,"image":430,"path":431,"readingTime":432,"recommend":282,"tags":437,"title":443,"type":301},[272],"2021-12-27 00:09:00","The labs are an essential part of learning CSAPP, but setting up Linux can be discouraging. Virtual machines bring installation errors, compatibility problems, and broken networking. WSL (Windows Subsystem for Linux), especially on Windows 10 version 2004 and later, provides a simpler, more direct Linux environment without the complexity and performance bottlenecks of a traditional VM.","https:\u002F\u002Fblog-img.774352199.xyz\u002FvqOC7N.webp","\u002Ffiddling\u002Fcsapplab0",{"text":433,"minutes":434,"time":435,"words":436},"6 min read",5.295,317700,1059,[438,439,440,441,442],"CSAPP","WSL2","Linux","GDB","Lab environment","Setting Up the CSAPP Lab Environment",{"categories":445,"date":446,"description":447,"image":448,"path":449,"readingTime":450,"recommend":282,"tags":455,"title":459,"type":301},[272],"2024-07-13 17:49:00","Using Debian as a side router offers a more stable and flexible alternative without depending on OpenWrt and LuCI. Configuring Debian directly gives you greater control over the system and avoids the limitations and instability of a GUI. Compared with common side-router setups, this approach makes transparent proxying more reliable and offers another option for those who value performance and efficiency.","https:\u002F\u002Fblog-img.774352199.xyz\u002FpPRU5x.webp","\u002Ffiddling\u002Fdebian-as-bypass-router",{"text":451,"minutes":452,"time":453,"words":454},"12 min read",11.79,707400,2358,[456,457,422,458,298],"Debian","Side router","AdGuard Home","Using Debian as a Side Router",{"categories":461,"date":273,"description":274,"image":277,"path":281,"readingTime":462,"recommend":282,"tags":463,"title":5,"type":301},[272],{"text":284,"minutes":285,"time":286,"words":287},[296,297,298,299,300],{"categories":465,"date":466,"description":467,"image":468,"path":469,"readingTime":470,"recommend":282,"tags":474,"title":478,"type":301},[272],"2024-08-15 23:50:00","Port forwarding on the main router often stops working when a side router is introduced. Setting the side router as the gateway changes the forwarding path, breaking mappings that previously relied on the main router. A gateway translates addresses and forwards traffic from the internal network to the outside, and each internal device needs one to communicate externally. Understanding this mechanism helps explain how to fix the forwarding problem.","https:\u002F\u002Fblog-img.774352199.xyz\u002FmRqws9.webp","\u002Ffiddling\u002Ffix-port-forward-in-bypass-router",{"text":312,"minutes":471,"time":472,"words":473},3.03,181800,606,[457,475,476,477],"Port forwarding","NAT","Network troubleshooting","Fixing Port Forwarding with a Side Router",{"categories":480,"date":481,"description":482,"image":483,"path":484,"readingTime":485,"recommend":282,"tags":490,"title":494,"type":301},[272],"2023-02-02 23:24:55","Inspiration struck during Chinese New Year: an article read on the train about running Go on bare metal sparked an interest in low-level system interfaces. Its successful implementation suggested exciting possibilities for combining a high-level language with an OS. Further research revealed earlier work on the idea, and that growing enthusiasm became a project full of anticipation that ultimately did not work out.","https:\u002F\u002Fblog-img.774352199.xyz\u002FxB1Ni5.webp","\u002Ffiddling\u002Fgo-os",{"text":486,"minutes":487,"time":488,"words":489},"8 min read",7.29,437400,1458,[491,407,355,492,493],"Go","Bare-metal programming","Runtime","A Project That Failed: Seven Not-So-Happy Days over Chinese New Year",{"categories":496,"date":497,"description":498,"image":499,"path":500,"readingTime":501,"recommend":282,"tags":506,"title":510,"type":301},[272],"2022-08-15 01:05:01","While refactoring a system, converting entities between layers made deep copying surprisingly awkward. A product VO in the view layer, an entity in the domain layer, and a PO in the persistence layer can look nearly identical, yet small type differences complicate direct conversion. I used reflection to build a general conversion method, reducing repetitive assembler methods and making the code more maintainable and flexible.","https:\u002F\u002Fblog-img.774352199.xyz\u002FBlhm0I.webp","\u002Ffiddling\u002Fgolang-deepcopy-between-different-type",{"text":502,"minutes":503,"time":504,"words":505},"3 min read",2.855,171300,571,[491,507,508,509],"Reflection","Deep copy","Struct conversion","Deep Copying Between Different Struct Types in Go",{"categories":512,"date":513,"description":514,"image":515,"path":516,"readingTime":517,"recommend":282,"tags":521,"title":527,"type":301},[272],"2025-03-31 23:51:00","Periodically syncing heart-rate data from Apple Health to a server and visualizing it in Grafana provides an intuitive way to monitor it. Health Auto Export sends the data to an HTTP endpoint through its REST API automation, the server stores it in InfluxDB, and Grafana presents a clear dashboard for tracking and analyzing personal heart-rate changes.","https:\u002F\u002Fblog-img.774352199.xyz\u002FF4qD2T.webp","\u002Ffiddling\u002Fheart-rate-to-grafana",{"text":502,"minutes":518,"time":519,"words":520},2.45,147000,490,[522,523,524,525,526],"Apple Watch","Health Auto Export","InfluxDB","Grafana","Heart rate monitoring","My Heart Beats for U: Visualizing Heart Rate in Grafana",{"categories":529,"date":530,"description":531,"image":532,"path":533,"readingTime":534,"recommend":538,"tags":539,"title":545,"type":301},[272],"2025-06-10 20:18:00","macOS and iPadOS 26 introduce the Liquid Glass design language, refreshing icons and windows with a more modern look. Windowed apps on iPad are a step toward making it a productivity device. The transparent Control Center and the integration of Launchpad have been controversial, however, and the experience still needs work. Despite its shortcomings, this update lays groundwork for a promising future.","https:\u002F\u002Fblog-img.774352199.xyz\u002FTPSaLE.webp","\u002Ffiddling\u002Fmacos-26-trial",{"text":312,"minutes":535,"time":536,"words":537},3.305,198300,661,5,[540,541,542,543,544],"macOS 26","iPadOS 26","Liquid Glass","Apple Intelligence","Operating system impressions","Trying Out macOS 26 and iPadOS 26",{"categories":547,"date":548,"description":549,"image":550,"path":551,"readingTime":552,"recommend":282,"tags":556,"title":560,"type":301},[272],"2026-06-11 10:00:00","Another WWDC brings new Apple Intelligence features in macOS 27. The workarounds from macOS 26 no longer get through, so the battle of wits with Apple continues.","https:\u002F\u002Fblog-img.774352199.xyz\u002FfOFucm.webp","\u002Ffiddling\u002Fmacos-27-apple-intelligence-chatgpt",{"text":433,"minutes":553,"time":554,"words":555},5.1,306000,1020,[557,543,558,559],"macOS 27","ChatGPT","Mainland China Mac","Getting Apple Intelligence Working on a China-Market Mac: Region Changes and Extracting ChatGPT",{"categories":562,"date":563,"description":564,"image":565,"path":566,"readingTime":567,"recommend":282,"tags":571,"title":577,"type":301},[272],"2025-07-20 23:32:00","MoonTV is a new video aggregation platform built with Next.js and React to make following shows convenient. It began as an attempt to improve LibreTV and has attracted substantial attention and usage over several months of development. Cursor made development efficient, although multi-platform support and complex data dependencies posed challenges. As its user base grows, MoonTV continues improving in response to feedback.","https:\u002F\u002Fblog-img.774352199.xyz\u002FnIeONi.webp","\u002Ffiddling\u002Fmoontv-vibe-coding",{"text":433,"minutes":568,"time":569,"words":570},5.76,345600,1152,[572,573,574,575,576],"MoonTV","LunaTV","Vibe Coding","Cursor","AI-assisted development","MoonTV: An Experiment in Vibe Coding",{"categories":579,"date":580,"description":581,"image":582,"path":583,"readingTime":584,"recommend":282,"tags":588,"title":591,"type":301},[272],"2024-10-07 16:51:00","BGP-based routing for Chinese and overseas IPs makes transparent proxying more efficient and accurate. Marking overseas destinations with FakeIP lets the main router route traffic more intelligently for smoother connectivity. The sing-box DNS configuration is also refined to handle queries more flexibly and efficiently, improving the overall network experience.","https:\u002F\u002Fblog-img.774352199.xyz\u002FMOmM1s.webp","\u002Ffiddling\u002Fmore-accurate-chnroute",{"text":312,"minutes":585,"time":586,"words":587},3.805,228300,761,[589,590,299,300],"BGP","IP address database","More Accurate Routing for Chinese and Overseas IPs with BGP",{"categories":593,"date":594,"description":595,"image":596,"path":597,"readingTime":598,"recommend":282,"tags":602,"title":607,"type":301},[272],"2025-12-14 14:31:00","A friend’s comment got me interested in simulation games. After buying Microsoft Flight Simulator, I discovered streamed maps and models, another account login, oddly hidden tutorials, and awkward keyboard controls. A flight stick and some tinkering with Pico VR finally rounded out the experience.","https:\u002F\u002Fblog-img.774352199.xyz\u002FlfhEuE.webp","\u002Ffiddling\u002Fmsfs2024-joystick-and-pico",{"text":416,"minutes":599,"time":600,"words":601},4.68,280800,936,[603,604,605,606],"Microsoft Flight Simulator 2024","Thrustmaster TCA","PICO VR","Flight simulation","Adventures with Microsoft Flight Simulator 2024",{"categories":609,"date":610,"description":611,"image":612,"path":613,"readingTime":614,"recommend":282,"tags":618,"title":624,"type":301},[272],"2025-06-05 23:26:00","My frequent phone changes took me from OnePlus to iPhone, and from enjoying tinkering to relying on an ecosystem. At my girlfriend’s suggestion, I recently bought an OPPO Find X8 Ultra to improve my photos. Migrating apps out of Apple’s ecosystem reminded me how uneven Android’s app selection remains and how difficult finding replacements can be. A month of migration has been an exercise in friction and adaptation between platforms.","https:\u002F\u002Fblog-img.774352199.xyz\u002F19NIhZ.webp","\u002Ffiddling\u002Fone-month-using-android",{"text":486,"minutes":615,"time":616,"words":617},7.61,456600,1522,[619,620,621,622,623],"Android","OPPO","iOS","Smartphone impressions","Ecosystem migration","One Month After Switching to Android",{"categories":626,"date":627,"description":628,"image":629,"path":630,"readingTime":631,"recommend":282,"tags":635,"title":641,"type":301},[272],"2026-05-11 22:43:00","I found a trip-planning tool on GitHub Trending and wanted to host my own instance. Since I was getting a new VPS anyway, I might as well install a little extra. Well, quite a lot extra.","https:\u002F\u002Fblog-img.774352199.xyz\u002FBBdDWW.webp","\u002Ffiddling\u002Fone-trek-twenty-stacks",{"text":433,"minutes":632,"time":633,"words":634},5.735,344100,1147,[636,637,638,639,640],"TREK","Docker Compose","Dockge","VPS","Self-hosting","One TREK, Twenty Stacks",{"categories":643,"date":644,"description":645,"image":646,"path":647,"readingTime":648,"recommend":282,"tags":653,"title":657,"type":301},[272],"2025-01-16 23:09:00","OPNsense is an open-source firewall and router with an attractive interface and a comprehensive feature set. After trying several routing setups, I came to appreciate its potential for transparent proxying and traffic routing. Combining it with BGP-based routing offers better security and stability, while its automatically updated IP lists make network management more convenient.","https:\u002F\u002Fblog-img.774352199.xyz\u002FxA8C1E.webp","\u002Ffiddling\u002Fopnsense-transparent-proxy",{"text":649,"minutes":650,"time":651,"words":652},"7 min read",6.47,388200,1294,[654,655,422,656,298,300],"OPNsense","FreeBSD","tun2socks","Transparent Proxying and Traffic Routing with OPNsense",{"categories":659,"date":660,"description":661,"image":662,"path":663,"readingTime":664,"recommend":264,"tags":668,"title":674,"type":301},[272],"2025-03-15 20:35:00","Distinguishing user-defined type names from ordinary variables is a challenge during parsing. A statement such as `a*b;` can be either an arithmetic expression or a declaration. Grammar rules, especially those involving type specifiers, can misidentify variables as types, affecting correctness and readability. The prevalence of declarations without initializers makes this ambiguity especially common.","https:\u002F\u002Fblog-img.774352199.xyz\u002F2VKHK9.webp","\u002Ffiddling\u002Fparser-type-variable-ambiguity",{"text":486,"minutes":665,"time":666,"words":667},7.475,448500,1495,[669,670,671,672,673],"Parsing","GLR","Symbol table","Scope","Disambiguation","Resolving Type Name and Variable Name Ambiguity in Parsing",{"categories":676,"date":677,"description":678,"image":679,"path":680,"readingTime":681,"recommend":282,"tags":685,"title":690,"type":301},[272],"2023-05-24 17:51:09","To install the RISC-V toolchain, first obtain the riscv-gnu-toolchain source. Using `--depth=1` when cloning reduces the download size. Check the README’s Prerequisites section and install the required dependencies. On Debian, a simple package installation command prepares the environment for building the toolchain.","https:\u002F\u002Fblog-img.774352199.xyz\u002FrWNOKx.webp","\u002Ffiddling\u002Fspike-install",{"text":380,"minutes":682,"time":683,"words":684},1.92,115200,384,[407,686,687,688,689],"Spike","riscv-pk","Cross-compilation","Toolchain","Installing the RISC-V Toolchain and Emulator",{"categories":692,"date":693,"description":694,"image":695,"path":696,"readingTime":697,"recommend":701,"tags":702,"title":709,"type":301},[272],"2026-09-09 23:59:00","This counts as NTR too, surely.","https:\u002F\u002Fblog-img.774352199.xyz\u002FNDPUwc.webp","\u002Ffiddling\u002Fsteamdeck-switch-60fps",{"text":486,"minutes":698,"time":699,"words":700},7.345,440700,1469,7,[703,704,705,706,707,708],"Steam Deck","Nintendo Switch","EmuDeck","Eden","Lossless Scaling","Frame generation","A Second Life for the Steam Deck: Switch Emulation and Frame Generation at 60 FPS",{"categories":711,"date":712,"description":713,"image":714,"path":715,"readingTime":716,"recommend":282,"tags":720,"title":725,"type":301},[272],"2024-06-23 15:31:32","The GFW does more than monitor an exit gateway: it inspects international traffic through passive taps, copying inbound and outbound IP packets to a cluster for analysis and filtering. Understanding where and how this happens matters when studying censorship circumvention. Examining the GFW’s network topology helps explain its blocking mechanisms and how to work around them.","https:\u002F\u002Fblog-img.774352199.xyz\u002FsOpJuL.webp","\u002Ffiddling\u002Ftech-about-gfw",{"text":451,"minutes":717,"time":718,"words":719},11.885,713100,2377,[721,722,723,724],"GFW","DNS poisoning","TCP","Internet censorship","How the Great Firewall Works",{"categories":727,"date":728,"description":729,"image":730,"path":731,"readingTime":732,"recommend":282,"tags":736,"title":742,"type":301},[272],"2022-04-16 00:01:28","In Java, using `this` can prevent the compiler from optimizing constants. Although `ab1` and `ab2` in this example appear to refer to the same static final variable `s`, comparing them produces different results. `ab1` concatenates a direct reference to the static variable, while `ab2` accesses it through `this`, preventing the same constant propagation optimization. This illustrates how a small syntactic difference can change compilation behavior.","https:\u002F\u002Fblog-img.774352199.xyz\u002FgKtkYe.webp","\u002Ffiddling\u002Fthis-in-javac-string-concat",{"text":502,"minutes":733,"time":734,"words":735},2.305,138300,461,[737,738,739,740,741],"Java","javac","String concatenation","Constant propagation","Bytecode","How Java’s this Keyword Can Prevent Compile-Time Constant Propagation",{"categories":744,"date":745,"description":746,"image":747,"path":748,"readingTime":749,"recommend":282,"tags":754,"title":760,"type":301},[272],"2025-01-29 21:58:00","A microblog lets you share short thoughts whenever they occur, without the overhead of publishing a full static-blog post. This implementation uses Cloudflare Workers for the backend and KV for storage and management. A Vue component embedded in VitePress displays the updates, adding a lively, interactive element to the blog.","https:\u002F\u002Fblog-img.774352199.xyz\u002FhZX6hr.webp","\u002Ffiddling\u002Fvitepress-memos-component",{"text":750,"minutes":751,"time":752,"words":753},"19 min read",18.96,1137600,3792,[755,756,757,758,759],"VitePress","Vue","Cloudflare Workers","Cloudflare KV","Microblogging","Adding a Microblog to VitePress",{"categories":762,"date":763,"description":764,"image":765,"path":766,"readingTime":767,"recommend":282,"tags":771,"title":774,"type":301},[272],"2025-03-15 16:24:00","A Telegram notification on an ordinary afternoon introduced a tempting VPS deal: a direct China Telecom CN2 route and 2.5G bandwidth. The plan includes IPv6, useful for unlocking streaming services, but not every connection needs to go through WARP. My previous script was convenient, yet its effects on speed and traffic routing called for a more flexible solution.","https:\u002F\u002Fblog-img.774352199.xyz\u002FMcjrrF.webp","\u002Ffiddling\u002Fvps-warp-ipv6",{"text":502,"minutes":768,"time":769,"words":770},2.34,140400,468,[772,773,639,299,300],"Cloudflare WARP","IPv6","Routing Selected VPS Traffic Through WARP over IPv6",{"categories":776,"date":777,"description":778,"image":779,"path":780,"readingTime":781,"recommend":785,"tags":786,"title":792,"type":301},[272],"2026-08-17 23:59:21","The more I tinker, the more I want to tinker. Still going strong in my old age, still going strong!","https:\u002F\u002Fblog-img.774352199.xyz\u002FqfxB0h.webp","\u002Ffiddling\u002Fxiaomi17-root-and-hide-root",{"text":416,"minutes":782,"time":783,"words":784},4.545,272700,909,6,[787,788,789,790,791],"Xiaomi 17","Bootloader","Android Root","Firmware flashing","Root hiding","Making the Xiaomi 17 My Daily Driver: Unlocking, Flashing, Rooting, and Hiding Root",{"categories":794,"date":796,"description":797,"image":798,"path":799,"readingTime":800,"recommend":282,"tags":804,"title":809,"type":301},[795],"notes","2022-01-20 22:29:00","Lab 1 asks us to implement a MapReduce system with two core components: a master and workers. This requires a good command of Go RPC and concurrent programming, along with a thorough understanding of the MapReduce workflow. I built two versions, starting with mutex locks and then moving to a more elegant channel-based implementation without explicit locks, whose design is simpler and clearer. The key to understanding the lab is to read the relevant documentation carefully, especially the flowcharts and explanations.","https:\u002F\u002Fblog-img.774352199.xyz\u002FibVwPJ.webp","\u002Fnotes\u002F65840\u002Fmapreducelab",{"text":486,"minutes":801,"time":802,"words":803},7.21,432600,1442,[805,806,491,807,808],"MIT 6.5840","MapReduce","RPC","Concurrent programming","6.5840 Lab 1: MapReduce",{"categories":811,"date":812,"description":813,"image":814,"path":815,"readingTime":816,"recommend":282,"tags":820,"title":825,"type":301},[795],"2022-01-16 17:32:00","MapReduce is an efficient parallel computing model designed to simplify processing large datasets. By defining the two key functions, Map and Reduce, users can break complex tasks into simple operations. The framework automatically handles data distribution and task scheduling, allowing developers to focus on the algorithm rather than low-level details. Its widespread use in distributed systems demonstrates its flexibility and practical value.","https:\u002F\u002Fblog-img.774352199.xyz\u002FApIDdC.webp","\u002Fnotes\u002F65840\u002Fmapreducepaper",{"text":416,"minutes":817,"time":818,"words":819},4.12,247200,824,[806,821,822,823,824],"Distributed systems","Paper notes","Parallel computing","Fault tolerance","Reading the MapReduce Paper",{"categories":827,"date":828,"description":829,"image":830,"path":831,"readingTime":832,"recommend":282,"tags":837,"title":841,"type":301},[795],"2022-12-16 02:06:10","Lab 2A focuses on implementing Raft leader election and heartbeats so that elections and term changes work correctly even under extreme conditions. The lab has four stages and lays the foundation for the distributed key-value store that follows. A design without explicit locks simplifies the Raft struct. The lab instructions provide the necessary background, but compared with the previous lab, this one relies on almost no reference material and places greater emphasis on implementing the system independently.","https:\u002F\u002Fblog-img.774352199.xyz\u002Fc11Uk4.webp","\u002Fnotes\u002F65840\u002Fraftlab2a",{"text":833,"minutes":834,"time":835,"words":836},"13 min read",12.235,734100,2447,[805,838,491,839,840],"Raft","Leader election","Distributed consensus","6.5840 Lab 2A: Leader Election",{"categories":843,"date":844,"description":845,"image":846,"path":847,"readingTime":848,"recommend":282,"tags":853,"title":855,"type":301},[795],"2022-12-03 21:40:09","Raft is a consensus algorithm designed to improve the efficiency of log replication. It is particularly suited to clusters of machines, allowing them to keep providing service even when some machines fail. It uses the replicated state machine model: logs record the order of commands so that every machine in the cluster can reach the same state. In Search of an Understandable Consensus Algorithm explores Raft’s design and compares it with Paxos, highlighting its understandability and providing a foundation for building reliable large-scale software systems. These reading notes aim to help explain the paper’s core concepts and their applications.","https:\u002F\u002Fblog-img.774352199.xyz\u002F7mmvIZ.webp","\u002Fnotes\u002F65840\u002Freftextendedpaper",{"text":849,"minutes":850,"time":851,"words":852},"16 min read",15.98,958800,3196,[838,840,854,822],"Log replication","Reading the Raft Paper",{"categories":857,"date":859,"description":860,"image":861,"path":862,"readingTime":863,"recommend":867,"tags":868,"title":872,"type":301},[858],"projects","2021-11-27 14:43:00","MYDB is a personal project exploring and implementing the fundamentals of databases, built in my spare time over a little more than half a month. I picked up some basic knowledge in my university database systems course, though during my internship I mostly used the classes as an excuse to slack off. My candid answers in an interview did not cause too much trouble, but they did make me reconsider what I knew about databases and decide to learn through hands-on practice. That was how this project began.","https:\u002F\u002Fblog-img.774352199.xyz\u002Fxfci2J.webp","\u002Fprojects\u002Fmydb\u002Fmydb0",{"text":416,"minutes":864,"time":865,"words":866},4.15,249000,830,1,[869,737,870,871],"MYDB","Database implementation","Database architecture","MYDB 0. Project Structure and a Few Things I Had to Say",{"categories":874,"date":875,"description":876,"image":877,"path":878,"readingTime":879,"recommend":282,"tags":883,"title":886,"type":301},[858],"2021-11-28 16:10:00","MYDB manages transactions through an XID file. Each transaction has a unique XID, incrementing from 1; XID 0 denotes a super transaction whose state is always committed. TransactionManager maintains this file and records three states: active, committed, and aborted. This mechanism supports accurate transaction state queries and management, providing a foundation for system stability and reliability.","https:\u002F\u002Fblog-img.774352199.xyz\u002FH4zZAK.webp","\u002Fprojects\u002Fmydb\u002Fmydb1",{"text":416,"minutes":880,"time":881,"words":882},4.755,285300,951,[869,737,884,885],"Transaction management","XID","MYDB 1. Starting with the Transaction Manager",{"categories":888,"date":889,"description":890,"image":891,"path":892,"readingTime":893,"recommend":282,"tags":897,"title":901,"type":301},[858],"2021-12-25 18:26:00","MYDB uses a client\u002Fserver architecture similar to MySQL, allowing multiple clients to connect to a server over sockets, execute SQL queries, and receive results. Communication uses a special binary format, though plain text would also be an option for a simpler implementation. The basic transport structure supports effective communication and processing between client and server.","https:\u002F\u002Fblog-img.774352199.xyz\u002FPAHrUZ.webp","\u002Fprojects\u002Fmydb\u002Fmydb10",{"text":416,"minutes":894,"time":895,"words":896},4.305,258300,861,[869,737,898,899,900],"Socket","Client-server architecture","Communication protocol","MYDB 10. Implementing the Server, Client, and Wire Protocol",{"categories":903,"date":904,"description":905,"image":906,"path":907,"readingTime":908,"recommend":282,"tags":912,"title":916,"type":301},[858],"2021-11-30 23:18:00","The Data Manager (DM) bridges higher-level modules and the filesystem, handling paging and caching while ensuring data safety and recovery. Its cache uses reference counting rather than traditional LRU, aiming for a reusable, efficient foundation for subsequent data operations.","https:\u002F\u002Fblog-img.774352199.xyz\u002FWdIGoG.webp","\u002Fprojects\u002Fmydb\u002Fmydb2",{"text":433,"minutes":909,"time":910,"words":911},5.725,343500,1145,[869,737,913,914,915],"Reference counting","Cache design","Shared memory","MYDB 2. A Reference-Counted Cache Framework and Shared Byte Arrays",{"categories":918,"date":919,"description":920,"image":921,"path":922,"readingTime":923,"recommend":282,"tags":927,"title":930,"type":301},[858],"2021-12-05 15:28:00","DM abstracts the filesystem into pages and uses them as the unit of reading, writing, and caching. The default page size is 8K, with larger pages available to improve write performance under heavy loads. With the general-purpose cache framework already in place, we now define the page structure and implement efficient page caching.","https:\u002F\u002Fblog-img.774352199.xyz\u002FjlFC4E.webp","\u002Fprojects\u002Fmydb\u002Fmydb3",{"text":416,"minutes":924,"time":925,"words":926},4.7,282000,940,[869,737,928,929],"Data pages","Cache management","MYDB 3. Caching and Managing Data Pages",{"categories":932,"date":933,"description":934,"image":935,"path":936,"readingTime":937,"recommend":282,"tags":941,"title":944,"type":301},[858],"2021-12-08 22:55:00","Log files are essential to MYDB’s design, allowing data to be recovered after a crash. DM logs every operation on underlying data, forming a continuous sequence of records. Stored in a specific binary format with checksums and individual operation records, these logs let the database accurately reconstruct its data on restart and maintain consistency and integrity.","https:\u002F\u002Fblog-img.774352199.xyz\u002FTRcbsj.webp","\u002Fprojects\u002Fmydb\u002Fmydb4",{"text":486,"minutes":938,"time":939,"words":940},7.885,473100,1577,[869,737,942,943],"Database logging","Crash recovery","MYDB 4. Log Files and Recovery Strategies",{"categories":946,"date":947,"description":948,"image":949,"path":950,"readingTime":951,"recommend":282,"tags":955,"title":958,"type":301},[858],"2021-12-11 15:16:00","The page index is an important part of DM, optimizing insertions by caching the free space available on each page. It lets higher-level modules quickly locate a suitable page without a lengthy search, making data operations more efficient. Its implementation works closely with the DataItem abstraction to support efficient database operation.","https:\u002F\u002Fblog-img.774352199.xyz\u002F22PSG1.webp","\u002Fprojects\u002Fmydb\u002Fmydb5",{"text":649,"minutes":952,"time":953,"words":954},6.37,382200,1274,[869,737,956,957],"Page index","Data management","MYDB 5. The Page Index and the Data Manager",{"categories":960,"date":961,"description":962,"image":963,"path":964,"readingTime":965,"recommend":282,"tags":969,"title":973,"type":301},[858],"2021-12-18 14:58:00","VM uses two-phase locking to ensure serializable schedules and introduces multiversion concurrency control (MVCC) to eliminate blocking between reads and writes. This chapter also defines conflicts between database operations, focusing on the interaction between updates and reads as a foundation for understanding transaction isolation levels.","https:\u002F\u002Fblog-img.774352199.xyz\u002F8YzotA.webp","\u002Fprojects\u002Fmydb\u002Fmydb6",{"text":329,"minutes":966,"time":967,"words":968},8.64,518400,1728,[869,737,970,971,972],"MVCC","Transaction isolation","Two-phase locking","MYDB 6. Record Versions and Transaction Isolation",{"categories":975,"date":976,"description":977,"image":978,"path":979,"readingTime":980,"recommend":282,"tags":984,"title":987,"type":301},[858],"2021-12-23 21:20:00","VM must handle version skipping introduced by MVCC as well as deadlocks. By simply marking a transaction, MYDB can cancel or roll it back and keep data from aborted transactions from affecting others. This design makes concurrent transaction handling more efficient and reliable, avoids the deadlock risks common with traditional 2PL, and improves overall stability and performance.","https:\u002F\u002Fblog-img.774352199.xyz\u002FBF3yDW.webp","\u002Fprojects\u002Fmydb\u002Fmydb7",{"text":486,"minutes":981,"time":982,"words":983},7.265,435900,1453,[869,737,985,986],"Deadlock detection","Version management","MYDB 7. Deadlock Detection and the Version Manager",{"categories":989,"date":990,"description":991,"image":992,"path":993,"readingTime":994,"recommend":282,"tags":995,"title":998,"type":301},[858],"2021-12-24 21:01:00","MYDB implements a clustered index using a B+ tree. IM interacts directly with the Data Manager (DM), bypassing the Version Manager (VM), so index data is written directly to the database file. This chapter details the binary-tree index structure and its basic node fields, including the leaf flag, key count, and sibling identifier, establishing the framework for indexed lookups.","https:\u002F\u002Fblog-img.774352199.xyz\u002Ff92X4o.webp","\u002Fprojects\u002Fmydb\u002Fmydb8",{"text":416,"minutes":864,"time":865,"words":866},[869,737,996,997],"B+ tree","Database indexing","MYDB 8. Index Management",{"categories":1000,"date":1001,"description":1002,"image":1003,"path":1004,"readingTime":1005,"recommend":282,"tags":1009,"title":1012,"type":301},[858],"2021-12-25 15:44:00","The Table Manager (TBM) manages field and table structures. Parser turns SQL-like statements into structured representations, wrapping their information in the corresponding classes to simplify subsequent operations. This chapter also covers MYDB’s SQL syntax as a foundation for understanding the management process.","https:\u002F\u002Fblog-img.774352199.xyz\u002FzOMyv5.webp","\u002Fprojects\u002Fmydb\u002Fmydb9",{"text":433,"minutes":1006,"time":1007,"words":1008},5.035,302100,1007,[869,737,1010,1011],"SQL parsing","Table management","MYDB 9. Field and Table Management",1789914050066]