summaryrefslogtreecommitdiff
path: root/mesh/node.c
diff options
context:
space:
mode:
authorInga Stotland <inga.stotland@intel.com>2020-05-21 17:34:55 -0700
committerBrian Gix <brian.gix@intel.com>2020-05-22 13:45:52 -0700
commit7cdc215ff5a196f86a7198e8e067c12b5d1feacc (patch)
tree3b6aaafb2574eba45f1a7ad4c1d35a8336f8d780 /mesh/node.c
parent7eca3becceed3d44c0abf1610d93307a023c1c79 (diff)
downloadbluez-7cdc215ff5a196f86a7198e8e067c12b5d1feacc.tar.gz
mesh: Add finalization of a newly created node
When a new node is created as a result of successful completion of either Join() or Create() or Import() methods and has been confirmed via successful token delivery to the application, clean up node's D-Bus resources (application path, element paths, etc) that have been gathered during the initial GetMAnagedObjects() call. Also, remove the agent instance associaed with the new node. These resources will be re-populated after the Attach() call verifies the node's integrity.
Diffstat (limited to 'mesh/node.c')
-rw-r--r--mesh/node.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/mesh/node.c b/mesh/node.c
index 8ad77639e..8cfe1ddc8 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -992,12 +992,6 @@ static void attach_io(void *a, void *b)
mesh_net_attach(node->net, io);
}
-/* Register callback for the node's io */
-void node_attach_io(struct mesh_node *node, struct mesh_io *io)
-{
- attach_io(node, io);
-}
-
/* Register callbacks for all nodes io */
void node_attach_io_all(struct mesh_io *io)
{
@@ -1467,7 +1461,6 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
const char *path;
struct mesh_node *node = req->node;
struct node_import *import;
- void *agent = NULL;
bool have_app = false;
unsigned int num_ele;
struct keyring_net_key net_key;
@@ -1515,13 +1508,11 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
const char *sender;
sender = l_dbus_message_get_sender(msg);
- agent = mesh_agent_create(path, sender,
+ node->agent = mesh_agent_create(path, sender,
&properties);
- if (!agent)
+ if (!node->agent)
goto fail;
- node->agent = agent;
-
} else if (!strcmp(MESH_PROVISIONER_INTERFACE,
interface)) {
node->provisioner = true;
@@ -1629,9 +1620,6 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
}
fail:
- if (agent)
- mesh_agent_remove(agent);
-
/* Handle failed requests */
if (node)
node_remove(node);
@@ -2348,3 +2336,26 @@ bool node_load_from_storage(const char *storage_dir)
{
return mesh_config_load_nodes(storage_dir, init_from_storage, NULL);
}
+
+/*
+ * This is called for a new node that:
+ * - has been created as a result of successful completion of Join()
+ * or Create() or Import() methods
+ * and
+ * - has been confirmed via successful token delivery to the application
+ *
+ * After a node has been created, the information gathered during initial
+ * GetManagedObjects() call is cleared. The subsequent call to Attach() would
+ * verify node's integrity and re-initialize node's D-Bus resources.
+ */
+void node_finalize_new_node(struct mesh_node *node, struct mesh_io *io)
+{
+ if (!node)
+ return;
+
+ free_node_dbus_resources(node);
+ mesh_agent_remove(node->agent);
+
+ /* Register callback for the node's io */
+ attach_io(node, io);
+}