|
@@ -83,8 +83,11 @@ var maxTimePerRound time.Duration = 5 * time.Second
|
|
var phase1Channel = make(chan net.Conn, maxNumberOfClients)
|
|
var phase1Channel = make(chan net.Conn, maxNumberOfClients)
|
|
var phase3Channel = make(chan net.Conn, maxNumberOfClients)
|
|
var phase3Channel = make(chan net.Conn, maxNumberOfClients)
|
|
|
|
|
|
-//variable for calculating the dbWrite size
|
|
|
|
-var publisherNumber float64
|
|
|
|
|
|
+//variables for calculating the dbWrite size
|
|
|
|
+const publisherRounds int = 3
|
|
|
|
+
|
|
|
|
+var publisherAmount float64
|
|
|
|
+var publisherHistory [publisherRounds]int
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
|
|
|
|
@@ -184,7 +187,7 @@ func main() {
|
|
for {
|
|
for {
|
|
clientConnection, err := lnClients.Accept()
|
|
clientConnection, err := lnClients.Accept()
|
|
if err != nil {
|
|
if err != nil {
|
|
- panic(err)
|
|
|
|
|
|
+ fmt.Println(err)
|
|
}
|
|
}
|
|
clientConnection.SetDeadline(time.Time{})
|
|
clientConnection.SetDeadline(time.Time{})
|
|
|
|
|
|
@@ -194,13 +197,17 @@ func main() {
|
|
//send leader publicKey
|
|
//send leader publicKey
|
|
_, err = clientConnection.Write(leaderPublicKey[:])
|
|
_, err = clientConnection.Write(leaderPublicKey[:])
|
|
if err != nil {
|
|
if err != nil {
|
|
- panic(err)
|
|
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ clientConnection.Close()
|
|
|
|
+ break
|
|
}
|
|
}
|
|
|
|
|
|
//send follower publicKey
|
|
//send follower publicKey
|
|
_, err = clientConnection.Write(followerPublicKey[:])
|
|
_, err = clientConnection.Write(followerPublicKey[:])
|
|
if err != nil {
|
|
if err != nil {
|
|
- panic(err)
|
|
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ clientConnection.Close()
|
|
|
|
+ break
|
|
}
|
|
}
|
|
|
|
|
|
var clientPublicKey *[32]byte
|
|
var clientPublicKey *[32]byte
|
|
@@ -208,7 +215,9 @@ func main() {
|
|
//gets publicKey from client
|
|
//gets publicKey from client
|
|
_, err = clientConnection.Read(tmpClientPublicKey[:])
|
|
_, err = clientConnection.Read(tmpClientPublicKey[:])
|
|
if err != nil {
|
|
if err != nil {
|
|
- panic(err)
|
|
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ clientConnection.Close()
|
|
|
|
+ break
|
|
}
|
|
}
|
|
|
|
|
|
clientPublicKey = &tmpClientPublicKey
|
|
clientPublicKey = &tmpClientPublicKey
|
|
@@ -277,10 +286,6 @@ func main() {
|
|
|
|
|
|
fmt.Println("phase3")
|
|
fmt.Println("phase3")
|
|
|
|
|
|
- if round == 1 {
|
|
|
|
- //addTestTweets()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//no tweets -> continue to phase 1 and mb get tweets
|
|
//no tweets -> continue to phase 1 and mb get tweets
|
|
topicList, topicAmount = lib.GetTopicList(0)
|
|
topicList, topicAmount = lib.GetTopicList(0)
|
|
if len(topicList) == 0 {
|
|
if len(topicList) == 0 {
|
|
@@ -364,8 +369,6 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
panic(err)
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Println("SizeToClient", dbWriteSize)
|
|
|
|
-
|
|
|
|
//tells client current round
|
|
//tells client current round
|
|
_, err = clientConnection.Write(roundAsBytes)
|
|
_, err = clientConnection.Write(roundAsBytes)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -677,13 +680,13 @@ func phase2(followerConnection net.Conn) {
|
|
}
|
|
}
|
|
|
|
|
|
var tweets []lib.Tweet
|
|
var tweets []lib.Tweet
|
|
- publisherNumber = 0
|
|
|
|
|
|
+ var currentPublisherAmount int = 0
|
|
for i := 0; i < dbSize; i++ {
|
|
for i := 0; i < dbSize; i++ {
|
|
//discard cover message
|
|
//discard cover message
|
|
if tmpdb[i][0] == 0 {
|
|
if tmpdb[i][0] == 0 {
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
- publisherNumber++
|
|
|
|
|
|
+ currentPublisherAmount++
|
|
//reconstruct tweet
|
|
//reconstruct tweet
|
|
var position int = 0
|
|
var position int = 0
|
|
var topics []string
|
|
var topics []string
|
|
@@ -723,14 +726,25 @@ func phase2(followerConnection net.Conn) {
|
|
|
|
|
|
C.resetDb()
|
|
C.resetDb()
|
|
|
|
|
|
- //calculates the dbWriteSize for this round
|
|
|
|
- if publisherNumber > 0 {
|
|
|
|
- dbWriteSize = int(math.Ceil(19.5 * publisherNumber))
|
|
|
|
|
|
+ //calculates the publisherAverage over the last publisherRounds rounds
|
|
|
|
+ index := round % publisherRounds
|
|
|
|
+ publisherHistory[index] = currentPublisherAmount
|
|
|
|
+
|
|
|
|
+ var publisherAmount int
|
|
|
|
+ for _, num := range publisherHistory {
|
|
|
|
+ publisherAmount += num
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ publisherAverage := 0
|
|
|
|
+ if round < publisherRounds {
|
|
|
|
+ publisherAverage = publisherAmount / round
|
|
} else {
|
|
} else {
|
|
- //default, handles 100 clients
|
|
|
|
- dbWriteSize = 1950
|
|
|
|
|
|
+ publisherAverage = publisherAmount / publisherRounds
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //calculates the dbWriteSize for this round
|
|
|
|
+ dbWriteSize = int(math.Ceil(19.5 * float64(publisherAverage)))
|
|
|
|
+
|
|
//writes dbWriteSize of current round to follower
|
|
//writes dbWriteSize of current round to follower
|
|
_, err = followerConnection.Write(intToByte(dbWriteSize))
|
|
_, err = followerConnection.Write(intToByte(dbWriteSize))
|
|
if err != nil {
|
|
if err != nil {
|