Convert Figma logo to code with AI

ssbc logossb-server

The gossip and replication server for Secure Scuttlebutt - a distributed social network

1,690
165
1,690
40

Top Related Projects

1,172

A database of unforgeable append-only feeds, optimized for efficient replication for peer to peer protocols

A decentralized messaging and sharing app built on top of Secure Scuttlebutt (SSB).

Quick Overview

SSB-Server is a secure scuttlebutt server implementation. It provides a decentralized database, identity system, and messaging platform, designed for offline-first applications and local-first development. SSB-Server is the core component of the Secure Scuttlebutt (SSB) ecosystem.

Pros

  • Decentralized and offline-first architecture
  • Strong focus on privacy and security
  • Flexible and extensible through plugins
  • Active community and ecosystem

Cons

  • Steep learning curve for newcomers
  • Limited scalability for large-scale applications
  • Slower synchronization compared to centralized systems
  • Requires careful management of storage due to append-only nature

Code Examples

  1. Creating an SSB client:
const ssbClient = require('ssb-client')

ssbClient((err, sbot) => {
  if (err) throw err
  // Use sbot to interact with the SSB network
})
  1. Publishing a message:
sbot.publish({
  type: 'post',
  text: 'Hello, Secure Scuttlebutt!'
}, (err, msg) => {
  if (err) throw err
  console.log('Message published:', msg.key)
})
  1. Querying messages:
sbot.query.read({
  limit: 10,
  reverse: true,
  query: [{
    $filter: {
      value: {
        content: { type: 'post' }
      }
    }
  }]
}, (err, messages) => {
  if (err) throw err
  console.log('Recent posts:', messages)
})

Getting Started

To get started with SSB-Server:

  1. Install SSB-Server:

    npm install ssb-server
    
  2. Create a new SSB-Server instance:

    const Server = require('ssb-server')
    const config = require('ssb-config')
    
    const server = Server(config)
    
    server.on('ready', () => {
      console.log('SSB-Server is ready')
    })
    
  3. Start using SSB-Server features or add plugins as needed.

Competitor Comparisons

1,172

A database of unforgeable append-only feeds, optimized for efficient replication for peer to peer protocols

Pros of ssb-db

  • More focused and modular approach to database management
  • Potentially easier to integrate into custom SSB applications
  • Lighter weight, with fewer dependencies

Cons of ssb-db

  • Less feature-rich compared to the full ssb-server implementation
  • May require additional setup and configuration for a complete SSB node
  • Lacks some built-in networking and replication features

Code Comparison

ssb-db:

const SecretStack = require('secret-stack')
const ssbKeys = require('ssb-keys')
const path = require('path')

const keys = ssbKeys.loadOrCreateSync(path.join(process.env.HOME, '.ssb', 'secret'))
const sbot = SecretStack({ appKey: require('ssb-caps').shs })
  .use(require('ssb-db'))
  .call(null, { keys })

ssb-server:

const Server = require('ssb-server')
const config = require('ssb-config')

const server = Server(config)

server.on('ready', () => {
  console.log('SSB server is ready')
})

The ssb-db code focuses on database initialization, while ssb-server provides a more complete server setup with additional features and configurations.

A decentralized messaging and sharing app built on top of Secure Scuttlebutt (SSB).

Pros of Patchwork

  • User-friendly GUI application, making it more accessible for non-technical users
  • Integrated social features like profiles, follows, and message threads
  • Cross-platform support (Windows, macOS, Linux)

Cons of Patchwork

  • Larger application size due to bundled dependencies and GUI components
  • May have slower performance compared to the lightweight ssb-server
  • Less flexibility for advanced users who prefer command-line interfaces

Code Comparison

ssb-server:

const Server = require('ssb-server')
const config = require('ssb-config')

Server(config)

Patchwork:

const electron = require('electron')
const Path = require('path')
const defaultMenu = require('electron-default-menu')
const WindowState = require('electron-window-state')
const Menu = electron.Menu

The code snippets highlight the difference in focus between the two projects. ssb-server is a lightweight, server-focused implementation, while Patchwork includes additional dependencies for building a desktop application using Electron.

Both projects are part of the Secure Scuttlebutt (SSB) ecosystem, with ssb-server serving as the core server implementation and Patchwork providing a user-friendly client application. While ssb-server offers more flexibility for developers and advanced users, Patchwork aims to make SSB more accessible to a broader audience through its graphical interface and integrated features.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

ssb-server

ssb-server is an open source peer-to-peer log store used as a database, identity provider, and messaging system. It has:

  • Global replication
  • File-synchronization
  • End-to-end encryption

ssb-server behaves just like a Kappa Architecture DB. In the background, it syncs with known peers. Peers do not have to be trusted, and can share logs and files on behalf of other peers, as each log is an unforgeable append-only message feed. This means ssb-servers comprise a global gossip-protocol mesh without any host dependencies.

If you are looking to use ssb-server to run a pub, consider using ssb-minimal-pub-server instead.

Join us in #scuttlebutt on Libera Chat.

build status

Install

How to Install ssb-server and create a working pub

  1. sudo apt install curl autotools-dev automake

  2. Install the Node Version Manager (NVM):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
  1. Close and reopen your terminal to start using nvm or run the following:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
  1. nvm install 10

  2. nvm alias default 10

  3. npm install -g node-gyp

  4. Then to add ssb-server to your available CLI commands, install it using the -g global flag:

npm install -g ssb-server

If you are running as the root user this command will fail. Ideally you would run ssb-server as a non-priviledged user, but if you have to run it as root you can do so with npm install -g ssb-server --unsafe-perm.

  1. nano ~/run-server.sh and input:
#!/bin/bash
while true; do
  ssb-server start
  sleep 3
done

Input Ctrl-X to save and quit.

Be sure to start the pub server from this script (as shown in step 10), as this script will run the pub server and restart it even if it crashes.

  1. mkdir ~/.ssb/

  2. nano ~/.ssb/config and input:

{
  "connections": {
    "incoming": {
      "net": [
        { "scope": "public", "host": "0.0.0.0", "external": "Your Host Name or Public IP", "transform": "shs", "port": 8008 }
      ]
    },
    "outgoing": {
      "net": [{ "transform": "shs" }]
    }
  }
}
  1. Now run sh ~/run-server.sh in a detachable session (e.g. screens)

  2. Detach the session and run ssb-server whoami to check to see if the server is working.

  3. Now is the time to think of a really cool name for your new pub server. Once you have it run:

ssb-server publish --type about --about {pub-id (this is the output from ssb-server whoami)} --name {Your pubs awesome name}

  1. Now it's time to create those invites! Just run ssb-server invite.create 1 and send those codes to your friends.

Congratulations! You are now ready to scuttlebutt with your friends!

Note for those running ssb-server from a home computer. You will need to make sure that your router will allow connections to port 8008. Thus, you will need to forward port 8008 to the local IP address of the computer running the server (look up how to do this online). If you haven't done this step, when a client tries to connect to your server using the invite code, they will get an error that your invite code is not valid.

Applications

There are already several applications built on ssb-server, one of the best ways to learn about secure-scuttlebutt is to poke around in these applications.

  • patchwork is a discussion platform that we use to anything and everything concerning ssb and decentralization.
  • patchbay is another take on patchwork - it's compatible, less polished, but more modular. The main goal of patchbay is to be very easy to add features to.
  • git-ssb is git (& github!) on top of secure-scuttlebutt. Although we still keep our repos on github, primary development is via git-ssb.

It is recommended to get started with patchwork, and then look into git-ssb and patchbay.

Starting an ssb-server

Command Line Usage Example

Start the server with extra log detail Leave this running in its own terminal/window

ssb-server start --logging.level=info

Javascript Usage Example

var Server = require('ssb-server')
var config = require('ssb-config')
var fs = require('fs')
var path = require('path')

// add plugins
Server
  .use(require('ssb-master'))
  .use(require('ssb-gossip'))
  .use(require('ssb-replicate'))
  .use(require('ssb-backlinks'))

var server = Server(config)

// save an updated list of methods this server has made public
// in a location that ssb-client will know to check
var manifest = server.getManifest()
fs.writeFileSync(
  path.join(config.path, 'manifest.json'), // ~/.ssb/manifest.json
  JSON.stringify(manifest)
)

see: github.com/ssbc/ssb-config for custom configuration.

Calling ssb-server Functions

There are a variety of ways to call ssb-server methods, from a command line as well as in a javascript program.

Command Line Usage Example

The command ssb-server can also used to call the running ssb-server.

Now, in a separate terminal from the one where you ran ssb-server start, you can run commands such as the following:

# publish a message
ssb-server publish --type post --text "My First Post!"

# stream all messages in all feeds, ordered by publish time
ssb-server feed

# stream all messages in all feeds, ordered by receive time
ssb-server log

# stream all messages by one feed, ordered by sequence number
ssb-server hist --id $FEED_ID

Javascript Usage Example

Note that the following involves using a separate JS package, called ssb-client. It is most suitable for connecting to a running ssb-server and calling its methods. To see further distinctions between ssb-server and ssb-client, check out this handbook article.

var pull = require('pull-stream')
var Client = require('ssb-client')

// create a ssb-server client using default settings
// (server at localhost:8080, using key found at ~/.ssb/secret, and manifest we wrote to `~/.ssb/manifest.json` above)
Client(function (err, server) {
  if (err) throw err

  // publish a message
  server.publish({ type: 'post', text: 'My First Post!' }, function (err, msg) {
    // msg.key           == hash(msg.value)
    // msg.value.author  == your id
    // msg.value.content == { type: 'post', text: 'My First Post!' }
    // ...
  })

  // stream all messages in all feeds, ordered by publish time
  pull(
    server.createFeedStream(),
    pull.collect(function (err, msgs) {
      // msgs[0].key == hash(msgs[0].value)
      // msgs[0].value...
    })
  )

  // stream all messages in all feeds, ordered by receive time
  pull(
    server.createLogStream(),
    pull.collect(function (err, msgs) {
      // msgs[0].key == hash(msgs[0].value)
      // msgs[0].value...
    })
  )

  // stream all messages by one feed, ordered by sequence number
  pull(
    server.createHistoryStream({ id: < feedId > }),
    pull.collect(function (err, msgs) {
      // msgs[0].key == hash(msgs[0].value)
      // msgs[0].value...
    })
  )
})

Use Cases

ssb-server's message-based data structure makes it ideal for mail and forum applications (see Patchwork). However, it is sufficiently general to be used to build:

  • Office tools (calendars, document-sharing, tasklists)
  • Wikis
  • Package managers

Because ssb-server doesn't depend on hosts, its users can synchronize over WiFi or any other connective medium, making it great for Sneakernets.

ssb-server is eventually-consistent with peers, and requires exterior coordination to create strictly-ordered transactions. Therefore, by itself, it would probably make a poor choice for implementing a crypto-currency. (We get asked that a lot.)


Getting Started

Key Concepts

Further Reading

License

MIT

NPM DownloadsLast 30 Days