Skip to content

Instantly share code, notes, and snippets.

@mafintosh
Last active November 25, 2022 23:30
Show Gist options
  • Save mafintosh/ec498f6f1ec32bfb74b777137b6f7d55 to your computer and use it in GitHub Desktop.
Save mafintosh/ec498f6f1ec32bfb74b777137b6f7d55 to your computer and use it in GitHub Desktop.

Hyperswarm DHT setup

Checking your network for P2Pness

Running a node

Running a dht node is as simple as installing the DHT cli.

npm i -g @hyperswarm/cli

Then to run the node do:

hyperswarm-dht

NOTE: If the above prints a warning that your network is NOT holepunchable, you might wanna look into opening port 49737.

That's it! You probably run to run the above command as a daemon so it get's decent uptime.

The DHT node will store IPs and ports from other users through an udp interface. The network is quite redundant so no worries if you shutdown your node or if it crashes :) It also shouldn't consume too much bandwidth as it's just simple small udp messages that exchanged when peers do discovery.

Stay in touch

We might upgrade the command set in the future so it's a good idea to hang in #dat on freenode so we can share updates and you can give us feedback.

Leaving a comment here that you are running a node for a bit will help us in this early phase of the rollout also so we can stay in touch :)

@bcomnes
Copy link

bcomnes commented Apr 18, 2020

Will update asap

@mafintosh
Copy link
Author

@bcomnes actually hold on, seeing something weird.

@mafintosh
Copy link
Author

All good now. >=3.6.2 is best.

@martinheidegger
Copy link

martinheidegger commented Apr 19, 2020

Maybe this is helpful to others, I am running following setup on an ubuntu linux:

(note: I am not a linux or server pro, but this seems to work; improvement suggestions warmly welcome)

  1. Make sure that only the required ports are open: (Port 49737 is used by the hyperswarm bootstrap nodes )

    sudo ufw allow 22
    sudo ufw allow 49737
    sudo ufw enable

    Note: Forgetting port 22 may disable the ssh connection 😅

  2. Add npm build dependencies:

    sudo apt-get install libtool autoconf g++
  3. Install @hyperswarm/cli globally with a sudo user.

    sudo npm i -g @hyperswarm/cli
  4. Create a dedicated hyperswarm user that doesn't have sudo privileges.

    sudo adduser hyperswarm
  5. Add the dht as a service to run as hyperswarm user:

    sudo npx add-to-systemd hyperswarm-dht \
       -u hyperswarm \
       -c "/home/hyperswarm" \
       -e PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
       "$(which hyperswarm-dht) --quiet --port 49737"

    Note: this works without specifying a port - it will use a random port - but for the firewall a static port should be better.

  6. Start the service:

    sudo systemctl start hyperswarm-dht.service
  7. See the status of the service:

    sudo systemctl status hyperswarm-dht --lines 20

    The output on my terminal looks like

    ● hyperswarm-dht.service
       Loaded: loaded (/etc/systemd/system/hyperswarm-dht.service; enabled; vendor preset: enabled)
       Active: active (running) since Tue 2020-04-21 13:20:40 JST; 27s ago
     Main PID: 883 (node)
       CGroup: /system.slice/hyperswarm-dht.service
               └─883 node /usr/bin/hyperswarm-dht --port=49737 --quiet
    
    Apr 21 13:20:40 os3-360-13230 systemd[1]: Started hyperswarm-dht.service.
    Apr 21 13:20:40 os3-360-13230 hyperswarm-dht[883]: DHT version 3.6.2
    Apr 21 13:20:40 os3-360-13230 hyperswarm-dht[883]:   id=6ee604068aa7c2396384f5841032ac3f40af7cc1e5893a8f715e7160e57eff78
    Apr 21 13:20:40 os3-360-13230 hyperswarm-dht[883]:   id-file=/tmp/dht-rpc-id
    Apr 21 13:20:40 os3-360-13230 hyperswarm-dht[883]:   port=49737
    Apr 21 13:20:40 os3-360-13230 hyperswarm-dht[883]:   address=0.0.0.0
    Apr 21 13:20:40 os3-360-13230 hyperswarm-dht[883]:   adaptive=true
    Apr 21 13:20:40 os3-360-13230 hyperswarm-dht[883]:   bootstrap=(default)
    Apr 21 13:20:40 os3-360-13230 hyperswarm-dht[883]:   verbose=false
    Apr 21 13:20:40 os3-360-13230 hyperswarm-dht[883]: Running in adaptive mode. Will go persistent once running for ~30 min and holepunchable
    Apr 21 13:20:40 os3-360-13230 hyperswarm-dht[883]: Listening on 0.0.0.0:49737 (udp,IPv4)
    Apr 21 13:20:41 os3-360-13230 hyperswarm-dht[883]: Network appears holepunchable (remote address is 133.167.44.234:49737)
    Apr 21 13:20:48 os3-360-13230 hyperswarm-dht[883]: DHT node fully bootstrapped
    

    with 6ee604068aa7c2396384f5841032ac3f40af7cc1e5893a8f715 being my current node id.

Up-/downgrading

To up-/downgrade the hyperswarm you need to...

  1. Install the version intended for use: sudo npm i -g @hyperswarm/cli@<version>
  2. Restart the service sudo systemctl restart hyperswarm-dht

@mafintosh
Copy link
Author

@martinheidegger thanks! i'm in the process of making a website for the swarm etc. will copy that onto there as well.

I also updated the gist to make use of the new cli you helped make.

@martinheidegger
Copy link

Happy to be useful 😺

@plankatron
Copy link

hi there , i am node id: 2f061d6437d6b9e35c1e99246e1e2d216860bce01a7adc47ab826c85b786d2a5

@plankatron
Copy link

my new id=d25df0e0420aefd3b7142d892d0bf38f09a7575504aee700fac313a873dc23f8

@bcomnes
Copy link

bcomnes commented Apr 22, 2020

Running 3.6.2 at dht.12core.net

@jwerle
Copy link

jwerle commented Apr 30, 2020

Running 3.6.3 at dht.12core.net with node ID: bdb7e9cae4a20000a00b09a9db7852d5db84e0587ada752ddef9982e469b2289

cc @bcomnes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment