virtual QPair<QByteArray, bool> GetBulkData(int)
      {
        QByteArray data(1024, 0);
        CreateDescriptor(data);

        SetTriggered();
        int my_idx = GetGroup().GetIndex(GetLocalId());
        int bad = Random::GetInstance().GetInt(0, GetGroup().Count());
        while(bad == my_idx) {
          bad = Random::GetInstance().GetInt(0, GetGroup().Count());
        }

        qDebug() << my_idx << "setting bad hash at" << bad;
        const Descriptor &cdes = GetMyDescriptor();
        QVector<QByteArray> hashes = cdes.XorMessageHashes();

        Library *lib = CryptoFactory::GetInstance().GetLibrary();
        QScopedPointer<Hash> hashalgo(lib->GetHashAlgorithm());
        hashes[bad] = hashalgo->ComputeHash(data);

        Descriptor descriptor(cdes.Length(), cdes.PublicDh(), hashes,
            cdes.CleartextHash());
        SetMyDescriptor(descriptor);

        QByteArray my_desc;
        QDataStream desstream(&my_desc, QIODevice::WriteOnly);
        desstream << GetMyDescriptor();
        return QPair<QByteArray, bool>(my_desc, false);
      }
Esempio n. 2
0
int hashlist_add_implemented(hashlist* list1,char* key_name,int x,int y,int z)
{
        int hash_value;
        int i;
        if ( list1->Hash == NULL )
        {
                 list1->Hash = (hash*)malloc(sizeof(hash) * list1->size );
                 for( i=0; i<list1->size-1; i++)
                        list1->Hash[i].valid=0;
        }

        /* Reallot Hashlist if it iis 80% full */
        float alloted_percent =  ((float)list1->alloted/list1->size)*100 ;
        //printf("Adding hash :- %s\t Hash:- %d \tAlloted %f\%\n",key_name,hashalgo(key_name,list1->size),alloted_percent);            
        if ( alloted_percent >= 80 )
                hashlist_reallot(list1);

        hash_value = hashalgo(key_name,list1->size);
        //printf("Hash Value  :- %d\n",hash_value);

        /*Closed Hashing, In collision look for the next available space to fit the key*/

        while (list1->Hash[hash_value].valid == 1)
        {
                /*Check if same key exist. If yes return*/
                if (!strcmp(list1->Hash[hash_value].key_name,key_name)) 
			return;
                if ( hash_value == list1->size-1 )
                        hash_value=-1;
                hash_value++;
        //      printf("Hash %d  Valid %d\n",hash_value,list1->Hash[hash_value].valid);
        }

        list1->Hash[hash_value].key_name = (char*)malloc(sizeof(char)*strlen(key_name)+1);
        strcpy(list1->Hash[hash_value].key_name,key_name);      
        list1->Hash[hash_value].x = x;
        list1->Hash[hash_value].y = y;
        list1->Hash[hash_value].z = z;
        list1->Hash[hash_value].valid = 1;
        list1->alloted++;
       
}