zerotier / libzt

Encrypted P2P sockets over ZeroTier
https://zerotier.com
Other
183 stars 54 forks source link

Node.js Integration #10

Open laduke opened 7 years ago

laduke commented 7 years ago

😎 Not sure how one goes about hooking a c library to javascript.

All the projects in my node_modules that use external c libraries use https://github.com/nodejs/node-gyp

and there's this thing which may or may not help https://github.com/charto/nbind

I'm going to give it a shot on the weekend and see how far I get.

joseph-henry commented 7 years ago

This would be really interesting. We'd wan't to expose the functions in include/libzt.h to the user. For now you'd want to use the experimental branch, but soon that will be merged back into master.

laduke commented 7 years ago

getting somewhere, but it fails to compile.

git clone https://github.com/laduke/libzt.git libzt-laduke git checkout laduke-gyp npm install npm run -s -- node-gyp rebuild

make: *** No rule to make target `zto/controller/EmbeddedNetworkController.o', needed by `static_lib'.  Stop.

which is the same error I get from just running make static_lib (on Darwin and Linux)

laduke commented 7 years ago

We have something that compiles now. Manual process to get it running:

git clone git@github.com:laduke/libzt.git 
git fetch origin laduke-gyp
git checkout laduke-gyp
git submodule init
git submodule update
make static_lib
npm install  //automatically compiles binding.cc
node test.js

Important files:

binding.cc
binding.gyp
test.js

rebuild binding.cc: npm run -- node-gyp rebuild

This branch^ has a compiled libzt.a in ./darwin, which is not ideal, but I saw that was how that go-lang repo was doing it. Getting node-gyp to compile picotcp and libzt correctly would be better, but I tried and it was quite hard.

All it does right now:

running 0
EXTRA[0] :  pico_protocol.c:  225:       pico_protocol_init: Protocol ethernet registered (layer: 2).
EXTRA[0] :  pico_protocol.c:  225:       pico_protocol_init: Protocol ipv4 registered (layer: 3).
EXTRA[0] :  pico_protocol.c:  225:       pico_protocol_init: Protocol ipv6 registered (layer: 3).
EXTRA[0] :  pico_protocol.c:  225:       pico_protocol_init: Protocol icmp4 registered (layer: 4).
EXTRA[0] :  pico_protocol.c:  225:       pico_protocol_init: Protocol icmp6 registered (layer: 4).
EXTRA[0] :  pico_protocol.c:  225:       pico_protocol_init: Protocol igmp registered (layer: 4).
EXTRA[0] :  pico_protocol.c:  225:       pico_protocol_init: Protocol udp registered (layer: 4).
EXTRA[0] :  pico_protocol.c:  225:       pico_protocol_init: Protocol tcp registered (layer: 4).
INFO [0] :        libzt.cpp: 1867:        zts_start_service: homeDir=./networks/8056c2e21c000001
INFO [0] :    SocketTap.cpp:  105:                SocketTap: set device name to: libzt0
EXTRA[0] :      pico_ipv4.c: 1321:       pico_ipv4_link_add: Assigned ipv4 29.18.59.241 to device libzt0
INFO [0] :      picoTCP.cpp:  114:      pico_init_interface: addr  = 29.18.59.241/7
INFO [0] :      picoTCP.cpp:  127:      pico_init_interface: addr6 = fd80:56c2:e21c::199:9342:d912:3aac
running 1
laduke commented 6 years ago

note to self: https://github.com/mafintosh/prebuildify https://github.com/mafintosh/turbo-net/blob/master/package.json

prebuild the libs

heri16 commented 4 years ago

What happened to the merged pull request? Why are the nodejs examples removed?

heri16 commented 4 years ago

Notes to self on creating a ztnet.createConnection() that returns a custom NodeJs Socket which _write() and _read() calls zts_send and zts_recv, to work with any existing npm libraries that use https://nodejs.org/docs/latest-v12.x/api/net.html#net_net_createconnection

Monkey-patching may be applied manually on a per-project basis to cause ztnet.createConnection to be called instead of net.createConnection.

laduke commented 4 years ago

I never got it into any kind of production state and libzt has changed a little since then. gonna check out your PR!

joseph-henry commented 4 years ago

Are there any questions I can answer about the library in order to help this effort, @heri16?

heri16 commented 3 years ago

@laduke did you manage to get this working?

laduke commented 3 years ago

Hi @heri16 I thought your PR got merged in? I haven't been able to follow this closely lately.

Did you end up using it for anything?

joseph-henry commented 3 years ago

It did get merged in, but enough changed since its merge that I cant guarantee that it works hence it being moved to the attic. If there's enough interest in bringing it up to feature-parity with the C API I'm not opposed to it being brought back.

bluet commented 3 years ago

Really looking forward to see js binding and use zt in our JavaScript/NodeJS based projects.

I'm looking for underlying module/solutions for building a new semi-private p2p application.

jerrychong25 commented 2 years ago

Hi all (@laduke @joseph-henry @heri16 @bluet ),

So far any solution to integrate zerotier into JavaScript/Node.js based application?

Thanks!

bluet commented 2 years ago

@jerrychong25 I have no idea. There's no update here.

jerrychong25 commented 2 years ago

@jerrychong25 I have no idea. There's no update here.

Ok thanks @bluet !

Let's hope for good news soon =)

janvanbouwel commented 1 year ago

I've opened a new issue at #234