|
@@ -17,12 +17,13 @@ import (
|
|
"crypto/x509/pkix"
|
|
"crypto/x509/pkix"
|
|
"encoding/pem"
|
|
"encoding/pem"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "log"
|
|
"math"
|
|
"math"
|
|
"math/big"
|
|
"math/big"
|
|
mr "math/rand"
|
|
mr "math/rand"
|
|
"net"
|
|
"net"
|
|
|
|
+ "os"
|
|
"sort"
|
|
"sort"
|
|
- "strconv"
|
|
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
"time"
|
|
"time"
|
|
@@ -52,23 +53,25 @@ var leaderPrivateKey *[32]byte
|
|
var leaderPublicKey *[32]byte
|
|
var leaderPublicKey *[32]byte
|
|
var followerPublicKey *[32]byte
|
|
var followerPublicKey *[32]byte
|
|
|
|
|
|
-const maxNumberOfClients = 10000000
|
|
|
|
|
|
+const maxNumberOfClients = 1000000
|
|
|
|
|
|
var topicList []byte
|
|
var topicList []byte
|
|
var topicAmount int
|
|
var topicAmount int
|
|
var archiveTopicAmount int
|
|
var archiveTopicAmount int
|
|
|
|
|
|
// every roundsBeforeUpdate the client updates his pirQuery
|
|
// every roundsBeforeUpdate the client updates his pirQuery
|
|
-const roundsBeforeUpdate = 3
|
|
|
|
-const neededSubscriptions = 4
|
|
|
|
|
|
+const roundsBeforeUpdate = 2
|
|
|
|
+const neededSubscriptions = 5
|
|
const numThreads = 12
|
|
const numThreads = 12
|
|
const dataLength = 256
|
|
const dataLength = 256
|
|
const minDBWriteSize = 1000
|
|
const minDBWriteSize = 1000
|
|
|
|
|
|
var dbWriteSize float64 = 10000
|
|
var dbWriteSize float64 = 10000
|
|
-var collisionCounter []float64
|
|
|
|
|
|
|
|
-var clientsConnected int
|
|
|
|
|
|
+//this is the number of positions for auditing
|
|
|
|
+var extraPositions int = 2
|
|
|
|
+var collisionCounter []float64
|
|
|
|
+var clientsConnected float64
|
|
|
|
|
|
var maxTimePerRound time.Duration = 10 * time.Second
|
|
var maxTimePerRound time.Duration = 10 * time.Second
|
|
|
|
|
|
@@ -80,7 +83,7 @@ var startPhase2 time.Time
|
|
var startPhase3 time.Time
|
|
var startPhase3 time.Time
|
|
|
|
|
|
//counts the number of rounds
|
|
//counts the number of rounds
|
|
-var round int = 0
|
|
|
|
|
|
+var round int
|
|
|
|
|
|
var startTime time.Time
|
|
var startTime time.Time
|
|
var startTimeRound time.Time
|
|
var startTimeRound time.Time
|
|
@@ -95,8 +98,30 @@ const publisherRounds int = 10
|
|
var publisherAmount float64
|
|
var publisherAmount float64
|
|
var publisherHistory [publisherRounds]int
|
|
var publisherHistory [publisherRounds]int
|
|
|
|
|
|
|
|
+//only prints auditing time for one client per round
|
|
|
|
+var firstAuditPrint bool
|
|
|
|
+var auditingStart time.Time
|
|
|
|
+var auditingEnd time.Time
|
|
|
|
+
|
|
|
|
+var firstTweetSend bool
|
|
|
|
+
|
|
func main() {
|
|
func main() {
|
|
|
|
|
|
|
|
+ f, err := os.OpenFile("evalData", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Fatalf("error opening file: %v", err)
|
|
|
|
+ }
|
|
|
|
+ defer f.Close()
|
|
|
|
+
|
|
|
|
+ log.SetOutput(f)
|
|
|
|
+ log.Println("roundsBeforeUpdate", roundsBeforeUpdate)
|
|
|
|
+ log.Println("neededSubscriptions", neededSubscriptions)
|
|
|
|
+ log.Println("dataLength", dataLength)
|
|
|
|
+ log.Println("maxTimePerRound~", maxTimePerRound*3)
|
|
|
|
+ log.Println("extraPositions", extraPositions)
|
|
|
|
+ log.Println("numClients", 500)
|
|
|
|
+ log.Println("Archiving is done every 24h, no Clients wants Archive")
|
|
|
|
+
|
|
//prevents race conditions for wrtiting
|
|
//prevents race conditions for wrtiting
|
|
m := &sync.RWMutex{}
|
|
m := &sync.RWMutex{}
|
|
|
|
|
|
@@ -258,10 +283,6 @@ func main() {
|
|
|
|
|
|
phase1Channel <- clientConnection
|
|
phase1Channel <- clientConnection
|
|
clientsConnected++
|
|
clientsConnected++
|
|
-
|
|
|
|
- if clientsConnected%1000 == 0 {
|
|
|
|
- fmt.Println("clientsConnected", clientsConnected)
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
|
|
|
|
@@ -282,7 +303,12 @@ func main() {
|
|
fmt.Println("clientsServedPhase3", clientsServedPhase3[round-1])
|
|
fmt.Println("clientsServedPhase3", clientsServedPhase3[round-1])
|
|
fmt.Println("dbWriteSize", dbWriteSize)
|
|
fmt.Println("dbWriteSize", dbWriteSize)
|
|
|
|
|
|
- fmt.Println("Phase 1 Round", round)
|
|
|
|
|
|
+ log.Println()
|
|
|
|
+ log.Println("Phase 1 Round", round)
|
|
|
|
+ log.Println()
|
|
|
|
+ bytesSaved := lib.GetBytesSaved()
|
|
|
|
+ log.Println("bytesSaved Percentage", bytesSaved)
|
|
|
|
+ firstAuditPrint = true
|
|
|
|
|
|
//creates a new write Db for this round
|
|
//creates a new write Db for this round
|
|
for i := 0; i < int(dbWriteSize); i++ {
|
|
for i := 0; i < int(dbWriteSize); i++ {
|
|
@@ -320,7 +346,9 @@ func main() {
|
|
|
|
|
|
wg.Wait()
|
|
wg.Wait()
|
|
|
|
|
|
- fmt.Println("fullDurationPhase1", time.Since(startPhase1).Seconds())
|
|
|
|
|
|
+ //log.Println("fullDurationPhase1", time.Since(startPhase1).Seconds())
|
|
|
|
+ log.Println("fullAuditingDuration~", auditingEnd.Sub(auditingStart).Seconds()*clientsConnected)
|
|
|
|
+ log.Println("auditingPercentage", (auditingEnd.Sub(auditingStart).Seconds()*clientsConnected)/(time.Since(startPhase1).Seconds()))
|
|
|
|
|
|
//Phase 2
|
|
//Phase 2
|
|
|
|
|
|
@@ -334,7 +362,7 @@ func main() {
|
|
|
|
|
|
phase2(followerConnection)
|
|
phase2(followerConnection)
|
|
|
|
|
|
- fmt.Println("fullDurationPhase2", time.Since(startPhase2).Seconds())
|
|
|
|
|
|
+ //log.Println("fullDurationPhase2", time.Since(startPhase2).Seconds())
|
|
|
|
|
|
//Phase 3
|
|
//Phase 3
|
|
|
|
|
|
@@ -356,6 +384,8 @@ func main() {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ firstTweetSend = true
|
|
|
|
+
|
|
phase[0] = 3
|
|
phase[0] = 3
|
|
startTimeRound = time.Now()
|
|
startTimeRound = time.Now()
|
|
|
|
|
|
@@ -372,7 +402,7 @@ func main() {
|
|
|
|
|
|
wg.Wait()
|
|
wg.Wait()
|
|
|
|
|
|
- fmt.Println("fullDurationPhase3", time.Since(startPhase3).Seconds())
|
|
|
|
|
|
+ log.Println("fullDurationPhase3", time.Since(startPhase3).Seconds())
|
|
|
|
|
|
lib.CleanUpdbR(round)
|
|
lib.CleanUpdbR(round)
|
|
}
|
|
}
|
|
@@ -398,11 +428,6 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
for clientConnection := range phase1Channel {
|
|
for clientConnection := range phase1Channel {
|
|
clientsServedPhase1[round] = clientsServedPhase1[round] + 1
|
|
clientsServedPhase1[round] = clientsServedPhase1[round] + 1
|
|
|
|
|
|
- if clientsServedPhase1[round]%1000 == 0 {
|
|
|
|
- fmt.Println("clientsServedPhase1", clientsServedPhase1[round])
|
|
|
|
- fmt.Println("timeTaken", time.Since(startPhase1))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
gotClient[0] = 1
|
|
gotClient[0] = 1
|
|
//tells follower that this worker got a clientConnection
|
|
//tells follower that this worker got a clientConnection
|
|
writeTo(followerConnection, gotClient)
|
|
writeTo(followerConnection, gotClient)
|
|
@@ -454,7 +479,9 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
}
|
|
}
|
|
|
|
|
|
//begin auditing
|
|
//begin auditing
|
|
- //auditingStart := time.Now()
|
|
|
|
|
|
+ if id == 0 && firstAuditPrint {
|
|
|
|
+ auditingStart = time.Now()
|
|
|
|
+ }
|
|
m.RLock()
|
|
m.RLock()
|
|
var clientKeys = clientData[clientConnection.RemoteAddr()]
|
|
var clientKeys = clientData[clientConnection.RemoteAddr()]
|
|
m.RUnlock()
|
|
m.RUnlock()
|
|
@@ -477,8 +504,10 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if id == 0 {
|
|
|
|
- //fmt.Println("Auditing duration", time.Since(auditingStart).Seconds())
|
|
|
|
|
|
+ if id == 0 && firstAuditPrint {
|
|
|
|
+ firstAuditPrint = false
|
|
|
|
+ auditingEnd = time.Now()
|
|
|
|
+ log.Println("Auditing duration", time.Since(auditingStart).Seconds(), "numVirtualAddresses", len(virtualAddresses))
|
|
}
|
|
}
|
|
|
|
|
|
m.Lock()
|
|
m.Lock()
|
|
@@ -673,7 +702,7 @@ func phase2(followerConnection net.Conn) {
|
|
}
|
|
}
|
|
|
|
|
|
var tweets []lib.Tweet
|
|
var tweets []lib.Tweet
|
|
- var currentPublisherAmount int = 0
|
|
|
|
|
|
+ var currentPublisherAmount float64
|
|
var collisions float64
|
|
var collisions float64
|
|
for i := 0; i < dbSize; i++ {
|
|
for i := 0; i < dbSize; i++ {
|
|
//discard cover message
|
|
//discard cover message
|
|
@@ -730,23 +759,17 @@ func phase2(followerConnection net.Conn) {
|
|
|
|
|
|
collisionCounter = append(collisionCounter, collisions)
|
|
collisionCounter = append(collisionCounter, collisions)
|
|
|
|
|
|
- if collisions/dbWriteSize > 0.05 {
|
|
|
|
- fmt.Println("Collision % this round", collisions/dbWriteSize, "dbWriteSize", dbWriteSize)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //fmt.Println("tweets recovered: ", tweets)
|
|
|
|
|
|
+ log.Println("Collision percentage this round", collisions/dbWriteSize, "dbWriteSize", dbWriteSize)
|
|
|
|
|
|
- //sort into read db
|
|
|
|
- //fmt.Println("newTweets", tweets)
|
|
|
|
lib.NewEntries(tweets, 0)
|
|
lib.NewEntries(tweets, 0)
|
|
|
|
|
|
C.resetDb()
|
|
C.resetDb()
|
|
|
|
|
|
//calculates the publisherAverage over the last publisherRounds rounds
|
|
//calculates the publisherAverage over the last publisherRounds rounds
|
|
index := round % publisherRounds
|
|
index := round % publisherRounds
|
|
- publisherHistory[index] = currentPublisherAmount
|
|
|
|
|
|
+ publisherHistory[index] = int(currentPublisherAmount)
|
|
|
|
|
|
- fmt.Println("currentPublisherAmount", currentPublisherAmount)
|
|
|
|
|
|
+ log.Println("currentPublisherAmount", currentPublisherAmount, "publisher percentage", currentPublisherAmount/clientsConnected)
|
|
|
|
|
|
var publisherAmount int
|
|
var publisherAmount int
|
|
for _, num := range publisherHistory {
|
|
for _, num := range publisherHistory {
|
|
@@ -773,24 +796,6 @@ func phase2(followerConnection net.Conn) {
|
|
lib.CleanUpdbR(round)
|
|
lib.CleanUpdbR(round)
|
|
}
|
|
}
|
|
|
|
|
|
-func addTestTweets() {
|
|
|
|
- //creates test tweets
|
|
|
|
- tweets := make([]lib.Tweet, 5)
|
|
|
|
-
|
|
|
|
- for i := range tweets {
|
|
|
|
- j := i
|
|
|
|
- if i == 1 {
|
|
|
|
- j = 0
|
|
|
|
- }
|
|
|
|
- text := "Text " + strconv.Itoa(i)
|
|
|
|
- var topics []string
|
|
|
|
- topics = append(topics, "Topic "+strconv.Itoa(j))
|
|
|
|
- tweets[i] = lib.Tweet{"", -1, topics, text, i}
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- lib.NewEntries(tweets, 0)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
//opti! mb it is quicker to send updated topicLists to clients first so pirQuerys are ready
|
|
//opti! mb it is quicker to send updated topicLists to clients first so pirQuerys are ready
|
|
func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGroup, m *sync.RWMutex) {
|
|
func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGroup, m *sync.RWMutex) {
|
|
|
|
|
|
@@ -1026,8 +1031,8 @@ func handleClientDC(wg *sync.WaitGroup, followerConnection net.Conn, channel cha
|
|
func createVirtualAddresses() []int {
|
|
func createVirtualAddresses() []int {
|
|
//array will be filled with unique random ascending values
|
|
//array will be filled with unique random ascending values
|
|
//adapted from: https://stackoverflow.com/questions/20039025/java-array-of-unique-randomly-generated-integers
|
|
//adapted from: https://stackoverflow.com/questions/20039025/java-array-of-unique-randomly-generated-integers
|
|
- //+1 to have a position to evaluate each received message
|
|
|
|
- arraySize := int(dbWriteSize) + 1
|
|
|
|
|
|
+ //+extraPositions to have a position to evaluate each received message
|
|
|
|
+ arraySize := int(dbWriteSize) + extraPositions
|
|
var maxInt int = int(math.Pow(2, 31))
|
|
var maxInt int = int(math.Pow(2, 31))
|
|
virtualAddresses := make([]int, arraySize)
|
|
virtualAddresses := make([]int, arraySize)
|
|
for i := 0; i < arraySize; i++ {
|
|
for i := 0; i < arraySize; i++ {
|
|
@@ -1085,7 +1090,6 @@ func getSendTweets(clientKeys clientKeys, archiveQuerys [][]byte, clientConnecti
|
|
tmpNeededSubscriptions = archiveTopicAmount
|
|
tmpNeededSubscriptions = archiveTopicAmount
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //fmt.Println("tmpNeededSubscriptions", tmpNeededSubscriptions)
|
|
|
|
|
|
|
|
tweets := make([][]byte, tmpNeededSubscriptions)
|
|
tweets := make([][]byte, tmpNeededSubscriptions)
|
|
for i := 0; i < tmpNeededSubscriptions; i++ {
|
|
for i := 0; i < tmpNeededSubscriptions; i++ {
|
|
@@ -1106,20 +1110,20 @@ func getSendTweets(clientKeys clientKeys, archiveQuerys [][]byte, clientConnecti
|
|
//Xor's sharedSecret with all tweets
|
|
//Xor's sharedSecret with all tweets
|
|
lib.Xor(expandedSharedSecret[:], tweets[i])
|
|
lib.Xor(expandedSharedSecret[:], tweets[i])
|
|
|
|
|
|
- //fmt.Println(tweets[0])
|
|
|
|
-
|
|
|
|
blockLength := len(tweets[i])
|
|
blockLength := len(tweets[i])
|
|
|
|
|
|
receivedTweets, _ := readFrom(followerConnection, blockLength, nil, 0)
|
|
receivedTweets, _ := readFrom(followerConnection, blockLength, nil, 0)
|
|
|
|
|
|
- //fmt.Println("receivedTweets", blockLength, len(receivedTweets))
|
|
|
|
- //fmt.Println("pubKey", *clientKeys.PublicKey, "Bytes", tweets, "follower", receivedTweets)
|
|
|
|
lib.Xor(receivedTweets, tweets[i])
|
|
lib.Xor(receivedTweets, tweets[i])
|
|
}
|
|
}
|
|
|
|
|
|
//sends tweets to client
|
|
//sends tweets to client
|
|
for i := 0; i < tmpNeededSubscriptions; i++ {
|
|
for i := 0; i < tmpNeededSubscriptions; i++ {
|
|
tweetsLengthBytes := intToByte(len(tweets[i]))
|
|
tweetsLengthBytes := intToByte(len(tweets[i]))
|
|
|
|
+ if firstTweetSend && archiveQuerys == nil {
|
|
|
|
+ firstTweetSend = false
|
|
|
|
+ log.Println("sending", len(tweets[0]), "bytes of data")
|
|
|
|
+ }
|
|
errorBool := writeToWError(clientConnection, tweetsLengthBytes, followerConnection, 2)
|
|
errorBool := writeToWError(clientConnection, tweetsLengthBytes, followerConnection, 2)
|
|
if errorBool {
|
|
if errorBool {
|
|
return true
|
|
return true
|