|
@@ -64,7 +64,7 @@ var archiveTopicAmount int
|
|
|
const roundsBeforeUpdate = 5
|
|
|
const neededSubscriptions = 1
|
|
|
const numThreads = 12
|
|
|
-const dataLength = 64
|
|
|
+const dataLength = 256
|
|
|
const minDBWriteSize = 1000
|
|
|
|
|
|
var dbWriteSize float64 = 20000
|
|
@@ -72,7 +72,7 @@ var collisionCounter []float64
|
|
|
|
|
|
var clientsConnected int
|
|
|
|
|
|
-var maxTimePerRound time.Duration = 10 * time.Second
|
|
|
+var maxTimePerRound time.Duration = 30 * time.Second
|
|
|
|
|
|
var clientsServedPhase1 []int
|
|
|
var clientsServedPhase3 []int
|
|
@@ -85,11 +85,12 @@ var startPhase3 time.Time
|
|
|
var round int = 0
|
|
|
|
|
|
var startTime time.Time
|
|
|
+var startTimeRound time.Time
|
|
|
|
|
|
//channel for goroutine communication with clients
|
|
|
-var waiCthannel = make(chan net.Conn, maxNumberOfClients)
|
|
|
+var waitChannel = make(chan net.Conn, maxNumberOfClients)
|
|
|
|
|
|
-//var waiCthannel = make(chan net.Conn, maxNumberOfClients)
|
|
|
+//var waitChannel = make(chan net.Conn, maxNumberOfClients)
|
|
|
|
|
|
//variables for calculating the dbWrite size
|
|
|
const publisherRounds int = 10
|
|
@@ -103,6 +104,8 @@ func main() {
|
|
|
//prevents race conditions for wrtiting
|
|
|
m := &sync.RWMutex{}
|
|
|
|
|
|
+ startTime = time.Now()
|
|
|
+
|
|
|
clientsServedPhase1 = make([]int, 1000)
|
|
|
clientsServedPhase3 = make([]int, 1000)
|
|
|
|
|
@@ -234,7 +237,7 @@ func main() {
|
|
|
break
|
|
|
}
|
|
|
|
|
|
- _, err = clientConnection.Write(intToByte(startTime.Second()))
|
|
|
+ _, err = clientConnection.Write(intToByte(int(startTime.Unix())))
|
|
|
if err != nil {
|
|
|
fmt.Println("error", err)
|
|
|
clientConnection.Close()
|
|
@@ -255,7 +258,7 @@ func main() {
|
|
|
clientData[remoteAddress] = keys
|
|
|
m.Unlock()
|
|
|
|
|
|
- waiCthannel <- clientConnection
|
|
|
+ waitChannel <- clientConnection
|
|
|
clientsConnected++
|
|
|
|
|
|
if clientsConnected%1000 == 0 {
|
|
@@ -270,8 +273,8 @@ func main() {
|
|
|
phase := make([]byte, 1)
|
|
|
|
|
|
for {
|
|
|
- startTime = time.Now()
|
|
|
startPhase1 = time.Now()
|
|
|
+ startTimeRound = time.Now()
|
|
|
|
|
|
phase[0] = 1
|
|
|
|
|
@@ -304,7 +307,7 @@ func main() {
|
|
|
}
|
|
|
followerConnection.SetDeadline(time.Time{})
|
|
|
|
|
|
- go phase1(id, phase, followerConnection, wg, m, startTime, virtualAddresses)
|
|
|
+ go phase1(id, phase, followerConnection, wg, m, virtualAddresses)
|
|
|
}
|
|
|
|
|
|
wg.Wait()
|
|
@@ -336,7 +339,7 @@ func main() {
|
|
|
}
|
|
|
|
|
|
phase[0] = 3
|
|
|
- startTime = time.Now()
|
|
|
+ startTimeRound = time.Now()
|
|
|
|
|
|
for id := 0; id < numThreads; id++ {
|
|
|
wg.Add(1)
|
|
@@ -346,7 +349,7 @@ func main() {
|
|
|
}
|
|
|
followerConnection.SetDeadline(time.Time{})
|
|
|
|
|
|
- go phase3(id, phase, followerConnection, wg, startTime, m)
|
|
|
+ go phase3(id, phase, followerConnection, wg, m)
|
|
|
}
|
|
|
|
|
|
wg.Wait()
|
|
@@ -357,15 +360,15 @@ func main() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGroup, m *sync.RWMutex, startTime time.Time, virtualAddresses []int) {
|
|
|
+func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGroup, m *sync.RWMutex, virtualAddresses []int) {
|
|
|
|
|
|
roundAsBytes := intToByte(round)
|
|
|
gotClient := make([]byte, 1)
|
|
|
gotClient[0] = 0
|
|
|
|
|
|
//wait until time is up
|
|
|
- for len(waiCthannel) == 0 {
|
|
|
- if time.Since(startTime) > maxTimePerRound {
|
|
|
+ for len(waitChannel) == 0 {
|
|
|
+ if time.Since(startTimeRound) > maxTimePerRound {
|
|
|
//tells follower that this worker is done
|
|
|
writeTo(followerConnection, gotClient)
|
|
|
wg.Done()
|
|
@@ -374,7 +377,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
time.Sleep(1 * time.Second)
|
|
|
}
|
|
|
|
|
|
- for clientConnection := range waiCthannel {
|
|
|
+ for clientConnection := range waitChannel {
|
|
|
clientsServedPhase1[round] = clientsServedPhase1[round] + 1
|
|
|
|
|
|
if clientsServedPhase1[round]%1000 == 0 {
|
|
@@ -402,7 +405,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
//tells client that phase 1 has begun
|
|
|
errorBool := writeToWError(clientConnection, phase, followerConnection, 5)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -413,7 +416,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
//tells client current dbWriteSize
|
|
|
errorBool = writeToWError(clientConnection, intToByte(int(dbWriteSize)), followerConnection, 5)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -424,7 +427,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
//tells client current round
|
|
|
errorBool = writeToWError(clientConnection, roundAsBytes, followerConnection, 5)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -439,7 +442,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
m.RUnlock()
|
|
|
clientKeys, pirQuery, errorBool := handlePirQuery(clientKeys, clientConnection, followerConnection, 0, true)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -448,7 +451,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
}
|
|
|
errorBool = getSendVirtualAddress(pirQuery[0], virtualAddresses, clientKeys.SharedSecret, clientConnection, followerConnection)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -467,7 +470,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
//accept dpfQuery from client
|
|
|
dpfLengthBytes, errorBool := readFrom(clientConnection, 4, followerConnection, 5)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -479,7 +482,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
dpfQueryAEncrypted, errorBool := readFrom(clientConnection, dpfLength, followerConnection, 5)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -489,7 +492,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
dpfQueryBEncrypted, errorBool := readFrom(clientConnection, dpfLength, followerConnection, 5)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -548,14 +551,14 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
C.xorIn(C.int(i), (*C.uchar)(&db[i][0]))
|
|
|
m.Unlock()
|
|
|
}
|
|
|
- waiCthannel <- clientConnection
|
|
|
+ waitChannel <- clientConnection
|
|
|
}
|
|
|
|
|
|
//loop that waits for new client or leaves phase1 if time is up
|
|
|
for {
|
|
|
- if time.Since(startTime) < maxTimePerRound {
|
|
|
+ if time.Since(startTimeRound) < maxTimePerRound {
|
|
|
//this worker handles the next client
|
|
|
- if len(waiCthannel) > 0 {
|
|
|
+ if len(waitChannel) > 0 {
|
|
|
break
|
|
|
//this worker waits for next client
|
|
|
} else {
|
|
@@ -685,7 +688,8 @@ func phase2(followerConnection net.Conn) {
|
|
|
topic = ""
|
|
|
} else {
|
|
|
//change this works for ints, need to be changed for strings
|
|
|
- topic = topic + fmt.Sprint((int(letter)))
|
|
|
+ //have
|
|
|
+ topic = topic + string(letter)
|
|
|
}
|
|
|
} else if position == 1 {
|
|
|
text = text + string(letter)
|
|
@@ -764,14 +768,14 @@ func addTestTweets() {
|
|
|
}
|
|
|
|
|
|
//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, startTime time.Time, m *sync.RWMutex) {
|
|
|
+func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGroup, m *sync.RWMutex) {
|
|
|
|
|
|
gotClient := make([]byte, 1)
|
|
|
gotClient[0] = 0
|
|
|
|
|
|
//wait until time is up
|
|
|
- for len(waiCthannel) == 0 {
|
|
|
- if time.Since(startTime) > maxTimePerRound*2 {
|
|
|
+ for len(waitChannel) == 0 {
|
|
|
+ if time.Since(startTimeRound) > maxTimePerRound*2 {
|
|
|
//tells follower that this worker is done
|
|
|
writeToWError(followerConnection, gotClient, nil, 0)
|
|
|
wg.Done()
|
|
@@ -780,7 +784,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
time.Sleep(1 * time.Second)
|
|
|
}
|
|
|
|
|
|
- for clientConnection := range waiCthannel {
|
|
|
+ for clientConnection := range waitChannel {
|
|
|
clientsServedPhase3[round] = clientsServedPhase3[round] + 1
|
|
|
|
|
|
if clientsServedPhase3[round]%1000 == 0 {
|
|
@@ -795,7 +799,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
//tells client current phase
|
|
|
errorBool := writeToWError(clientConnection, phase, followerConnection, 2)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -832,7 +836,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
//tells client what leader expects
|
|
|
errorBool = writeToWError(clientConnection, subPhase, followerConnection, 2)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -857,7 +861,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
if subPhase[0] == 0 {
|
|
|
errorBool := sendTopicLists(clientConnection, followerConnection, false)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -866,7 +870,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
}
|
|
|
clientKeys, _, errorBool = handlePirQuery(clientKeys, clientConnection, followerConnection, int(subPhase[0]), false)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -876,7 +880,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
} else if subPhase[0] == 1 {
|
|
|
errorBool := sendTopicLists(clientConnection, followerConnection, false)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -889,7 +893,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
clientKeys, _, errorBool = handlePirQuery(clientKeys, clientConnection, followerConnection, int(subPhase[0]), false)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -900,7 +904,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
errorBool = getSendTweets(clientKeys, nil, clientConnection, followerConnection, m)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -910,7 +914,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
wantsArchive, errorBool := readFrom(clientConnection, 1, followerConnection, 2)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -923,7 +927,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
if wantsArchive[0] == 1 && archiveTopicAmount > 0 {
|
|
|
_, archiveQuerys, errorBool := handlePirQuery(clientKeys, clientConnection, followerConnection, -1, false)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -932,7 +936,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
}
|
|
|
errorBool = getSendTweets(clientKeys, archiveQuerys, clientConnection, followerConnection, m)
|
|
|
if errorBool {
|
|
|
- contBool := handleClientDC(wg, followerConnection, waiCthannel)
|
|
|
+ contBool := handleClientDC(wg, followerConnection, waitChannel)
|
|
|
if contBool {
|
|
|
continue
|
|
|
} else {
|
|
@@ -946,12 +950,12 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
clientData[clientConnection.RemoteAddr()] = clientKeys
|
|
|
m.Unlock()
|
|
|
|
|
|
- waiCthannel <- clientConnection
|
|
|
+ waitChannel <- clientConnection
|
|
|
|
|
|
for {
|
|
|
- if time.Since(startTime) < 2*maxTimePerRound {
|
|
|
+ if time.Since(startTimeRound) < 2*maxTimePerRound {
|
|
|
//this worker handles the next client
|
|
|
- if len(waiCthannel) > 0 {
|
|
|
+ if len(waitChannel) > 0 {
|
|
|
break
|
|
|
//this worker waits for next client
|
|
|
} else {
|
|
@@ -973,7 +977,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
func handleClientDC(wg *sync.WaitGroup, followerConnection net.Conn, channel chan net.Conn) bool {
|
|
|
//loop that waits for new client or leaves phase1 if time is up
|
|
|
for {
|
|
|
- if time.Since(startTime) < maxTimePerRound {
|
|
|
+ if time.Since(startTimeRound) < maxTimePerRound {
|
|
|
//this worker handles the next client
|
|
|
if len(channel) > 0 {
|
|
|
return true
|