Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pubsub support #5

Closed
RangerMauve opened this issue Apr 13, 2022 · 11 comments · Fixed by #6
Closed

Pubsub support #5

RangerMauve opened this issue Apr 13, 2022 · 11 comments · Fixed by #6
Assignees
Labels
enhancement New feature or request

Comments

@RangerMauve
Copy link
Member

RangerMauve commented Apr 13, 2022

  • Add a /pubsub/ path to the gateway
  • GET /pubsub/{topic}/ with Accept=event-stream => Get an event stream of events by subscriing to that topic
    • Base format on hypercore-fetch
    • Use peer ID for events as the id of the event
    • Use topic as the event name, or omit the event name entirely so it'll be the default "message"
    • Should we encode peer data in the message body?
  • POST /pubsub/{topic}/ {body here} publish data to that topic

Limitations: We need to either use text mode or a base64 encoding to make things easier to work with browsers. e.g. with https://developer.mozilla.org/en-US/docs/Web/API/atob

@RangerMauve RangerMauve added the enhancement New feature or request label Apr 13, 2022
@makew0rld
Copy link
Collaborator

In progress on pubsub branch.

@makew0rld
Copy link
Collaborator

makew0rld commented Apr 22, 2022

Current pubsub message format, received as an event in an event-stream:

id: FuhB2orEIwE=
data: {"from":"QmfULfLaRtF7Kg3ShjFdiYL97P7eEcyL4PcvQLhkzCPCeG","data":"aGVsbG8=","topics":["test"]}

aGVsbG8= is base64-encoded hello

@makew0rld
Copy link
Collaborator

makew0rld commented Apr 25, 2022

There is also the possibility of an error message:

[removed]

@makew0rld makew0rld mentioned this issue Apr 25, 2022
@RangerMauve
Copy link
Member Author

There is also the possibility of an error message:

data: something failed blah blah
id: error

Just double checked this, and the format is more like

data: The error message
type: error
id: ""

Which I think is the the best approach. 😁

@makew0rld
Copy link
Collaborator

Ah I miswrote that, I think you did too though. It would actually be like:

data: something failed blah blah
event: error

The id is not included which is allowed.

@makew0rld
Copy link
Collaborator

If you're happy with this format, I will add it to the spec in #4. I know there were some concerns about the levels of encodings.

@RangerMauve
Copy link
Member Author

Yeah, one thing that's feeling a bit off is the encoding bit.

What do you think about a querystring param for the encoding of the message body?

E.g. ?format=json will have the gateway parse the data as json and emit errors for invalid messages, or ?format=utf8 will parse the data as utf8 strings.

Then the default could be the same as ?format=base64 to base64 encode the binary data.

@RangerMauve
Copy link
Member Author

Also, is there a way to publish a data to be sent to a particular peer identified by it's from value? Or can we only broadcast to everyone (not sure if its even relevant actually).

@makew0rld
Copy link
Collaborator

You can only send to specific topics using pubsub, not to specific peers. You could send a message to a secret topic only you and your peer know.

@RangerMauve
Copy link
Member Author

Cool, sounds good then, forgot I mentioned it. 😁

@makew0rld
Copy link
Collaborator

makew0rld commented Apr 29, 2022

Added support for format parameters in 1998b75. Supported formats are json, utf8, base64. Default is base64, and an unrecognized format will cause an error. It is case-insensitive.

This adds a new kind of error message, for when decoding fails.

event: error-decode
data: not valid UTF-8

makew0rld added a commit that referenced this issue Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants