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

refactor: c-bindings #619

Merged
merged 3 commits into from
Aug 10, 2023
Merged

refactor: c-bindings #619

merged 3 commits into from
Aug 10, 2023

Conversation

richard-ramos
Copy link
Member

@richard-ramos richard-ramos commented Aug 2, 2023

Updates the c-bindings to match the style of using success and error callbacks defined by @Ivansete-status in nwaku's c-bindings.

  • Use callbacks in c library
  • reorg mobile and c library to reuse same code but with different response format
  • update docs
  • update example

@status-im-auto
Copy link

status-im-auto commented Aug 2, 2023

Jenkins Builds

Click to see older builds (51)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 5d4ea59 #1 2023-08-02 21:05:42 ~1 min linux 📦deb
✖️ 5d4ea59 #1 2023-08-02 21:06:04 ~1 min tests 📄log
✖️ 5d4ea59 #1 2023-08-02 21:06:30 ~2 min nix-flake 📄log
✔️ 5d4ea59 #1 2023-08-02 21:08:32 ~4 min android 📦tgz
✔️ 5d4ea59 #1 2023-08-02 21:10:16 ~5 min ios 📦tgz
✔️ 1fc9acf #2 2023-08-03 21:25:43 ~1 min linux 📦deb
✖️ 1fc9acf #2 2023-08-03 21:26:13 ~1 min tests 📄log
✖️ 1fc9acf #2 2023-08-03 21:26:21 ~1 min nix-flake 📄log
✔️ 1fc9acf #2 2023-08-03 21:28:21 ~3 min android 📦tgz
✔️ 1fc9acf #2 2023-08-03 21:29:15 ~4 min ios 📦tgz
✔️ a050408 #3 2023-08-03 21:57:31 ~1 min linux 📦deb
✖️ a050408 #3 2023-08-03 21:57:39 ~1 min tests 📄log
✖️ a050408 #3 2023-08-03 21:57:59 ~1 min nix-flake 📄log
✔️ a050408 #3 2023-08-03 21:59:41 ~3 min ios 📦tgz
✔️ a050408 #3 2023-08-03 22:00:29 ~4 min android 📦tgz
✔️ 1ac6044 #4 2023-08-03 22:14:09 ~32 sec linux 📦deb
✖️ 1ac6044 #4 2023-08-03 22:15:05 ~1 min tests 📄log
✖️ 1ac6044 #4 2023-08-03 22:15:25 ~1 min nix-flake 📄log
✔️ 1ac6044 #4 2023-08-03 22:17:02 ~3 min android 📦tgz
✔️ 1ac6044 #4 2023-08-03 22:17:52 ~4 min ios 📦tgz
✖️ 0660ffa #5 2023-08-03 22:20:58 ~22 sec tests 📄log
✔️ 0660ffa #5 2023-08-03 22:21:07 ~35 sec linux 📦deb
✖️ 0660ffa #5 2023-08-03 22:22:21 ~1 min nix-flake 📄log
✔️ 0660ffa #5 2023-08-03 22:23:44 ~3 min ios 📦tgz
✔️ 0660ffa #5 2023-08-03 22:24:05 ~3 min android 📦tgz
✔️ 25d8f92 #6 2023-08-03 22:24:44 ~28 sec linux 📦deb
✔️ 25d8f92 #6 2023-08-03 22:25:55 ~1 min tests 📄log
✖️ 25d8f92 #6 2023-08-03 22:26:18 ~2 min nix-flake 📄log
✔️ 25d8f92 #6 2023-08-03 22:27:22 ~3 min android 📦tgz
✔️ 25d8f92 #6 2023-08-03 22:27:30 ~3 min ios 📦tgz
✔️ b7014e6 #7 2023-08-03 22:29:08 ~32 sec linux 📦deb
✔️ b7014e6 #7 2023-08-03 22:30:18 ~1 min tests 📄log
✖️ b7014e6 #7 2023-08-03 22:30:20 ~1 min nix-flake 📄log
✔️ b7014e6 #7 2023-08-03 22:31:52 ~3 min android 📦tgz
✔️ b7014e6 #7 2023-08-03 22:31:54 ~3 min ios 📦tgz
✖️ b7014e6 #8 2023-08-04 12:31:53 ~1 min nix-flake 📄log
✔️ b12fcd7 #8 2023-08-04 13:51:34 ~31 sec linux 📦deb
✔️ b12fcd7 #8 2023-08-04 13:52:37 ~1 min tests 📄log
✖️ b12fcd7 #9 2023-08-04 13:52:49 ~1 min nix-flake 📄log
✔️ b12fcd7 #8 2023-08-04 13:54:30 ~3 min android 📦tgz
✔️ b12fcd7 #8 2023-08-04 13:54:39 ~3 min ios 📦tgz
✔️ 3cd22a7 #9 2023-08-04 14:02:49 ~42 sec linux 📦deb
✔️ 3cd22a7 #9 2023-08-04 14:03:54 ~1 min tests 📄log
✖️ 3cd22a7 #10 2023-08-04 14:04:00 ~1 min nix-flake 📄log
✔️ 3cd22a7 #9 2023-08-04 14:05:08 ~3 min android 📦tgz
✔️ 3cd22a7 #9 2023-08-04 14:08:01 ~5 min ios 📦tgz
✖️ 85ebcc5 #10 2023-08-04 14:15:01 ~55 sec tests 📄log
✖️ 85ebcc5 #11 2023-08-04 14:16:11 ~2 min nix-flake 📄log
✔️ 85ebcc5 #10 2023-08-04 14:16:28 ~2 min linux 📦deb
✔️ 85ebcc5 #10 2023-08-04 14:17:46 ~3 min android 📦tgz
✔️ 85ebcc5 #10 2023-08-04 14:18:21 ~4 min ios 📦tgz
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 721c71b #11 2023-08-04 14:20:49 ~31 sec linux 📦deb
✔️ 721c71b #12 2023-08-04 14:22:11 ~1 min nix-flake 📄log
✔️ 721c71b #11 2023-08-04 14:22:56 ~2 min tests 📄log
✔️ 721c71b #11 2023-08-04 14:23:31 ~3 min android 📦tgz
✔️ 721c71b #11 2023-08-04 14:23:36 ~3 min ios 📦tgz
✔️ 721c71b #1 2023-08-09 08:00:13 ~3 min tests 📄log
✔️ c23b1cb #12 2023-08-10 13:09:52 ~1 min linux 📦deb
✔️ c23b1cb #12 2023-08-10 13:10:12 ~1 min tests 📄log
✔️ c23b1cb #13 2023-08-10 13:10:26 ~1 min nix-flake 📄log
✔️ c23b1cb #2 2023-08-10 13:11:30 ~2 min tests 📄log
✔️ c23b1cb #12 2023-08-10 13:12:06 ~3 min android 📦tgz
✔️ c23b1cb #12 2023-08-10 13:12:24 ~3 min ios 📦tgz

@Ivansete-status
Copy link

It looks very nice! I look forward to becoming a reviewer :)

@richard-ramos richard-ramos force-pushed the c-bindings-2 branch 3 times, most recently from 1ac6044 to 0660ffa Compare August 3, 2023 22:20
@richard-ramos richard-ramos force-pushed the c-bindings-2 branch 2 times, most recently from 25d8f92 to b7014e6 Compare August 3, 2023 22:28
@richard-ramos richard-ramos marked this pull request as ready for review August 3, 2023 22:29
@richard-ramos
Copy link
Member Author

Finally done with this PR :) . It ended up being quite large due to moving a lot of files and extracting functions so they could be used both for the mobile bindings and the c bindings

@Ivansete-status:

Here's the generated header if it makes it simpler to review, instead of focusing in mostly repetitive code changes in go: https://gist.github.com/richard-ramos/bb1a6b6a2ae59cb3949a4627ab0b139b . 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?

@richard-ramos
Copy link
Member Author

@chaitanyaprem I just noticed the infinite number of codeclimate issues that were generated. I'll try to fix them :)

@richard-ramos richard-ramos force-pushed the c-bindings-2 branch 3 times, most recently from 3cd22a7 to 85ebcc5 Compare August 4, 2023 14:13
@chaitanyaprem
Copy link
Collaborator

Noticed that ReadMe intro section needs to be modified to change nwaku to go-waku.

Native applications that wish to integrate Waku may not be able to use nwaku and its JSON RPC API due to constraints

Copy link
Collaborator

@chaitanyaprem chaitanyaprem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Left few minor comments, which are not critical.

C.StatusServiceSignalEvent(str)
dataStr := string(data)
str := C.CString(dataStr)
C.StatusServiceSignalEvent(str, C.size_t(len(data)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rename this to ServiceSignalEvent?

}

// StoreLocalQuery is used to retrieve historic messages stored in the localDB using waku store protocol.
func StoreLocalQuery(queryJSON string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are 2 different methods required?
I am thinking, wouldn't it be better to expose to the user a simple method called StoreQuery which checks localDB and if not present fetches from the peer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that you do not know if the data you have locally is complete. For an specific time period you might have n messages on your db, and the peer might have n+m message, so attempting to retrieve messages locally might return results and still end up missing messages. 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it's the users responsibility to identify what is missing and query peer accordingly.

@richard-ramos
Copy link
Member Author

Noticed that ReadMe intro section needs to be modified to change nwaku to go-waku.

Native applications that wish to integrate Waku may not be able to use nwaku and its JSON RPC API due to constraints

Ah yes, i agree. The reason why it is like that is because when the bindings were created, the idea was for go-waku to only act as library, and not as a service node, hence the mention of nwaku, instead of go-waku

@richard-ramos richard-ramos merged commit 164c925 into master Aug 10, 2023
2 checks passed
@richard-ramos richard-ramos deleted the c-bindings-2 branch August 10, 2023 13:30
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.

4 participants