Пример #1
0
	void handleReceivedUDP(const boost::system::error_code& error,
						   std::size_t bytes_transferred)
	{
		if (error == boost::asio::error::operation_aborted)
			return;    /* we're done */

		if (error) {
			printf("SC_UdpInPort: received error - %s", error.message().c_str());
			startReceiveUDP();
			return;
		}

		if (mWorld->mDumpOSC) dumpOSC(mWorld->mDumpOSC, bytes_transferred, recvBuffer.data());

		OSC_Packet * packet = (OSC_Packet*)malloc(sizeof(OSC_Packet));

		packet->mReplyAddr.mProtocol = kUDP;
		packet->mReplyAddr.mAddress  = remoteEndpoint.address();
		packet->mReplyAddr.mPort     = remoteEndpoint.port();
		packet->mReplyAddr.mSocket   = udpSocket.native_handle();
		packet->mReplyAddr.mReplyFunc = udp_reply_func;
		packet->mReplyAddr.mReplyData = (void*)&udpSocket;

		packet->mSize = bytes_transferred;

		if (!UnrollOSCPacket(mWorld, bytes_transferred, recvBuffer.data(), packet))
			free(packet);

		startReceiveUDP();
	}
Пример #2
0
    void IpPool::OnDisConnect(const boost::asio::ip::udp::endpoint& end_point, bool is_active)
    {
        if (is_running_ == false) return;

        LOG4CPLUS_INFO_LOG(logger_ippool, "IpPool::OnDisConnect Endpoint=" << end_point);

        protocol::SocketAddr socket_addr(end_point.address().to_v4().to_ulong(), end_point.port());
        std::map<protocol::SocketAddr, CandidatePeer::p>::iterator iter = candidate_peers_.find(socket_addr);
        if (iter == candidate_peers_.end())
            return;

        CandidatePeer::p peer = iter->second;
        assert(peer);

        IPPoolIndexUpdating updating(peer, shared_from_this());
        peer->last_active_time_ = framework::timer::TickCounter::tick_count();

        // reset last_connect_time_ to avoid re-connecting the peer immediately		
        peer->last_connect_time_ = peer->last_active_time_;

        peer->is_connecting_ = false;
        peer->is_connected_ = false;

        if (is_active)
        {
            protocol::CloseSessionPacket packet(protocol::Packet::NewTransactionID(), 
                protocol::PEER_VERSION, end_point);

            AppModule::Inst()->DoSendPacket(packet, protocol::PEER_VERSION);
        }
    }
FaceUri::FaceUri(const boost::asio::ip::udp::endpoint& endpoint)
{
  m_isV6 = endpoint.address().is_v6();
  m_scheme = m_isV6 ? "udp6" : "udp4";
  m_host = endpoint.address().to_string();
  m_port = boost::lexical_cast<std::string>(endpoint.port());
}
Пример #4
0
void NetworkIF_i::IPCCAdjDiscoveredFtor::do_process(
  const boost::asio::ip::udp::endpoint&  sender_endpointl)
{
  if (sender_endpointl.address().is_v4())
  {
    m_networkIF.createIPCC(sender_endpointl.address().to_v4().to_ulong(),
                           sender_endpointl.port());
  }
}
Пример #5
0
 static void
 receive_robot_state (boost::asio::ip::udp::endpoint& endpoint,
                      uint16_t comp_id,
                      uint16_t msg_type,
                      shared_ptr<const roah_rsbb_msgs::RobotState> msg)
 {
   cout << "Received RobotState from " << endpoint.address().to_string()
        << ":" << endpoint.port()
        << ", COMP_ID " << comp_id
        << ", MSG_TYPE " << msg_type << endl
        << "  time: " << msg->time().sec() << "." << msg->time().nsec() << endl
        << "  messages_saved: " << msg->messages_saved() << endl
        << flush;
 }
Пример #6
0
 static void
 receive_benchmark_state (boost::asio::ip::udp::endpoint& endpoint,
                          uint16_t comp_id,
                          uint16_t msg_type,
                          shared_ptr<const roah_rsbb_msgs::BenchmarkState> msg)
 {
   cout << "Received BenchmarkState from " << endpoint.address().to_string()
        << ":" << endpoint.port()
        << ", COMP_ID " << comp_id
        << ", MSG_TYPE " << msg_type << endl
        << "  benchmark_type: " << msg->benchmark_type() << endl
        << "  benchmark_state: " << msg->benchmark_state() << endl
        << flush;
 }
Пример #7
0
 static void
 receive_robot_beacon (boost::asio::ip::udp::endpoint& endpoint,
                       uint16_t comp_id,
                       uint16_t msg_type,
                       shared_ptr<const roah_rsbb_msgs::RobotBeacon> msg)
 {
   cout << "Received RobotBeacon from " << endpoint.address().to_string()
        << ":" << endpoint.port()
        << ", COMP_ID " << comp_id
        << ", MSG_TYPE " << msg_type << endl
        << "  team_name: " << msg->team_name() << endl
        << "  robot_name: " << msg->robot_name() << endl
        << "  time: " << msg->time().sec() << "." << msg->time().nsec() << endl
        << flush;
 }
Пример #8
0
 static void
 receive_tablet_beacon (boost::asio::ip::udp::endpoint& endpoint,
                        uint16_t comp_id,
                        uint16_t msg_type,
                        shared_ptr<const roah_rsbb_msgs::TabletBeacon> msg)
 {
   cout << "Received TabletBeacon from " << endpoint.address().to_string()
        << ":" << endpoint.port()
        << ", COMP_ID " << comp_id
        << ", MSG_TYPE " << msg_type << endl
        << "  last_call: " << msg->last_call().sec() << "." << msg->last_call().nsec() << endl
        << "  last_pos: " << msg->last_pos().sec() << "." << msg->last_pos().nsec() << endl
        << "  x: " << msg->x() << endl
        << "  y: " << msg->y() << endl
        << flush;
 }
Пример #9
0
    void IpPool::OnConnectSucced(const boost::asio::ip::udp::endpoint& end_point)
    {
        if (is_running_ == false) return;

        LOG4CPLUS_INFO_LOG(logger_ippool, "IpPool::OnConnectSucced Endpoint=" << end_point);

        protocol::SocketAddr socket_addr(end_point.address().to_v4().to_ulong(), end_point.port());
        std::map<protocol::SocketAddr, CandidatePeer::p>::iterator iter = candidate_peers_.find(socket_addr);
        if (iter == candidate_peers_.end())
            return;

        CandidatePeer::p peer = iter->second;
        assert(peer);

        IPPoolIndexUpdating updating(peer, shared_from_this());
        peer->last_active_time_ = framework::timer::TickCounter::tick_count();
        peer->is_connecting_ = false;
        peer->is_connected_ = true;
    }
Пример #10
0
    void
    receive_rsbb_beacon (boost::asio::ip::udp::endpoint& endpoint,
                         uint16_t comp_id,
                         uint16_t msg_type,
                         shared_ptr<const roah_rsbb_msgs::RoahRsbbBeacon> rsbb_beacon)
    {
      cout << "Received RoahRsbbBeacon from " << endpoint.address().to_string()
           << ":" << endpoint.port()
           << ", COMP_ID " << comp_id
           << ", MSG_TYPE " << msg_type << endl;

      unsigned short connect_port = 0;
      for (auto const& bt : rsbb_beacon->benchmarking_teams()) {
        cout << "  team_name: " << bt.team_name()
             << ", robot_name: " << bt.robot_name()
             << ", rsbb_port: " << bt.rsbb_port() << endl;
        if ( (bt.team_name() == TEAM_NAME) && (bt.robot_name() == ROBOT_NAME)) {
          connect_port = bt.rsbb_port();
          // break; // Commented to show all entries
        }
      }

      lock_guard<mutex> lock (private_channel_mutex_);
      if (connect_port != (private_channel_ ? private_channel_->port() : 0)) {
        if (private_channel_) {
          cout << "Disconnecting private channel" << endl;
          private_channel_.reset();
        }
        if (connect_port) {
          cout << "Connecting private channel to " << endpoint.address().to_string()
               << ":" << connect_port << endl;
          private_channel_ = make_shared<PrivateChannel<CerrErrorHandler>> (endpoint.address().to_string(), connect_port, CRYPTO_KEY, CRYPTO_CIPHER);
          private_channel_->signal_benchmark_state_received().connect (&DumpComm::receive_benchmark_state);
          private_channel_->signal_robot_state_received().connect (&DumpComm::receive_robot_state);
        }
      }

      cout << flush;
    }
Пример #11
0
void ReceiveHandle(const boost::system::error_code e, const std::size_t size)
{
	StartReceive();

	if (e)
	{
		std::cout << e.value() << " " <<  e.message() << std::endl;
		return;
	}

	const std::string data(recv_buf.data(), size);
	
	std::cout << "Received: " << data << std::endl;

	std::vector<std::string> args;
	boost::algorithm::split(args, data, boost::algorithm::is_space());

	if (args.size() > 1)
	{
		boost::asio::ip::udp::resolver resolver(io_service);
		boost::asio::ip::udp::resolver::query query(boost::asio::ip::udp::v4(), args[0], args[1]);
		boost::asio::ip::udp::endpoint clientEp = *resolver.resolve(query);
		
		const std::string hello("ping!");
		g_pSocket->send_to(boost::asio::buffer(hello), clientEp);
		const std::string epStr = clientEp.address().to_string() + ":" + conv::cast<std::string>(clientEp.port());

		std::cout << "Sending ping! to: " << epStr << std::endl;
	}
	else
	{
		const std::string hello("pong!");
		g_pSocket->send_to(boost::asio::buffer(hello), ep);
		const std::string epStr = ep.address().to_string() + ":" + conv::cast<std::string>(ep.port());

		std::cout << "Sending pong! to: " << epStr << std::endl;
	}
}
Пример #12
0
void message::encode_endpoint(
    database::byte_buffer & body, const boost::asio::ip::udp::endpoint & ep
    )
{
    /**
     * Write the type.
     */
    body.write_uint16(attribute_type_endpoint);
    
    /**
     * Write the length.
     */
    body.write_uint16(ep.address().is_v4() ? 8 : 20);
    
    /**
     * Encode the padding.
     */
    body.write_uint8(0);
    
    /**
     * Write the ip address version.
     */
    body.write_uint8(
        ep.address().is_v4() ? constants::ipv4 : constants::ipv6
    );
    
    /**
     * Write the port.
     */
    body.write_uint16(ep.port());
    
    /**
     * Write the ip address.
     */
    body.write_address(ep.address());
}
Пример #13
0
	Endpoint::Endpoint(boost::asio::ip::udp::endpoint const &ep) :
		m_addr(ep.address()),
		m_port(ep.port()) {}
Пример #14
0
std::string EMServer::get_address_from_endpoint(boost::asio::ip::udp::endpoint &endpoint) const
{
	return endpoint.address().to_string() + ":" + std::to_string(endpoint.port());
}
Пример #15
0
bool udp_handler::on_async_receive_from(
    const boost::asio::ip::udp::endpoint & ep, const char * buf,
    const std::size_t & len
    )
{
    if (auto n = node_impl_.lock())
    {
        if (static_cast<std::uint8_t> (buf[0]) & protocol::message_flag_0x40)
        {
            if (
                static_cast<std::uint8_t> (buf[0]) &
                protocol::message_flag_encrypted
                )
            {
                /**
                 * Allocate the message.
                 */
                message msg(buf, len);
                
                /**
                 * Get the shared secret.
                 */
                auto shared_secret = n->get_key_pool()->find(ep);

                if (shared_secret.size() > 0 && msg.decrypt(shared_secret))
                {
                    on_data(ep, msg.data(), msg.size());
                }
                else
                {
                    protocol::header_t hdr;
                    
                    std::memcpy(&hdr, buf, sizeof(hdr));
       
                    hdr.transaction_id = ntohs(hdr.transaction_id);
                
                    log_debug(
                        "UDP handler, message " << hdr.transaction_id  <<
                        " decryption failed."
                    );
                    
                    /**
                     * Allocate the protocol::message_code_public_key_ping.
                     */
                    std::shared_ptr<message> request(
                        new message(protocol::message_code_public_key_ping)
                    );
                    
                    /**
                     * Add their public endpoint as a
                     * message::attribute_type_endpoint.
                     */
                    message::attribute_endpoint attr1;
                    
                    attr1.type = message::attribute_type_endpoint;
                    attr1.length = 0;
                    attr1.value = ep;
                    
                    request->endpoint_attributes().push_back(attr1);
                    
                    /**
                     * Add our public key as a message::attribute_string of
                     * type message::attribute_type_public_key.
                     */
                    message::attribute_string attr2;
                    
                    attr2.type = message::attribute_type_public_key;
                    attr2.length = n->get_ecdhe()->public_key().size();
                    attr2.value = n->get_ecdhe()->public_key();
                    
                    request->string_attributes().push_back(attr2);
                    
                    /**
                     * Send the request.
                     */
                    send_message(ep, request);

                    return false;
                }
            }
            else
            {
                on_data(ep, buf, len);
            }
        }
        else
        {
            n->on_app_udp_receive(
                ep.address().to_string().c_str(), ep.port(), buf, len
            );
        }
    }
    else
    {
        return false;
    }
    
    return true;
}
void refBoxTransport::handle_recv_error(boost::asio::ip::udp::endpoint &endpoint, std::string msg)
{
    printf("Receive error from %s:%u: %s\n",
	 endpoint.address().to_string().c_str(), endpoint.port(), msg.c_str());
}
void
handle_recv_error(boost::asio::ip::udp::endpoint &endpoint, std::string msg)
{
  ROS_WARN("Receive error from %s:%u: %s",
           endpoint.address().to_string().c_str(), endpoint.port(), msg.c_str());
}
Пример #18
0
 fc::ip::endpoint to_fc_ep( const boost::asio::ip::udp::endpoint& e ) {
   return fc::ip::endpoint( e.address().to_v4().to_ulong(), e.port() );
 }
Пример #19
0
uint64_t kcp_client::endpoint_to_i(const boost::asio::ip::udp::endpoint& ep)
{
    uint64_t addr_i = ep.address().to_v4().to_ulong();
    uint32_t port = ep.port();
    return (addr_i << 32) + port;
}