|
@@ -40,15 +40,15 @@ type tweet struct {
|
|
|
const leader string = "127.0.0.1:4441"
|
|
|
|
|
|
//needs to be changed at leader/follower/client at the same time
|
|
|
-const neededSubscriptions = 1
|
|
|
-const numClients = 1
|
|
|
+const numClients = 50
|
|
|
const dataLength int = 128
|
|
|
const numThreads int = 12
|
|
|
|
|
|
-var dbWriteSize int = 100
|
|
|
+var dbWriteSize int
|
|
|
var round int
|
|
|
var topicList []string
|
|
|
var archiveTopicList []string
|
|
|
+var neededSubscriptions int
|
|
|
|
|
|
//todo! expand this for multiple clients
|
|
|
var archiveInterests = make([]int, 1)
|
|
@@ -58,8 +58,8 @@ var wantsArchive = make([]byte, 1)
|
|
|
|
|
|
var leaderPublicKey *[32]byte
|
|
|
var followerPublicKey *[32]byte
|
|
|
-var clientPrivateKey *[32]byte
|
|
|
-var clientPublicKey *[32]byte
|
|
|
+var clientPrivateKey [numClients]*[32]byte
|
|
|
+var clientPublicKey [numClients]*[32]byte
|
|
|
|
|
|
func main() {
|
|
|
wg := &sync.WaitGroup{}
|
|
@@ -77,8 +77,8 @@ func client(clientNumber int) {
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
|
- clientPrivateKey = generatedPrivateKey
|
|
|
- clientPublicKey = generatedPublicKey
|
|
|
+ clientPrivateKey[clientNumber] = generatedPrivateKey
|
|
|
+ clientPublicKey[clientNumber] = generatedPublicKey
|
|
|
|
|
|
C.initializeCipher()
|
|
|
|
|
@@ -112,7 +112,10 @@ func client(clientNumber int) {
|
|
|
followerPublicKey = &tmpFollowerPubKey
|
|
|
|
|
|
//sends own public key
|
|
|
- writeTo(leaderConn, clientPublicKey[:])
|
|
|
+ writeTo(leaderConn, clientPublicKey[clientNumber][:])
|
|
|
+
|
|
|
+ neededSubscriptionsBytes := readFrom(leaderConn, 4)
|
|
|
+ neededSubscriptions = byteToInt(neededSubscriptionsBytes)
|
|
|
|
|
|
//setup ends above
|
|
|
//while client is active he is always connected and has to participate
|
|
@@ -121,7 +124,7 @@ func client(clientNumber int) {
|
|
|
//gets current phase
|
|
|
phase := readFrom(leaderConn, 1)
|
|
|
|
|
|
- fmt.Println("Phase ", phase[0])
|
|
|
+ //fmt.Println("Phase ", phase[0])
|
|
|
|
|
|
if phase[0] == 1 {
|
|
|
|
|
@@ -168,7 +171,7 @@ func client(clientNumber int) {
|
|
|
if err != nil {
|
|
|
panic("couldn't get randomness for nonce!")
|
|
|
}
|
|
|
- dpfQueryAEncrypted := box.Seal(nonce[:], queryAPlaintext, &nonce, leaderPublicKey, clientPrivateKey)
|
|
|
+ dpfQueryAEncrypted := box.Seal(nonce[:], queryAPlaintext, &nonce, leaderPublicKey, clientPrivateKey[clientNumber])
|
|
|
|
|
|
//encrypts queryB and appends it to message
|
|
|
queryBPlaintext := C.GoBytes(unsafe.Pointer(dpfQueryB), C.int(intQuerySize))
|
|
@@ -178,7 +181,7 @@ func client(clientNumber int) {
|
|
|
if err != nil {
|
|
|
panic("couldn't get randomness for nonce!")
|
|
|
}
|
|
|
- dpfQueryBEncrypted := box.Seal(nonce[:], queryBPlaintext, &nonce, followerPublicKey, clientPrivateKey)
|
|
|
+ dpfQueryBEncrypted := box.Seal(nonce[:], queryBPlaintext, &nonce, followerPublicKey, clientPrivateKey[clientNumber])
|
|
|
|
|
|
//writes the dpfQuery to the leader
|
|
|
dpfLengthBytes := intToByte(len(dpfQueryAEncrypted))
|
|
@@ -250,19 +253,21 @@ func client(clientNumber int) {
|
|
|
//creates and sends the pirQuerys for each server
|
|
|
func createPIRQuery(subPhase int, clientNumber int) ([]byte, []byte) {
|
|
|
//later this will be taken from gui, this is only for testing
|
|
|
- topicsOfInterest := make([]int, 1)
|
|
|
- topicsOfInterest[0] = 1
|
|
|
-
|
|
|
+ topicsOFInterest := make([]int, 10)
|
|
|
+ topicsOFInterest[0] = 1
|
|
|
+ topicsOFInterest[1] = 1
|
|
|
+ topicsOFInterest[9] = 1
|
|
|
archiveInterests[0] = 1
|
|
|
|
|
|
- tmptopicsOfInterest := make([]int, len(topicsOfInterest))
|
|
|
- copy(tmptopicsOfInterest, topicsOfInterest)
|
|
|
-
|
|
|
+ //todo! repeat for archive
|
|
|
tmpNeededSubscriptions := neededSubscriptions
|
|
|
if tmpNeededSubscriptions > len(topicList) {
|
|
|
tmpNeededSubscriptions = len(topicList)
|
|
|
}
|
|
|
|
|
|
+ tmptopicsOfInterest := make([]int, len(topicList))
|
|
|
+ copy(tmptopicsOfInterest, topicsOFInterest)
|
|
|
+
|
|
|
tmpTopicList := make([]string, len(topicList))
|
|
|
copy(tmpTopicList, topicList)
|
|
|
if wantsArchive[0] == 1 && subPhase == -1 {
|
|
@@ -274,26 +279,15 @@ func createPIRQuery(subPhase int, clientNumber int) ([]byte, []byte) {
|
|
|
copy(tmpTopicList, archiveTopicList)
|
|
|
}
|
|
|
|
|
|
- topicsOfInterestAsBytes := make([][]byte, tmpNeededSubscriptions)
|
|
|
- for i := range topicsOfInterestAsBytes {
|
|
|
- topicsOfInterestAsBytes[i] = make([]byte, len(tmpTopicList))
|
|
|
- }
|
|
|
-
|
|
|
//creates fake topicsOfInterest if client is boooring
|
|
|
if len(tmptopicsOfInterest) < tmpNeededSubscriptions && subPhase != -1 {
|
|
|
tmptopicsOfInterest = addFakeInterests(len(tmpTopicList), tmptopicsOfInterest, false)
|
|
|
}
|
|
|
|
|
|
- for topic, position := range tmptopicsOfInterest {
|
|
|
- if position > 0 {
|
|
|
- topicsOfInterestAsBytes[topic][position-1] = 1
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //pirQuery [serverAmount][topicsofinterest][topicAmount]byte
|
|
|
- pirQuerys := make([][][]byte, 2)
|
|
|
+ //pirQuery [topicsofinterest][serverAmount][topicAmount]byte
|
|
|
+ pirQuerys := make([][][]byte, len(tmptopicsOfInterest))
|
|
|
for i := range pirQuerys {
|
|
|
- pirQuerys[i] = make([][]byte, len(tmptopicsOfInterest))
|
|
|
+ pirQuerys[i] = make([][]byte, 2)
|
|
|
for j := range pirQuerys[i] {
|
|
|
pirQuerys[i][j] = make([]byte, len(tmpTopicList))
|
|
|
}
|
|
@@ -307,19 +301,33 @@ func createPIRQuery(subPhase int, clientNumber int) ([]byte, []byte) {
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
|
- pirQuerys[0][topic][index] = byte(bit.Int64())
|
|
|
+ pirQuerys[topic][0][index] = byte(bit.Int64())
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tmptopicsOfInterestBytes := make([]byte, tmpNeededSubscriptions)
|
|
|
+ for index := range tmptopicsOfInterestBytes {
|
|
|
+ if tmptopicsOfInterest[index] == 1 {
|
|
|
+ tmptopicsOfInterestBytes[index] = 1
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //creating last manually with result and wanted
|
|
|
- //if position random result correct -> 0, not correct -> 1
|
|
|
for topic := range tmptopicsOfInterest {
|
|
|
for index := range tmpTopicList {
|
|
|
- if pirQuerys[0][topic][index] == topicsOfInterestAsBytes[topic][index] {
|
|
|
- pirQuerys[1][topic][index] = 0
|
|
|
+ if topic == index {
|
|
|
+ if pirQuerys[topic][0][index] == 1 {
|
|
|
+ pirQuerys[topic][1][index] = 0
|
|
|
+ } else {
|
|
|
+ pirQuerys[topic][1][index] = 1
|
|
|
+ }
|
|
|
} else {
|
|
|
- pirQuerys[1][topic][index] = 1
|
|
|
+ if pirQuerys[topic][0][index] == 0 {
|
|
|
+ pirQuerys[topic][1][index] = 0
|
|
|
+ } else {
|
|
|
+ pirQuerys[topic][1][index] = 1
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -332,9 +340,9 @@ func createPIRQuery(subPhase int, clientNumber int) ([]byte, []byte) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for server := 0; server < 2; server++ {
|
|
|
- for topic := range pirQuerys[server] {
|
|
|
- messagesFlattened[server] = append(messagesFlattened[server], pirQuerys[server][topic][:]...)
|
|
|
+ for server := range messagesFlattened {
|
|
|
+ for topic := range pirQuerys {
|
|
|
+ messagesFlattened[server] = append(messagesFlattened[server], pirQuerys[topic][server]...)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -343,13 +351,13 @@ func createPIRQuery(subPhase int, clientNumber int) ([]byte, []byte) {
|
|
|
if err != nil {
|
|
|
panic("couldn't get randomness for nonce!")
|
|
|
}
|
|
|
- encryptedQueryLeader := box.Seal(nonce[:], messagesFlattened[0], &nonce, leaderPublicKey, clientPrivateKey)
|
|
|
+ encryptedQueryLeader := box.Seal(nonce[:], messagesFlattened[0], &nonce, leaderPublicKey, clientPrivateKey[clientNumber])
|
|
|
|
|
|
_, err = rand.Read(nonce[:])
|
|
|
if err != nil {
|
|
|
panic("couldn't get randomness for nonce!")
|
|
|
}
|
|
|
- encryptedQueryFollower := box.Seal(nonce[:], messagesFlattened[1], &nonce, followerPublicKey, clientPrivateKey)
|
|
|
+ encryptedQueryFollower := box.Seal(nonce[:], messagesFlattened[1], &nonce, followerPublicKey, clientPrivateKey[clientNumber])
|
|
|
|
|
|
return encryptedQueryLeader, encryptedQueryFollower
|
|
|
}
|
|
@@ -402,6 +410,8 @@ func receiveTweets(sharedSecret [2][32]byte, leaderConn net.Conn, getArchive boo
|
|
|
|
|
|
tweets := readFrom(leaderConn, tweetsLength)
|
|
|
|
|
|
+ //fmt.Println(tweets[:10])
|
|
|
+
|
|
|
//expand sharedSecret so it is of right length
|
|
|
expandBy := len(tweets) / 32
|
|
|
expandedSharedSecrets := make([][]byte, 2)
|
|
@@ -420,9 +430,11 @@ func receiveTweets(sharedSecret [2][32]byte, leaderConn net.Conn, getArchive boo
|
|
|
index := strings.Index(string(tweets), ";;;")
|
|
|
if index != -1 {
|
|
|
text := string(tweets)[:index]
|
|
|
- fmt.Println("received in round", round, "Text", text)
|
|
|
+ fmt.Println("received in round", round, "Text", text, len(tweets))
|
|
|
} else {
|
|
|
- fmt.Println("received text not of correct format", round, "Text:", string(tweets))
|
|
|
+ fmt.Println("Round", round, "Text:", string(tweets))
|
|
|
+ fmt.Println("länge", byteToInt(tweetsLengthBytes))
|
|
|
+ panic("received text not of correct format")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -478,13 +490,13 @@ func createAuditPIRQuery(clientNumber int) ([]byte, []byte) {
|
|
|
if err != nil {
|
|
|
panic("couldn't get randomness for nonce!")
|
|
|
}
|
|
|
- encryptedQueryLeader := box.Seal(nonce[:], messagesFlattened[0], &nonce, leaderPublicKey, clientPrivateKey)
|
|
|
+ encryptedQueryLeader := box.Seal(nonce[:], messagesFlattened[0], &nonce, leaderPublicKey, clientPrivateKey[clientNumber])
|
|
|
|
|
|
_, err = rand.Read(nonce[:])
|
|
|
if err != nil {
|
|
|
panic("couldn't get randomness for nonce!")
|
|
|
}
|
|
|
- encryptedQueryFollower := box.Seal(nonce[:], messagesFlattened[1], &nonce, followerPublicKey, clientPrivateKey)
|
|
|
+ encryptedQueryFollower := box.Seal(nonce[:], messagesFlattened[1], &nonce, followerPublicKey, clientPrivateKey[clientNumber])
|
|
|
|
|
|
return encryptedQueryLeader, encryptedQueryFollower
|
|
|
}
|
|
@@ -562,7 +574,7 @@ func getTweet(clientNumber int) []byte {
|
|
|
|
|
|
r := mr.New(mr.NewSource(time.Now().UnixNano()))
|
|
|
|
|
|
- maxTopics := r.Intn(4)
|
|
|
+ maxTopics := r.Intn(6)
|
|
|
if maxTopics == 0 {
|
|
|
maxTopics = 1
|
|
|
}
|
|
@@ -581,8 +593,7 @@ func getTweet(clientNumber int) []byte {
|
|
|
}
|
|
|
|
|
|
sort.Ints(topicNumbers)
|
|
|
- fmt.Println("Writing to", topicNumbers)
|
|
|
-
|
|
|
+ //fmt.Println("topicNumbers", topicNumbers)
|
|
|
var topics []byte
|
|
|
|
|
|
topicIndex := 0
|
|
@@ -597,11 +608,13 @@ func getTweet(clientNumber int) []byte {
|
|
|
|
|
|
topics = append(topics, []byte(";")[0])
|
|
|
|
|
|
- text := []byte("I am a house in a mouse " + strconv.Itoa(r.Intn(10000)) + ";")
|
|
|
+ text := []byte(strconv.Itoa(r.Intn(10000)) + ";")
|
|
|
tweet = append(tweet, topics...)
|
|
|
tweet = append(tweet, text...)
|
|
|
tweet = append(tweet, []byte(";")[0])
|
|
|
|
|
|
+ //fmt.Println("writing", string(text))
|
|
|
+
|
|
|
//adds padding
|
|
|
length := dataLength - len(tweet)
|
|
|
padding := make([]byte, length)
|
|
@@ -626,6 +639,7 @@ func readFrom(connection net.Conn, size int) []byte {
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
|
+
|
|
|
return array
|
|
|
}
|
|
|
|