+ // get min_connects and max_connects
+
+ assert(mesh->devclass >= 0 && mesh->devclass <= _DEV_CLASS_MAX);
+
+ int min_connects = dev_class_traits[mesh->devclass].min_connects;
+ int max_connects = dev_class_traits[mesh->devclass].max_connects;
+
+ logger(mesh, MESHLINK_INFO, "* min_connects = %d", min_connects);
+ logger(mesh, MESHLINK_INFO, "* max_connects = %d", max_connects);
+
+
+ // find the best one for initial connect
+
+ if(cur_connects < min_connects)
+ {
+ splay_tree_t *nodes = splay_alloc_tree(node_compare_devclass_asc_lsc_desc, NULL);
+
+ for splay_each(node_t, n, mesh->nodes)
+ {
+ logger(mesh, MESHLINK_INFO, "* n->devclass = %d", n->devclass);
+ if(n != mesh->self && n->devclass <= mesh->devclass && !n->connection && (n->last_connect_try == 0 || (time(NULL) - n->last_connect_try) > retry_timeout))
+ { splay_insert(nodes, n); }
+ }
+
+ if(nodes->head)
+ {
+ logger(mesh, MESHLINK_INFO, "* found best one for initial connect");
+
+ //timeout = 0;
+ connect_to = (node_t*)nodes->head->data;
+ }
+ else
+ { logger(mesh, MESHLINK_INFO, "* could not find node for initial connect"); }
+
+ splay_free_tree(nodes);
+ }
+
+
+ // find better nodes to connect to