FFI share lib + initial uniffi-bindgen-go implementation (#4394)

* fixed rebase conflict with cargo.lock

* shared cleanup

* moved returncode to shared

* first pass at Go binding structure

* minor cleanup

* working on custom type udl

* trying to get LDFLAG script working

* commit before changing alias -> proper types

* converted CCallbacks from aliases to Struct

* cleanup comments

* temp

* push to share

* cleanup

* trait Lift not implemented for *const i8 issue

* test of refactor:
* move c-specific var casting out of shared/ into cpp/
* error returning in go/ over ffi boundary with uniffi

*  _internal functions ffi wrapper agnostic
* moved lang-specific type conversions to cpp / go bindings and out of
  shared
* got send_message working in c/c++ & go
* split out c/c++-specific types to mod

* cont. with making _internal fns lang agnostic
* working on final fn for C and shared (listening for incoming messages)

* fixed return err on listen_for_incoming

* got full example run running again after shared/ refactor

* removed unused struct

* code comments

* got first runthrough of go example code

* script cleanup

* clean up readme instructions

* clippy

* removed unused imports

* rustfmt

* Update sdk/ffi/go/README.md with link to example file

Co-authored-by: Mark Sinclair <14054343+mmsinclair@users.noreply.github.com>

* updated readme with extra build and usage info

* renamed binding outer directory for nicer path
* moved example file from ffi/main.go -> ./example.go

* updated README with new example file name

---------

Co-authored-by: mfahampshire <mfahampshire@pm.me>
Co-authored-by: Mark Sinclair <14054343+mmsinclair@users.noreply.github.com>
This commit is contained in:
mx
2024-03-18 15:15:59 +01:00
committed by GitHub
parent 8044ad5445
commit ae6c80f0cd
27 changed files with 14259 additions and 196 deletions
+7 -5
View File
@@ -67,6 +67,7 @@ int main() {
// - execute
// - get() returned val
// - handle val
// initialise an ephemeral client - aka one without specified keystore
boost::packaged_task<char> init(boost::bind(init_ephemeral));
boost::unique_future<char> init_future = init.get_future();
init();
@@ -77,7 +78,7 @@ int main() {
return_code = get_self_address(string_callback_function);
handle(return_code);
// send a message through the mixnet - in this case to ourselves
// send a message through the mixnet - in this case to ourselves using the value from get_self_address
std::cout << "(c++) message to send through mixnet: " << message << std::endl;
boost::packaged_task<char> send(boost::bind(send_message, addr, message));
boost::unique_future<char> send_future = send.get_future();
@@ -94,16 +95,17 @@ int main() {
return_code = listen_future.get();
handle(return_code);
// replying to incoming message (from ourselves) with SURBs- note that sending a message to a recipient and
// replying to an incoming are different functions
// replying to incoming message (from ourselves) with SURBs - note that sending a message to a recipient and
// replying to an incoming are different functions: replying relies on parsing the incoming sender_tag on the Rust
// side and creating an AnonymousSenderTag type, instead of the Recipient type which relies on a nym address
boost::packaged_task<char> reply_fn(boost::bind(reply, sender_tag, reply_message));
boost::unique_future<char> reply_future = reply_fn.get_future();
reply_fn();
return_code = reply_future.get();
handle(return_code);
// sleep so that the nym side logging can catch up - in reality you'd have another process running to keep logging
// going, so this is only necessary for this reference implementation
// sleep so that the client processes can catch up - in reality you'd have another process running to keep logging
// going, so this is only necessary for this reference
std::this_thread::sleep_for(std::chrono::seconds(40));
return 0;