How to use the ssb-ref.isAddress 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 / gossip / index.js View on Github external
connect: valid.async(function (addr, cb) {
        if(ref.isFeed(addr))
          addr = gossip.get(addr)
        server.emit('log:info', ['SBOT', stringify(addr), 'CONNECTING'])
        if(!ref.isAddress(addr.address))
          addr = ma.decode(addr)
        if (!addr || typeof addr != 'object')
          return cb(new Error('first param must be an address'))

        if(!addr.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.address, function (err, rpc) {
          if (err) {
            p.error = err.stack
github mmckegg / patchwork-next / lib / persistent-gossip / index.js View on Github external
add: valid.sync(function (addr, source) {
        addr = ref.parseAddress(addr)
        if(!ref.isAddress(addr))
          throw new Error('not a valid address:' + JSON.stringify(addr))
        // check that this is a valid address, and not pointing at self.

        if(addr.key === home.key) return
        if(addr.host === home.host && addr.port === home.port) return

        var f = gossip.get(addr)

        if(!f) {
          // new peer
          addr.source = source
          addr.announcers = 1
          addr.duration = addr.duration || null
          peers.push(addr)
          notify({ type: 'discover', peer: addr, source: source || 'manual' })
          return addr
github ssbc / ssb-server / plugins / gossip / index.js View on Github external
add: valid.sync(function (addr, source) {

        if(isObject(addr)) {
          addr.address = coearseAddress(addr)
        }
        else {
         var _addr = ma.decode(addr)
          if(!_addr) throw new Error('not a valid address:'+addr)
          _addr.address = addr
          addr = _addr
        }
        if(!ref.isAddress(addr.address) /*&& !ref.isAddress(addr)*/)
          throw new Error('not a valid address:' + JSON.stringify(addr))
        // check that this is a valid address, and not pointing at self.

        if(addr.key === server.id) return

        var f = gossip.get(addr)

        if(!f) {
          // new peer
          addr.source = source
          addr.announcers = 1
          addr.duration = addr.duration || null
          peers.push(addr)
          notify({ type: 'discover', peer: addr, source: source || 'manual' })
          return addr
        } else if (source === 'friends' || source === 'local') {
github ssbc / ssb-server / plugins / gossip.js View on Github external
add: valid.sync(function (addr, source) {
        if (!ref.isAddress(addr)) { throw new Error('not a valid address:' + JSON.stringify(addr)) }
        // check that this is a valid address, and not pointing at self.

        if (addr.key === server.id) return

        // peers[addr.key] = addr

        var multiserverAddress = toMultiserverAddress(addr)
        connectionManager.peer.addRoute({multiserverAddress, isLocal: source === 'local'})
      }, 'string|object', 'string?'),
github ssbc / ssb-server / plugins / gossip / init.js View on Github external
pull.drain(function (msg) {
        if(msg.sync) return
        if(!msg.content.address) return
        if(ref.isAddress(msg.content.address))
          gossip.add(msg.content.address, 'pub')
      }, function () {
        console.warn('[gossip] warning: this can happen if the database closes', arguments)
github ssbc / ssb-server / plugins / gossip / index.js View on Github external
function coearseAddress (address) {
  if(isObject(address)) {
    if(ref.isAddress(address.address))
      return address.address
    var protocol = 'net'
    if (address.host && address.host.endsWith(".onion"))
        protocol = 'onion'
    return [protocol, address.host, address.port].join(':') +'~'+['shs', toBase64(address.key)].join(':')
  }
  return address
}
github mmckegg / patchwork-next / lib / persistent-gossip / init.js View on Github external
pull.drain(function (msg) {
      if(msg.sync) return
      if(!msg.content.address) return
      if(ref.isAddress(msg.content.address))
        gossip.add(msg.content.address, 'pub')
    })
  )