void Property::construct( shared_str const& property_id, Manager& manager_r ) { m_id._set( property_id ); VERIFY2( pSettings->section_exist( m_id ), make_string( "Section of upgrade property [%s] does not exist!", m_id.c_str() ) ); m_name = CStringTable().translate( pSettings->r_string( id(), "name" ) ); m_icon._set( pSettings->r_string(id(), "icon") ); // functor LPCSTR functor_str = pSettings->r_string( id(), "functor" ); m_desc.parameter = ""; m_desc.parameter2 = id_str(); R_ASSERT2( ai().script_engine().functor( functor_str, m_desc.functr ), make_string( "Failed to get upgrade property functor in section[%s], functor[%s]", id_str(), functor_str ) ); m_desc(); // test LPCSTR funct_params_str = pSettings->r_string( id(), "params" ); PSTR temp = (PSTR)_alloca( (xr_strlen(funct_params_str) + 1) * sizeof(char) ); for ( int n = _GetItemCount( funct_params_str ), i = 0; i < n; ++i ) { LPCSTR i_param = ( _GetItem( funct_params_str, i, temp ) ); m_functor_params.push_back( i_param ); } }
bool Net::send(node_t *src, node_id_t dst, std::unique_ptr<net_msg_t> msg) { auto inqit = inqs.find(dst); MASSERT(inqs.count(src->get_nid()) > 0, "src unregisterd to network"); if( inqit == inqs.end() ) { // Can happen when you send to dead node l::og(l::DEBUG, "send: No inq for node %s\n", id_str(dst)); msg = nullptr; return false; } // "NIC" fills in pkt_num and source of message // NB: Clients can copy messages before sending them, so best to // assign number here rather than at message creation msg->pkt_num = net_msg_t::_pkt_num++; msg->sent_tick = now(); msg->src = src->get_nid(); stat.tot_msg_send++; stat.sends[src->get_nid()]++; // Just log recv //l::og(l::DEBUG, // "%s %s to %s S(%03lld)\n", // src->id_str(), msg->descr, id_str(dst), msg->pkt_num); inqit->second->push_back(std::move(msg)); return true; }
unsigned int GetFileId(const std::string &filepath) { std::string::size_type slash_pos = filepath.find_last_of('/'); std::string::size_type dot_pos = filepath.find_last_of('.'); std::string id_str(filepath.substr(slash_pos + 1, dot_pos - slash_pos - 1)); return atoi(id_str.c_str()); }
void conf_check( void ) { char hexbuf[HEX_LEN+1]; if( _main->conf->hostname != NULL ) { log_info( "Hostname: '%s' (-h)", _main->conf->hostname ); log_info( "Host ID: %s", id_str( _main->conf->host_id, hexbuf ), _main->conf->hostname ); } else { log_info( "Hostname: <none> (-h)" ); } log_info( "Node ID: %s", id_str( _main->conf->node_id, hexbuf ) ); log_info( "Bootstrap Node: %s (-ba)", _main->conf->bootstrap_node ); log_info( "Bootstrap Port: UDP/%s (-bp)", _main->conf->bootstrap_port ); if( _main->conf->mode == CONF_FOREGROUND ) { log_info( "Mode: Foreground (-d)" ); } else { log_info( "Mode: Daemon (-d)" ); } if( _main->conf->quiet == CONF_BEQUIET ) { log_info( "Verbosity: Quiet (-q)" ); } else { log_info( "Verbosity: Verbose (-q)" ); } if( _main->conf->interface ) { log_info( "Listen to UDP/%s (-p), interface '%s' (-i)", _main->conf->port, _main->conf->interface ); } else { log_info( "Listen to UDP/%s (-p), interface <any> (-i)", _main->conf->port, _main->conf->interface ); } /* Port == 0 => Random source port */ if( str_isSafePort( _main->conf->port ) < 0 ) { log_err( "Invalid www port number. (-p)" ); } /* Check bootstrap server port */ if( str_isSafePort( _main->conf->bootstrap_port ) < 0 ) { log_err( "Invalid bootstrap port number. (-bp)" ); } log_info( "Worker threads: %i", _main->conf->cores ); if( _main->conf->cores < 1 || _main->conf->cores > 128 ) { log_err( "Invalid core number." ); } }
bbtype_t pushfn(char* fn_id) { std::string id_str(fn_id); sym_t* st_entry = lookup_valid(id_str); inst("push rax"); return st_entry->type; }
const std::vector<uint8_t> get_pub_key_by_id(const std::vector<uint8_t>& id){ std::string id_str(&id[0], &id[0]+id.size()); if(id_str=="client") return std::vector<uint8_t>(client_pub, client_pub+sizeof(client_pub)); else if(id_str=="server") return std::vector<uint8_t>(server_pub, server_pub+sizeof(server_pub)); return std::vector<uint8_t>(0); }
void Upgrade::log_hierarchy( LPCSTR nest ) { u32 sz = (xr_strlen(nest) + 4) * sizeof(char); PSTR nest2 = (PSTR)_alloca( sz ); strcpy_s( nest2, sz , nest ); strcat( nest2, " " ); Msg( "%s<u> %s", nest2, id_str() ); inherited::log_hierarchy( nest2 ); }
void paxserver::do_heartbeat() { switch(vc_state.mode) { case vc_state_t::ACTIVE: { // Primary heartbeats servers in view. No one has to heartbeat the // primary, since if we don't hear from it, we will vc if(primary()) { std::set<node_id_t> servers = get_other_servers(vc_state.view); for(const auto& serv : servers) { if(net->timop(recent_send[serv], ps_timo.heartbeat_timo)) { LOG(l::DBG_EV, id_str() << " pr heartbeat now:" << net->now() << " recent send: " << recent_send[serv] << " nid:" << serv << "\n"); send_msg(serv, std::make_unique<nop_msg>()); } } } } break; case vc_state_t::MANAGER: { // If I'm the manager, heartbeat all servers // Underlings don't need to heartbeat, they will timeout on manager std::set<node_id_t> servers = net->get_serv_ids(nid); for(const auto& serv : servers) { // Send heartbeat to any server in our view that // we haven't sent a message to in a while if(net->timop(recent_send[serv], ps_timo.heartbeat_timo)) { LOG(l::DBG_EV, id_str() << " heartbeat now:" << net->now() << " recent send: " << recent_send[serv] << " nid:" << serv << "\n"); send_msg(serv, std::make_unique<nop_msg>()); } } } break; case vc_state_t::UNDERLING: // No need, just timeout if manager doesn't contact us break; } }
void DataLoader::SaveModel(float * pParam, unsigned int paramLen, char * identifier) { string id_str(identifier); string fileName = "modelsave/modelSave_" + id_str + ".txt"; std::cout << "Snapshotting model to : " << fileName << std::endl; ofstream ofs; ofs.open(fileName.c_str(), std::ofstream::out); for (int i = 0; i < paramLen; i++) { stringstream ss (stringstream::in | stringstream::out); ss << pParam[i]; ofs << ss.str() << ", "; } ofs.close(); }
bbtype_t pushmember(char* id, char* member) { std::string id_str(id); std::string member_str(member); sym_t* record = lookup_valid(id_str); sym_t* member_record = lookup_member(id_str, member_str); if (record->local) { int stack_offset = record->stack_offset; inst("push QWORD [r12 - %d]", (member_record->type_offset + stack_offset) * 8 + 8); } else { inst("push QWORD [%s_%d + %d]", id, record->scope, member_record->type_offset * 8); } return member_record->type; }
void web_reply( void *ctx, UCHAR *id, UCHAR *address ) { char buffer[512]; char addrbuf[INET6_ADDRSTRLEN+1]; char hexbuf[HEX_LEN+1]; struct request *request; request = (struct request *) ctx; if( address ) { inet_ntop( AF_INET6, address, addrbuf, sizeof(addrbuf) ); sprintf( buffer, reply_fmt, strlen( addrbuf ), addrbuf ); log_debug( "Web: Answer request for '%s':\n%s", id_str( id, hexbuf ), addrbuf ); sendto( request->clientfd, buffer, strlen( buffer ), 0, (struct sockaddr*) &request->clientaddr, sizeof(IP) ); } close( request->clientfd ); myfree( request, "masala-web" ); }
bbtype_t pushid(char* id) { std::string id_str(id); // ID must be previously declared for defined behavior. sym_t* st_entry = lookup_valid(id_str); int id_scope = st_entry->scope; bbtype_t type = st_entry->type; if (st_entry->local) { // We lookup the offset of the local variable needed, and add an 8 offset // to move past the saved ebp register for the stack frame. int offset = st_entry->stack_offset * 8 + 8; inst("push QWORD [r12 - %d]", offset); } else { inst("push QWORD [%s_%d]", id, id_scope); } return type; }
std::unique_ptr<net_msg_t> Net::recv(node_t* me) { if( inqs.count(me->get_nid()) == 0 ) { l::og(l::WARN, "recv: No inq for node %s\n", me->id_str()); return nullptr; } auto inq = inqs[me->get_nid()].get(); if( inq->size() > 0 ) { if(dssim->shuffle()) { std::shuffle( std::begin(*inq), std::end(*inq), dssim->rand_gen ); } stat.tot_msg_recv++; stat.recvs[me->get_nid()]++; std::unique_ptr<net_msg_t> msg = std::move(inq->front()); inq->pop_front(); l::og(l::DEBUG, "%s %s from %s R(%03lld)\n", me->id_str(), msg->descr, id_str(msg->src), msg->pkt_num); return std::move(msg); } return nullptr; }
bbtype_t pusharr(char* id, bbtype_t index_type) { std::string id_str(id); typechk_index(index_type); sym_t* st_entry = lookup_valid(id_str); bbtype_t id_type = st_entry->type; inst("pop rbx"); array_bounds_check(st_entry); if (st_entry->local) { int offset = st_entry->stack_offset * 8 + 8; inst("neg rbx"); inst("push QWORD [r12 + rbx * 8 - %d]", offset); } else { inst("push QWORD [%s_%d + rbx * 8]", id, st_entry->scope); } return id_type; }
//-----------------------------------------------------------------------------------------------// REP_HANDLE jpi_open_rep(const MNGR_HANDLE mHandle, const char* id) { try { JasperManagerItem_Sp& mngr = JPI_MNGR_TBL->getByHandle(mHandle); try { std::string id_str(id); try { return mngr->getManager()->openReport(id_str); } catch ( JaspGetConfigExc ) { setLastError_I(JPI_OPREP_INVALIDID_E); return INVALID_REP_HANDLE; } } catch ( ... ) { setLastError_I(JPI_EXC_ERROR); return INVALID_REP_HANDLE; } } catch ( ... ) { setLastError_I(JPI_NOMNGR_ERROR); return INVALID_REP_HANDLE; } }
// Generate a unique user ID. We're using a GUID form, // but not jumping through hoops to make it cryptographically // secure. We just want it to distinguish unique users. static nsresult InitUserID(nsACString& aUserID) { nsID id; // copied shamelessly from nsUUIDGenerator.cpp #if defined(XP_WIN) HRESULT hr = CoCreateGuid((GUID*)&id); if (NS_FAILED(hr)) return NS_ERROR_FAILURE; #elif defined(XP_MACOSX) CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault); if (!uuid) return NS_ERROR_FAILURE; CFUUIDBytes bytes = CFUUIDGetUUIDBytes(uuid); memcpy(&id, &bytes, sizeof(nsID)); CFRelease(uuid); #else // UNIX or some such thing id.m0 = random(); id.m1 = random(); id.m2 = random(); *reinterpret_cast<PRUint32*>(&id.m3[0]) = random(); *reinterpret_cast<PRUint32*>(&id.m3[4]) = random(); #endif char* id_cstr = id.ToString(); NS_ENSURE_TRUE(id_cstr, NS_ERROR_OUT_OF_MEMORY); nsDependentCString id_str(id_cstr); aUserID = Substring(id_str, 1, id_str.Length()-2); PR_Free(id_cstr); return NS_OK; }
static int get_control(snd_ctl_t *handle, snd_ctl_elem_id_t *id, snd_config_t *top) { snd_ctl_elem_value_t *ctl; snd_ctl_elem_info_t *info; snd_config_t *control, *comment, *item, *value; const char *s; char buf[256]; unsigned int idx; int err; unsigned int device, subdevice, index; const char *name; snd_ctl_elem_type_t type; unsigned int count; snd_ctl_elem_value_alloca(&ctl); snd_ctl_elem_info_alloca(&info); snd_ctl_elem_info_set_id(info, id); err = snd_ctl_elem_info(handle, info); if (err < 0) { error("Cannot read control info '%s': %s", id_str(id), snd_strerror(err)); return err; } if (snd_ctl_elem_info_is_inactive(info) || !snd_ctl_elem_info_is_readable(info)) return 0; snd_ctl_elem_value_set_id(ctl, id); err = snd_ctl_elem_read(handle, ctl); if (err < 0) { error("Cannot read control '%s': %s", id_str(id), snd_strerror(err)); return err; } err = snd_config_compound_add(top, num_str(snd_ctl_elem_info_get_numid(info)), 0, &control); if (err < 0) { error("snd_config_compound_add: %s", snd_strerror(err)); return err; } err = snd_config_compound_add(control, "comment", 1, &comment); if (err < 0) { error("snd_config_compound_add: %s", snd_strerror(err)); return err; } buf[0] = '\0'; buf[1] = '\0'; if (snd_ctl_elem_info_is_readable(info)) strcat(buf, " read"); if (snd_ctl_elem_info_is_writable(info)) strcat(buf, " write"); if (snd_ctl_elem_info_is_inactive(info)) strcat(buf, " inactive"); if (snd_ctl_elem_info_is_volatile(info)) strcat(buf, " volatile"); if (snd_ctl_elem_info_is_locked(info)) strcat(buf, " locked"); if (snd_ctl_elem_info_is_user(info)) strcat(buf, " user"); err = snd_config_string_add(comment, "access", buf + 1); if (err < 0) { error("snd_config_string_add: %s", snd_strerror(err)); return err; } type = snd_ctl_elem_info_get_type(info); device = snd_ctl_elem_info_get_device(info); subdevice = snd_ctl_elem_info_get_subdevice(info); index = snd_ctl_elem_info_get_index(info); name = snd_ctl_elem_info_get_name(info); count = snd_ctl_elem_info_get_count(info); s = snd_ctl_elem_type_name(type); err = snd_config_string_add(comment, "type", s); if (err < 0) { error("snd_config_string_add: %s", snd_strerror(err)); return err; } err = snd_config_integer_add(comment, "count", count); if (err < 0) { error("snd_config_integer_add: %s", snd_strerror(err)); return err; } switch (type) { case SND_CTL_ELEM_TYPE_BOOLEAN: break; case SND_CTL_ELEM_TYPE_INTEGER: { long min = snd_ctl_elem_info_get_min(info); long max = snd_ctl_elem_info_get_max(info); long step = snd_ctl_elem_info_get_step(info); if (step) sprintf(buf, "%li - %li (step %li)", min, max, step); else sprintf(buf, "%li - %li", min, max); err = snd_config_string_add(comment, "range", buf); if (err < 0) { error("snd_config_string_add: %s", snd_strerror(err)); return err; } if (snd_ctl_elem_info_is_tlv_readable(info)) { err = add_tlv_comments(handle, id, info, comment); if (err < 0) return err; } break; } case SND_CTL_ELEM_TYPE_INTEGER64: { long long min = snd_ctl_elem_info_get_min64(info); long long max = snd_ctl_elem_info_get_max64(info); long long step = snd_ctl_elem_info_get_step64(info); if (step) sprintf(buf, "%Li - %Li (step %Li)", min, max, step); else sprintf(buf, "%Li - %Li", min, max); err = snd_config_string_add(comment, "range", buf); if (err < 0) { error("snd_config_string_add: %s", snd_strerror(err)); return err; } break; } case SND_CTL_ELEM_TYPE_ENUMERATED: { unsigned int items; err = snd_config_compound_add(comment, "item", 1, &item); if (err < 0) { error("snd_config_compound_add: %s", snd_strerror(err)); return err; } items = snd_ctl_elem_info_get_items(info); for (idx = 0; idx < items; idx++) { snd_ctl_elem_info_set_item(info, idx); err = snd_ctl_elem_info(handle, info); if (err < 0) { error("snd_ctl_card_info: %s", snd_strerror(err)); return err; } err = snd_config_string_add(item, num_str(idx), snd_ctl_elem_info_get_item_name(info)); if (err < 0) { error("snd_config_string_add: %s", snd_strerror(err)); return err; } } break; } default: break; } s = snd_ctl_elem_iface_name(snd_ctl_elem_info_get_interface(info)); err = snd_config_string_add(control, "iface", s); if (err < 0) { error("snd_config_string_add: %s", snd_strerror(err)); return err; } if (device != 0) { err = snd_config_integer_add(control, "device", device); if (err < 0) { error("snd_config_integer_add: %s", snd_strerror(err)); return err; } } if (subdevice != 0) { err = snd_config_integer_add(control, "subdevice", subdevice); if (err < 0) { error("snd_config_integer_add: %s", snd_strerror(err)); return err; } } err = snd_config_string_add(control, "name", name); if (err < 0) { error("snd_config_string_add: %s", snd_strerror(err)); return err; } if (index != 0) { err = snd_config_integer_add(control, "index", index); if (err < 0) { error("snd_config_integer_add: %s", snd_strerror(err)); return err; } } switch (type) { case SND_CTL_ELEM_TYPE_BYTES: case SND_CTL_ELEM_TYPE_IEC958: { size_t size = type == SND_CTL_ELEM_TYPE_BYTES ? count : sizeof(snd_aes_iec958_t); char buf[size * 2 + 1]; char *p = buf; char *hex = "0123456789abcdef"; const unsigned char *bytes = (const unsigned char *)snd_ctl_elem_value_get_bytes(ctl); for (idx = 0; idx < size; idx++) { int v = bytes[idx]; *p++ = hex[v >> 4]; *p++ = hex[v & 0x0f]; } *p = '\0'; err = snd_config_string_add(control, "value", buf); if (err < 0) { error("snd_config_string_add: %s", snd_strerror(err)); return err; } return 0; } default: break; } if (count == 1) { switch (type) { case SND_CTL_ELEM_TYPE_BOOLEAN: err = snd_config_string_add(control, "value", snd_ctl_elem_value_get_boolean(ctl, 0) ? "true" : "false"); if (err < 0) { error("snd_config_string_add: %s", snd_strerror(err)); return err; } return 0; case SND_CTL_ELEM_TYPE_INTEGER: err = snd_config_integer_add(control, "value", snd_ctl_elem_value_get_integer(ctl, 0)); if (err < 0) { error("snd_config_integer_add: %s", snd_strerror(err)); return err; } return 0; case SND_CTL_ELEM_TYPE_INTEGER64: err = snd_config_integer64_add(control, "value", snd_ctl_elem_value_get_integer64(ctl, 0)); if (err < 0) { error("snd_config_integer64_add: %s", snd_strerror(err)); return err; } return 0; case SND_CTL_ELEM_TYPE_ENUMERATED: { unsigned int v = snd_ctl_elem_value_get_enumerated(ctl, 0); snd_config_t *c; err = snd_config_search(item, num_str(v), &c); if (err == 0) { err = snd_config_get_string(c, &s); assert(err == 0); err = snd_config_string_add(control, "value", s); } else { err = snd_config_integer_add(control, "value", v); } if (err < 0) error("snd_config add: %s", snd_strerror(err)); return 0; } default: error("Unknown control type: %d\n", type); return -EINVAL; } } err = snd_config_compound_add(control, "value", 1, &value); if (err < 0) { error("snd_config_compound_add: %s", snd_strerror(err)); return err; } switch (type) { case SND_CTL_ELEM_TYPE_BOOLEAN: for (idx = 0; idx < count; idx++) { err = snd_config_string_add(value, num_str(idx), snd_ctl_elem_value_get_boolean(ctl, idx) ? "true" : "false"); if (err < 0) { error("snd_config_string_add: %s", snd_strerror(err)); return err; } } break; case SND_CTL_ELEM_TYPE_INTEGER: for (idx = 0; idx < count; idx++) { err = snd_config_integer_add(value, num_str(idx), snd_ctl_elem_value_get_integer(ctl, idx)); if (err < 0) { error("snd_config_integer_add: %s", snd_strerror(err)); return err; } } break; case SND_CTL_ELEM_TYPE_INTEGER64: for (idx = 0; idx < count; idx++) { err = snd_config_integer64_add(value, num_str(idx), snd_ctl_elem_value_get_integer64(ctl, idx)); if (err < 0) { error("snd_config_integer64_add: %s", snd_strerror(err)); return err; } } break; case SND_CTL_ELEM_TYPE_ENUMERATED: for (idx = 0; idx < count; idx++) { unsigned int v = snd_ctl_elem_value_get_enumerated(ctl, idx); snd_config_t *c; err = snd_config_search(item, num_str(v), &c); if (err == 0) { err = snd_config_get_string(c, &s); assert(err == 0); err = snd_config_string_add(value, num_str(idx), s); } else { err = snd_config_integer_add(value, num_str(idx), v); } if (err < 0) { error("snd_config add: %s", snd_strerror(err)); return err; } } break; default: error("Unknown control type: %d\n", type); return -EINVAL; } return 0; }
void* web_loop( void* _ ) { int rc; int val; struct addrinfo hints, *servinfo, *p; struct timeval tv; UCHAR id[SHA_DIGEST_LENGTH]; char hexbuf[HEX_LEN+1]; int sockfd, clientfd; IP sockaddr, clientaddr; char clientbuf[1500]; struct request *request; char *hex_start, *hex_end; socklen_t addr_len = sizeof(IP); char addrbuf[FULL_ADDSTRLEN+1]; const char *addr = _main->conf->web_addr; const char *ifce = _main->conf->web_ifce; const char *port = _main->conf->web_port; memset( &hints, 0, sizeof(hints) ); hints.ai_flags = AI_PASSIVE; hints.ai_family = AF_INET6; hints.ai_socktype = SOCK_STREAM; if( (rc = getaddrinfo( addr, port, &hints, &servinfo ) ) == 0 ) { for( p = servinfo; p != NULL; p = p->ai_next ) { memset( &sockaddr, 0, sizeof(IP) ); sockaddr = *((IP*) p->ai_addr); freeaddrinfo(servinfo); break; } } else { log_err( "Web: getaddrinfo failed: %s", gai_strerror( rc ) ); return NULL; } if( (sockfd = socket( PF_INET6, SOCK_STREAM, IPPROTO_TCP )) < 0 ) { log_err( "Web: Failed to create socket: %s", strerror( errno ) ); return NULL; } if( ifce && setsockopt( sockfd, SOL_SOCKET, SO_BINDTODEVICE, ifce, strlen( ifce )) ) { log_err( "Web: Unable to set interface '%s': %s", ifce, strerror( errno ) ); return NULL; } val = 1; if( (rc = setsockopt( sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &val, sizeof(val) )) < 0 ) { log_err( "Web: Failed to set socket options: %s", strerror( errno ) ); return NULL; } val = 1; setsockopt( sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val) ); /* Set receive timeout */ tv.tv_sec = 1; tv.tv_usec = 0; if( (rc = setsockopt( sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv) )) < 0 ) { log_err( "Web: Failed to set socket options: %s", strerror( errno ) ); return NULL; } if( (rc = bind( sockfd, (struct sockaddr*) &sockaddr, sizeof(IP) )) < 0 ) { log_err( "Web: Failed to bind socket to address: %s", strerror( errno ) ); return NULL; } listen( sockfd, ntohs( sockaddr.sin6_port ) ); log_info( "Web: Bind socket to %s, interface %s.", addr ? addr_str( &sockaddr, addrbuf ) : "<any>", ifce ? ifce : "<any>" ); clientfd = 0; while( _main->status == MAIN_ONLINE ) { /* Close file descriptor that has not been used previously */ if( clientfd > 0 ) { close( clientfd ); } clientfd = accept( sockfd, (struct sockaddr*)&clientaddr, &addr_len ); rc = recv( clientfd, clientbuf, sizeof(clientbuf) - 1, 0 ); if( rc < 0 ) { continue; } /* Only handle GET requests. */ if( rc < 6 || strncmp( "GET /", clientbuf, 5 ) != 0 ) { continue; } /* Jump after slash */ hex_start = clientbuf + 5; clientbuf[rc] = ' '; hex_end = strchr( hex_start, ' ' ); if( hex_end == NULL ) { continue; } *hex_end = '\0'; if( strlen( hex_start ) == 0 || strcmp( hex_start, "favicon.ico" ) == 0 ) { continue; } /* That is the lookup key */ p2p_compute_id( id, hex_start ); log_debug( "Web: Lookup '%s' as '%s'.", hex_start, id_str( id, hexbuf ) ); request = (struct request *) myalloc( sizeof(struct request), "masalla-web" ); memcpy( &request->clientaddr, &clientaddr, sizeof(IP) ); request->clientfd = clientfd; web_lookup( &web_reply, request, id ); /* File descriptor is closed in callback */ clientfd = 0; } return NULL; }
void Net::die(node_id_t node) { LOG(l::DEBUG, id_str(node) << " dies with " << inqs[node]->size() << " msgs in queue\n"); inqs.erase(node); }
// Primarily our action depends on incoming message type, but // drop all normal requests (execute, replicate, accept) during view // change void paxserver::dispatch(paxmsg_t &paxmsg) { net->rpc_incr(paxmsg.rpc_id); // Set basis for timeout if(paxmsg.rpc_id != execute_arg::ID) { if(paxmsg.sent_tick > recent_recv[paxmsg.src]) { // Note that I rely on reasonably synchronized clocks here, by checking // a tick count done on a different machine recent_recv[paxmsg.src] = paxmsg.sent_tick; } } if(vc_state.mode != vc_state_t::ACTIVE && is_normal_msg(paxmsg.rpc_id)) { net->drop(this, paxmsg, "not ACTIVE"); return; } switch(paxmsg.rpc_id) { case nop_msg::ID: break; case execute_arg::ID: execute_arg(static_cast<const struct execute_arg&>(paxmsg)); break; case replicate_arg::ID: replicate_arg(static_cast<const struct replicate_arg&>(paxmsg)); break; case replicate_res::ID: replicate_res(static_cast<const struct replicate_res&>(paxmsg)); break; case accept_arg::ID : accept_arg(static_cast<const struct accept_arg&>(paxmsg)); break; case view_change_arg::ID: view_change_arg(static_cast<const struct view_change_arg&>(paxmsg)); break; case view_change_reject::ID: view_change_reject( static_cast<const struct view_change_reject&>(paxmsg)); break; case view_change_accept::ID: view_change_accept( static_cast<const struct view_change_accept&>(paxmsg)); break; case new_view_arg::ID: new_view_arg(static_cast<const struct new_view_arg&>(paxmsg)); break; case new_view_res::ID: new_view_res(static_cast<const struct new_view_res&>(paxmsg)); break; case init_view_request::ID: init_view_request( static_cast<const struct init_view_request&>(paxmsg)); break; case init_view_arg::ID: init_view_arg(static_cast<const struct init_view_arg&>(paxmsg)); break; case getstate_arg::ID: getstate_arg(static_cast<const struct getstate_arg&>(paxmsg)); break; case getstate_res::ID: getstate_res(static_cast<struct getstate_res&>(paxmsg)); break; default: MASSERT(0, "%s %d Should be a handler for each RPC", id_str(), paxmsg.rpc_id); } }
// NB: For each timeout in struct pax_serv_timo, there should // be code here to process the timeout void paxserver::do_timo() { // If we just woke up, chill on initiating vc (routes to which are below) // Because we just sent nops, which should induce vc if we aren't part of the view // XXX hardcoded constant if((net->now() - unpaused_tick) < 15) { return; } switch(vc_state.mode) { case vc_state_t::ACTIVE: { std::set<node_id_t> servers = get_other_servers(vc_state.view); if(primary()) { // First check if we have heard from someone not in our view with // a packet sent "recently" (i.e., around half of heartbeat_timo). // If so, view change. for(auto rr_it = recent_recv.begin(); rr_it != recent_recv.end(); ++rr_it) { if(servers.count(rr_it->first) == 0 // XXX hardcoded constant && (net->now() - rr_it->second) < 40) { // Recently received a message from an out of view host, vc LOG(l::DBG_EV, id_str() << " out of view now:" << net->now() << " host: " << rr_it->first << " gotit:" << rr_it->second << "\n"); rr_it->second = 0; initiate_vc(true); return; } } // Now check to see we have heard from everyone in view for(const auto& serv : servers) { if(net->timop(recent_recv[serv], ps_timo.dead_timo)) { LOG(l::DBG_EV, id_str() << " active timeout now:" << net->now() << " recent recv: " << recent_recv[serv] << " nid:" << serv << "\n"); initiate_vc(true); return; } } } else { // Everyone else checks primary if(net->timop(recent_recv[vc_state.view.primary], ps_timo.dead_timo)) { // If we haven't heard from the manager, initiate_vc LOG(l::DBG_EV, id_str() << " non-primary timeout now:" << net->now() << " recent recv: " << recent_recv[vc_state.view.primary] << " pr: " << vc_state.view.primary << "\n"); initiate_vc(true); return; } } } break; case vc_state_t::MANAGER: { // If we haven't announced new view, & it is possible // see if we have waited long enough if(vc_mgr.announce_nv == false && vc_mgr.view_possible && net->timop(vc_mgr.view_possible, ps_timo.vca_timo)) { LOG(l::DBG_EV, id_str() << " manager vc complete timeout now:" << net->now() << "\n"); form_newview(); announce_newview(); vc_mgr.announce_nv = true; } MASSERT(ps_timo.vca_timo < ps_timo.dead_timo, "Should wait longer for dead node than to complete a vc"); // Now see if we haven't heard from anyone in too long a time. std::set<node_id_t> servers = net->get_serv_ids(nid); tick_t most_recent_recv = (tick_t)0; node_id_t recent_nid = 0; for(const auto& serv : servers) { if(recent_recv[serv] > most_recent_recv) { most_recent_recv = recent_recv[serv]; recent_nid = serv; } } if(net->timop(most_recent_recv, ps_timo.dead_timo)) { LOG(l::DBG_EV, id_str() << " manager timeout now:" << net->now() << " most recent: " << most_recent_recv << " nid:" << recent_nid << "\n"); initiate_vc(true); return; } } break; case vc_state_t::UNDERLING: { if(net->timop(recent_recv[vc_state.proposed_vid.manager], ps_timo.dead_timo)) { // If we don't hear from the manager, initiate_vc LOG(l::DBG_EV, id_str() << " underling timeout now:" << net->now() << " recent_recv: " << recent_recv[vc_state.proposed_vid.manager] << " nid:" << vc_state.proposed_vid.manager << "\n"); initiate_vc(true); } } break; default: MASSERT(0, "Yikes"); } }
void Upgrade::construct( const shared_str& upgrade_id, Group& parental_group, Manager& manager_r ) { inherited::construct( upgrade_id, manager_r ); m_parent_group = &parental_group; // name : StringTable(); icon; description; m_name = CStringTable().translate( pSettings->r_string(id(), "name") ); m_description = CStringTable().translate( pSettings->r_string(id(), "description") ); m_icon._set( pSettings->r_string(id(), "icon") ); // section -------------------------------------------------------------------------- LPCSTR section_str = pSettings->r_string( id(), "section" ); VERIFY2( pSettings->section_exist( section_str ), make_string( "Upgrade <%s> : settings section [%s] not exist!", id_str(), section_str ) ); VERIFY2( pSettings->line_count( section_str ), make_string( "Upgrade <%s> : settings section [%s] is empty !", id_str(), section_str ) ); m_section._set( section_str ); // precondition_functor LPCSTR precondition_functor_str = pSettings->r_string( id(), "precondition_functor" ); m_preconditions.parameter = pSettings->r_string( id(), "precondition_parameter" ); m_preconditions.parameter2 = m_section.c_str(); R_ASSERT2( ai().script_engine().functor( precondition_functor_str, m_preconditions.functr ), make_string( "Failed to get precondition functor in section[%s], functor[%s]", id_str(), precondition_functor_str ) ); m_preconditions(); // effect_functor LPCSTR effect_functor_str = pSettings->r_string( id(), "effect_functor" ); m_effects.parameter = pSettings->r_string( id(), "effect_parameter" ); m_effects.parameter2 = m_section.c_str(); m_effects.parameter3 = 1; R_ASSERT2( ai().script_engine().functor( effect_functor_str, m_effects.functr ), make_string( "Failed to get effect functor in section[%s], functor[%s]", id_str(), effect_functor_str ) ); m_effects(); // prereq_functor (1,2) : m_prerequisites, m_tooltip LPCSTR prereq_functor_str = pSettings->r_string( id(), "prereq_functor" );//prerequisites_functor // LPCSTR tooltip_functor_str = pSettings->r_string( id(), "prereq_tooltip_functor" ); m_prerequisites.parameter = pSettings->r_string( id(), "prereq_params" );//prerequisites_params m_prerequisites.parameter2 = m_section.c_str(); // m_tooltip.parameter = pSettings->r_string( id(), "prereq_params" ); R_ASSERT2( ai().script_engine().functor( prereq_functor_str, m_prerequisites.functr ), make_string( "Failed to get prerequisites functor in section[%s], functor[%s]", id_str(), prereq_functor_str ) ); m_prerequisites(); /*R_ASSERT2( ai().script_engine().functor( tooltip_functor_str, m_tooltip.functr ), make_string( "Failed to get tooltip functor in section[%s], functor[%s]", id_str(), tooltip_functor_str ) ); m_tooltip();*/ // effects = groups LPCSTR groups_str = pSettings->r_string( id(), "effects" ); if ( groups_str ) { add_dependent_groups( groups_str, manager_r ); } m_known = !!READ_IF_EXISTS( pSettings, r_bool, id(), "known", false ); m_property = pSettings->r_string( id(), "property" ); VERIFY2( m_property.size(), make_string( "Upgrade <%s> : property is empty !", id_str() ) ); VERIFY2( manager_r.get_property( m_property ), make_string( "Upgrade <%s> : property [%s] is unknown (not found in upgrade manager) !", id_str(), m_property.c_str() ) ); m_scheme_index.set( -1, -1 ); m_scheme_index = pSettings->r_ivector2( id(), "scheme_index" ); m_highlight = false; } // Upgrade()