I would like to untangle hypermerge from the hypercore so that alternative feed / replication mechanism could be provided (I'm specifically looking into IPFS base one). While it's certainly possible to just copy & paste and replace relevant bits, I think there is plenty of code that is hypercore agnostic and it might be useful to try and refactor relevant bits to facilitate better reuse / simplify implementation of alternative protocol providers.
This is my best attempt to do so & in it's current state I could use some feedback. Below are some highlights:
Moved hypercore/lib/crypto dependency into hypercore module to expose keyPair function instead. IMO it also should be made as async as corresponding browser native APIs is async and so is the API exposed by IPFS. It also probably would make sense to make keyPair an option passed to Repo and things it delegates to.
Feed interface from hypercore is very fat and opinionated, furthermore all uses of it tend to wrap around with promises. I renamed former Feed to HypercoreFeed and defined new Feed with a thinner promise based API to reflect only things that are actually used by hypermerge.
Peer interface from hypercore is also complex exposing internal .stream that from what I can tell is only used for sending a message (feed id) to the corresponding peer. There for I defined new Peer interface that just exposes send, onmessage and onclose. It would be a lot easier to comply with this API than the original. Also ondata takes care of buffering that originally was done via download + sync coordinated events.
Repo().stream seems awkward, I get it's used for replication with a swarm, but still assumes a lot of implementation details. One option wolud be to change that to move stream function to the hypercore.ts instead but that does not seem ideal. I think it would be better to move it into Feed somehow, however I'm not exactly sure how yet. Since it used across libs it is a lot more difficult for me to see all the edges.
I am also little unsure on
why does feed IDs are communicated the way they are. Or put it differently why is it not just a special message in the feed ? Only reason I can think of is to replicate with higher priority, but actual insight would be help.
P.S.: I apologize for formatting changes, just noticed those & I presume they're caused by prettier plugin.
I would like to untangle hypermerge from the hypercore so that alternative feed / replication mechanism could be provided (I'm specifically looking into IPFS base one). While it's certainly possible to just copy & paste and replace relevant bits, I think there is plenty of code that is hypercore agnostic and it might be useful to try and refactor relevant bits to facilitate better reuse / simplify implementation of alternative protocol providers.
This is my best attempt to do so & in it's current state I could use some feedback. Below are some highlights:
hypercore/lib/crypto
dependency intohypercore
module to exposekeyPair
function instead. IMO it also should be made as async as corresponding browser native APIs is async and so is the API exposed by IPFS. It also probably would make sense to makekeyPair
an option passed toRepo
and things it delegates to.Feed
interface from hypercore is very fat and opinionated, furthermore all uses of it tend to wrap around with promises. I renamed formerFeed
toHypercoreFeed
and defined newFeed
with a thinner promise based API to reflect only things that are actually used by hypermerge.Peer
interface from hypercore is also complex exposing internal.stream
that from what I can tell is only used for sending a message (feed id) to the corresponding peer. There for I defined newPeer
interface that just exposessend
,onmessage
andonclose
. It would be a lot easier to comply with this API than the original. Alsoondata
takes care of buffering that originally was done viadownload
+sync
coordinated events.Repo().stream
seems awkward, I get it's used for replication with a swarm, but still assumes a lot of implementation details. One option wolud be to change that to movestream
function to thehypercore.ts
instead but that does not seem ideal. I think it would be better to move it intoFeed
somehow, however I'm not exactly sure how yet. Since it used across libs it is a lot more difficult for me to see all the edges.I am also little unsure on
P.S.: I apologize for formatting changes, just noticed those & I presume they're caused by prettier plugin.