exchange-protocol
Hypercore-extension that enables two peers to exchange feed keys and descriptors.
Following extension hosts are supported:
- hypercore
- hypercore-protocol
- decentstack (built-in by default)
Take a look at exchange-protocol docs page for a higher level description and sequence diagrams.
Usage
Given the following manifest:
// Header-values are allowed to contain primitive types or Buffers// if you want to use a custom encoder/decoderconst myManifest = key: 'deadbeefdeadbeefdeadbeefdeadbeef' headers: seq: 1 hello: 'world' key: otherKey headers: seq: 55 hello: 'planet' title: 'My awesome feed'
And given the following handlers Object:
const exchangeHandlers = { sharednamespace // => String - 'default' sharedfeeds // => Array<Object> - offered keys for const feed of feeds // Print the manifest contents. console console // `accept` is a Function that directly responds to a given // manifest with `FeedRequest' const acceptedKeys = sharedfeeds // accept all keys // This is a stub, you should let your replication manager // take care of joining the other feeds into the feed stream. acceptedKeys } { reqmanifest_id // => Number - increment reqnamespace // => String - 'default' reqkeys // => Array - requested keys // Another replication manager stub reqkeys } { throw err }
Using hypercore-protocol
const Protocol = const stream = trueconst ext = const key = Buffer const channel = stream
Or using vanilla hypercore
const hypercore = const ram = const exchange = const feed = const ext = feed
Result
In a real world scenario your peer would not be communicating with it self.
But in this example, if we were to send myManifest
to the exchangeHandlers
the log lines would produce the following output:
> Remote shared feed: deadbeefdeadbeefdeadbeefdeadbeef
> Headers: { seq: 1, hello: 'world' }
>
> Remote shared feed: 1234feed43afdeafa41efeed4124beeb
> Headers: { seq: 55, hello: 'planet', title: 'My awesome feed' }
>
License
GNU GPLv3