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

Daemon as shared library. #20

Closed
cheatfate opened this issue Nov 6, 2018 · 13 comments
Closed

Daemon as shared library. #20

cheatfate opened this issue Nov 6, 2018 · 13 comments

Comments

@cheatfate
Copy link

In most of the cases daemon usage is fine, but sometimes your project could not spawn actual daemon executable. Is it possible to wrap the daemon inside of simple shared library, this library can export for example just two functions start(configuration) and stop().

So when application loads shared library and calls to start(configuration) daemon's main() function will be executed in new thread (or in any other possible ways). In such case all the named sockets created will be inside of application, so it can be possible to use daemon in iOS (for example).

This is of course not priority issue, but it would be very handy to have such feature.

@raulk
Copy link
Member

raulk commented Nov 14, 2018

So the idea would be to compile the daemon down to a shared library. This wouldn't be too efficient, because to my knowledge, the library will embed the Go runtime. Anybody knows if this would be possible with little effort?

Browsing -build-mode=c-shared examples, they look pretty flat and only import stdlib. Uncertain what the result would look like with the dependency tree we have.

Would it be so simple as keeping everything as-is, and creating exported entrypoints functions as suggested in the description?

@raulk
Copy link
Member

raulk commented Nov 14, 2018

@bigs @vyzo @Stebalien – any clue here?

@Stebalien
Copy link
Member

Yeah, this actually looks like it might work.

@bigs
Copy link
Contributor

bigs commented Nov 15, 2018

yep. as long as the exported interface is very simple (like the start/stop) i think it should work

@Stebalien
Copy link
Member

I assume we'd expose the API, right? That is, start, stop, newstream (returns a handle), close, read, write, reset, etc...

@cheatfate
Copy link
Author

@Stebalien, nope, the only API exposed is start(config) and stop.
start(config) starts opens control socket and start serving on like it currently does.
stop() stops all processing.
All other APIs are available through control socket.

@vyzo
Copy link
Collaborator

vyzo commented Nov 16, 2018

This sounds like a very reasonable. We should be able to export Start/Stop functions for embedding in the application.

@raulk raulk mentioned this issue Nov 20, 2018
@jrhea
Copy link

jrhea commented Nov 20, 2018

I like the idea of packaging this as an .so and have an immediate need for it. I am going to see if I have time to prove this idea out this week.

@bigs
Copy link
Contributor

bigs commented Nov 20, 2018 via email

@jrhea
Copy link

jrhea commented Nov 22, 2018

@bigs @vyzo @raulk

tldr;
i was able to run the daemon from Java. do u mind providing some guidance (or an easy button) on how to test the daemon?

i created a .so and exported a start() and stop() to Java via C and JNI. I made a sample Java app to prove that I could run the daemon from Java. This is the output I get after calling start() from Java:

$ java p2pd
Control socket: /tmp/p2pd.sock
Peer ID: QmQXh4GVy1EYv79nfJEdkkzF8o6877UTqqg3eZHRyrvDpP
Peer Addrs:
/p2p-circuit
/ip4/127.0.0.1/tcp/64150
/ip4/192.168.1.129/tcp/64150
/ip6/::1/tcp/64151

Thanks,
Jonny

@vyzo
Copy link
Collaborator

vyzo commented Nov 22, 2018

There are some example programs you can use as a starting point for testing in gerbil-libp2p/example.
There is also the go client which has a bunch of tests.

@bitnom
Copy link

bitnom commented Jun 14, 2019

Re-opening as reference and possible request for comment for same Nim repo issue: vacp2p/nim-libp2p#21

@aschmahmann
Copy link

Is this still a requested feature? It seems to me like a large amount of the functionality could be achieved by using go-libp2p as a shared library and not the daemon itself, or by just running the daemon and then writing a client api for a target language.

Feel free to reopen if this is still a requested feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants