Wednesday, April 26, 2023

GCC


some tips when i trying compile opengl programs in conda
  • g++ -I/home/hongy19/miniconda3/envs/opengl/include/ : include *.h
  • g++ -L/home/hongy19/miniconda3/envs/opengl/lib   :add folder of *.so for link(ld)
  • g++ -lglfw: use libglfw.so for link(ld)
  • LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/hongy19/miniconda3/envs/opengl/lib ./a.out: add library search path for dynamic *.so 
  • static compile
    • -static compile for static link need *.a and *.o library and *.so doesn't work for static compile, see link.  The error of following code is due to missing of *.a or *.o even *.so existed.
(opengl) hongy19@WSL opengl$ gcc glfw-1.cpp -static -lglfw -lGL
/usr/sbin/ld: cannot find -lglfw: No such file or directory
/usr/sbin/ld: cannot find -lGL: No such file or directory
collect2: error: ld returned 1 exit status

  • pkgconfig
    • PKG_CONFIG_PATH=$CONDA_PREFIX/lib/pkgconfig pkg-config --list-all
    • PKG_CONFIG_PATH=$CONDA_PREFIX/lib/pkgconfig pkg-config --cflags glfw3 -I/home/hongy19/miniconda3/envs/opengl/include
    • PKG_CONFIG_PATH=$CONDA_PREFIX/lib/pkgconfig pkg-config --cflags  gtk+-3.0

Saturday, April 22, 2023

X11 and wayland

 

see Environment variables for Wayland hackers and Wayland-specific environment variables for detail and what is setting in wsl2.

  • WAYLAND_DISPLAY
    • wayland unix socket
    • WAYLAND_DISPLAY=wayland-0
  • XDG_RUNTIME_DIR
    • directory of wayland unix socket
    • XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir/ or XDG_RUNTIME_DIR=/run/user/1000/
  • DISPLAY
    • X11 unix socket
    • DISPLAY=:0 and /tmp/.X11-unix/X0
  • GDK_BACKEND
gtk3/gtk3 in conda has disabled wayland support, see link.  
  • with pygobject, GDK_BACKEND=wayland doesn't work but chrome/weston-terminal is OK and pygobject is OK with GDK_BACKEND=wayland, x11 or GDK_BACKEND=x11. 
  • with GDK_BACKEND=help, gtk3 only support x11, not wayland
  • condas gtk3.0/gtk4.0 only support x11, not wayland since no  ~/miniconda3/envs/gtk/include/gtk-3.0/gdk/gdkwayland.h.
  (gtk) hongy19@WSL cairo$ GDK_BACKEND=help python test1.py
  Supported GDK backends: x11

Sunday, April 16, 2023

keyboard

 

According to Archlinux wiki and How Keys Are Turned Into Actions , here comes how keystroke information is transferred in computer.
  • Keyboard send scancode to computer
  • Linux kernel convert scancode to keycode
  • Keyboard layout convert keycode to symbol/keysym
  • Linux terminal convert keysym into ASCII sequences
And there are two types of key (see link )
  • Ordinary key, like "a", "b". we should use them to input text
  • Special keys, which you would use to tell xterm to perform some action. They could not be to used to input text. They will generate escape sequences.
.inputrc is readline initialization file and used to map key sequence to readline function like "end-of-history". Then you need to use text to describe "special keys" or "escape sequences", see following example.
  • "\e[1~": beginning-of-line      # Home Key
  • "\e[4~": end-of-line            # End Key
  • "\e[3~": delete-char      # Delete Key
  • "\e\e[C": forward-word      # Alt-Right
You could use "showkey -k" or "od -c" to show escape sequence of special keys.

Monday, April 10, 2023

Wayland and weston

  • Wayland
    • see overview: Wayland Weston overview
    • Wayland is a communication protocol that specifies the communication between a display server and its clients, from wikipedia
    • Weston is the reference implementation of a Wayland compositor, from weston github.


  • Weston
    • backends, from "man weston"
      • drm-backend.so: The DRM backend uses Linux KMS for output and evdev devices for input
      • wayland-backend.so: The  Wayland  backend  runs on another Wayland server, a different Weston instance
      • x11-backend.so: The X11 backend runs on an X server
      • rdp-backend.so: The  RDP backend runs in memory without the need of graphical hardware.
      • to run weston from wsl2, use wayland-backend.so.
      • to run weston for rdp connection, use rdp-backend.so
      • all for drm connector, see "/sys/class/drm"
    • modules/shell
      • all *.so are located at usr/lib/weston for modules and shell in weston.ini
    • weston terminal
  • scale: scale text for high DPI screen
    • GDK setting for GTK application from application level
      • export GDK_BACKEND=wayland
      • #To scale UI elements by an integer only factor
      • #GTK3/4 does not support fractional scaling currently, so fractional factors will be ignored
      • export GDK_SCALE=1
      • #GDK_DPI_SCALE can be used to scale text only
      • export GDK_DPI_SCALE=1.2
    • composition level
      • "[output]" on weston.ini, only work for drm and X11. set "scale=1.5".

font, 2D drawing on linux

 Here come several basic concept for font, drawing on linux



  • font
    • Anti-aliasing and subpixel rendering, see "A Closer Look At Font Rendering" for concept introduction. 
      • black and white rendering is first generation rendering and print still use it.
      • gray-scale rending (anti-aliasing) is second generation rendering to utilize controlling the brightness of each pixel.
      • subpixel (ClearType in windows) is third generation rendering to utilize controlling pixel colors. it is for LCD on which screens, the red, green and blue subpixels that control the color and brightness of the pixel.
      • Archlinux enable Anti-aliasing and subpixel by default.
    • font configuration on Archlinux wiki introduce default configuration for Archlinux.
  • fontconfig/freetype/pango
    • Very good overview introduction: Modern text rendering with Linux: Overview
    • Text Rendering Notes
    • Font basic concept introduction, see CSS Fonts Module Level 3


    • pango
      • what pango is doing: "here's a piece of text render it in this box I don't care what you do." from link.
      • See one pango code example: link.
      • harfbuzz is text shaping engine which is incorporated into Pango .
      • pango-view --font=monospace --language=zh 1.txt or pango-view --height=300 --width=100 --font=monospace --language=zh 1.txt

  • fontconfig
    • user guideline: fonts-conf
    • pattern, element: 
      • font patterns may contain essentially any properties, fontconfig use pattern to query fonts. element is which properties are listed on output
      • basic syntax of pattern are: <families>-<point sizes>:<name1>=<values1>:<name2>=<values2>, see "Font Names" section of fonts-conf
      • fc-list also use this pattern, see link. 
    • fc-list  lists  fonts  and  styles available on the system for applications using fontconfig. if no font match query pattern, then nothing return. If wrong pattern used, then fc-list output result of "fc-list", see link. fc-list not read configuration file.
    • fc-match  matches pattern (empty pattern by default) using the normal fontconfig matching rules to find the best font available.
    • fc-query  queries font-file(s) using the normal fontconfig rules and prints out font pattern for each face found. fc-qury not read configuration file.
    • charset
      • charset is Unicode chars encoded by the font.
      • charset from output of fc-list and fc-match is base85, not human-readable, see link for detai.  
      • The difference Between Unicode and UTF-8, see link and link.
        • Encoding translates numbers into binary. Character sets translates characters to numbers.
        • Unicode is a character set. UTF-8 is encoding. 
        • Unicode is a list of characters with unique decimal numbers (code points). A = 65, B = 66, C = 67, ....
        • This list of decimal numbers represent the string "hello": 104 101 108 108 111
        • Encoding is how these numbers are translated into binary numbers to be stored in a computer:
        • UTF-8 encoding will store "hello" like this (binary): 01101000 01100101 01101100 01101100  01101111
      • 4E00 is for one of CJK unicode charset, see link
    • lang, see CSS Fonts Module Level 3 - 6.2. Language-specific display
      • "lang causing a glyph change on the same codepoint given", see link
      • No zh, but using :lang=zh-cn

Friday, April 07, 2023

remote desktop on linux

  • X11 forwarding, see my blog
  • RDP
    • xrdp
      • this one seems only work for Xwindows, not wayland.
    • Wayland
      • Not all wayland application support RDP, some only support VNC.
      • sway doesn't support rdp but only vnc, see link.
    • weston, see link
      • On the target linux device, install freerdp and weston
        • pacman -S freerdp
        • pacman -S weston
      • On the target linux device, generate RDP certificates
        • sudo mkdir -p /etc/freerdp/keys/
        • sudo winpr-makecert -rdp -path /etc/freerdp/keys/
      • On the target linux device, start weston
        • weston --backend=rdp-backend.so --rdp-tls-cert=/etc/freerdp/keys/server.crt --rdp-tls-key=/etc/freerdp/keys/server.key
      • On the windows side, start "Remote Desktop Connection" and fill in targe linux server ip.
  • waypipe, see link.
    • installed waypipe on both the local and remote computers
      • yay -Y waypipe
    • run waypipe on local linux/wsl
      • waypipe ssh user@theserver weston-terminal

Wednesday, April 05, 2023

clash

  • clash (link) 可以在linux/windows/Android上使用。它通过定义proxy group and rule来实现基于rule的traffic分发。简单的说,proxy group是proxy的集合,并可以通过type来定义怎么从一组proxy中找到一个proxy用于traffic proxy。rule就是根据ip/url把traffic mapping到不同的proxy group.
  • clash configuration file is config.yaml. 各种机场需要提高相应的config.yaml for proxy group and rule. 
    • 用wget下载bywa机场的订阅链接,得到的是base64 encode的ss serverlist,不是clash config.yaml。可以通过"curl -H "User-Agent: ClashForAndroid/2.0.0" <url>"得到clash config.yaml,详见link
    • 或者使用订阅转换服务,将其它订阅转换为 Clash 订阅。
  • web interface
    • update config.yaml
      • external-controller:9090
      • # A relative path to the configuration directory or an absolute path to a
      • # directory in which you put some static web resource. Clash core will then
      • # serve it at `http://{{external-controller}}/ui`.
      • external-ui: ui
    • get clash-dashboard
      • git clone https://github.com/Dreamacro/clash-dashboard.git
      • cd clash-dashboard
      • git checkout -b gh-pages origin/gh-pages
      • ln -s clash-dashboard ui
    • visit 192.168.1.4:9090/ui for control 
  • clt control interface
    • https://github.com/George-Miao/clashctl
    • pacman -S rust
    • git clone https://github.com/George-Miao/clashctl.git
    • cd clashctl
    • cargo install --path ./clashctl
    • mv .cargo/bin/clashctl  ~/bin
  • good guideline: link

Sunday, April 02, 2023

X11 forwarding

 I tried to ssh to linux server (Archlinux) from wsl2 and run X-windows application on wsls. Here comes summary

  • wsl2 support wslg by default, see link. You could close it by setting "guiApplications=false" in  .wslconfig  on windows side
  • on linux server side
    • enable "X11Forwarding yes " in /etc/ssh/sshd_config" and restart sshd.
    • install xauth by "pacman -S xorg-xauth"
  • on wsl2 side
    • enable "ForwardX11 yes" and "ForwardX11Trusted yes" on .ssh/config
    • no need to install xauth on wsl2 side
  • DISPLAY variable
    • host:display[.screen], for example: localhost:10.0
    • see link for detail
  • answer from kenorb at link gives a good summary.
At beginning, I always fail since I use "ssh -X linux-server" but actually I should use "ssh -Y linux-server". -X is untrust X11 forwarding and  -Y is trust X11 forwarding. untrust X11 forwarding need X server support and I guess wsl2 doesn't support it. See detail on link1, link2 .
  • from link1, "Untrusted X11 forwarding was meant to be a way to allow logins to unknown or insecure systems.  It generates a cookie with xauth and uses the Security extension to limit what the remote client is allowed to do. But this is widely considered to be not useful, because the Security extension uses an arbitrary and limited access control policy, which results in a lot of applications not working correctly and what is really a false sense of security."
  • from link2 ,  "This is not a limitation of SSH client, but of X server.  SSH client should be able to forward untrusted X11 connection if used with X server with SECURITY extension."
  • from  link2 , "To answer last question, no X Security Extension can not be enabled at runtime, because it is build-time disabled and deprecated by Xorg years ago. Re-enabling was done in RHEL6, it was also considered for RHEL7, but it was not decided to do so" 

You could just igore following error message when you "ssh linux server"
"debug1: No xauth program.
Warning: No xauth data; using fake authentication data for X11 forwarding.
debug1: Requesting X11 forwarding with authentication spoofing.
debug1: Remote: No xauth program; cannot forward X11."

Saturday, April 01, 2023

rtorrent/clash/ipfs/ipv6-dhcp

  • torrent
    • 基本概念
      • DHT
        • DHT其实就是去中心化(tracker list)的p2p网络。但是DHT需要bootstrapping node做为启动节点,否则无法找到其它DHT server
      • tracker list
        • tracker list包含了一系列的track server。track server可以看见所有的bt node. bt node也需要tracker server发现包含下载资源的node。tracker sever一般包含在torrent种子中,也可以手动在rtorrent下载界面中添加相关tracer server。 
    • rtorrent
      • 基本配置可以参考rtorrent@archlinux wiki.
      • 需要注意的是rtorrent无法做到server and client mode。如果rtorrent做为daemon运行,除非利用XMLRPC,否则无法通过client控制和查看daemon。所以只能通过screen实现headless运行,需要注意的是如果通过linux host远程到服务器端的rtorrent,则linux host段不能运行screeen,否则容易screen快捷键冲突。
      • rtorrent的DHT需要配置才能开启,另外需要添加bootstrapping DHT server,详细配置可见 link1 and link2
      • rtorrent的配置语法有点特别。"schedule2 = watch_directory_1,10,10,"load.start=~/Download/watch_stuff1/*.torrent"中的等号后面其实是schedule2命令的参数,这里并不是给schedule2赋值。如果函数没有参数,也需要加上等号。比如"dht.statistics="
      • 关键快捷键
        • ctrl+x: 输入命令
        • backspace/enter: 输入magnet link or torrent 
        • ctrl+q: 退出rtorrent
  • clash
    • clash其实只是一个proxy配置应用。clash可以有效的配置每个socket request该怎么分配到不同的proxy上。
    • proxy and proxy group其实就是proxy的集合,proxy group定义了该怎么选择proxy集合中的proxy。Android上clash里的proxy其实就是proxy group。
    • rule定义了如何将socket request mapping到proxy/proxy-group上。rule可以根据后缀,IP等不同方式分配不同的proxy。Android上的clash可以做到不同的app走不同的proxy。
    • rule provider其实其实一组rule的集合,但是它并不包含proxy target。Android clash里的Providers其实就是rule provider。
  • ipfs
    • ipfs其实和bitorrent都是p2p file sharing network。
    • ipfs把文件分成block(树状结构),文件的CID只是根节点的hash值,并不是整个文件的hash.
    • ipfs refs查看block,而不是整个文件。
  • ipv6 dhcp
    • ipv6 dhcp的概念和ipv4不太一样。ipv6有四种方式: Static (manual), SLAAC, Stateless DHCPv6, Stateful DCHPv6 。
    • iptables防火墙需要特殊设置才能enable ipv6. default ufw has related settting.
    • Following is just copy from link:
      • Static (manual) address assignment – exactly like with IPv4, you can go on and apply the address yourself. I believe this is straight forward and therefore I am not going to demonstrate that.
      • Stateless Address Auto Configuration (SLAAC) – nodes listen for ICMPv6 Router Advertisements (RA) messages periodically sent out by routers on the local link, or requested by the node using an RA solicitation message. They can then create a Global unicast IPv6 address by combining its interface EUI-64 (based on the MAC address on Ethernet interfaces) plus the Link Prefix obtained via the Router Advertisement. This is a unique feature only to IPv6 which provides simple “plug & play” networking. By default, SLAAC does not provide anything to the client outside of an IPv6 address and a default gateway. SLAAC is greatly discussed in RFC 4862.
      • Stateless DHCPv6 – with this option SLAAC is still used to get the IP address, but DHCP is used to obtain “other” configuration options, usually things like DNS, NTP, etc. The advantage here is that the DHCP server is not required to store any dynamic state information about any individual clients. In case of large networks which has huge number of end points attached to it, implementing stateless DHCPv6 will highly reduce the number of DHCPv6 messages that are needed for address state refreshment.
      • Stateful DCHPv6 – functions exactly the same as IPv4 DHCP in which hosts receive both their IPv6 address and additional parameters from the DHCP server. Like DHCP for IPv4, the components of a DHCPv6 infrastructure consist of DHCPv6 clients that request configuration, DHCPv6 servers that provide configuration, and DHCPv6 relay agents that convey messages between clients and servers when clients are on subnets that do not have a DHCPv6 server. You can learn more about DHCP for IPv6 in RFC 3315.