jb55 / lnsocket

A minimal C & js library for sending messages to lightning nodes
Other
61 stars 9 forks source link

Node Push Data #7

Open lnbc1QWFyb24 opened 2 years ago

lnbc1QWFyb24 commented 2 years ago

Is it possible for this library to receive a message from the remote node it is connected to? My use case would be to have a plugin running on the coreln node that listens for events and would then push those events over the lnsocket. Is that possible?

jb55 commented 2 years ago

yes! unless you disconnect the connection will stay open and receive messages. lnsocket_recv will return a ln tlv packet with the type decoded. if you just keep calling that function you can get all incoming packets. see lnrpc.c to see how that works, you'll notice it listens for many commando packets and discards non-commando packets like pings.

one thing to note is that CLN will disconnect you if you don't respond to pings, and the library doesn't currently do that for you.

jb55 commented 2 years ago

How this might work:

lnsocket client connects with a specific pubkey (once we have that feature), or send a packet with an auth token/rune. The plugin then registers that node for notifications. Once you get a notification on the plugin side it then sends a packet to that registered node. I haven't done something like this yet but would be cool to see how to do it on the plugin side...

You could use the sendcustommsg rpc with the nodeid to send the event.

lnbc1QWFyb24 commented 2 years ago

Awesome! Thanks for the detailed replies. I will give the sendcustommsg rpc a try and see how it goes. I don't know c, but will try and grok what is going on as best I can. Thanks for creating this library, I think there are a lot of super interesting ideas that can be built on this primitive!

jb55 commented 2 years ago

On Mon, Jul 11, 2022 at 03:47:36PM -0700, Aaron Barnard wrote:

I don't know c, but will try and grok what is going on as best I can.

ah yeah perhaps I could put together a js demo that listens to and prints lightning messages...

lnbc1QWFyb24 commented 2 years ago

ah yeah perhaps I could put together a js demo that listens to and prints lightning messages...

That would be amazing 🙏