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

chore: update c-bindings rfc to use callbacks #17

Merged
merged 1 commit into from
Mar 1, 2024
Merged

Conversation

jimstir
Copy link
Collaborator

@jimstir jimstir commented Feb 29, 2024

By @richard-ramos
Was Approved
Reference pull request: vacp2p/rfc#609

@Ivansete-status:

Here's the updated RFC using the callback API you proposed for nwaku c-bindings. Notice that some functions in here receive a callback, while they don't in nwaku, (waku_start and waku_stop can fail in go-waku). Should we have the same signature in nwaku even if it is not possible for it to fail on start/stop? (the onErrCallback will never be called there)

Something else that I wanted to discuss with you is how are we going to handle functions that do not receive a string result. for example these:

// Get number of connected peers
extern int waku_peer_cnt(WakuCallBack onOkCb, WakuCallBack onErrCb);

// Determine if there are enough peers to publish a message on a topic. Use NULL
// to verify the number of peers in the default pubsub topic
extern int waku_relay_enough_peers(char* topic, WakuCallBack onOkCb, WakuCallBack onErrCb);
The peer count is supposed to be a number, and the second function is supposed to be a boolean. In this PR I'm returning the string representation of a number and a boolean, but IMO it's ugly. Do you think we should have instead different types of callbacks instead? something like this:

typedef void (WakuStringCallBack) (const char msg, size_t len_0);

typedef void (*WakuIntCallBack) (int value);
Then WakuIntCallBack could be used both for numbers and booleans (returning 1 or 0).
What do you think?

@jimstir jimstir changed the title Update bindings-api.md chore: update c-bindings rfc to use callbacks Mar 1, 2024
@kaiserd kaiserd merged commit 98a702e into main Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants