d99kris / nchat

Terminal-based Telegram / WhatsApp client for Linux and macOS
MIT License
728 stars 48 forks source link

Connect error when setting up WhatsApp from Arch Container #155

Closed formula-spectre closed 11 months ago

formula-spectre commented 1 year ago

Description: nchat -s, works fine, I input my phone number for whatsapp, but then it fails; no qr-code, and the only message at screen is Setup Failed. this is ~/.nchat/log.txt:

2023-11-13 10:39:09.813 | INFO  | starting nchat v3.96  (main.cpp:239)
2023-11-13 10:39:18.460 | INFO  | whatsmeow Upgrading database to v1  (gowm.go:388)
2023-11-13 10:39:18.472 | INFO  | whatsmeow Upgrading database to v2  (gowm.go:388)
2023-11-13 10:39:18.480 | INFO  | whatsmeow Upgrading database to v3  (gowm.go:388)
2023-11-13 10:39:18.488 | INFO  | whatsmeow Upgrading database to v4  (gowm.go:388)
2023-11-13 10:39:18.496 | INFO  | whatsmeow Upgrading database to v5  (gowm.go:388)
2023-11-13 10:39:18.552 | WARN  | failed to connect &fmt.wrapError{msg:"couldn't dial whatsapp web websocket: dial tcp 0.0.0.0:443: connect: connection refused", err:(*net.OpError)(0xc000150190)}  (gowm.go:1584)

How to reproduce it: install an arch container, either by distrobox or podman, preferably distrobox as to reproduce the issue 1:1, install nchat-git from the aur, then do nchat -s, select whatsapp, insert your phone number

Environment:

d99kris commented 1 year ago

Hi @formula-spectre - thanks for the detailed bug report, I'll look into this.

Btw, would you be able to help share the commands you use to install/setup the arch container with distrobox?

It suspect it's fairly straight-forward, but I haven't really used containers much before, so I rather ask to ensure our setups are as close as possible.

formula-spectre commented 1 year ago

@d99kris sure! 0 - install podman/docker (I recommend podman since it's rootless) 1 - install distrobox from your distro's repository, or follow their (README's alternative method)[https://github.com/89luca89/distrobox#alternative-methods] 2 - distrobox create --name arch -i archlinux:latest 3 - distrobox enter arch 4 - sudo pacman -Syu base-devel git (maybe not needed) 5 - install nchat

d99kris commented 1 year ago

Thanks! Getting an error though, after calling distrobox create --name arch -i archlinux:latest:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I'll try with docker instead and see if that works better.

d99kris commented 1 year ago

Hm. After switching from podman to docker, I instead get the error


Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/images/create?fromImage=archlinux&tag=latest": dial unix /var/run/docker.sock: connect: permission denied```
d99kris commented 1 year ago

Btw, I tested the above on Ubuntu, as it's my "main" Linux installation. But if you have the steps to set up your container environment (podman, distrobox) on Gentoo perhaps you could share that too, then I can test on Gentoo.

formula-spectre commented 1 year ago

Hm. After switching from podman to docker, I instead get the error

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/images/create?fromImage=archlinux&tag=latest": dial unix /var/run/docker.sock: connect: permission denied```

add your user to the docker group, and start the daemon if it's not already running (systemctl start docker if you're using systemd)

formula-spectre commented 1 year ago

Btw, I tested the above on Ubuntu, as it's my "main" Linux installation. But if you have the steps to set up your container environment (podman, distrobox) on Gentoo perhaps you could share that too, then I can test on Gentoo.

1) follow gentoo's handbook, skip the partitioning, make it a chroot, it's easier for you to troubleshoot. download the llvm|musl|openrc stage3 tarball tho, it's the one I'm using 2) after following the procedure install distrobox and podman/docker 3) set up docker/podman 4) see my comment on how to set up distrobox containers

d99kris commented 1 year ago

Thanks a lot for the pointers! 👍 So I eventually managed to set it up. For the record I used these commands (on Ubuntu 22.04):

sudo groupadd docker
sudo usermod -aG docker ${USER}
sudo apt install docker.io
sudo snap install distrobox --edge --devmode
sudo systemctl restart docker
distrobox create --name arch -i archlinux:latest
distrobox enter arch
# inside container:
sudo pacman -Syu git
git clone https://github.com/d99kris/nchat && cd nchat
./make.sh deps
# manually edited CMakeLists.txt to set `option(HAS_TELEGRAM "Telegram" OFF)` to shorten build time
./make.sh build
./build/bin/nchat -s

After entering phone number, the QR code is displayed in the Terminal. So it appears it's not a general Arch container issue.

I assume you're on x86_64 and not Arm, right?

And networking generally works, so you can ping hosts like api.whatsapp.com and web.whatsapp.com inside the container?

I'll see if I can get a chance to try this out on Gentoo, but it make take a couple of days.

formula-spectre commented 1 year ago

sorry for the late response, but here it is:

distrobox enter arch 
[formula@arch ~]$ ping api.whatsapp.com
ping: socktype: SOCK_RAW
ping: socket: Operation not permitted
ping: => missing cap_net_raw+p capability or setuid?
[formula@arch ~]$ cd^C
[formula@arch ~]$ git clone https://github.com/formula-spectre/ww^C
[formula@arch ~]$ ping web.whatsapp.com
ping: socktype: SOCK_RAW
ping: socket: Operation not permitted
ping: => missing cap_net_raw+p capability or setuid?
d99kris commented 1 year ago

Looks like ping is not allowed for regular user, perhaps you can try the following command instead: dig api.whatsapp.com

And also the output of uname -a would be useful.

Thanks!

formula-spectre commented 1 year ago
dig api.whatsapp.com

; <<>> DiG 9.18.20 <<>> api.whatsapp.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7237
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;api.whatsapp.com.              IN      A

;; ANSWER SECTION:
api.whatsapp.com.       770     IN      CNAME   web.whatsapp.com.
web.whatsapp.com.       468     IN      CNAME   mmx-ds.cdn.whatsapp.net.
mmx-ds.cdn.whatsapp.net. 60     IN      A       31.13.86.51

;; Query time: 20 msec
;; SERVER: 192.168.1.4#53(192.168.1.4) (UDP)
;; WHEN: Sat Nov 18 06:34:56 CET 2023
;; MSG SIZE  rcvd: 116

uname -a inside the container: Linux arch.nexus-prime 5.15.72-xanmod1-1-lts #1 SMP Thu, 06 Oct 2022 10:20:20 +0000 x86_64 GNU/Linux
outside: Linux nexus-prime 5.15.72-xanmod1-1-lts #1 SMP Thu, 06 Oct 2022 10:20:20 +0000 x86_64 Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz GenuineIntel GNU/Linux

formula-spectre commented 11 months ago

if anyone else is experiencing this issue, do a sysctl net.ipv4.ping_group_range="0 2147483647" closed :)

d99kris commented 11 months ago

if anyone else is experiencing this issue, do a sysctl net.ipv4.ping_group_range="0 2147483647" closed :)

Great, thanks for sharing 👍