|
@@ -65,14 +65,14 @@ const roundsBeforeUpdate = 5
|
|
const neededSubscriptions = 1
|
|
const neededSubscriptions = 1
|
|
const numThreads = 12
|
|
const numThreads = 12
|
|
const dataLength = 256
|
|
const dataLength = 256
|
|
-const minDBWriteSize = 1000
|
|
|
|
|
|
+const minDBWriteSize = 10
|
|
|
|
|
|
var dbWriteSize float64 = 20000
|
|
var dbWriteSize float64 = 20000
|
|
var collisionCounter []float64
|
|
var collisionCounter []float64
|
|
|
|
|
|
var clientsConnected int
|
|
var clientsConnected int
|
|
|
|
|
|
-var maxTimePerRound time.Duration = 30 * time.Second
|
|
|
|
|
|
+var maxTimePerRound time.Duration = 25 * time.Second
|
|
|
|
|
|
var clientsServedPhase1 []int
|
|
var clientsServedPhase1 []int
|
|
var clientsServedPhase3 []int
|
|
var clientsServedPhase3 []int
|
|
@@ -88,9 +88,8 @@ var startTime time.Time
|
|
var startTimeRound time.Time
|
|
var startTimeRound time.Time
|
|
|
|
|
|
//channel for goroutine communication with clients
|
|
//channel for goroutine communication with clients
|
|
-var waitChannel = make(chan net.Conn, maxNumberOfClients)
|
|
|
|
-
|
|
|
|
-//var waitChannel = make(chan net.Conn, maxNumberOfClients)
|
|
|
|
|
|
+var phase1Channel = make(chan net.Conn, maxNumberOfClients)
|
|
|
|
+var phase3Channel = make(chan net.Conn, maxNumberOfClients)
|
|
|
|
|
|
//variables for calculating the dbWrite size
|
|
//variables for calculating the dbWrite size
|
|
const publisherRounds int = 10
|
|
const publisherRounds int = 10
|
|
@@ -258,7 +257,7 @@ func main() {
|
|
clientData[remoteAddress] = keys
|
|
clientData[remoteAddress] = keys
|
|
m.Unlock()
|
|
m.Unlock()
|
|
|
|
|
|
- waitChannel <- clientConnection
|
|
|
|
|
|
+ phase1Channel <- clientConnection
|
|
clientsConnected++
|
|
clientsConnected++
|
|
|
|
|
|
if clientsConnected%1000 == 0 {
|
|
if clientsConnected%1000 == 0 {
|
|
@@ -298,6 +297,16 @@ func main() {
|
|
writeTo(followerConnection, intToByte(virtualAddresses[i]))
|
|
writeTo(followerConnection, intToByte(virtualAddresses[i]))
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //moves all clients to phase1
|
|
|
|
+ if len(phase3Channel) > 0 {
|
|
|
|
+ for client := range phase3Channel {
|
|
|
|
+ phase1Channel <- client
|
|
|
|
+ if len(phase3Channel) == 0 {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
for id := 0; id < numThreads; id++ {
|
|
for id := 0; id < numThreads; id++ {
|
|
wg.Add(1)
|
|
wg.Add(1)
|
|
|
|
|
|
@@ -330,6 +339,16 @@ func main() {
|
|
|
|
|
|
//Phase 3
|
|
//Phase 3
|
|
|
|
|
|
|
|
+ //moves all clients to phase3
|
|
|
|
+ if len(phase1Channel) > 0 {
|
|
|
|
+ for client := range phase1Channel {
|
|
|
|
+ phase3Channel <- client
|
|
|
|
+ if len(phase1Channel) == 0 {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
startPhase3 = time.Now()
|
|
startPhase3 = time.Now()
|
|
|
|
|
|
//no tweets -> continue to phase 1 and mb get tweets
|
|
//no tweets -> continue to phase 1 and mb get tweets
|
|
@@ -367,7 +386,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
gotClient[0] = 0
|
|
gotClient[0] = 0
|
|
|
|
|
|
//wait until time is up
|
|
//wait until time is up
|
|
- for len(waitChannel) == 0 {
|
|
|
|
|
|
+ for len(phase1Channel) == 0 {
|
|
if time.Since(startTimeRound) > maxTimePerRound {
|
|
if time.Since(startTimeRound) > maxTimePerRound {
|
|
//tells follower that this worker is done
|
|
//tells follower that this worker is done
|
|
writeTo(followerConnection, gotClient)
|
|
writeTo(followerConnection, gotClient)
|
|
@@ -377,7 +396,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
time.Sleep(1 * time.Second)
|
|
time.Sleep(1 * time.Second)
|
|
}
|
|
}
|
|
|
|
|
|
- for clientConnection := range waitChannel {
|
|
|
|
|
|
+ for clientConnection := range phase1Channel {
|
|
clientsServedPhase1[round] = clientsServedPhase1[round] + 1
|
|
clientsServedPhase1[round] = clientsServedPhase1[round] + 1
|
|
|
|
|
|
if clientsServedPhase1[round]%1000 == 0 {
|
|
if clientsServedPhase1[round]%1000 == 0 {
|
|
@@ -405,7 +424,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
//tells client that phase 1 has begun
|
|
//tells client that phase 1 has begun
|
|
errorBool := writeToWError(clientConnection, phase, followerConnection, 5)
|
|
errorBool := writeToWError(clientConnection, phase, followerConnection, 5)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase1Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -416,7 +435,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
//tells client current dbWriteSize
|
|
//tells client current dbWriteSize
|
|
errorBool = writeToWError(clientConnection, intToByte(int(dbWriteSize)), followerConnection, 5)
|
|
errorBool = writeToWError(clientConnection, intToByte(int(dbWriteSize)), followerConnection, 5)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase1Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -427,7 +446,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
//tells client current round
|
|
//tells client current round
|
|
errorBool = writeToWError(clientConnection, roundAsBytes, followerConnection, 5)
|
|
errorBool = writeToWError(clientConnection, roundAsBytes, followerConnection, 5)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase1Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -442,7 +461,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
m.RUnlock()
|
|
m.RUnlock()
|
|
clientKeys, pirQuery, errorBool := handlePirQuery(clientKeys, clientConnection, followerConnection, 0, true)
|
|
clientKeys, pirQuery, errorBool := handlePirQuery(clientKeys, clientConnection, followerConnection, 0, true)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase1Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -451,7 +470,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
}
|
|
}
|
|
errorBool = getSendVirtualAddress(pirQuery[0], virtualAddresses, clientKeys.SharedSecret, clientConnection, followerConnection)
|
|
errorBool = getSendVirtualAddress(pirQuery[0], virtualAddresses, clientKeys.SharedSecret, clientConnection, followerConnection)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase1Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -470,7 +489,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
//accept dpfQuery from client
|
|
//accept dpfQuery from client
|
|
dpfLengthBytes, errorBool := readFrom(clientConnection, 4, followerConnection, 5)
|
|
dpfLengthBytes, errorBool := readFrom(clientConnection, 4, followerConnection, 5)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase1Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -482,7 +501,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
dpfQueryAEncrypted, errorBool := readFrom(clientConnection, dpfLength, followerConnection, 5)
|
|
dpfQueryAEncrypted, errorBool := readFrom(clientConnection, dpfLength, followerConnection, 5)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase1Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -492,7 +511,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
dpfQueryBEncrypted, errorBool := readFrom(clientConnection, dpfLength, followerConnection, 5)
|
|
dpfQueryBEncrypted, errorBool := readFrom(clientConnection, dpfLength, followerConnection, 5)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase1Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -551,14 +570,14 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
C.xorIn(C.int(i), (*C.uchar)(&db[i][0]))
|
|
C.xorIn(C.int(i), (*C.uchar)(&db[i][0]))
|
|
m.Unlock()
|
|
m.Unlock()
|
|
}
|
|
}
|
|
- waitChannel <- clientConnection
|
|
|
|
|
|
+ phase3Channel <- clientConnection
|
|
}
|
|
}
|
|
|
|
|
|
//loop that waits for new client or leaves phase1 if time is up
|
|
//loop that waits for new client or leaves phase1 if time is up
|
|
for {
|
|
for {
|
|
if time.Since(startTimeRound) < maxTimePerRound {
|
|
if time.Since(startTimeRound) < maxTimePerRound {
|
|
//this worker handles the next client
|
|
//this worker handles the next client
|
|
- if len(waitChannel) > 0 {
|
|
|
|
|
|
+ if len(phase1Channel) > 0 {
|
|
break
|
|
break
|
|
//this worker waits for next client
|
|
//this worker waits for next client
|
|
} else {
|
|
} else {
|
|
@@ -726,6 +745,8 @@ func phase2(followerConnection net.Conn) {
|
|
index := round % publisherRounds
|
|
index := round % publisherRounds
|
|
publisherHistory[index] = currentPublisherAmount
|
|
publisherHistory[index] = currentPublisherAmount
|
|
|
|
|
|
|
|
+ fmt.Println("currentPublisherAmount", currentPublisherAmount)
|
|
|
|
+
|
|
var publisherAmount int
|
|
var publisherAmount int
|
|
for _, num := range publisherHistory {
|
|
for _, num := range publisherHistory {
|
|
publisherAmount += num
|
|
publisherAmount += num
|
|
@@ -774,7 +795,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
gotClient[0] = 0
|
|
gotClient[0] = 0
|
|
|
|
|
|
//wait until time is up
|
|
//wait until time is up
|
|
- for len(waitChannel) == 0 {
|
|
|
|
|
|
+ for len(phase3Channel) == 0 {
|
|
if time.Since(startTimeRound) > maxTimePerRound*2 {
|
|
if time.Since(startTimeRound) > maxTimePerRound*2 {
|
|
//tells follower that this worker is done
|
|
//tells follower that this worker is done
|
|
writeToWError(followerConnection, gotClient, nil, 0)
|
|
writeToWError(followerConnection, gotClient, nil, 0)
|
|
@@ -784,7 +805,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
time.Sleep(1 * time.Second)
|
|
time.Sleep(1 * time.Second)
|
|
}
|
|
}
|
|
|
|
|
|
- for clientConnection := range waitChannel {
|
|
|
|
|
|
+ for clientConnection := range phase3Channel {
|
|
clientsServedPhase3[round] = clientsServedPhase3[round] + 1
|
|
clientsServedPhase3[round] = clientsServedPhase3[round] + 1
|
|
|
|
|
|
if clientsServedPhase3[round]%1000 == 0 {
|
|
if clientsServedPhase3[round]%1000 == 0 {
|
|
@@ -799,7 +820,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
//tells client current phase
|
|
//tells client current phase
|
|
errorBool := writeToWError(clientConnection, phase, followerConnection, 2)
|
|
errorBool := writeToWError(clientConnection, phase, followerConnection, 2)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -836,7 +857,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
//tells client what leader expects
|
|
//tells client what leader expects
|
|
errorBool = writeToWError(clientConnection, subPhase, followerConnection, 2)
|
|
errorBool = writeToWError(clientConnection, subPhase, followerConnection, 2)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -861,7 +882,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
if subPhase[0] == 0 {
|
|
if subPhase[0] == 0 {
|
|
errorBool := sendTopicLists(clientConnection, followerConnection, false)
|
|
errorBool := sendTopicLists(clientConnection, followerConnection, false)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -870,7 +891,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
}
|
|
}
|
|
clientKeys, _, errorBool = handlePirQuery(clientKeys, clientConnection, followerConnection, int(subPhase[0]), false)
|
|
clientKeys, _, errorBool = handlePirQuery(clientKeys, clientConnection, followerConnection, int(subPhase[0]), false)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -880,7 +901,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
} else if subPhase[0] == 1 {
|
|
} else if subPhase[0] == 1 {
|
|
errorBool := sendTopicLists(clientConnection, followerConnection, false)
|
|
errorBool := sendTopicLists(clientConnection, followerConnection, false)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -893,7 +914,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
clientKeys, _, errorBool = handlePirQuery(clientKeys, clientConnection, followerConnection, int(subPhase[0]), false)
|
|
clientKeys, _, errorBool = handlePirQuery(clientKeys, clientConnection, followerConnection, int(subPhase[0]), false)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -904,7 +925,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
errorBool = getSendTweets(clientKeys, nil, clientConnection, followerConnection, m)
|
|
errorBool = getSendTweets(clientKeys, nil, clientConnection, followerConnection, m)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -914,7 +935,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
wantsArchive, errorBool := readFrom(clientConnection, 1, followerConnection, 2)
|
|
wantsArchive, errorBool := readFrom(clientConnection, 1, followerConnection, 2)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -927,7 +948,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
if wantsArchive[0] == 1 && archiveTopicAmount > 0 {
|
|
if wantsArchive[0] == 1 && archiveTopicAmount > 0 {
|
|
_, archiveQuerys, errorBool := handlePirQuery(clientKeys, clientConnection, followerConnection, -1, false)
|
|
_, archiveQuerys, errorBool := handlePirQuery(clientKeys, clientConnection, followerConnection, -1, false)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -936,7 +957,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
}
|
|
}
|
|
errorBool = getSendTweets(clientKeys, archiveQuerys, clientConnection, followerConnection, m)
|
|
errorBool = getSendTweets(clientKeys, archiveQuerys, clientConnection, followerConnection, m)
|
|
if errorBool {
|
|
if errorBool {
|
|
- contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
|
|
|
+ contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
if contBool {
|
|
if contBool {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
@@ -950,12 +971,12 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
clientData[clientConnection.RemoteAddr()] = clientKeys
|
|
clientData[clientConnection.RemoteAddr()] = clientKeys
|
|
m.Unlock()
|
|
m.Unlock()
|
|
|
|
|
|
- waitChannel <- clientConnection
|
|
|
|
|
|
+ phase1Channel <- clientConnection
|
|
|
|
|
|
for {
|
|
for {
|
|
if time.Since(startTimeRound) < 2*maxTimePerRound {
|
|
if time.Since(startTimeRound) < 2*maxTimePerRound {
|
|
//this worker handles the next client
|
|
//this worker handles the next client
|
|
- if len(waitChannel) > 0 {
|
|
|
|
|
|
+ if len(phase3Channel) > 0 {
|
|
break
|
|
break
|
|
//this worker waits for next client
|
|
//this worker waits for next client
|
|
} else {
|
|
} else {
|