Sunday, December 31, 2023

Gravitational lensing by an LLM

 A nice short article on gravitational lensing written by an LLM:

Title: Exploring the Cosmic Mirages: Gravitational Lensing

Introduction

In the vast expanse of the universe, where light and matter dance together in the cosmic ballet, there exists a phenomenon that has captivated astronomers and astrophysicists for decades: gravitational lensing. This mesmerizing effect, first predicted by Albert Einstein in his theory of general relativity, has revolutionized our understanding of the cosmos and unveiled hidden secrets about distant galaxies and the nature of gravity itself.


The Essence of Gravitational Lensing

Gravitational lensing is a consequence of Einstein's theory of general relativity, which describes how massive objects warp the fabric of spacetime around them. When light from a distant object passes close to a massive celestial body, such as a galaxy or a black hole, the gravitational field of the massive object bends the path of the light, creating a lens-like effect. This phenomenon allows us to see multiple images of a single distant object, creating captivating cosmic mirages.


Types of Gravitational Lensing

There are several types of gravitational lensing, each offering unique insights into the universe:

1. Strong Lensing: In strong lensing, the gravitational field of a massive object is so strong that it distorts and magnifies the background object into multiple distinct images. This effect often results in the formation of strikingly beautiful, concentric rings known as Einstein rings or gravitational arcs.

2. Weak Lensing: Weak lensing occurs when the gravitational field is not strong enough to produce multiple images but instead slightly distorts the shape of the background object. By studying these subtle distortions, astronomers can map the distribution of dark matter and measure the mass of galaxy clusters, shedding light on the mysterious dark side of the universe.

3. Microlensing: Microlensing involves smaller, less massive objects acting as gravitational lenses. This phenomenon has been instrumental in the discovery of exoplanets by detecting the brief brightening of a background star when an exoplanet passes in front of it.


Applications and Discoveries

Gravitational lensing has become an indispensable tool in modern astrophysics. Some of its notable applications and discoveries include:

1. Dark Matter Mapping: By studying the weak gravitational lensing effects on background galaxies, astronomers have mapped the distribution of dark matter in galaxy clusters, revealing the invisible scaffolding that shapes the cosmos.

2. Cosmic Magnifying Glass: Strong gravitational lensing can magnify distant galaxies, allowing astronomers to observe objects that would otherwise be too faint to detect. This technique has led to the discovery of some of the most distant galaxies known to science.

3. Measuring Cosmic Expansion: Gravitational lensing can also help measure the Hubble constant, a fundamental parameter describing the rate of cosmic expansion. This has important implications for our understanding of the age and fate of the universe.


Conclusion

Gravitational lensing is a remarkable phenomenon that has opened a new window into the cosmos. It allows us to peer into the depths of space and time, revealing hidden galaxies, dark matter, and the true nature of gravity. As our understanding of gravitational lensing continues to deepen, we can look forward to even more astonishing discoveries that will reshape our understanding of the universe and our place within it. This cosmic mirage reminds us that the universe is full of wonders, waiting to be unveiled by the curious eyes of science.

Wednesday, April 19, 2023

Anycast IP addresses and their use in DNS servers

What are Anycast IP addresses?
Multiple servers having the same IP addresses. The routers pick the closest server with the least BGP hops.

How are Anycast IP addresses implemented?
Anycast is simply that the same network is advertised from multiple places. A router receiving multiple advertisements for the same network will choose which advertisement to place in its routing table based on the metrics of the routing protocol. This results in the closest (from the perspective of the routing protocol metrics) destination being used by a router.

Why use Anycast IP addresses for DNS servers?
Excerpt from [1]:
With Unicast, DNS client resolvers can be configured with multiple DNS name server targets. In the event the resolver doesn't receive any response from the first server on the list, it will typically wait a time out value, before it switches to the second server (and subsequent servers) in the resolver list. The next time the resolver has to perform a look up, it won't "remember" servers in the list were non-responsive, and it will start querying with the first server in the list even though it is still unavailable.  Depending on the operating system of the client, it could be one to five seconds as it rotates through the resolver list each time, attempting the failed server.  

With anycast DNS IP addresses, this delay is eliminated and handled by the routing protocol.

References
 

Friday, March 17, 2023

Difference between ramdisk (e.g. initramfs) and loopback device filesystem

My interpretation. Both are types of virtual ramdisks. 
  • Ramdisk uses memory (non-swappable) as a virtual device, while a loopback device uses a file (IF=input_file) as the input. dd if=file_name > of=/dev/loop, then we mount -o loop /dev/loop /mnt
  • The loopback filesystem associates a file on another filesystem as a complete device. For Ramdisks, the device does not refer to any physical hardware, but to a portion of memory that is set aside for the purpose.
  • Loopback vs Ramdisks. During boot - The initial ramdisk device in Linux is another important mechanism that we need to be able to use a loopback device as a the root filesystem.
  • Using Losetup script in Linux to create a disk image.
    • Create an empty image, use losetup to associate that with a loopback device that is not in use (check losetup -a), mkfs to create a file system, mount to /mnt, copy desired files to /mnt, umount /mnt, losetup -d to detach the loopback device from the file.

Friday, February 3, 2023

Which one to use - SHA256sum vs md5sum

  • Both algorithms SHA256sum and md5sum generate a hash. 
  • md5sum generates 128bit hash vs 256 bit hash for sha256sum. In theory, that can reduce hash collisions i.e. two different files/entities being hashed generating the same hash value.
  • Which algorithm to use depends on the use case i.e. the entity/ file being hashed. We want to pick something that does not result in a hash collision.
  • For most cases, 132bit hash sum is more than good enough for supporting a large number of unique items with very low probability of collision [2]. e.g. with a 160bit hash with 2* 10^20 unique entities, the odds of collision are 1 in 100million which is great for most purposes.
  • Considering the limited number of unique objects of a particular type being compared, for most cases a 32bit hash sum suffices.
label: programming, utilities, linux, artifact comparison, SHA256sum vs md5sum, CRC32

Reference
[1] md5sum vs sha256sum - Good discussion, but I do not agree with the hash collision discussion here.
[2] Hash collision probabilities  - Nice algorithm for computing probability of hash collision.

Thursday, February 2, 2023

Comparison between unix sockets and TCP/IP sockets

Netlink sockets are the way entities communicate to each other.
  • Address: Unix domain sockets do not need a IP address + port number, TCP/IP sockets do. 
  • Reach: Unix sockets are local to that machine, while TCP/IP sockets need not be.
  • Speed: Unix sockets are faster since they do not go through the TCP/IP stack which ends up being faster.
  • Types: TCP/IP sockets are of the type streaming, datagram, or Raw. There are no further types of Unix sockets.
  • Application: Unix sockets are used for inter process communication on the same system. They behave like system pipes. TCP/IP sockets have a wide range of applications e.g. Telnet.
  • Scope control: Unix domain sockets can be chmod protected while TCP/IP sockets have global scope. [2]
label: TLDR, Sockets, application, comparison, Unix, Networking, pipes, differences

References

Wednesday, February 1, 2023

SWD vs JTAG and the use of semihosting

  • JTAG (Joint test access group interface) [4] and SWD (Serial wire debug) [5] are interfaces used to connect to a remote embedded processor for debugging and tracking execution. 
    • SWD is a 2 wire interface which is ARM specific, while JTAG is used more widely in the industry. 
    • JTAG supports boundary scan [5] a mechanism used to inspect IC pin states and measure voltages.
  • Semihosting [1] is a way by which a target device connected via a JTAG or SWD interface can use a remote hosts (e.g. a laptops) keyboard and console. This is enabled via a C library compiled with the target's code that allows the injection of breakpoints when these inputs or outputs are required and allows communication with the remote host via a debugger interface (JTAG/SWD) [2].
  • Debugging or printing is usually slow with the JTAG interface because the clock speed is slow on those lines [3].
labels: embedded development, semihosting, SWD, JTAG interface, debugging, TLDR, Summary

References
[1] Semihosting - The ARM guide
[2] Semihosting ARM interface

Tuesday, January 31, 2023

How does Linux load rootfs

  • To load rootfs, you need a basic set of tools. How does the kernel bring them in? Initramfs
  • Initramfs is a RAM based FS that brings support for the basic things.  Command line to setup the kernel at start: vmlinuz initrd=initramfs.img root=/dev/sdaX
  • Moving from initramfs to rootfs: Initramfs does a pivot and switch to rootfs. (1) Move initramfs mountpoints to new rootfs mountpoints, (2) This initramfs contains the essential tools required to create and launch the rootfs. Final switch is done by: switch_root /newroot /bin/bash. Finally once the switch_root is done, run the init from the new rootfs.
Labels: switch_root, Linux, Kernel, rootfs, initramfs, build, systems, TLDR, summary

Code Snippet:
# First, find and mount the new filesystem.      mkdir /newroot    mount /dev/whatever /newroot      # Unmount everything else you've attached to rootfs.  (Moving the filesystems    # into newroot is something useful to do with them.)      mount --move /sys /newroot/sys    mount --move /proc /newroot/proc    mount --move /dev /newroot/dev      # Now switch to the new filesystem, and run /sbin/init out of it.  Don't    # forget the "exec" here, because you want the new init program to inherit    # PID 1.      exec switch_root /newroot /sbin/init

Thursday, January 26, 2023

TLDR: WPA3-SAE - How does it work

  • WPA3 - SAE - stands for simultaneous authentication of equals. This is a more secure mechanism than the previous WPA2-PSK [1].
  • This relies on 3 fundamental components:
    • DH - Diffie-hellman key exchange - Helps to generate a common shared key between the two WiFi entities e.g. station and client.
    • ECC (elliptic curve cryptography) - Elliptic-curve cryptography (ECC) is an approach to public-key cryptography based on the algebraic structure of elliptic curves over finite fields. ECC allows smaller keys compared to non-EC cryptography (based on plain Galois fields) to provide equivalent security [2]. ECC is used once a common pairwise key is generated using the DH key exchange.
    • Dragonfly key exchange is a mechanism for key exchange using discrete logarithm cryptography [3]. This is used with the two components above to setup SAE. See the reference for details on how it is setup [3]. Also covered in RFC7664.
labels: WiFi, TLDR, summary article, WPA3, SAE, security, 

Reference:

Sunday, January 22, 2023

Difference between POE-PD and POE-PSE, POE vs POE+

  • POE stands for power over ethernet
  • A POE system consists of two components - a POE-PSE (Power sourcing equipment) the device which provides the power, and a POE-PD (Power delivered) equipment which receives the power over ethernet.
  • PSE equipment examples - POE switches, POE injectors, POE media convertors [1]
  • PD equipment examples - APs, IP cameras, other devices.
  • PSE has 4 types based on PSE, PD power ratings with a 90W PSE max allowing a 71W PD draw on a port [2].
  • PD ratings are only based on the power draw limit - max of 71W - class 8 PD [2]
  • Power delivery limits are based on negotiations determined by the 802.3 standard. 802.3at (POE) delivers 15.4W, 802.3af (POE+)  delivers 25.5W. This is the difference between POE and POE+.
labels: POE, ethernet, difference, solution, networking, IP networks, TLDR

Reference

Saturday, January 14, 2023

(Programming) Combining the constant and volatile keywords in C

Sometimes asked as an interview question in embedded programming, this summary article covers an interesting use case of combining two seemingly opposite keywords in C [1].

Here is a TLDR of what this means:
1. int volatile x; Tells the compiler that x can change independent of the code e.g a register change that happens in Hardware.
2. uint16_t const x; Is used to tell the compiler that the variable x is immutable.
3. So when can we end up using these together? The article [1] talks about 3 cases, but they are essentially the same thing. We can use these keywords together for a pointer where the address of the pointer does not change (constant) but the value contained at that address is volatile (e.g. a register, shared memory etc). 
e.g. Constant address of volatile hardware register / memory. uint8_t volatile * const p_ptr; i.e the p_ptr has a constant address for a volatile (register).
 
Reference:
[1] Embedded.com. Michael Barr Combining C's volatile and constant 

GITHUB POCO C++ libraries

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.