How to use the ssb-ref.parseAddress function in ssb-ref

To help you get started, we’ve selected a few ssb-ref examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ssbc / ssb-server / plugins / invite.js View on Github external
}, function (err) {
          // emit the invite code: our server address, plus the key-seed
          if(err) cb(err)
          else if(opts.modern) {
            var ws_addr = getInviteAddress().split(';').sort(function (a, b) {
               return +/^ws/.test(b) - +/^ws/.test(a)
            }).shift()


            if(!/^ws/.test(ws_addr)) throw new Error('not a ws address:'+ws_addr)
            cb(null, ws_addr+':'+seed.toString('base64'))
          }
          else {
            addr = ref.parseAddress(addr)
            cb(null, [opts.external ? opts.external : addr.host, addr.port, addr.key].join(':') + '~' + seed.toString('base64'))
          }
        })
      }, 'number|object', 'string?'),
github mmckegg / patchwork-next / lib / persistent-gossip / index.js View on Github external
connect: valid.async(function (addr, cb) {
        addr = ref.parseAddress(addr)
        if (!addr || typeof addr != 'object')
          return cb(new Error('first param must be an address'))

        if(!addr.key) return cb(new Error('address must have ed25519 key'))
        // add peer to the table, incase it isn't already.
        gossip.add(addr, 'manual')
        var p = gossip.get(addr)
        if(!p) return cb()

        p.stateChange = Date.now()
        p.state = 'connecting'
        server.connect(p, function (err, rpc) {
          if (err) {
            p.state = undefined
            p.failure = (p.failure || 0) + 1
            p.stateChange = Date.now()
github ssbc / ssb-server / test / gossip.js View on Github external
ssbServer.gossip.peers().map(function (e) {
      console.log(e, ref.parseAddress(e.address))
      return ref.parseAddress(e.address)
    }),
    peers
github ssbc / ssb-server / test / util.js View on Github external
exports.pub = function (address) {
  return {
    type: 'pub',
    address: ref.parseAddress(address)
  }
}
github ssbc / ssb-server / plugins / invite.js View on Github external
opts = {uses: opts}
        else if(isObject(opts)) {
          if(opts.modern)
            opts.uses = 1
        }
        else if(isFunction(opts))
          cb = opts, opts = {}

        var addr = getInviteAddress()
        if(!addr) return cb(new Error(
          'no address available for creating an invite,'+
          'configuration needed for server.\n'+
          'see: https://github.com/ssbc/ssb-config/#connections'
        ))
        addr = addr.split(';').shift()
        var host = ref.parseAddress(addr).host
        if(typeof host !== 'string') {
          return cb(new Error('Could not parse host portion from server address:' + addr))
        }

        if (opts.external)
          host = opts.external

        if(!config.allowPrivate && (ip.isPrivate(host) || 'localhost' === host || host === ''))
          return cb(new Error('Server has no public ip address, '
                            + 'cannot create useable invitation'))

        //this stuff is SECURITY CRITICAL
        //so it should be moved into the main app.
        //there should be something that restricts what
        //permissions the plugin can create also:
        //it should be able to diminish it's own permissions.
github ssbc / ssb-server / plugins / local.js View on Github external
local.on('data', function (buf) {
      if (buf.loopback) return
      var data = buf.toString()
      var peer = ref.parseAddress(data)
      if (peer && peer.key !== sbot.id) {
        addrs[peer.key] = peer
        lastSeen[peer.key] = Date.now()
        sbot.gossip.add(data, 'local')
      }
    })
github mmckegg / patchwork-next / lib / persistent-gossip / index.js View on Github external
init: function (server, config) {
    var notify = Notify()
    var conf = config.gossip || {}
    var home = ref.parseAddress(server.getAddress())

    var stateFile = AtomicFile(path.join(config.path, 'gossip.json'))

    //Known Peers
    var peers = []

    function getPeer(id) {
      return u.find(peers, function (e) {
        return e && e.key === id
      })
    }

    var timer_ping = 5*6e4

    var gossip = {
      wakeup: 0,