Ejemplo n.º 1
0
  QByteArray BulkRound::ProcessMessage(int des_idx, int msg_index)
  {
    int count = _messages.size();
    const Descriptor &des = GetDescriptors()[des_idx];
    int length = des.Length();
    QByteArray msg(length, 0);

    Hash hashalgo;
    bool good = true;

    for(int idx = 0; idx < count; idx++) {
      const char *tmsg = _messages[idx].constData() + msg_index;
      QByteArray xor_msg(QByteArray::fromRawData(tmsg, length));

      if(des.XorMessageHashes()[idx] != hashalgo.ComputeHash(xor_msg)) {
        qWarning() << "Xor message does not hash properly";
        _bad_message_hash.append(BadHash(des_idx, idx));
        good = false;
      }

      if(good) {
        Xor(msg, msg, xor_msg);
      }
    }

    if(good) {
      return msg;
    } else {
      return QByteArray();
    }
  }
Ejemplo n.º 2
0
static void DetectCacheAndTLB(size_t& descriptorFlags)
{
	const Descriptors descriptors = GetDescriptors();
	for(Descriptors::const_iterator it = descriptors.begin(); it != descriptors.end(); ++it)
	{
		const Descriptor descriptor = *it;
		if(HandleSpecialDescriptor(descriptor, descriptorFlags))
			continue;

		const Characteristics* characteristics = CharacteristicsFromDescriptor(*it);
		if(!characteristics)
			continue;

		if((descriptorFlags & SKIP_CACHE_DESCRIPTORS) && !characteristics->IsTLB())
			continue;

		x86_x64::Cache cache;
		cache.Initialize(characteristics->Level(), characteristics->Type());
		cache.numEntries    = characteristics->NumEntries();
		cache.entrySize     = characteristics->EntrySize();
		cache.associativity = characteristics->associativity;
		cache.sharedBy      = 1;	// (safe default)
		if(characteristics->IsTLB())
			AddTLB(cache);
		else
			AddCache(cache);
	}
}
Ejemplo n.º 3
0
      virtual QByteArray GenerateXorMessage(int idx)
      { 
        if(_bad == -1) {
          _bad = Random::GetInstance().GetInt(0, GetShuffleSink().Count());
        }

        QByteArray msg = BulkRound::GenerateXorMessage(idx);
        if(GetDescriptors().size() != _bad + 1) {
          return msg;
        }
        
        SetTriggered();
        CryptoRandom().GenerateBlock(msg);
        return msg;
      }
      virtual QByteArray GenerateXorMessage(int idx)
      { 
        if(_bad == -1) {
          _bad = Random::GetInstance().GetInt(0, GetShuffleSink().Count());
        }

        QByteArray msg = BulkRound::GenerateXorMessage(idx);
        if(GetDescriptors().size() != _bad + 1) {
          return msg;
        }
        
        SetTriggered();
        Library *lib = CryptoFactory::GetInstance().GetLibrary();
        QScopedPointer<Random> rng(lib->GetRandomNumberGenerator());
        rng->GenerateBlock(msg);
        return msg;
      }
Ejemplo n.º 5
0
  void BulkRound::HandleAggregatedBulkData(QDataStream &stream, const Id &from)
  {
    if(from == GetLocalId()) {
      return;
    }

    qDebug() << GetGroup().GetIndex(GetLocalId()) << GetLocalId().ToString() <<
      ": received aggregated bulk data from " << GetGroup().GetIndex(from) <<
      from.ToString();

    if(GetGroup().GetLeader() != from) {
      throw QRunTimeError("Received aggregated bulk data from non-leader.");
    }

    if(_state != ReceivingLeaderData) {
      throw QRunTimeError("Not expected at this time.");
    }

    QVector<QByteArray> cleartexts;
    stream >> cleartexts;

    const QVector<Descriptor> &des = GetDescriptors();

    if(cleartexts.count() != des.count()) {
      throw QRunTimeError("Cleartext count does not match descriptor count: " +
          QString::number(cleartexts.count()) + " " +
          QString::number(des.count()));
    }

    Hash hashalgo;

    for(int idx = 0; idx < cleartexts.count(); idx++) {
      QByteArray cleartext = cleartexts[idx];
      QByteArray hash = hashalgo.ComputeHash(cleartext);
      if(hash != des[idx].CleartextHash()) {
        throw QRunTimeError("Cleartext hash does not match descriptor hash.");
      }
      if(!cleartext.isEmpty()) {
        PushData(GetSharedPointer(), cleartext);
      }
    }

    Finish();
  }
Status KeyframeVisualOdometry::Update(const Image& image) {
  // Extract keypoints from the frame.
  std::vector<Keypoint> keypoints;
  Status status = GetKeypoints(image, &keypoints);
  if (!status.ok()) return status;

  // Extract features and descriptors from the keypoints.
  std::vector<Feature> features;
  std::vector<Descriptor> descriptors;
  status = GetDescriptors(image, &keypoints, &features, &descriptors);
  if (!status.ok()) return status;

  // Set the annotator's image.
  if (options_.draw_tracks || options_.draw_features) {
    annotator_.SetImage(image);
  }

  // Initialize the very first view if we don't have one yet.
  if (current_keyframe_ == kInvalidView) {
    Landmark::SetRequiredObservations(2);
    InitializeFirstView(features, descriptors);
    return Status::Ok();
  }

  // Initialize the second view if we don't have one yet using 2D<-->2D
  // matching.
  if (view_indices_.size() == 1) {
    status = InitializeSecondView(features, descriptors);
    if (status.ok()) {
      Landmark::SetRequiredObservations(options_.num_observations_to_triangulate);
    }
    return status;
  }

  // Create a camera with an unknown pose.
  Camera camera;
  camera.SetIntrinsics(intrinsics_);
  View::Ptr new_view = View::Create(camera);

  // Is this new image going to be a keyframe?
  const bool is_keyframe =
      initialize_new_keyframe_ ||
      NumEstimatedTracks() < options_.min_num_feature_tracks;
  if (is_keyframe) {
    initialize_new_keyframe_ = false;
  }

  // Update feature tracks and add matched features to the view.
  status = UpdateFeatureTracks(features,
                               descriptors,
                               new_view->Index(),
                               is_keyframe);
  if (!status.ok()) {
    View::DeleteMostRecentView();
    return status;
  }

  // Compute the new camera pose.
  status = EstimatePose(new_view->Index());
  if (!status.ok()) {
    View::DeleteMostRecentView();
  } else {
    view_indices_.push_back(new_view->Index());
  }

  if (is_keyframe && options_.perform_bundle_adjustment) {
    // Bundle adjust views in the sliding window.
    BundleAdjuster bundle_adjuster;
    if (!bundle_adjuster.Solve(options_.bundle_adjustment_options,
                               SlidingWindowViewIndices()))
      return Status::Cancelled("Failed to perform bundle adjustment.");
  }

  // Annotate tracks and features.
  if (options_.draw_features) {
    annotator_.AnnotateFeatures(features);
  }
  if (options_.draw_tracks) {
    annotator_.AnnotateTracks(tracks_);
  }
  if (options_.draw_tracks || options_.draw_features) {
    annotator_.Draw();
  }

  return status;
}
Ejemplo n.º 7
0
tERROR
CProxySessionManager::ProxyMain(SOCKET Server, SOCKET Server_v6, SOCKET CrService, SOCKET CrService_v6 )
{
    int RetVal = 0;
    DWORD dwCount;    
    CProxySession* Session;
    fd_set fds;
    TIMEVAL Timeout = { 1, 0 }; // 1 second Timeout

    SOCKET MySock = INVALID_SOCKET;

    while(true)
    {
        FD_ZERO(&fds);
        
        if ( Server != INVALID_SOCKET )
            FD_SET(Server, &fds);
        if ( Server_v6 != INVALID_SOCKET )
            FD_SET(Server_v6, &fds);
        if ( CrService != INVALID_SOCKET )
            FD_SET(CrService, &fds);
        if ( CrService_v6 != INVALID_SOCKET )
            FD_SET(CrService_v6, &fds);        

        // ѕолучаем набор дескрипторов, у которых мы ожидаем какой-либо активности.
        dwCount = GetDescriptors( &fds );

        CKAHCR::SetWatchdogTimeout( ( SESSION_LIST_REFRESH_TIMEOUT / 1000 ) * 2);
        
        // выгрызаем из набора дескриптор с событием.
        RetVal = select( 0, &fds, NULL, NULL, &Timeout );

        // KLSTD_TRACE1( KLMC_TRACELEVEL, "CProxySessionManager::ProxyMain : select return %d\n", RetVal );

        CKAHCR::SetWatchdogTimeout( ( SESSION_LIST_REFRESH_TIMEOUT / 1000 ) * 2);

        // проверка на выгрузку
        if ( WAIT_OBJECT_0 == WaitForSingleObject( m_hStopEvent, 0 ))
        {
            // global stop event
            KLSTD_TRACE0( KLMC_TRACELEVEL, "CProxySessionManager::ProxyMain => Received m_hStopEvent\n" );
            break;
        }

        if ( WAIT_OBJECT_0 == WaitForSingleObject( m_hRequestSessionStop, 0 ))
        {
            KLSTD_TRACE0( KLMC_TRACELEVEL, "CProxySessionManager::ProxyMain => Received m_hRequestSessionStop\n" );

            ProcessPseudoStop();
            continue;
        }

        if ( RetVal == SOCKET_ERROR )
        {
            KLSTD_TRACE2( KLMC_TRACELEVEL, "CProxySessionManager::ProxyMain => select returned %d. err = %d\n", RetVal, WSAGetLastError() );

            break;
        }

        // обработка новых подключений к слушающим сокетам
        if ( FD_ISSET(Server, &fds) )
        {
            FD_CLR( Server, &fds );
            ProcessNewConnection( Server );
            continue;
        }

        if ( FD_ISSET(Server_v6, &fds) )
        {
            FD_CLR( Server_v6, &fds );
            ProcessNewConnection( Server_v6 );
            continue;
        }

        if ( FD_ISSET(CrService, &fds) )
        {
            FD_CLR( CrService, &fds );
            ProcessNewConnection( CrService );
            continue;
        }

        if ( FD_ISSET(CrService_v6, &fds) )
        {
            FD_CLR( CrService_v6, &fds );
            ProcessNewConnection( CrService_v6 );
            continue;
        }
        
        // обработка "сп¤щих" клиентов.
        Session = GetClient( &fds );

        if ( Session )
        {            
            if ( !Session->StartClient() )
            {
                KLSTD_TRACE1( KLMC_TRACELEVEL, "CProxySessionManager::ProxyMain: Unable To restart Client %x \n", Session );
                Sleep( 1000 );
                AddClient( Session );
            }
        }
        else
        {
            // timeout 
            m_SessionList.erase( remove_if( m_SessionList.begin(), m_SessionList.end(),CDoneSession()), m_SessionList.end());
        }
    }

    if ( Server != INVALID_SOCKET )
        closesocket( Server );

    if ( Server_v6 != INVALID_SOCKET )
        closesocket( Server_v6 );

    if ( CrService != INVALID_SOCKET )
        closesocket( CrService );

    if ( CrService_v6 != INVALID_SOCKET )
        closesocket( CrService_v6 );

    return errOK;
}