예제 #1
0
func UnvanishData_acc(kadem *Kademlia, vdo VanashingDataObject, epoch int64) (data []byte) {

	map_value := make(map[byte][]byte)
	//used to see if the number of valid nodes is enough where we can find value in it.
	number_valid_location := 0
	//Use AccessKey and CalculateSharedKeyLocations to search for at least vdo.Threshold keys in the DHT.

	AccessKey := GenerateRandomAccessKey(epoch)

	keysLocation := CalculateSharedKeyLocations(AccessKey, int64(vdo.NumberKeys))

	if len(keysLocation) < int(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
		}

		if len(value) == 0 {
			continue
		} else {
			all := []byte(value)
			k := all[0]
			v := all[1:]
			map_value[k] = v

		}
	}

	if number_valid_location < int(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)

	//use decrypt to unencrypt vdo.Ciphertext.
	data = decrypt(real_key, vdo.Ciphertext)

	return
}
예제 #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()
	}
}