|
@@ -10,7 +10,7 @@ package main
|
|
*/
|
|
*/
|
|
import "C"
|
|
import "C"
|
|
|
|
|
|
-
|
|
+
|
|
import (
|
|
import (
|
|
lib "2PPS/lib"
|
|
lib "2PPS/lib"
|
|
"bytes"
|
|
"bytes"
|
|
@@ -23,6 +23,7 @@ import (
|
|
mr "math/rand"
|
|
mr "math/rand"
|
|
"net"
|
|
"net"
|
|
"sort"
|
|
"sort"
|
|
|
|
+ "strconv"
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
"time"
|
|
"time"
|
|
@@ -40,7 +41,11 @@ const leader string = "127.0.0.1:4441"
|
|
|
|
|
|
|
|
|
|
const neededSubscriptions = 1
|
|
const neededSubscriptions = 1
|
|
-const numClients = 1
|
|
+const numClients = 2
|
|
|
|
+const dataLength int = 64
|
|
|
|
+const numThreads int = 12
|
|
|
|
+
|
|
|
|
+var dbWriteSize int = 4
|
|
|
|
|
|
var topicList []string
|
|
var topicList []string
|
|
var archiveTopicList []string
|
|
var archiveTopicList []string
|
|
@@ -51,66 +56,22 @@ var sharedSecret [numClients][2][32]byte = createSharedSecret()
|
|
|
|
|
|
var wantsArchive = make([]byte, 1)
|
|
var wantsArchive = make([]byte, 1)
|
|
|
|
|
|
-var dataLen int = 64
|
|
|
|
-var numThreads int = 12
|
|
|
|
-var dbWriteSize int = 4
|
|
|
|
-
|
|
|
|
var leaderPublicKey *[32]byte
|
|
var leaderPublicKey *[32]byte
|
|
var followerPublicKey *[32]byte
|
|
var followerPublicKey *[32]byte
|
|
var clientPrivateKey *[32]byte
|
|
var clientPrivateKey *[32]byte
|
|
var clientPublicKey *[32]byte
|
|
var clientPublicKey *[32]byte
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
-
|
|
|
|
-
|
|
|
|
- tweets := make([][]byte, numClients)
|
|
|
|
- for i := range tweets {
|
|
|
|
- tweets[i] = make([]byte, dataLen)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for i := 0; i < numClients; i++ {
|
|
|
|
- var tweet []byte
|
|
|
|
- if i == 0 {
|
|
|
|
- topics := []byte("house, mouse;")
|
|
|
|
- text := []byte("I am a house in a mouse;")
|
|
|
|
- tweet = append(tweet, topics...)
|
|
|
|
- tweet = append(tweet, text...)
|
|
|
|
- }
|
|
|
|
- tweet = append(tweet, []byte(";")[0])
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- length := dataLen - len(tweet)
|
|
|
|
- padding := make([]byte, length)
|
|
|
|
- rand.Read(padding)
|
|
|
|
- tweet = append(tweet, padding...)
|
|
|
|
-
|
|
|
|
- tweets[i] = tweet
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
wg := &sync.WaitGroup{}
|
|
wg := &sync.WaitGroup{}
|
|
|
|
|
|
for i := 0; i < numClients; i++ {
|
|
for i := 0; i < numClients; i++ {
|
|
wg.Add(1)
|
|
wg.Add(1)
|
|
- go client(tweets[i], i)
|
|
+ go client(i)
|
|
}
|
|
}
|
|
wg.Wait()
|
|
wg.Wait()
|
|
}
|
|
}
|
|
|
|
|
|
-func client(tweet []byte, clientNumber int) {
|
|
+func client(clientNumber int) {
|
|
-
|
|
|
|
-
|
|
|
|
- if len(os.Args) != 4 {
|
|
|
|
- fmt.Println("try again with: numThreads, dataLength, numRows")
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- serverAmount, _ = strconv.Atoi(os.Args[1])
|
|
|
|
- serverAmount++
|
|
|
|
- dataLen, _ = strconv.Atoi(os.Args[2])
|
|
|
|
- numThreads, _ = strconv.Atoi(os.Args[3])
|
|
|
|
- dbSize, _ = strconv.Atoi(os.Args[4])
|
|
|
|
- */
|
|
|
|
|
|
|
|
generatedPublicKey, generatedPrivateKey, err := box.GenerateKey(rand.Reader)
|
|
generatedPublicKey, generatedPrivateKey, err := box.GenerateKey(rand.Reader)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -181,6 +142,8 @@ func client(tweet []byte, clientNumber int) {
|
|
sendQuerys(encryptedQueryLeader, encryptedQueryFollower, leaderConn, false)
|
|
sendQuerys(encryptedQueryLeader, encryptedQueryFollower, leaderConn, false)
|
|
pos := receiveVirtualAddress(sharedSecret[clientNumber], leaderConn)
|
|
pos := receiveVirtualAddress(sharedSecret[clientNumber], leaderConn)
|
|
|
|
|
|
|
|
+ tweet := getTweet(clientNumber)
|
|
|
|
+
|
|
|
|
|
|
dataSize := len(tweet)
|
|
dataSize := len(tweet)
|
|
querySize := make([]byte, 4)
|
|
querySize := make([]byte, 4)
|
|
@@ -294,11 +257,17 @@ func createPIRQuery(subPhase int, clientNumber int) ([]byte, []byte) {
|
|
copy(tmptopicsOfInterest, topicsOfInterest)
|
|
copy(tmptopicsOfInterest, topicsOfInterest)
|
|
|
|
|
|
tmpNeededSubscriptions := neededSubscriptions
|
|
tmpNeededSubscriptions := neededSubscriptions
|
|
|
|
+ if tmpNeededSubscriptions > len(topicList) {
|
|
|
|
+ tmpNeededSubscriptions = len(topicList)
|
|
|
|
+ }
|
|
|
|
|
|
tmpTopicList := make([]string, len(topicList))
|
|
tmpTopicList := make([]string, len(topicList))
|
|
copy(tmpTopicList, topicList)
|
|
copy(tmpTopicList, topicList)
|
|
if wantsArchive[0] == 1 && subPhase == -1 {
|
|
if wantsArchive[0] == 1 && subPhase == -1 {
|
|
tmpNeededSubscriptions = len(archiveInterests)
|
|
tmpNeededSubscriptions = len(archiveInterests)
|
|
|
|
+ if tmpNeededSubscriptions > len(archiveTopicList) {
|
|
|
|
+ tmpNeededSubscriptions = len(archiveTopicList)
|
|
|
|
+ }
|
|
copy(tmptopicsOfInterest, archiveInterests)
|
|
copy(tmptopicsOfInterest, archiveInterests)
|
|
copy(tmpTopicList, archiveTopicList)
|
|
copy(tmpTopicList, archiveTopicList)
|
|
}
|
|
}
|
|
@@ -310,12 +279,11 @@ func createPIRQuery(subPhase int, clientNumber int) ([]byte, []byte) {
|
|
|
|
|
|
|
|
|
|
if len(tmptopicsOfInterest) < tmpNeededSubscriptions && subPhase != -1 {
|
|
if len(tmptopicsOfInterest) < tmpNeededSubscriptions && subPhase != -1 {
|
|
- tmptopicsOfInterest = addFakeInterests(neededSubscriptions, len(tmpTopicList), tmptopicsOfInterest, false)
|
|
+ tmptopicsOfInterest = addFakeInterests(len(tmpTopicList), tmptopicsOfInterest, false)
|
|
}
|
|
}
|
|
|
|
|
|
for topic, position := range tmptopicsOfInterest {
|
|
for topic, position := range tmptopicsOfInterest {
|
|
-
|
|
+ topicsOfInterestAsBytes[topic][position] = 1
|
|
- topicsOfInterestAsBytes[topic][position-1] = 1
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -414,8 +382,14 @@ func receiveVirtualAddress(sharedSecret [2][32]byte, leaderConn net.Conn) int {
|
|
func receiveTweets(sharedSecret [2][32]byte, leaderConn net.Conn, getArchive bool) int {
|
|
func receiveTweets(sharedSecret [2][32]byte, leaderConn net.Conn, getArchive bool) int {
|
|
|
|
|
|
tmpNeededSubscriptions := neededSubscriptions
|
|
tmpNeededSubscriptions := neededSubscriptions
|
|
|
|
+ if tmpNeededSubscriptions > len(topicList) {
|
|
|
|
+ tmpNeededSubscriptions = len(topicList)
|
|
|
|
+ }
|
|
if getArchive {
|
|
if getArchive {
|
|
tmpNeededSubscriptions = len(archiveInterests)
|
|
tmpNeededSubscriptions = len(archiveInterests)
|
|
|
|
+ if tmpNeededSubscriptions > len(archiveTopicList) {
|
|
|
|
+ tmpNeededSubscriptions = len(archiveTopicList)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
for i := 0; i < tmpNeededSubscriptions; i++ {
|
|
for i := 0; i < tmpNeededSubscriptions; i++ {
|
|
|
|
|
|
@@ -441,10 +415,8 @@ func receiveTweets(sharedSecret [2][32]byte, leaderConn net.Conn, getArchive boo
|
|
|
|
|
|
|
|
|
|
split := strings.Split(string(tweets), ";")
|
|
split := strings.Split(string(tweets), ";")
|
|
- topic := split[0]
|
|
+ text := split[:len(split)-1]
|
|
- text := split[1]
|
|
+ fmt.Println(text)
|
|
- fmt.Println("Topics: ", topic)
|
|
|
|
- fmt.Println("Text: ", text)
|
|
|
|
}
|
|
}
|
|
return 0
|
|
return 0
|
|
}
|
|
}
|
|
@@ -512,12 +484,17 @@ func createAuditPIRQuery(clientNumber int) ([]byte, []byte) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-func addFakeInterests(length, max int, topicsOfInterest []int, doAuditing bool) []int {
|
|
+func addFakeInterests(max int, topicsOfInterest []int, doAuditing bool) []int {
|
|
- fakeTopicsOfInterest := make([]int, length)
|
|
+ tmpNeededSubscriptions := neededSubscriptions
|
|
|
|
+ if tmpNeededSubscriptions > len(topicList) {
|
|
|
|
+ tmpNeededSubscriptions = len(topicList)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fakeTopicsOfInterest := make([]int, tmpNeededSubscriptions)
|
|
maxInt := max
|
|
maxInt := max
|
|
|
|
|
|
|
|
|
|
- for i := 0; i < length; i++ {
|
|
+ for i := 0; i < tmpNeededSubscriptions; i++ {
|
|
fakeTopicsOfInterest[i] = mr.Intn(maxInt)
|
|
fakeTopicsOfInterest[i] = mr.Intn(maxInt)
|
|
|
|
|
|
for j := 0; j < i; j++ {
|
|
for j := 0; j < i; j++ {
|
|
@@ -538,7 +515,7 @@ func addFakeInterests(length, max int, topicsOfInterest []int, doAuditing bool)
|
|
if !inList(number, topicsOfInterest) {
|
|
if !inList(number, topicsOfInterest) {
|
|
topicsOfInterest = append(topicsOfInterest, number)
|
|
topicsOfInterest = append(topicsOfInterest, number)
|
|
}
|
|
}
|
|
- if len(topicsOfInterest) == neededSubscriptions {
|
|
+ if len(topicsOfInterest) == tmpNeededSubscriptions {
|
|
break
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -574,6 +551,26 @@ func receiveTopicLists(leaderConn net.Conn) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func getTweet(clientNumber int) []byte {
|
|
|
|
+ var tweet []byte
|
|
|
|
+
|
|
|
|
+ r := mr.New(mr.NewSource(time.Now().UnixNano()))
|
|
|
|
+
|
|
|
|
+ topics := []byte("house, mouse;")
|
|
|
|
+ text := []byte("I am a house in a mouse " + strconv.Itoa(r.Intn(100)) + ";")
|
|
|
|
+ tweet = append(tweet, topics...)
|
|
|
|
+ tweet = append(tweet, text...)
|
|
|
|
+ tweet = append(tweet, []byte(";")[0])
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ length := dataLength - len(tweet)
|
|
|
|
+ padding := make([]byte, length)
|
|
|
|
+ rand.Read(padding)
|
|
|
|
+ tweet = append(tweet, padding...)
|
|
|
|
+
|
|
|
|
+ return tweet
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
func writeToConn(connection net.Conn, array []byte) {
|
|
func writeToConn(connection net.Conn, array []byte) {
|
|
_, err := connection.Write(array)
|
|
_, err := connection.Write(array)
|