{"id":687,"date":"2020-03-04T18:06:47","date_gmt":"2020-03-04T17:06:47","guid":{"rendered":"http:\/\/people.iola.dk\/arj\/?p=687"},"modified":"2020-03-04T20:43:30","modified_gmt":"2020-03-04T19:43:30","slug":"how-to-setup-a-pub-for-ssb-browser","status":"publish","type":"post","link":"https:\/\/people.iola.dk\/arj\/2020\/03\/04\/how-to-setup-a-pub-for-ssb-browser\/","title":{"rendered":"How to setup a PUB for SSB browser"},"content":{"rendered":"\n<p><a href=\"https:\/\/github.com\/arj03\/ssb-browser-demo\">SSB-browser<\/a> as mentioned in my last blog post runs a SSB client in the browser. In order to communicate with other peer it needs a pub to relay messages through. Furthermore the pub acts as a super node allowing the browser peer to do <a href=\"https:\/\/github.com\/arj03\/ssb-partial-replication\">partial replication<\/a> without necessarily needing to store the full feeds of peers.<\/p>\n\n\n\n<p>We don&#8217;t really gain very much compared to the classical client-server setup if we rely too much on especially a single pub. The browser client can of course run fully off-line, but still when it needs to communicate  messages with other peers it needs some intermediary.<\/p>\n\n\n\n<p>In this post I will show how to setup a pub that can be used together with ssb browser. I will also show how this can be used to build a totally seperate network from the main scuttlebutt network for local groups and communities.  <\/p>\n\n\n\n<p>First of all one needs to install the basic ssb-server. On my pub I use  <a href=\"https:\/\/github.com\/ssbc\/ssb-minimal-pub-server\">ssb-minimal-pub-server<\/a>. The good thing is that this already comes with everything we need for peer invites. So we just need to install the before mentioned <a href=\"https:\/\/github.com\/arj03\/ssb-partial-replication\">ssb-partial-replication<\/a> module into ~\/.ssb\/node_modules\/. Easiest is just to git clone and npm install it from the directory. It is also recommended to install <a href=\"https:\/\/github.com\/ssbc\/ssb-tunnel\">ssb-tunnel<\/a> but this is not required.<\/p>\n\n\n\n<p>Lastly we need to configure ssb-server to use the modules and to enable web sockets so the browser will be able to connect.<\/p>\n\n\n\n<pre>{<br>   \"connections\": {<br>     \"incoming\": {<br>       \"net\": [{ \"port\": 8008, \"host\": \"::\", \"scope\": \"public\", \"transform\": \"shs\", \"external\": [\"between-two-worlds.dk\"] }],<br>       \"ws\": [{ \"port\": 8989, \"host\": \"::\", \"scope\": \"public\", \"transform\": \"shs\", \"external\": [\"between-two-worlds.dk\"], \"key\": \"\/etc\/letsencrypt\/live\/between-two-worlds.dk\/privkey.pem\", \"cert\": \"\/etc\/letsencrypt\/live\/between-two-worlds.dk\/cert.pem\" }]<br>     },<br>     \"outgoing\": {<br>       \"net\": [{ \"transform\": \"shs\" }],<br>       \"tunnel\": [{ \"transform\": \"shs\" }]<br>     }<br>   },<br>   \"logging\": {<br>     \"level\": \"info\"<br>   },<br>   \"plugins\": {<br>     \"ssb-device-address\": true,<br>     \"ssb-identities\": true,<br>     \"ssb-peer-invites\": true,<br>     \"ssb-tunnel\": true,<br>     \"ssb-partial-replication\": true<br>   },<br> }<\/pre>\n\n\n\n<p>As one can see this uses letsencrypt, but that is not strictly needed.<\/p>\n\n\n\n<p>Lastly we need to start up the server. I run it using the following bash script that will make sure the pub keeps running even if it should crash.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre>\n#!\/bin\/bash\nwhile true; do<br>     sbot server --port 8008 &gt;&gt; log.txt 2&gt;&amp;1<br>     sleep 30<br> done<\/pre>\n<\/div><\/div>\n\n\n\n<p>This is everything you need to run your own scuttlebutt pub that supports browser clients.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Separate network<\/h2>\n\n\n\n<p>If one wants to run a totally different network than the main scuttlebutt network one needs to use a different caps key. This means that messages from this network will never appear on the main network. This can generated using using node:<\/p>\n\n\n\n<pre>crypto.randomBytes(32).toString('base64')<\/pre>\n\n\n\n<p>And can be added to the config file on the pub using:<\/p>\n\n\n\n<pre>\n\"caps\": {<br>  \"shs\": \"72I4EC\/gZUuNffHEwooHob4hhtXHAj0HE5xKM3njRSg=\"<br> }<\/pre>\n\n\n\n<p><a href=\"https:\/\/github.com\/arj03\/ssb-browser-core\">SSB-browser-core<\/a> needs a little tweak to use the same caps.  Change browser.js to:<\/p>\n\n\n\n<pre>require('.\/core').init(dir, { \n  caps: { \n   shs: '72I4EC\/gZUuNffHEwooHob4hhtXHAj0HE5xKM3njRSg=' \n  }\n})<\/pre>\n\n\n\n<p>It might also be a good idea to change hops to 2 in the client. In order to bootstrap the network, generate an invite or follow the first user from the command line of the pub in order for messages to start propagating.<\/p>\n\n\n\n<pre>sbot publish --type contact --contact '@feedId=.ed25519' --following<\/pre>\n\n\n\n<p>That is all you need to run your seperate network \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SSB-browser as mentioned in my last blog post runs a SSB client in the browser. In order to communicate with other peer it needs a pub to relay messages through. Furthermore the pub acts as a super node allowing the browser peer to do partial replication without necessarily needing to store the full feeds of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[308],"tags":[],"class_list":["post-687","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/posts\/687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/comments?post=687"}],"version-history":[{"count":16,"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/posts\/687\/revisions"}],"predecessor-version":[{"id":704,"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/posts\/687\/revisions\/704"}],"wp:attachment":[{"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/media?parent=687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/categories?post=687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/people.iola.dk\/arj\/wp-json\/wp\/v2\/tags?post=687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}