Example #1
0
func VanishData(kadem *Kademlia, VDOID ID, data []byte, numberKeys byte,
	threshold byte) (vdo VanashingDataObject) {
	vdo.NumberKeys = numberKeys
	vdo.Threshold = threshold
	//vdo.VDOID = NewRandomID()
	//Use the provided "GenerateRandomCryptoKey" function to create a random cryptographic key (K)
	random_K := GenerateRandomCryptoKey()

	//Use the provided "encrypt" function by giving it the random key(K) and text
	cyphertext := encrypt(random_K, data)

	vdo.Ciphertext = cyphertext

	map_K, err := sss.Split(numberKeys, threshold, random_K)
	if err != nil {
		log.Fatal("Split", err)
		fmt.Println("ERROR: Split: ", err)
		return
	} else {

		//Use provided GenerateRandomAccessKey to create an access key
		vdo.AccessKey = GenerateRandomAccessKey(CalculateEpochNumber())

		//Use "CalculateSharedKeyLocations" function to find the right []ID to send RPC
		keysLocation := CalculateSharedKeyLocations(vdo.AccessKey, int64(numberKeys))
		for i := 0; i < len(keysLocation); i++ {
			k := byte(i + 1)
			v := map_K[k]
			all := []byte{k}
			for x := 0; x < len(v); x++ {
				all = append(all, v[x])
			}

			kadem.DoIterativeStore(keysLocation[i], all)

		}
	}

	vdo.VDOID = VDOID

	return
}
Example #2
0
func Refresh(kadem *Kademlia, vdoid ID, timeout int) {
	// the unit of timeout is second
	for {

		time.Sleep(time.Duration(timeout) * time.Second)
		kadem.VDOmap.Lock()

		temp_vdo := kadem.VDOmap.m[vdoid]

		//----------------------------------------
		//retrieve the key
		keysLocation := CalculateSharedKeyLocations(temp_vdo.AccessKey, int64(temp_vdo.NumberKeys))

		number_valid_location := 0
		map_value := make(map[byte][]byte)
		if len(keysLocation) < int(temp_vdo.Threshold) {
			fmt.Println("ERR: Could not obtain a sufficient number of shared keys")
			return
		}

		//Use sss.Combine to recreate the key, K
		for i := 0; i < len(keysLocation); i++ {
			value := kadem.DoIterativeFindValue_UsedInVanish(keysLocation[i])
			if len(value) != 0 {
				number_valid_location += 1
			}
			fmt.Println("Value is ", value)
			if len(value) == 0 {
				continue
			} else {
				all := []byte(value)
				k := all[0]
				v := all[1:]
				map_value[k] = v

				//fmt.Println(k, "'s value is ", v)

			}
		}

		if number_valid_location < int(temp_vdo.Threshold) {
			fmt.Println("ERR: Could not obtain a sufficient number of valid nodes")
			return
		}

		//Use sss.Combine to recreate the key, K
		real_key := sss.Combine(map_value)

		//---------------------------------------
		//resplit real_key

		map_K, err := sss.Split(temp_vdo.NumberKeys, temp_vdo.Threshold, real_key)
		if err != nil {
			return
		} else {

			//Use provided GenerateRandomAccessKey to create an access key
			temp_vdo.AccessKey = GenerateRandomAccessKey(CalculateEpochNumber())

			//Use "CalculateSharedKeyLocations" function to find the right []ID to send RPC
			keysLocation = CalculateSharedKeyLocations(temp_vdo.AccessKey, int64(temp_vdo.NumberKeys))

			//fmt.Println("InVanish: len of keyslocation", len(keysLocation))

			for i := 0; i < len(keysLocation); i++ {
				k := byte(i + 1)
				v := map_K[k]
				all := []byte{k}
				for x := 0; x < len(v); x++ {
					all = append(all, v[x])
				}

				kadem.DoIterativeStore(keysLocation[i], all)

			}
		}
		kadem.VDOmap.m[vdoid] = temp_vdo

		kadem.VDOmap.Unlock()
	}
}