void c_net_node::add_to_inbox (char *data, size_t size, const ip::address &source_address) { _info("add_to_inbox"); std::lock_guard<std::mutex> lg(m_inbox_mutex); s_message message; message.m_data.assign(data, size); message.m_source_id = source_address.to_string(); m_inbox.emplace_back(std::move(message)); }
promise< mac::address > arp_win32::resolve( const ip::address &ip_address ) { auto self = false; auto ret = promise< mac::address >(); for ( auto nif : machine::self().nifs() ) { if ( nif.address() == ip_address ) { mac::address mac = nif.mac_address(); runloop::shared().dispatch( [=]() mutable { ret.resolve( std::move( mac ) ); } ); self = true; break; } } if ( !self ) { std::thread t( [=]() mutable { IPAddr dest; ULONG bytes[ 2 ]; ULONG len = sizeof( bytes ); mac::address mac; auto err = std::error_code(); ip_address >> dest; auto aerr = SendARP( dest, INADDR_ANY, &bytes, &len ); ncheck_error_action( aerr == NO_ERROR, err = make_error_code( std::errc::no_such_device_or_address ), exit, "SendARP to % failed (%)", ip_address.to_string(), err ); ncheck_error_action( len == 6, err = make_error_code( std::errc::no_such_device_or_address ), exit, "bad mac address size: %", len ); mac = mac::address( reinterpret_cast< std::uint8_t* >( &bytes ), len ); mlog( marker::arp, log::level_t::info, "% -> %", ip_address.to_string(), mac.to_string() ); exit: runloop::shared().dispatch( [=]() mutable { if ( !err ) { ret.resolve( std::move( mac ) ); } else { ret.reject( err ); } } ); } );