|
@@ -94,16 +94,6 @@ func main() {
|
|
|
leaderPrivateKey = generatedPrivateKey
|
|
|
leaderPublicKey = generatedPublicKey
|
|
|
|
|
|
-
|
|
|
- if len(os.Args) != 4 {
|
|
|
- fmt.Println("try again with: numThreads, dataLength, numRows")
|
|
|
- return
|
|
|
- }
|
|
|
- numThreads, _ = strconv.Atoi(os.Args[2])
|
|
|
- dataLength, _ = strconv.Atoi(os.Args[3])
|
|
|
- numRows, _ = strconv.Atoi(os.Args[4])
|
|
|
- */
|
|
|
-
|
|
|
C.initializeServer(C.int(numThreads))
|
|
|
|
|
|
|
|
@@ -125,7 +115,7 @@ func main() {
|
|
|
followerPublicKey = &tmpFollowerPubKey
|
|
|
|
|
|
|
|
|
- writeTo(followerConnection, leaderPublicKey[:], nil, 0)
|
|
|
+ writeTo(followerConnection, leaderPublicKey[:])
|
|
|
|
|
|
|
|
|
go func() {
|
|
@@ -255,7 +245,7 @@ func main() {
|
|
|
virtualAddresses := createVirtualAddresses()
|
|
|
|
|
|
for i := 0; i <= dbWriteSize; i++ {
|
|
|
- writeTo(followerConnection, intToByte(virtualAddresses[i]), nil, 0)
|
|
|
+ writeTo(followerConnection, intToByte(virtualAddresses[i]))
|
|
|
}
|
|
|
|
|
|
for id := 0; id < numThreads; id++ {
|
|
@@ -326,7 +316,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
for len(phase1Channel) == 0 {
|
|
|
if time.Since(startTime) > maxTimePerRound {
|
|
|
|
|
|
- writeTo(followerConnection, gotClient, nil, 0)
|
|
|
+ writeTo(followerConnection, gotClient)
|
|
|
wg.Done()
|
|
|
return
|
|
|
}
|
|
@@ -337,13 +327,13 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
gotClient[0] = 1
|
|
|
|
|
|
- writeTo(followerConnection, gotClient, nil, 0)
|
|
|
+ writeTo(followerConnection, gotClient)
|
|
|
|
|
|
|
|
|
m.RLock()
|
|
|
clientPublicKey := clientData[clientConnection.RemoteAddr()].PublicKey
|
|
|
m.RUnlock()
|
|
|
- writeTo(followerConnection, clientPublicKey[:], nil, 0)
|
|
|
+ writeTo(followerConnection, clientPublicKey[:])
|
|
|
|
|
|
|
|
|
dbSize := int(C.dbSize)
|
|
@@ -353,7 +343,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
}
|
|
|
|
|
|
|
|
|
- errorBool := writeTo(clientConnection, phase, followerConnection, 5)
|
|
|
+ errorBool := writeToWError(clientConnection, phase, followerConnection, 5)
|
|
|
if errorBool {
|
|
|
contBool := handleClientDC(wg, followerConnection, phase1Channel)
|
|
|
if contBool {
|
|
@@ -364,7 +354,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
}
|
|
|
|
|
|
|
|
|
- errorBool = writeTo(clientConnection, intToByte(dbWriteSize), followerConnection, 5)
|
|
|
+ errorBool = writeToWError(clientConnection, intToByte(dbWriteSize), followerConnection, 5)
|
|
|
if errorBool {
|
|
|
contBool := handleClientDC(wg, followerConnection, phase1Channel)
|
|
|
if contBool {
|
|
@@ -375,7 +365,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
}
|
|
|
|
|
|
|
|
|
- errorBool = writeTo(clientConnection, roundAsBytes, followerConnection, 5)
|
|
|
+ errorBool = writeToWError(clientConnection, roundAsBytes, followerConnection, 5)
|
|
|
if errorBool {
|
|
|
contBool := handleClientDC(wg, followerConnection, phase1Channel)
|
|
|
if contBool {
|
|
@@ -444,10 +434,9 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- writeTo(followerConnection, dpfLengthBytes, nil, 0)
|
|
|
+ writeToWError(followerConnection, dpfLengthBytes, nil, 0)
|
|
|
|
|
|
- writeTo(followerConnection, dpfQueryBEncrypted, nil, 0)
|
|
|
+ writeToWError(followerConnection, dpfQueryBEncrypted, nil, 0)
|
|
|
|
|
|
|
|
|
var decryptNonce [24]byte
|
|
@@ -464,7 +453,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
dataShareFollower, _ := readFrom(followerConnection, ds, nil, 0)
|
|
|
|
|
|
- writeTo(followerConnection, dataShareLeader, nil, 0)
|
|
|
+ writeToWError(followerConnection, dataShareLeader, nil, 0)
|
|
|
|
|
|
auditXOR := make([]byte, ds)
|
|
|
passedAudit := true
|
|
@@ -514,7 +503,7 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
gotClient[0] = 0
|
|
|
|
|
|
- writeTo(followerConnection, gotClient, nil, 0)
|
|
|
+ writeTo(followerConnection, gotClient)
|
|
|
|
|
|
wg.Done()
|
|
|
return
|
|
@@ -540,12 +529,12 @@ func phase2(followerConnection net.Conn) {
|
|
|
}
|
|
|
|
|
|
|
|
|
- writeTo(followerConnection, seedLeader, nil, 0)
|
|
|
+ writeTo(followerConnection, seedLeader)
|
|
|
|
|
|
|
|
|
|
|
|
for i := 0; i < dbSize; i++ {
|
|
|
- writeTo(followerConnection, tmpdbLeader[i], nil, 0)
|
|
|
+ writeTo(followerConnection, tmpdbLeader[i])
|
|
|
}
|
|
|
|
|
|
|
|
@@ -577,7 +566,7 @@ func phase2(followerConnection net.Conn) {
|
|
|
|
|
|
|
|
|
for i := 0; i < dbSize; i++ {
|
|
|
- writeTo(followerConnection, C.GoBytes(unsafe.Pointer(ciphersLeader[i]), 16), nil, 0)
|
|
|
+ writeTo(followerConnection, C.GoBytes(unsafe.Pointer(ciphersLeader[i]), 16))
|
|
|
}
|
|
|
|
|
|
|
|
@@ -666,7 +655,7 @@ func phase2(followerConnection net.Conn) {
|
|
|
dbWriteSize = int(math.Ceil(19.5 * float64(publisherAverage)))
|
|
|
|
|
|
|
|
|
- writeTo(followerConnection, intToByte(dbWriteSize), nil, 0)
|
|
|
+ writeTo(followerConnection, intToByte(dbWriteSize))
|
|
|
}
|
|
|
|
|
|
func addTestTweets() {
|
|
@@ -697,7 +686,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
for len(phase3Channel) == 0 {
|
|
|
if time.Since(startTime) > maxTimePerRound {
|
|
|
|
|
|
- writeTo(followerConnection, gotClient, nil, 0)
|
|
|
+ writeToWError(followerConnection, gotClient, nil, 0)
|
|
|
wg.Done()
|
|
|
return
|
|
|
}
|
|
@@ -708,10 +697,10 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
|
|
|
gotClient[0] = 1
|
|
|
|
|
|
- writeTo(followerConnection, gotClient, nil, 0)
|
|
|
+ writeToWError(followerConnection, gotClient, nil, 0)
|
|
|
|
|
|
|
|
|
- errorBool := writeTo(clientConnection, phase, followerConnection, 2)
|
|
|
+ errorBool := writeToWError(clientConnection, phase, followerConnection, 2)
|
|
|
if errorBool {
|
|
|
contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
|
if contBool {
|
|
@@ -748,7 +737,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
}
|
|
|
|
|
|
|
|
|
- errorBool = writeTo(clientConnection, subPhase, followerConnection, 2)
|
|
|
+ errorBool = writeToWError(clientConnection, subPhase, followerConnection, 2)
|
|
|
if errorBool {
|
|
|
contBool := handleClientDC(wg, followerConnection, phase3Channel)
|
|
|
if contBool {
|
|
@@ -758,12 +747,11 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
- writeTo(followerConnection, subPhase, nil, 0)
|
|
|
+ writeToWError(followerConnection, subPhase, nil, 0)
|
|
|
|
|
|
|
|
|
- writeTo(followerConnection, clientKeys.PublicKey[:], nil, 0)
|
|
|
+ writeTo(followerConnection, clientKeys.PublicKey[:])
|
|
|
|
|
|
|
|
|
clientKeys.roundsParticipating = roundsParticipating + 1
|
|
@@ -837,7 +825,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- writeTo(followerConnection, wantsArchive, nil, 0)
|
|
|
+ writeToWError(followerConnection, wantsArchive, nil, 0)
|
|
|
|
|
|
if wantsArchive[0] == 1 && archiveTopicAmount > 0 {
|
|
|
_, archiveQuerys, errorBool := handlePirQuery(clientKeys, clientConnection, followerConnection, -1, false)
|
|
@@ -880,7 +868,7 @@ func phase3(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
|
} else {
|
|
|
|
|
|
gotClient[0] = 0
|
|
|
- writeTo(followerConnection, gotClient, nil, 0)
|
|
|
+ writeToWError(followerConnection, gotClient, nil, 0)
|
|
|
wg.Done()
|
|
|
return
|
|
|
}
|
|
@@ -906,7 +894,7 @@ func handleClientDC(wg *sync.WaitGroup, followerConnection net.Conn, channel cha
|
|
|
gotClient := make([]byte, 1)
|
|
|
gotClient[0] = 0
|
|
|
|
|
|
- writeTo(followerConnection, gotClient, nil, 0)
|
|
|
+ writeTo(followerConnection, gotClient)
|
|
|
|
|
|
wg.Done()
|
|
|
return false
|
|
@@ -960,7 +948,7 @@ func getSendVirtualAddress(pirQuery []byte, virtualAddresses []int, sharedSecret
|
|
|
virtualAddress[i] = virtualAddress[i] ^ virtualAddressFollower[i]
|
|
|
}
|
|
|
|
|
|
- errorBool := writeTo(clientConnection, virtualAddress, followerConnection, 5)
|
|
|
+ errorBool := writeToWError(clientConnection, virtualAddress, followerConnection, 5)
|
|
|
|
|
|
return errorBool
|
|
|
}
|
|
@@ -980,7 +968,7 @@ func getSendTweets(clientKeys clientKeys, archiveQuerys [][]byte, clientConnecti
|
|
|
}
|
|
|
|
|
|
|
|
|
- expandBy := len(tweets) / 32
|
|
|
+ expandBy := len(tweets[i]) / 32
|
|
|
var expandedSharedSecret []byte
|
|
|
for i := 0; i < expandBy; i++ {
|
|
|
expandedSharedSecret = append(expandedSharedSecret, clientKeys.SharedSecret[:]...)
|
|
@@ -1002,11 +990,11 @@ func getSendTweets(clientKeys clientKeys, archiveQuerys [][]byte, clientConnecti
|
|
|
|
|
|
for i := 0; i < tmpNeededSubscriptions; i++ {
|
|
|
tweetsLengthBytes := intToByte(len(tweets[i]))
|
|
|
- errorBool := writeTo(clientConnection, tweetsLengthBytes, followerConnection, 2)
|
|
|
+ errorBool := writeToWError(clientConnection, tweetsLengthBytes, followerConnection, 2)
|
|
|
if errorBool {
|
|
|
return true
|
|
|
}
|
|
|
- errorBool = writeTo(clientConnection, tweets[i], followerConnection, 2)
|
|
|
+ errorBool = writeToWError(clientConnection, tweets[i], followerConnection, 2)
|
|
|
if errorBool {
|
|
|
return true
|
|
|
}
|
|
@@ -1018,10 +1006,6 @@ func handlePirQuery(clientKeys clientKeys, clientConnection net.Conn, followerCo
|
|
|
|
|
|
clientPublicKey := clientKeys.PublicKey
|
|
|
|
|
|
- test := make([]byte, 1)
|
|
|
- test[0] = 1
|
|
|
- followerConnection.Write(test)
|
|
|
-
|
|
|
|
|
|
msgLengthBytes, errorBool := readFrom(clientConnection, 4, followerConnection, 5)
|
|
|
if errorBool {
|
|
@@ -1049,7 +1033,7 @@ func handlePirQuery(clientKeys clientKeys, clientConnection net.Conn, followerCo
|
|
|
return clientKeys, nil, true
|
|
|
}
|
|
|
|
|
|
- writeTo(followerConnection, archiveNeededSubscriptions, nil, 0)
|
|
|
+ writeToWError(followerConnection, archiveNeededSubscriptions, nil, 0)
|
|
|
tmpNeededSubscriptions = byteToInt(archiveNeededSubscriptions)
|
|
|
tmpTopicAmount = archiveTopicAmount
|
|
|
}
|
|
@@ -1059,11 +1043,10 @@ func handlePirQuery(clientKeys clientKeys, clientConnection net.Conn, followerCo
|
|
|
}
|
|
|
|
|
|
|
|
|
- fmt.Println(msgLengthBytes)
|
|
|
- writeTo(followerConnection, msgLengthBytes, nil, 0)
|
|
|
+ writeToWError(followerConnection, msgLengthBytes, nil, 0)
|
|
|
|
|
|
|
|
|
- writeTo(followerConnection, followerBox, nil, 0)
|
|
|
+ writeToWError(followerConnection, followerBox, nil, 0)
|
|
|
|
|
|
var decryptNonce [24]byte
|
|
|
copy(decryptNonce[:], leaderBox[:24])
|
|
@@ -1139,11 +1122,11 @@ func sendTopicLists(clientConnection, followerConnection net.Conn, setup bool) b
|
|
|
topicListLengthBytes := intToByte(len(topicList))
|
|
|
|
|
|
if !setup {
|
|
|
- err := writeTo(clientConnection, topicListLengthBytes, followerConnection, 5)
|
|
|
+ err := writeToWError(clientConnection, topicListLengthBytes, followerConnection, 5)
|
|
|
if err {
|
|
|
return true
|
|
|
}
|
|
|
- err = writeTo(clientConnection, topicList, followerConnection, 5)
|
|
|
+ err = writeToWError(clientConnection, topicList, followerConnection, 5)
|
|
|
if err {
|
|
|
return true
|
|
|
}
|
|
@@ -1162,9 +1145,23 @@ func sendTopicLists(clientConnection, followerConnection net.Conn, setup bool) b
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-func writeTo(connection net.Conn, array []byte, followerConnection net.Conn, size int) bool {
|
|
|
+func writeTo(connection net.Conn, array []byte) {
|
|
|
_, err := connection.Write(array)
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func writeToWError(connection net.Conn, array []byte, followerConnection net.Conn, size int) bool {
|
|
|
+ var err error
|
|
|
+ if connection.RemoteAddr().String() == follower {
|
|
|
+ arrayWError := make([]byte, 1)
|
|
|
+ arrayWError = append(arrayWError, array[:]...)
|
|
|
+ _, err = connection.Write(arrayWError)
|
|
|
+ } else {
|
|
|
+ _, err = connection.Write(array)
|
|
|
+ }
|
|
|
+
|
|
|
if err != nil {
|
|
|
|
|
|
if connection.RemoteAddr().String() != follower {
|