kappa-db / workshop

let's learn how to write peer-to-peer applications in javascript!
https://kappa-db.github.io/workshop
71 stars 26 forks source link

`full_game.js` : if (typeof initiator !== 'boolean') throw new Error('Must specify initiator boolean in replication stream') #30

Closed raphael10-collab closed 3 years ago

raphael10-collab commented 3 years ago

I opened two windows and executed in both of them full_game.js:

(base) raphy@pc:~/hypercore/kappa-db/workshop$ node full_game.js 
/home/raphy/hypercore/kappa-db/workshop/node_modules/hypercore-protocol/index.js:314
    if (typeof initiator !== 'boolean') throw new Error('Must specify initiator boolean in replication stream')
                                        ^

Error: Must specify initiator boolean in replication stream
    at new ProtocolStream (/home/raphy/hypercore/kappa-db/workshop/node_modules/hypercore-protocol/index.js:314:47)
    at new Multiplexer (/home/raphy/hypercore/kappa-db/workshop/node_modules/multifeed/mux.js:42:32)
    at Multiplexer (/home/raphy/hypercore/kappa-db/workshop/node_modules/multifeed/mux.js:24:46)
    at Multifeed.replicate (/home/raphy/hypercore/kappa-db/workshop/node_modules/multifeed/index.js:258:13)
    at Kappa.replicate (/home/raphy/hypercore/kappa-db/workshop/node_modules/kappa-core/index.js:125:21)
    at Swarm.<anonymous> (/home/raphy/hypercore/kappa-db/workshop/full_game.js:40:18)
    at Swarm.emit (events.js:315:20)
    at onhandshake (/home/raphy/hypercore/kappa-db/workshop/node_modules/discovery-swarm/index.js:444:10)
    at Socket.readable (/home/raphy/hypercore/kappa-db/workshop/node_modules/length-prefixed-message/index.js:46:5)
    at Socket.emit (events.js:315:20)
(base) raphy@pc:~/hypercore/kappa-db/workshop$ 
okdistribute commented 3 years ago

The version of hypercore is wrong! this is likely our fault. Try updating the example code to be compatible with the latest hypercore, or downgrade the hypercore version. Related: https://github.com/kappa-db/workshop/issues/20

hackergrrl commented 3 years ago

Closing, assuming this is a duplicate of #29 and is now also resolved. Let me know @raphael10-collab if this is still relevant.

raphael10-collab commented 3 years ago

@hackergrrl

(base) raphy@pc:~/hypercore/kappa-db/workshop$ git fetch origin
remote: Enumerating objects: 55, done.
remote: Counting objects: 100% (55/55), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 31 (delta 26), reused 31 (delta 26), pack-reused 0
Unpacking objects: 100% (31/31), 3.29 KiB | 187.00 KiB/s, done.
From https://github.com/kappa-db/workshop
   54dc54e..83cd8c8  master     -> origin/master
(base) raphy@pc:~/hypercore/kappa-db/workshop$ git reset --hard origin/master
HEAD is now at 83cd8c8 Rebuilds html.
(base) raphy@pc:~/hypercore/kappa-db/workshop$ rm -rf node_modules/

(base) raphy@pc:~/hypercore/kappa-db/workshop$ npm install

added 429 packages, and audited 430 packages in 23s

70 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Executing on the two machines, I do not get that previous error anymore, but, as far as I can understand, I do not see any interaction between the two instances of the game , one on the pc and the other one on the laptop.

What am I doing wrongly and / or what am I missing?

hackergrrl commented 3 years ago

It might not be something you're doing. To see if your machines can find each other over hyperswarm, try doing this on each machine:

npm i -g airpaste

Then on one run echo 'hello' | airpaste and on the other just run airpaste and see if the 'hello' text gets through. If it hangs indefinitely it's likely an issue with your network blocking multicast traffic.

raphael10-collab commented 3 years ago

@hackergrrl I tried as you suggested. And in the machine which should receive the 'hello' message, the command airpaste hangs for a while (few minutes) and then quits itself.

So, I guess, this is my network blocking multicast traffic.

What do you suggest me to check, and to modify (if I'm allowed to) in my network configuration, in order to remove this blocking multicast traffic?

hackergrrl commented 3 years ago

@raphael10-collab This is a good point to do some web searches :)

raphael10-collab commented 3 years ago

@hackergrrl as far as I see, and understand, MULTICAST is already enabled, and running, on both machines :

(laptop) :

(base) marco@marco-U36SG:~$ ifconfig
enp5s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.9  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::d066:3bd4:7b2c:8f7a  prefixlen 64  scopeid 0x20<link>
        ether c8:60:00:28:46:45  txqueuelen 1000  (Ethernet)
        RX packets 16575  bytes 12105185 (12.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14260  bytes 4996621 (4.9 MB)
        TX errors 0  dropped 0 overruns 0  carrier 1  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1753  bytes 216522 (216.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1753  bytes 216522 (216.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.182.2  netmask 255.255.255.0  broadcast 192.168.182.255
        inet6 fe80::f204:e95f:2715:222e  prefixlen 64  scopeid 0x20<link>
        ether ac:72:89:a4:d2:5b  txqueuelen 1000  (Ethernet)
        RX packets 1752  bytes 148649 (148.6 KB)
        RX errors 0  dropped 791  overruns 0  frame 0
        TX packets 1547  bytes 185076 (185.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

(base) marco@marco-U36SG:~$ sudo tcpdump -i enp5s0 ip multicast -v
tcpdump: listening on enp5s0, link-type EN10MB (Ethernet), capture size 262144 bytes
18:33:38.271662 IP (tos 0x0, ttl 1, id 16692, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
    vodafone.station > all-systems.mcast.net: igmp query v2
18:33:45.954624 IP (tos 0xc0, ttl 1, id 0, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
    marco-U36SG > 224.0.0.251: igmp v2 report 224.0.0.251
18:35:43.270704 IP (tos 0x0, ttl 1, id 21213, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
    vodafone.station > all-systems.mcast.net: igmp query v2
18:35:47.810561 IP (tos 0xc0, ttl 1, id 0, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
    marco-U36SG > 224.0.0.251: igmp v2 report 224.0.0.251
18:37:48.269891 IP (tos 0x0, ttl 1, id 30097, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
    vodafone.station > all-systems.mcast.net: igmp query v2
18:37:56.578624 IP (tos 0xc0, ttl 1, id 0, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
    marco-U36SG > 224.0.0.251: igmp v2 report 224.0.0.251
18:39:53.258993 IP (tos 0x0, ttl 1, id 39217, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
    vodafone.station > all-systems.mcast.net: igmp query v2
18:40:02.018627 IP (tos 0xc0, ttl 1, id 0, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
    marco-U36SG > 224.0.0.251: igmp v2 report 224.0.0.251

^C
13 packets captured
13 packets received by filter
0 packets dropped by kernel

and on (pc) :

(base) raphy@pc:~$ ifconfig
enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.7  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::7a24:afff:fe43:ef5c  prefixlen 64  scopeid 0x20<link>
        ether 78:24:af:43:ef:5c  txqueuelen 1000  (Ethernet)
        RX packets 2910044  bytes 3704589180 (3.7 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1427270  bytes 267286425 (267.2 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 109178  bytes 8895241 (8.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 109178  bytes 8895241 (8.8 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lxdbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.65.116.1  netmask 255.255.255.0  broadcast 0.0.0.0
        inet6 fd42:2159:3d69:bcae::1  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::216:3eff:fec0:73b  prefixlen 64  scopeid 0x20<link>
        ether 00:16:3e:c0:07:3b  txqueuelen 1000  (Ethernet)
        RX packets 163826  bytes 74275228 (74.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 140705  bytes 76523171 (76.5 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethfc2e044e: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 72:5c:d2:ba:f6:5d  txqueuelen 1000  (Ethernet)
        RX packets 163826  bytes 76568792 (76.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 140705  bytes 76523171 (76.5 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp5s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether c0:4a:00:09:0e:80  txqueuelen 1000  (Ethernet)
        RX packets 5529  bytes 2894924 (2.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3542  bytes 809092 (809.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

(base) raphy@pc:~$ sudo tcpdump -i enp3s0 ip multicast -vv
tcpdump: listening on enp3s0, link-type EN10MB (Ethernet), capture size 262144 bytes
18:41:58.285923 IP (tos 0x0, ttl 1, id 48387, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
    vodafone.station > all-systems.mcast.net: igmp query v2
18:44:03.286228 IP (tos 0x0, ttl 1, id 58997, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
    vodafone.station > all-systems.mcast.net: igmp query v2
18:46:08.275434 IP (tos 0x0, ttl 1, id 2697, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
    vodafone.station > all-systems.mcast.net: igmp query v2

^C
3 packets captured
3 packets received by filter
0 packets dropped by kernel
hackergrrl commented 3 years ago

@raphael10-collab I'm not sure why the multicast traffic isn't getting through. Something to try would be trying a tool that uses multicast outside of the nodejs ecosystem, and see if that works. If it does, then it could mean there is a bug in the multicast-dns module (which many p2p projects in the node world use), or even in the nodejs multicast impl (much less likely).

This seems beyond the scope of the kappa-db workshop though, so I'm going to close this issue.