Skip to main content

js-module-system

· One min read
Spark light
Spark light
Left

CommonJS vs (ESModules)

moduleCommonJSESModules
in/outrequire(),module.exports={....}import/export
ref vs copycjs module.exports的是值得拷贝ESM export的是值引用
html use<script src=""></><script type=module src=""></>
加载运行时加载编译时加载.先加载在执行(es2020 提案引入import())
import namerequire("module")import "module.js" 需要ext名
  • ESModules import必须要带ext后缀的决策考虑: ESModules设计为可以用在浏览器上,浏览器import加载http server后端时没有后缀,只能盲猜后缀或多次请求.js,.mjs等后缀, 带来极差的用户体验
  • .ts编译为.js后 所有import "module" 修改为了 import "module.js"

https://www.typescriptlang.org/tsconfig#target

check point: package.json: "type":"module" #define as ESModules tsconfig: "compilerOptions.module": "commonjs|Node16|ES6", # tsconfig: "compilerOptions.target":"ESNext|es2017|ES6", # filename *.cjs CommonJS, *.js esmodule

workable match:

package.json(no type:module) tsconfig.compilerOptions.module = commonjs tsconfig.compilerOptions.target = es2017

js-ts-node-system-traps

· 2 min read
Spark light
Spark light
Left
import * as allsupertest from 'supertest'; //import all as new js collection obj
import request from 'supertest'; //import the default
import { Test, Agent } from 'supertest'

tsconfig("esModuleInterop": true) , will let allsupertest() function call build error, it should avoid use still style call

tsc: package.main="dist/index.js" tsocnfig.compilerOptions.outDir="./dist/" 时tsc默认人文dist也是源码目录 dist=>dist build会报错 tsc目标文件覆盖源文件错误. 额外加上package.types=""dist/indx.d.ts", 就可以避免tsc吧 dist目录当作源码, 通过tsocnfig.exclude无法排除掉这个场景下的dist/目录,exlude只排除include匹配到的项目,这个官方文档描述清楚了

vscode识别tsconfig文件名模式:tsconfig.*.json 其他tsconfig-xxx.json匹配解析

yarn plugin import typescript 会在.yarnrc.yml中记录plugin并下载plugin到 .yarn/plugins/到. 如果后续删除.yarn目录但是不清理.yarnrc.yml中的plugin条目。后续任何yarn命令将报plugin加载错误。策略:不删除.yarn目录 只删除.yarn/cache目录. 或 yarn cache clean

typescript build

tsc -p tsconfig.json #build single tsconfig.json (not use reference define in tsconfig.json) tsc -b tsconfig.json "declarationMap": true, 当ts源码 的mod1 import mod2时。如果mod2的ts的rootDir不和package.json在同一级目录。而在./src等子目录下时候 vscode不code intelli 不work。需要declarationMap:true 通过编译输出的map文件来辅助code intellli

dns, dns over http(doh), dns over tls(dot)

· 2 min read
Spark light
Spark light
Left

参考文章

DNS TERM

  • RRSet (Resource Record Set) Resource Record group
  • DNSSEC(Domain Name System Security Extensions)(域名查询结果签名机制,防止伪造 串改) ref RR record(DNSKEY,DS,RRSIG,NSEC)
  • DNSSEC: ref:https://medium.com/iocscan/how-dnssec-works-9c652257be0
  • TLD,TLDN(top level domain), like:(.com,.cn)
  • SLD,2LD(second level domain), like:(googl.com,china.cn)

Master files?

$ORIGIN Directive, #define set current domain to a domain, 后续的各种RR记录都是相对于此domain的 $ORIGIN uk.example.com. @ | domain.com. #(apex record)(naked domains)(the current domain)(the current $origin)

  • IN A 222.222.222.222 #(any undefined domain,泛域名与泛解析)

RR (Resouce Record) TYPE ref

A (ipv4)
AAAA (ipv6)
CNAME (alias)
TXT(任意文本备注)
NS(authoritative name server list) nslookup -type=ns test.com
SOA(Start Of authority), the very(first) importent one in NS list(name server).
HINFO(host information)
SRV(record for microsoft active directory)
PTR (ip -> domain query) nslookup -q=ptr 8.8.8.8
MX(mail exchange)
DNSKEY()contains the public signing key
DS(Delegation Signer),contains the hash of DNSKEY
RRSIG(resource record signature)contains the cryptographic signature for an associated record set
NSEC()contains a denial-of-existence record

RR (Resouce Record) Class

  • IN,1 the Internet
  • CS 2 the CSNET class (Obsolete)
  • CH 3 the CHAOS class
  • HS 4 Hesiod [Dyer 87]

nslookup

8.8.8.8
8.8.4.4
223.5.5.5
223.6.6.6
119.29.29.29

DOH(DNS over http)

x# https://dns.google/dns-query
https://doh.pub/dns-query
https://dns.alidns.com/dns-query
x# https://cloudflare-dns.com/dns-query
x# https://doh.dns.sb/dns-query
https://doh.sb/dns-query
https://45.11.45.11/dns-query
https://185.222.222.222/dns-query
x# https://dns.twnic.tw/dns-query

DOT(dns over tls)

tls://8.8.4.4:853
tls://162.14.21.56 #tls_auth_name dot.pub
tls://162.14.21.178 #tls_auth_name dot.pub
tls://223.5.5.5 #tls_auth_name dns.alidns.com
tls://223.6.6.6 #tls_auth_name dns.alidns.com

about-ipv6

· One min read
Spark light
Spark light
Left
lsmod | grep ipv6
sysctl -a | grep ipv6
modprobe ipv6
modinfo ipv6
ip -6 a show
cat /etc/network/interfaces
ifreload -a
ping6 www.qq.com
ping -6 www.qq.com
dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com
curl -I -6 https://www.qq.com
wget -6 https://www.qq.com

ifdown $IFACE
ifup $IFACE
systemctl restart networking
find /lib/modules/$(uname -r) -type f -name ipv6.ko

pve support ipv6 only need this cfg

cat /etc/sysctl.d/98.ipv6.conf
net.ipv6.conf.all.accept_ra=2
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.all.autoconf = 1
net.ipv6.conf.all.use_tempaddr=2
net.ipv6.conf.vmbr0.accept_ra = 2
EOF
systemctl restart networking

below cfg is not need, but still can leave for referenece

~~echo ipv6 >>  /etc/modules-load.d/ipv6.conf~~  #ipv6 is build in kernel, ifconfig output has inet6,ipv6 already loaded
~~echo "source /etc/network/interfaces.d/*" >> /etc/network/interfaces~~
~~cat <<EOF > /etc/network/interfaces.d/ipv6~~
~~iface vmbr0 inet6 auto~~
~~ dhcp 1~~
~~iface vmbr0 inet6 dhcp~~
~~ request_prefix 1~~
~~iface vmbr0 inet6 manual~~
~~ up dhclient -6 vmbr0~~
~~EOF~~
~~/etc/init.d/networking restart #this not work, /etc/init.d/networking file miss~~

#iface vmbr0 inet6 auto> auto vs dhcp :https://superuser.com/questions/630275/cannot-get-an-ipv6-address-on-debian ##auto is for SLAAC (stateless autoconfiguration #https://forum.proxmox.com/threads/proxmox-host-ipv6-dhcp-not-working.85565/ #https://www.hpc.mil/program-areas/networking-overview/2013-10-03-17-24-38/ipv6-knowledge-base-ip-transport/enabling-ipv6-in-debian-and-ubuntu-linux

nfs-howto

· One min read
Spark light
Spark light
Left

*(rw,no_root_squash,subtree_check,sync,insecure)

#add a share conf
echo "/multi-example 192.168.1.0/24(rw,no_root_squash,subtree_check,sync,insecure) 172.16.1.0/24(ro) 10.11.12.0/24(rw)" >> /etc/exports
#check config
exportfs -rav
#server reload
/etc/init.d/nfs-kernel-server reload
#check nfs ver support status
cat /proc/fs/nfsd/versions
#test nfs mount
mount 192.168.1.100:/example /mnt/example
#if remote mount stuck, check iptable/ufw
#nfs need port: tcp port 111, 2049, 4000-4004 udp port 4001
ufw disable

nfs mac client

  • In the Finder > Go > Connect to server window, specify:
#need add line "nfs.client.mount.options = vers=4.0" to /etc/nfs.conf
nfs://192.168.0.51:/<share_full_path>/
  • or without modify /etc/nfs/conf for vers 4 refs
nfs://vers=4,nuc.local:/mnt/tb
nfs://vers=4,nuc.local:/mnt/tb
nfs://vers=4,rw,192.168.1.3:/mnt/sgex16data
rw
  * mount -t nfs -o vers=4.0 192.168.0.51:/<share_full_path>/ /mnt/nfs
* mount -t nfs -o soft,timeo=900,retrans=3,vers=3,proto=tcp nas01:/sales /private/sales
* nfsstat -m

showmount -e vhbw.rbat.tk rpcinfo -a vhbw.rbat.tk sudo mount -t nfs -o vers=4,rw,resvport vhbw.rbat.tk:/opt/use_webrtc /Users/mac/r/wk/use_webrtc

refs

关于大容量储存的阅读记录

· 6 min read
Spark light
Spark light
Left

摘自

接口线相关常识

  • 电源线颜色一般符合规范 黄yellow:12v 红red:5v 橙色orange3.3v 黑灰black:GND
  • 参考 SATA_Pinout
  • http://www.interfacebus.com/Design_Connector_Serial_ATA.html
  • SATA数据接口L形插7口孔 L从上到下编号1-7的分别是(1:GND,2:A+,3:A-,4:GND,5:B-,6:B+,7:GND) A is transmit
  • SATA电源接口L形插15口孔 L从上到下编号15-1分别是(15,14,13:12V)(12,11,10:GND),(9,8,7:5V),(6,5,4:GND),(3,2,1:3.3V)
  • PATA电源线(俗称大4D口 4Pin)

Sata Data 7Pin Sata Power 15Pin

网络存储接口简介

主流的硬盘对接接口是sata接口和M2接口(其他接口: IDE,SCSI), (SAS,Fibre Channel企业服务级使用的)

主板上也提供1-4个sata接口进行对接,也提供少量的M.2接口进行对接(主板M2接口一般是让设备平躺在主板上进行安装的, 所以说,能安装的M2接口的设备的尺寸一定要跟主板上预留的M2安装空间相匹配)

主板上也提供PCIE接口 一般购买PCIE扩展卡 可以扩展出更多sata接口和M.2接口, 用于存储设备的连接

也有M2接口扩展卡扩展出多个SATA接口的转接卡

M2接口的传输速率比SATA接口的传输速率高很多, 主流的笔记本主存储方案都是用的M2接口连接SSD固态硬盘

但是在大容量扩展扩展存储,或者是网络存储方案中, 主流还是使用SATA接口的硬盘设备。 个人猜测,主要原因还是SATA的抗干扰能力比较强,可以使用软性连接,或者是扩展卡进行比较长的走线,然后扩展出更多的硬盘设备, 同时,现在主流的超大容量(2T-18T) 机械硬盘里提供的是SATA接口进行连接, SSD固态硬盘可以提供SATA和M2两种接口形式进行连接

网络存储从接口协议上进行分类

  • NVMe #给固态硬盘设计的传输协议,可以吧PCIE总线性能拉满
  • AHCI:Advanced Host Controller Interface #给机械硬盘设计的传输协议

PCIE为什么这么牛

因为他可以跳过(慢速度的)南桥芯片组直连北桥,和内存RAM同等待遇, 但也有吧PCIE链接到南桥芯片上的主板应该会损失性能 参见[https://en.wikipedia.org/wiki/Southbridge_(computing)] PCI-E to NorthBridge

网络存储方案选择考虑

在设计多盘为存储方案是, 比如4到8以上的盘位是, 由于机械硬盘功率消耗较高, 机箱电源功率上需要做特别考虑 一般NAS方案就是一个小型主机连接多个存储设备, 然后通过主机的网络接口, 使用软件对外提供存储服务, 普通的家用主机甚至是闲置,笔记本都听都可以提供类似的服务,只是在存储容量上会有些限制 如果还需要扩展出更多的存储, 拓展硬盘柜也是可以考虑, 可以看作是一个超大型的U盘(USB接口或者type-c接口), 必须连接额外的主机才能提供存储服务。 所以NAS+扩展机柜不失为一个好的选择 扩展硬盘柜比如: JMS576 和 JMB393 双主控芯片的方案

商用存储方案

在机房或者影视剧制作公司的存储方案上会采用光纤交换机连接存储设备, 接口上也会使用SAS和Fibre Channel链接

NAS主板

  • 映泰的j4105
  • asrock-j3455-itx

参考

compress and index algorithm

· One min read
Spark light
Spark light
Left

git subtree origin desc and manul

· One min read
Spark light
Spark light
Left

git subtree is powerful, but it document is not easy find by search engine. if search git subtree you got many article but not the origin doc.

so may be search by: git subtree txt

here is core desc of git subtree documentaion:

git split

 	Extract a new, synthetic project history from the
history of the <prefix> subtree of <local-commit>, or of
HEAD if no <local-commit> is given. The new history
includes only the commits (including merges) that
affected <prefix>, and each of those commits now has the
contents of <prefix> at the root of the project instead
of in a subdirectory. Thus, the newly created history
is suitable for export as a separate git repository.

so git subtree core

 # split all commit relative with in /subdir into a new branch "tmpbranch"
git subtree split --prefix subdir -b tmpbranch
# push this branch to new repo
git push git@github.com/xxx/newrepo tmpbranch:main

one shortcut cmd do same of above

git subtree push --prefix subdir  git@github.com/xxx/newrepo main

loopback interface and loopback ip address

· 2 min read
Spark light
Spark light
Left

loopback interface是系统虚拟出来的一个接口。所以不会因为线路或接口问题而down掉

loopback interface一般是绑定的127.0.0.1回环地址(只用于本机系统内的地址)

loopback interface也可以绑定其他类型的ip,比如局域网ip或者公网ip,用于实现特殊目的

比如LVS的实现的后台服务器上(多个机器的loopback都设置为一个同样的ip)都可以对这个ip地址提供处理服务,而LVS的前端根据一定的分配策略将dest是这个ip的报文分发到这些机器上以后进行处理

在比如:bgp的peer对等体互联实现中多建议将 可达ip地址放在loopback interface上。并建议用此ip生成BGP Router ID

refs