void Discoverable::runDeviceService() { try { std::tr1::shared_ptr<Service_t> service(RemoteDiscovery::service()); std::string address = "urn:"; address += randUuid( service->getSoap() ); std::string xaddrs = baseServ_->m_endpoint; Scopes_t scopes = Scopes_t(); scopes.item = vector_join(baseServ_->m_scopes, " "); EndpointReference_t endpoint = EndpointReference_t(); endpoint.address = &address; probeMatches_.resize(1); probeMatches_.back().endpoint = &endpoint; probeMatches_.back().scopes = &scopes; probeMatches_.back().types = &baseServ_->m_type; probeMatches_.back().xaddrs = &xaddrs; probeMatches_.back().version = 1; proxy_.reset(RemoteDiscovery::proxy()); proxy_->hello(probeMatches_.back()); SIGRLOG( SIGRDEBUG2, "[runDeviceService] Starting the service loop" ); if( service->bind(this) == -1 ) throw UnixException( errno ); while (true) { pthread_mutex_lock(&mutex_); if(bExitRequest_) { service->destroy(); bExitRequest_ = false; break; } pthread_mutex_unlock(&mutex_); if (service->accept() == -1) { SIGRLOG( SIGRWARNING, "Accept failed" ); continue; } if( service->serve() != 0 ) continue; service->destroy(); } service.reset(); proxy_.reset(RemoteDiscovery::proxy()); proxy_->bye(probeMatches_.back()); } catch (std::exception & ex) { SIGRLOG( SIGRWARNING, "[runDeviceService] Caught an exception: %s", ex.what() ); } SIGRLOG( SIGRDEBUG0, "[runDeviceService] The service loop stopped" ); }
/* * Log a command. Takes the argument vector, the configuration line that * matched the command, and the principal running the command. */ void server_log_command(struct iovec **argv, struct confline *cline, const char *user) { char *command, *p; unsigned int i; unsigned int *j; struct vector *masked; const char *arg; masked = vector_new(); for (i = 0; argv[i] != NULL; i++) { arg = NULL; if (cline != NULL) { if (cline->logmask != NULL) for (j = cline->logmask; *j != 0; j++) { if (*j == i) { arg = "**MASKED**"; break; } } if (i > 0 && (cline->stdin_arg == (long) i || (cline->stdin_arg == -1 && argv[i + 1] == NULL))) { arg = "**DATA**"; } } if (arg != NULL) vector_add(masked, arg); else vector_addn(masked, argv[i]->iov_base, argv[i]->iov_len); } command = vector_join(masked, " "); vector_free(masked); /* Replace non-printable characters with . when logging. */ for (p = command; *p != '\0'; p++) if (*p < 9 || (*p > 9 && *p < 32) || *p == 127) *p = '.'; notice("COMMAND from %s: %s", user, command); free(command); }
void play_game(const Circuits& C) { static const bool debug = false; // enumerate bases const std::vector<list_type>& bases = C.m_bases; DBGG("checking " << bases.size() << " bases:"); std::cout << "graph G {\n" << " graph [splines=false,K=2.6]\n" << " node []\n" << " edge []\n"; TauGraph tau; // iterate over all bases: for (auto base : bases) { list_type cbase = complement(base, C.ground_size()); if (C.contains_circuit(cbase)) continue; //std::cout << "compl: " << cbase << " -> " << contains_circuit(cbase) << std::endl; DBGG(base << " / " << cbase << " -> "); // for all items check unique exchange property for (size_t i = 0; i < C.ground_size(); ++i) { if (contains(base, i)) { list_type clist = insert(cbase, i); DBGG(" " << clist); list_type circuit; C.find_circuit(clist, circuit); DBGG(" -> " << circuit); std::vector<list_type> UElinks; for (auto sw : circuit) { if (sw == i) continue; list_type cxlist = insert(remove(base, i), sw); list_type cylist = insert(remove(cbase, sw), i); DBGG(" -- " << i << " <-> " << sw << " -- " << cxlist << " / " << cylist << " -- " << C.contains_circuit(cxlist) << " / " << C.contains_circuit(cylist)); if (!C.contains_circuit(cxlist) && !C.contains_circuit(cylist)) UElinks.push_back(cxlist); } if (UElinks.size() == 1) { std::cout << vector_join(base, "") << " -- " << vector_join(UElinks[0], "") << std::endl; TauGraph::vertex_iterator basev = tau.discover_vertex(Tree(base)); TauGraph::vertex_iterator destv = tau.discover_vertex(Tree(UElinks[0])); tau.add_edge(basev, destv, TauEdge(1, 0, 0)); } } else { list_type clist = insert(base, i); DBGG(" " << clist); list_type circuit; C.find_circuit(clist, circuit); DBGG(" -> " << circuit); std::vector<list_type> UElinks; for (auto sw : circuit) { if (sw == i) continue; list_type cxlist = insert(remove(base, sw), i); list_type cylist = insert(remove(cbase, i), sw); DBGG(" -- " << i << " <-> " << sw << " -- " << cxlist << " / " << cylist << " -- " << C.contains_circuit(cxlist) << " / " << C.contains_circuit(cylist)); if (!C.contains_circuit(cxlist) && !C.contains_circuit(cylist)) UElinks.push_back(cxlist); } if (UElinks.size() == 1) { std::cout << vector_join(base, "") << " -- " << vector_join(UElinks[0], "") << std::endl; TauGraph::vertex_iterator basev = tau.discover_vertex(Tree(base)); TauGraph::vertex_iterator destv = tau.discover_vertex(Tree(UElinks[0])); tau.add_edge(basev, destv, TauEdge(1, 0, 0)); } } } } std::cout << "}\n"; //std::cout << graphviz(tau, TauGraphDecorator()) << "\n"; bool conn = tau.is_connected(); std::cerr << "connected: " << conn << std::endl; if (!conn) return; std::cout << "// RESULT" << " tau_num_vertex=" << tau.num_vertex() << " tau_num_edge=" << tau.num_edge() << " tau_min_degree=" << tau.get_min_degree() << " tau_max_degree=" << tau.get_max_degree() << " tau_avg_degree=" << tau.get_avg_degree() << " tau_regularity=" << tau.get_regularity() //<< " tau_average_plens=" << itau.get_average_path_length() //<< " tau_diameter=" << itau.get_diameter() //<< " tau_radius=" << itau.get_radius() //<< " tau_diameter_path=[" << dfrom->label << "]-[" << dto->label << "]" //<< " kernel=" << write_graph6(calc_kernel(g)) ; unsigned int dia = tau.get_ue_diameter_generic(C.m_ground_size, BaseGraph(), BaseComplementer(C.m_ground_size)); std::cout << " ue_diameter=" << dia; //calcExpansionParameters(g); std::cout << std::endl; if (dia != C.m_ground_size / 2) abort(); if (!conn) abort(); }