open-source-ideas / ideas

💡 Looking for inspiration for your next open source project? Or perhaps you've got a brilliant idea you can't wait to share with others? Open Source Ideas is a community built specifically for this! 👋
6.58k stars 221 forks source link

An RPC wrapper library #49

Open KOLANICH opened 6 years ago

KOLANICH commented 6 years ago

Project description

A tool in python which wraps another library.

Use cases:

It depends on how the main program invokes its plug-ins. If the main program uses fork and exec to invoke plug-ins, and they establish intimate communication by sharing complex data structures, or shipping complex data structures back and forth, that can make them one single combined program.

Using shared memory to communicate with complex data structures is pretty much equivalent to dynamic linking.

If the main program and the plugins are a single combined program then this means you must license the plug-in under the GPL or a GPL-compatible free software license and distribute it with source code in a GPL-compliant way.

though this opinion may be biased and I'm not a lawer.

Look & Feel

import tool_name
#the tool registers custom import hook

tool_name.remote.add("some_lib_which_can_cause_crash") # marking that lib as to be remotely used
import some_lib_which_can_cause_crash # import hooks work

some_lib_which_can_cause_crash.doSomething() # crashing the lib process won't crash the process using the lib

The tool contains of 2 parts sharing the same code: 1 a cli tool as a backend 2 a library as a frontdend

The library should add an import hook and have a set of modules imported through that lib. When a the hook is activated, it checks if the name asked to be imported is in the set, and if it is, it starts the backend and communicates to it via a shared memory page (in the case of local one) or via network. All the communication must be authenticated and optionally encrypted. The backend imports the library and allows the frontend which have started it to remotely execute code by sending special commands in a custom binary protocol. This protocol must have some comands to get values of variables.

The frontend creates a lazy object returning objects of special kind. When a user used any library functions which produce a value other than null (Note in the case of python) a pair of objects is created: the returned value on a backend and a proxy object on a frontend. When a method is called on a proxy object, the data is serialized and passed to backend. When a proxy object is used in a function on the frontend, the value is passed to frontend.

Relevant Technology

ksamuel commented 6 years ago

Wouldn't crossbar.io and the WAMP protocol already fit the bill ?

KOLANICH commented 6 years ago

@ksamuel, is the handwritten schema and manual registration required? I mean that the usage of the lib should be transparent as if it is used in the same process.

ksamuel commented 6 years ago

You don't need to write schema. You do need registration, but it's one line. And honestly, it's preferable: you really don't want all your functions to be exposed to the network.

The call is not transparent as:

However, it's pretty great:

KOLANICH commented 6 years ago

Thank you. This would simplify the task. For the local use (as a way to avoid viral licenses restrictions with the look & feel the same as if a real lib was used) I'd prefer it be as transparent as possible, so it is possible to tinker a lib around it hooking everything needed to make it transparent.