Browse Source

various bugfixes

Simon 2 years ago
parent
commit
aa66dadc61
4 changed files with 14 additions and 21 deletions
  1. 3 6
      client/client.go
  2. 3 7
      follower/follower.go
  3. 7 8
      leader/leader.go
  4. 1 0
      lib/databaseRead.go

+ 3 - 6
client/client.go

@@ -379,7 +379,7 @@ func receiveVirtualAddress(sharedSecret [2][32]byte, leaderConn net.Conn) int {
 	return byteToInt(virtualAddressByte)
 }
 
-func receiveTweets(sharedSecret [2][32]byte, leaderConn net.Conn, getArchive bool) int {
+func receiveTweets(sharedSecret [2][32]byte, leaderConn net.Conn, getArchive bool) {
 
 	tmpNeededSubscriptions := neededSubscriptions
 	if tmpNeededSubscriptions > len(topicList) {
@@ -413,12 +413,10 @@ func receiveTweets(sharedSecret [2][32]byte, leaderConn net.Conn, getArchive boo
 			lib.Xor(expandedSharedSecrets[i][:], tweets)
 		}
 
-		//tweets can be displayed
-		split := strings.Split(string(tweets), ";")
-		text := split[:len(split)-1]
+		index := strings.Index(string(tweets), ";;")
+		text := string(tweets)[:index]
 		fmt.Println(text)
 	}
-	return 0
 }
 
 //creates a shared secret for each server
@@ -452,7 +450,6 @@ func createAuditPIRQuery(clientNumber int) ([]byte, []byte) {
 	copy(pirQuerys[1], pirQuerys[0])
 
 	//the positon the virtual address will be taken from
-	//todo! invalid argument error
 	pos := mr.Intn(dbWriteSize)
 	pirQuerys[0][pos] = 1
 	pirQuerys[1][pos] = 0

+ 3 - 7
follower/follower.go

@@ -145,8 +145,7 @@ func main() {
 
 	for {
 
-		//phase1
-		fmt.Println("phase1")
+		fmt.Println("Phase 1")
 
 		//create write db for this round
 		for i := 0; i < dbWriteSize; i++ {
@@ -172,8 +171,7 @@ func main() {
 		}
 		wg.Wait()
 
-		//phase2
-		fmt.Println("phase2")
+		fmt.Println("Phase 2")
 		leaderConnection, err := lnLeader.Accept()
 		if err != nil {
 			panic(err)
@@ -182,9 +180,7 @@ func main() {
 
 		phase2(leaderConnection)
 
-		//phase3
-
-		fmt.Println("phase3")
+		fmt.Println("Phase 3")
 
 		if round == 1 {
 			//addTestTweets()

+ 7 - 8
leader/leader.go

@@ -230,11 +230,10 @@ func main() {
 
 	for {
 
-		//phase1
 		startTime = time.Now()
 		phase[0] = 1
 
-		fmt.Println("phase1")
+		fmt.Println("Phase 1")
 
 		//creates a new write Db for this round
 		for i := 0; i < dbWriteSize; i++ {
@@ -262,9 +261,7 @@ func main() {
 
 		wg.Wait()
 
-		fmt.Println("phase2")
-
-		//phase2
+		fmt.Println("Phase 2")
 
 		followerConnection, err := tls.Dial("tcp", follower, conf)
 		if err != nil {
@@ -274,9 +271,7 @@ func main() {
 
 		phase2(followerConnection)
 
-		//phase3
-
-		fmt.Println("phase3")
+		fmt.Println("Phase 3")
 
 		//no tweets -> continue to phase 1 and mb get tweets
 		topicList, topicAmount = lib.GetTopicList(0)
@@ -654,6 +649,10 @@ func phase2(followerConnection net.Conn) {
 	//calculates the dbWriteSize for this round
 	dbWriteSize = int(math.Ceil(19.5 * float64(publisherAverage)))
 
+	if dbWriteSize < 100 {
+		dbWriteSize = 100
+	}
+
 	//writes dbWriteSize of current round to follower
 	writeTo(followerConnection, intToByte(dbWriteSize))
 }

+ 1 - 0
lib/databaseRead.go

@@ -141,6 +141,7 @@ func tweetsToByteArray(tweetsToReturn [][]Tweet) []byte {
 			tweetToAppend = append(tweetToAppend, []byte(";")[0])
 		}
 		//adds padding
+		tweetToAppend = append(tweetToAppend, []byte(";")[0])
 		length := minimumBlockSize - len(tweetToAppend)
 		padding := make([]byte, length)
 		rand.Read(padding)