UNPKG

9.95 kBMarkdownView Raw
1---
2title: FBP Network Protocol
3layout: documentation
4permalink: index.html
5---
6The Flow-Based Programming network protocol (*FBP protocol*) has been designed primarily for flow-based programming interfaces like the [Flowhub](https://flowhub.io) to communicate with various FBP runtimes. However, it can also be utilized for communication between different runtimes, for example server-to-server or server-to-microcontroller.
7
8## Implementations
9
10Clients
11
12* [noflo-ui](https://github.com/noflo/noflo-ui) is an open source visual IDE, which powers [Flowhub](http://flowhub.io)
13* [fbp-spec](https://github.com/flowbased/fbp-spec) is a data-driven testing tool for FBP components/graphs.
14* [fbp-protocol-client](https://github.com/flowbased/fbp-protocol-client) is a low-level JavaScript client library supporting all the common FBP protocol transports
15* [fbp-client](https://github.com/flowbased/fbp-client) is a higher-level JavaScript client library supporting all the common FBP protocol transports
16
17Runtimes
18
19* [noflo-runtime-base](https://github.com/noflo/noflo-runtime-base) is a transport-independent implementation of the protocol for [NoFlo](http://noflojs.org), client-side and server-side JavaScript programming. WebSocket, WebRTC and iFrame implementations exists.
20* [microflo](https://github.com/jonnor/microflo) is a WebSocket implementation of the protocol in JS/C++, for microcontrollers and embedded systems
21* [Elixir FBP](http://www.elixirfbp.org/) is a WebSocket implementation in Elixir, for programming with systems in Elixir runnin on the Erlang VM.
22* [imgflo](https://github.com/jonnor/imgflo) is a WebSocket implementation in C, for image processing
23* [javafbp-runtime](https://github.com/jonnor/javafbp-runtime) is a Websocket implementation in Java for [JavaFBP](https://github.com/jpaulm/javafbp), for JRE and Android development
24* [sndflo](https://github.com/jonnor/sndflo) is a WebSocket implementation for the SuperCollider audio programming environment
25* [MsgFlo](https://github.com/the-grid/msgflo) is a Websocket implementation in Node.js for heterogenous distributed systems communicating via message queues
26* [rill](https://github.com/PermaData/rill) is a Python FBP runtime implementation, with support for the protocol over WebSocket.
27
28Some [examples](https://github.com/flowbased/protocol-examples) have also been created, to help implementors.
29
30## Test suite
31
32The [fbp-protocol](https://github.com/flowbased/fbp-protocol) tool provides a set of tests for FBP protocol implementations.
33
34## Changes
35
36* 2018-03-27:
37 - Added schema for `network:edges` output message
38 - Modified `subgraph` key of `network:data` and other network packet events to be an array as specified in the text
39* 2018-03-26:
40 - Fixed documentation for `component:setsource` to use `component:source` input, and `component:component` output
41 - Added schema for `trace:error` message
42 - Added `:error` output to all capabilities where user can perform actions that may fail
43* 2018-03-23:
44 - Added optional `graph` key to `network:error` payloads
45* 2018-03-22: **Version 0.7**
46 - Added `network:debug` and `network:getstatus` to the `network:control` permission
47* 2018-03-21:
48 - Fixed signature of `runtime:packet.payload`, `runtime:packetsent.payload`, and port definition `default` to accept any payload type
49 - Added `values` and `default` keys for port definitions
50 - Added schema for `component:componentsready` output message
51 - Added schema for `graph:clear` output message
52 - Added `packetsent` response for `runtime:packet` input message
53* 2017-09-17:
54 - Added `schema` support for ports and packets
55 - Documented known metadata keys for various graph entities
56* 2017-04-09: **Version 0.6**
57 - Version 0.6. No breaking changes over 0.5.
58 - Added additional capabilities `graph:readonly`, `network:control`, `network:data`, `network:status`. Especially useful for read-only access.
59 - Deprecated the `protocol:network` capability in favor of the new fine-gained `network:*` capabilities.
60 - Each capability now defines the set of messages contained in it. Available as `inputs` and `outputs` in the schema `/shared/capabilities`.
61* 2017-05-04:
62 - Fixed protocol errors (`graph:error`, `component:error` and `runtime:error`) to have mandatory `message` string payload.
63 - Fixed missing `required` markers in some JSON schemas for `graph` protocol. Affected messages:
64`graph:renamegroup`, `graph:renameinport`, `graph:removeinport`, `graph:addinitial`, `graph:changeedge`
65 - More readable HTML output, including property value types and examples
66* 2017-05-03:
67 - Added more optional metadata to `runtime:runtime` message: `repository`, `repositoryVersion` and `namespace`
68* 2017-02-20:
69 - Fixed payload definition of `network:edges` missing mandatory `graph` key
70* 2016-07-01:
71 - `network:error` payload may now contain an optional `stacktrace`
72* 2016-06-23:
73 - Trace subprotocol also available in machine-readable format
74* 2016-06-17:
75 - Protocol definition available as machine-readable JSON [schemas](https://github.com/flowbased/fbp-protocol/tree/master/schema/yaml).
76 - The human-readable HTML documentation is generated from this defintion.
77 - The npm package `fbp-protocol` contains the schemas as YAML, JSON and .js modules.
78* 2015-11-20:
79 - Initial `trace` subprotocol, for [Flowtrace](https://github.com/flowbased/flowtrace) support
80* 2015-03-27:
81 - Documented `network` `persist` and `component` `componentsready` messages
82* 2015-03-26: **Version 0.5**
83 - All messages sent to runtime should include the `secret` in payload
84 - Runtime description message includes an `allCapabilities` array describing capabilities of the runtime, including ones not available to current user
85* 2014-10-23
86 - added clarifications to network running state in `status`, `started`, and `stopped` messages
87* 2014-09-26
88 - Add `secret` as payload to `getruntime` to support [access levels](https://github.com/noflo/noflo-ui/issues/278)
89* 2014-08-05:
90 - Add get, list, graph, graphsdone commands to the graph protocol
91 - Add list, network commands to the network protocol
92* 2014-07-15:
93 - Add changenode, changeedge, addgroup, removegroup, renamegroup,
94 changegroup commands to the graph protocol
95* 2014-03-13: **Version 0.4**
96 - Capability discovery support
97 - Network exported port messaging for remote subgraphs
98* 2014-02-18: **Version 0.3**
99 - Support for exported graph ports
100* 2014-01-09: **Version 0.2**
101 - Multi-graph support via the `graph` key in payload
102 - Harmonization with [JSON format](http://noflojs.org/documentation/json/) by renaming `from`/`to` in edges to `src`/`tgt`
103 - Network `edges` message
104
105## Basics
106
107The FBP protocol is a message-based protocol that can be handled using various different transport mechanisms. The messages are designed to be independent, and not to form a request-response cycle in order to allow highly asynchronous operations and situations where multiple protocol clients talk with the same runtime.
108
109There are currently three transports utilized commonly:
110
111* [Web Messaging](http://en.wikipedia.org/wiki/Web_Messaging) (`postMessage`) for communication between different web pages or WebWorkers running inside the same browser instance
112* [WebSocket](http://en.wikipedia.org/wiki/WebSocket) for communicating between a browser and a server, or between two server instances
113* [WebRTC](http://en.wikipedia.org/wiki/WebRTC) for peer-to-peer communications between a runtime and a client
114
115Different transports can be utilized as needed. It could be interesting to implement the FBP protocol using [MQTT](http://en.wikipedia.org/wiki/MQ_Telemetry_Transport), for instance.
116
117### Sub-protocols
118
119The FBP protocol is divided into sub-protocols for each of the major resources that can be manipulated:
120
121* [`runtime`](#runtime-protocol): communications about runtime capabilities and its exported ports
122* [`graph`](#graph-protocol): communications about graph changes
123* [`component`](#component-protocol): communications about available components and changes to them
124* [`network`](#network-protocol): communications related to running a FBP graph
125* [`trace`](#trace-protocol): communications related to tracing a FBP network
126
127### Capabilities
128
129Not all runtimes implementation supports all features of the protocol. Also, a runtime may restrict *access* to features, either to all clients based on configuration, or based on the *secret* provided in the messages. To support this a set of **capabilities** are defined, which are reported by the runtime in the [runtime:runtime](#runtime-runtime) message.
130
131When receiving a message, the runtime should check for the associated capability. If the capability is not supported, or the client does not have access to the capability, the runtime should respond with an `error` reply on the relevant `protocol`.
132
133A few commands do not require any capabilities: the runtime info request/response ([runtime:getruntime](#runtime-getruntime) and [runtime:runtime](#runtime-runtime)), and the error responses ([runtime:error](#runtime-error), [graph:error](#graph-error), [network:error](#network-error), [component:error](#component-error)).
134
135<%= capabilities %>
136
137### Message structure
138
139This document describes all messages as the data structures that are passed. The way these are encoded depends on the transport being used. For example, with WebSockets all messages are encoded as stringified JSON.
140
141All messages consist of three parts:
142
143* Sub-protocol identifier (`graph`, `component`, or `network`)
144* Topic (for example, `addnode`)
145* Message payload (typically a data structure specific to the sub-protocol and topic)
146
147The keys listed in specific messages are for the message `payload`.
148
149An example message
150```
151"protocol": "graph",
152"command": "addnode",
153"payload": {
154 "component": "canvas/Draw",
155 "graph": "hello-canvas-example",
156 "id": "draw",
157 "metadata": {
158 "label": "Draw onto canvas element"
159 }
160}
161```
162
163<%= messages %>
164