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 :)

@mafintosh
Copy link
Author

@DeltaF1 that’s awesome, mind sharing your node id jere?

@DeltaF1
Copy link

DeltaF1 commented Jul 17, 2019

node id: 7c312f3958183e19381662c76d76428aca473b66cbb08e701382619972b73434

I'll try and leave this running on my phone for the next couple days

@DeltaF1
Copy link

DeltaF1 commented Jul 22, 2019

Is there any way to re-launch a node with a specific node id? (assuming that you need a consistent list of node ids for testing)

@mafintosh
Copy link
Author

@DeltaF1 no, but just update your ID here :) i'm mostly just tracking for fun to see how the dht grows

@bcomnes
Copy link

bcomnes commented Jul 27, 2019

node id: ae3d7d7f0012323924075b3950b5466c54c7ed78dfcc06b17097eed417a52816
dht node fully bootstrapped

Running in NYC

@bcomnes
Copy link

bcomnes commented Jul 27, 2019

Sorry f6e18194de12bb53633d6069b5b8902df6f01181945f83a3ce4d362d6887343f. I guess the node id changes.

@mafintosh
Copy link
Author

Added some updated logic so would be nice if anyone here still running a node could reinstall and restart it

@martinheidegger
Copy link

26f76f77676c2400357bb12465a3ae41d86001d772532c0c1d88b368e612325d

@bcomnes
Copy link

bcomnes commented Feb 20, 2020

New node running at node id: 260bc18966282f7be31f403ded90ad8e922db98821154f8ae5d11a6118804097 at http://dht.12core.net.

We might be killing the node from time to it should be stable at that URL though.

@martinheidegger
Copy link

martinheidegger commented Apr 8, 2020

new node id: db34a9500e7f7cef695bc1f39c7fd366b3f380b1fd2f361eb8b41dcbe3d12321

@mafintosh
Copy link
Author

@martinheidegger perfect! @Frando @bcomnes @DeltaF1 @RangerMauve if you could all update to latest version of restart that'd be great :) assuming you're still running a node

@bcomnes
Copy link

bcomnes commented Apr 8, 2020

Yeah will update this week.

@bcomnes
Copy link

bcomnes commented Apr 8, 2020

OK running 3.5.2 at dht.12core.net

@mafintosh
Copy link
Author

Hi all!

We rolled out a bigger update for better DHT health. If you could all install @hyperswarm/dht >= 3.6.1 and restart that'd be awesome :) Currently your nodes are disconnected from the bootstrappers until you do that.

Also there is a flag node --quiet if you don't all those pesky logs.
Thanks again for the help. I really appreciate it.

@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