-
Notifications
You must be signed in to change notification settings - Fork 36
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
shared object - ref impl with java/jni #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a separate binary for the client.
@vyzo & @mhchia almost done here. These are the final tasks (for this PR):
i am leaning towards packaging
into a Java API that exposes all the functionality needed to implement the beacon chain. this would save me the trouble of implementing all the p2pclient code in Java. this pattern might be useful for other beacon chain implementations that don't have libp2p implemented in their project's language. Thoughts? |
that sounds reasonable -- looking good so far. |
662ca5a
to
c2b21e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will need a rebase for pubsub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more comments. This mode of usage for the daemon is welcome. But please bear with us, @jrhea, as we gain consensus around the elements and concepts this PR introduces.
…. added some additional functionality to the goclient to test the java daemon - added a gitignore and updated the import paths
-mmacosx-version-min flag is now set dynamically -switched from ld to gcc linking command and removed ignore unused errors flag. -prefixed the cgo headers with go- and jni c headers with java- for clarity. -added a conditional check for OS (darwin or linux) so that the build can be customized for either
…ent builds in Makefile. - finished passing all CL args from so to Go. remove domain socket on client fail.
…ndings folder for all Makefile and code related to langage bindings
c2b21e2
to
a18dc15
Compare
@vyzo & @raulk I resolved all the issues and reorganized the code I added into a bindings folder. The dir structure now looks like:
If you type
Please take a look and let me know what you think. |
@vyzo thanks for the review. I pushed the changes. I have more functionality to implement in the client side, specifically in p2pclient/p2pc.go The code only supports these commands:
I was holding off on implementing more functionality until you guys OK this mode of operation. That highlights one negative aspect of this mode...going forward there will potentially be one more touch point when functionality is added to the daemon. We will need to make sure it is made available to the shared object. That being said, the other option would be to create a "LibP2P Client Library" where this is housed. Thoughts? |
yep i would prefer it live within the repo. will do a thorough review tomorrow |
Thanks @bigs . Sorry in advance for the pain in the ass this review will be 😱 |
@bigs have you been able to take a look at this PR? I'd be happy to jump on a call or chat on gitter about this if it would help. |
mad drawing skillz! |
Hey @jrhea – FINALLY I had time to review this in-depth! Thank you so much for spearheading this effort in the community 🎉 Being only vaguely familiar with Cgo, I would've expected the native interface to mimic the client's public interface. In my head, the design would look like this:
How does that sound, @jrhea? Happy to collaborate to push this forward. |
@raulk Thanks for the reply!
All good my man. I was happy to do it. I appreciate you guys letting me participate.
Totally agree and that is exactly what I would like to discuss on our call. I just implemented the startClient piece with 'magic strings' as commands to prove it works. When I started the PR I could see that the daemon was still early in development and I didn't want to waste too much time nailing down an interface until you guys were ready. I figured that once you guys were ready, we could all agree on what this interface would look like.
Cool. I think that structs are the only type that might be a problem (unless they are defined in C), but I think we can work around this issue.
Yes, exactly. That is probably the key thing to work out. The Java or C# side could either poll for a message received that matches the stream id or it might be cool to just call an externally defined method from Go like ext_stream_rvcd(int id) - sort of like a callback - and that could avoid polling.
Perfect!
I like your brain. I think we are on the same page! I really think there is tremendous value in creating a rich interface to other languages so that must of the heavy lifting is done on the Go side. That being said, some teams (e.g. @mhchia ) have already picked the IPC endpoint as their integration point. That is fine though. That is why I had the Makefile create two versions of the shared library:
|
Lol thanks! Who said developers can't draw? Amiright? 🎨 |
@jrhea yesterday I updated the target branch for this PR to the Notes from the callAttendees: @jrhea @vyzo @bigs @mkalinin @Nashatyrev @akhila-raju @schroedingerscode @raulk We see this moving forward as a set of discrete PRs:
We discussed concurrency models, i.e. how to expose native API methods whose Go client counterparts deal with channels. Callbacks and event loops were two suggested models. @jrhea to open issue to discuss. Instead of creating one glue/translation layer (.so lib) between native API <=> Go client, we can create one per each concurrency model we want to support. Anything else you guys want to add? |
SGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some nits in the C (which i do think should be cleaned) but this looks good
char *arg1 = (char *) 0 ; | ||
(void)jenv; | ||
(void)jcls; | ||
arg1 = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really sure i understand what's going on here haha. could the preceding lines of this block not be simplified to
char *arg1 = NULL;
char *arg1 = (char *) 0 ; | ||
(void)jenv; | ||
(void)jcls; | ||
arg1 = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@@ -54,6 +57,15 @@ func NewDaemon(ctx context.Context, path string, opts ...libp2p.Option) (*Daemon | |||
|
|||
go d.listen() | |||
|
|||
sigc := make(chan os.Signal, 1) | |||
signal.Notify(sigc, os.Interrupt, syscall.SIGTERM) | |||
go func(ln net.Listener, c chan os.Signal) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh this is great!
sorry this took a thousand years. looking good! |
Resolves #20
@vyzo @bigs @raulk I am not totally done, but it might be worth taking a look at what i have done so far to make sure i am coloring in the lines.
Build Instructions:
make deps
make
ormake go-daemon
make go-client
make java-daemon
make java-client
Modifications
complete:
added a client option to main.gomade a separate executable for the client called p2pcFunctionality
i can fire up two daemons on two different domain sockets:The first one is run from java
the second one from go:
Then I can run two clients to interact with each daemon respectively:
client 1 - listen for message
client 2 - connect to other daemon then send message
The message
FOOOOOBAAAAAAARR
is displayed by client 1