Inspiration

We were originally going to extend the HVM, but we realized only 2.5 people on our team actually knew rust, which it's written in. Thus one of us sacrificed his honors thesis project idea and now we're doing language-agnostic IPC. In essence, while working with python is great, it is a slow language and it would be great if we can extend the speedyness of C to it. Or, using JavaScript is fun, but what if I want to do machine learning on it without using the infamously bad tensorjs? It would be great if we can design a library that takes care of inter-language function calls with minimal overhead while achieving security, speed, and correctness.

What it does

It allows you to call functions from other languages like you're importing a library. It's as easy as that. Behind the scenes of course it's a bit more complicated than that, we have to establish a socket from the client, send back the function mainfest from the server, then send and receive all the various packets across the socket, but for the end user basically all you have to do is decorate a couple functions and say loadPY("myfile.py"). An example we have is trying to interact with python-native code through Javascript. Imagine you want to jump onto the AI bandwagon and try out the different AI libraries or run a local LLM, but you only know Javascript. Fear not, with onedef, you can call python libraries easier than ever. In our example, the python code loads up a local LLM and we can interact with it via Javascript.

How we built it

Pure NodeJS and pure python. We used their respective socket libraries and built up everything around it form the ground up. Each language has their corresponding encoding and decoding parts that can invoke a function call in the other language and decipher the results. The demo website is done using express and hosted on an on-demand AWS EC2 instance structured through Terraform.

Challenges we ran into

It was basically impossible to test anything until we had basically all the code in place. This is because in order for us to do anything there were a bunch of handshakes that would happen first and a lot of data exchange over sockets. If you don't have what you're exchanging or don't have the sockets set up yet then it's hard to test one without the other. We also had issues with python asyncio--it's truly the worst async functionality any language provides. AWS CLI is also very unforgiving when it comes to trying to SSH into the server to have it host our website, we ran into multiple errors surrounding SSH keys and SSH timeouts.

Accomplishments that we're proud of

We have full python-JavaScript interoperability. You can use either as a client and the other as a server. Heck, you could even use either of them as a server. We also have a very robust package spec, which while was non-trivial to encode and decode, is very efficient (we don't just send JSON back and forth lol). We are also proud that we were able successfully use a IaC tool, Terraform, and set up an EC2 instance to host our website within the time constraint.

What we learned

We learned recursive C macros, UNIX domain sockets, sockets in general, sockets in specific, python async, and how to stay awake for 24 hours straight.

We learned to work with binaries, encoding data and data types into their corresponding binaries to follow a IPC protocol. Having to encode arrays, we also learned to deal with writing complex recursive algorithms.

We also learned how to create EC2 instances using Terraform and being able to work with SSH keys to remotely access the EC2 instance we created (without touching the AWS EC2 Console at all!)

What's next for onedef

More languages! First on the list is C, then maybe Rust. These languages aren't totally trivial to just pump out so we could only finish two for this hackathon, but this IPC spec is portable to any language. We could also absolutely swap out our UNIX domain sockets for TCP sockets and have it act as a websocket. Eventually, it can be implemented for all languages and there will be very minimal overhead for programmers to enjoy the inter-langiage capabilities they will grasp on their hands.

Built With

Share this project:

Updates