+/* Adds 'db' to the set of databases served out by 'svr'. Returns true if
+ * successful, false if 'db''s name is the same as some database already in
+ * 'server'. */
+bool
+ovsdb_jsonrpc_server_add_db(struct ovsdb_jsonrpc_server *svr, struct ovsdb *db)
+{
+ /* The OVSDB protocol doesn't have a way to notify a client that a
+ * database has been added. If some client tried to use the database
+ * that we're adding and failed, then forcing it to reconnect seems like
+ * a reasonable way to make it try again.
+ *
+ * If this is too big of a hammer in practice, we could be more selective,
+ * e.g. disconnect only connections that actually tried to use a database
+ * with 'db''s name. */
+ ovsdb_jsonrpc_server_reconnect(svr);
+
+ return ovsdb_server_add_db(&svr->up, db);
+}
+
+/* Removes 'db' from the set of databases served out by 'svr'. Returns
+ * true if successful, false if there is no database associated with 'db'. */
+bool
+ovsdb_jsonrpc_server_remove_db(struct ovsdb_jsonrpc_server *svr,
+ struct ovsdb *db)
+{
+ /* There might be pointers to 'db' from 'svr', such as monitors or
+ * outstanding transactions. Disconnect all JSON-RPC connections to avoid
+ * accesses to freed memory.
+ *
+ * If this is too big of a hammer in practice, we could be more selective,
+ * e.g. disconnect only connections that actually reference 'db'. */
+ ovsdb_jsonrpc_server_reconnect(svr);
+
+ return ovsdb_server_remove_db(&svr->up, db);
+}
+
+void
+ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *svr)
+{
+ struct shash_node *node, *next;
+
+ SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) {
+ ovsdb_jsonrpc_server_del_remote(node);
+ }
+ shash_destroy(&svr->remotes);
+ ovsdb_server_destroy(&svr->up);
+ free(svr);
+}
+
+struct ovsdb_jsonrpc_options *
+ovsdb_jsonrpc_default_options(const char *target)
+{
+ struct ovsdb_jsonrpc_options *options = xzalloc(sizeof *options);
+ options->max_backoff = RECONNECT_DEFAULT_MAX_BACKOFF;
+ options->probe_interval = (stream_or_pstream_needs_probes(target)
+ ? RECONNECT_DEFAULT_PROBE_INTERVAL
+ : 0);
+ return options;
+}
+
+/* Sets 'svr''s current set of remotes to the names in 'new_remotes', with
+ * options in the struct ovsdb_jsonrpc_options supplied as the data values.
+ *
+ * A remote is an active or passive stream connection method, e.g. "pssl:" or
+ * "tcp:1.2.3.4". */
+void
+ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *svr,
+ const struct shash *new_remotes)
+{
+ struct shash_node *node, *next;
+
+ SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) {
+ struct ovsdb_jsonrpc_remote *remote = node->data;
+ struct ovsdb_jsonrpc_options *options
+ = shash_find_data(new_remotes, node->name);
+
+ if (!options) {
+ VLOG_INFO("%s: remote deconfigured", node->name);
+ ovsdb_jsonrpc_server_del_remote(node);
+ } else if (options->dscp != remote->dscp) {
+ ovsdb_jsonrpc_server_del_remote(node);
+ }
+ }
+ SHASH_FOR_EACH (node, new_remotes) {
+ const struct ovsdb_jsonrpc_options *options = node->data;
+ struct ovsdb_jsonrpc_remote *remote;
+
+ remote = shash_find_data(&svr->remotes, node->name);
+ if (!remote) {
+ remote = ovsdb_jsonrpc_server_add_remote(svr, node->name, options);
+ if (!remote) {
+ continue;
+ }
+ }
+
+ ovsdb_jsonrpc_session_set_all_options(remote, options);
+ }
+}
+
+static struct ovsdb_jsonrpc_remote *
+ovsdb_jsonrpc_server_add_remote(struct ovsdb_jsonrpc_server *svr,
+ const char *name,
+ const struct ovsdb_jsonrpc_options *options)