bunsenbrowser / bunsen

🔥 Bunsen Browser provides easy to use offline P2P application and file distribution that is verifiable on Android devices. https://bunsenbrowser.github.io/
117 stars 7 forks source link

Display stats for peer connections on history page #43

Open chrisekelley opened 6 years ago

chrisekelley commented 6 years ago

Peer connections are currently displayed at the bottom of the screen, with a substring of the dat's uuid. this data does not need to always be displayed. Why not enhance the history page to display it, and offer more options?

Current history screen:

screenshot_20180415-122621

Proposed update: beside each link there would be a button that displays current number of peers. Clicking this button would reveal peer sharing details. The button marked C would clone the dat.

bunsen-history-buttons

chrisekelley commented 6 years ago

To map the hashbase url to the dat uuid, datGateway, which extends DatLibrarian, has a promising method:

resolve
Promification of dat-link-resolve for convenience's sake.

Parameters

link (String | Buffer) Link to a Dat archive

Examples

DatLibrarian.resolve('garbados.hashbase.io').then((key) => {
  console.log(key)
  > 'c33bc8d7c32a6e905905efdbf21efea9ff23b00d1c3ee9aea80092eaba6c4957'
})
Returns Promise<Buffer> Key of that Dat archive

See bunsen/www/nodejs_project/index.js for example of using DatGateway:

const gateway = new DatGateway({ dir, dat, max, period, ttl })
gateway
    .load()
    .then(() => {
        return gateway.listen(port)
    })
    .then(function () {
        console.log('[dat-gateway] Now listening on port ' + port)
    })
    .catch(console.error)
// gateway.on('join', (dat) => {
//     // let dar = dat.archive.
//     let connections = dat.network.connections.length
//     let key = dat.options.key
//     console.log(key + " has " + connections + " peers.")
// })

So, this may be as simple as

gateway.resolve('garbados.hashbase.io').then((key) => {
  console.log(key)
  > 'c33bc8d7c32a6e905905efdbf21efea9ff23b00d1c3ee9aea80092eaba6c4957'
})

We'd then need to provide it as a service by the node server.

Then we need to make this available to the bunsen-ui polymer custom element code. So, in bunsen-ui/src/bunsen-app/bunsen-app.js, we'd fetch this array of hashbase urls:dat uuids from the server, and then fetch them when writing the datSites localStorage object

{"address": "${address}", "url": "${url}"}
chrisekelley commented 6 years ago

Here's where we are with the peers UI:

screen shot 2018-04-15 at 9 41 00 pm