Nearby was designed to be simple and extensible. The Nearby framework advertises subservices, passes messages and distributes plugins. In order to ensure maximum extensibility it was decided to use sockets as the interprocess communication method, which allows plugins to be written in any language with minimal effort. To ensure the maximum availability of the plugins, the plugin distribution support was built transparently into Nearby, ensuring that the users are always running the latest version of the plugins.

Implementation

At the core Nearby is a multithreaded Python program. Three of the threads are used by pyzeroconf to listen on the multicast address for Zeroconf information. When a nearby service is broadcast over Zeroconf a callback is thrown which initiates a local socket connection on port 8001 from the pyzeroconf thread to the main thread (which is running the twisted main loop). This socket connection is used for interthread communications to transfer the information about the service from the pyzeroconf threads to the main thread in a thread safe manner.

When the main thread receives information about a new node joining the network, it connects to a remote object located on the new node using twisted's perspective broker. When the local node wishes to send a message to the remote node, it invokes a method on the remote object which then delivers the message to the remote node's proper subservice. In order to send a message to the whole network, the local node maintains a global list of all the remote objects it has connections to. That way when one of its subservices has a message to send, Nearby iterates through all of the remote objects and calls the proper method on each one.

Plugin Distribution

When a user clicks on the Nearby icon, Nearby dynamically builds the menu from the list of all the current services it knows about on the network in addition to all of the local plugins it is aware of.

When a user chooses a subservice, Nearby checks its list of subservices that are available on the network. If a newer version is available of a plugin that is already installed, it is automatically downloaded from the network, extracted and then run. Nearby facilities this functionality by a strict adherence to file naming standards and a copy of twisted's web server running on port 8003 which serves the dist folder located in Nearby's root folder.