Skip to content
Snippets Groups Projects
Unverified Commit f69d4bc8 authored by capossele's avatar capossele
Browse files

:construction: Split vote context to fit into an FPC update

parent 11162ca8
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,8 @@ const (
CfgServerAddress = "analysis.client.serverAddress"
// defines the report interval of the reporting in seconds.
reportIntervalSec = 5
// maxVoteContext defines the maximum number of vote context to fit into an FPC update
maxVoteContext = 50
)
func init() {
......@@ -148,29 +150,57 @@ func onRoundExecuted(roundStats *vote.RoundStats) {
nodeID = local.GetInstance().ID().Bytes()
}
rs := vote.RoundStats{
Duration: roundStats.Duration,
RandUsed: roundStats.RandUsed,
ActiveVoteContexts: roundStats.ActiveVoteContexts,
}
chunks := splitFPCVoteContext(roundStats.ActiveVoteContexts)
hb := &packet.FPCHeartbeat{
OwnID: nodeID,
RoundStats: rs,
}
connLock.Lock()
defer connLock.Unlock()
data, err := packet.NewFPCHeartbeatMessage(hb)
if err != nil {
log.Info(err, " - FPC heartbeat message skipped")
return
for _, chunk := range chunks {
rs := vote.RoundStats{
Duration: roundStats.Duration,
RandUsed: roundStats.RandUsed,
ActiveVoteContexts: chunk,
}
hb := &packet.FPCHeartbeat{
OwnID: nodeID,
RoundStats: rs,
}
data, err := packet.NewFPCHeartbeatMessage(hb)
if err != nil {
log.Info(err, " - FPC heartbeat message skipped")
return
}
log.Info("Client: onRoundExecuted data size: ", len(data))
if _, err = managedConn.Write(data); err != nil {
log.Debugw("Error while writing to connection", "Description", err)
return
}
}
}
log.Info("Client: onRoundExecuted data size: ", len(data))
func splitFPCVoteContext(ctx map[string]*vote.Context) (chunk []map[string]*vote.Context) {
chunk = make([]map[string]*vote.Context, 1)
i, counter := 0, 0
chunk[i] = make(map[string]*vote.Context)
connLock.Lock()
defer connLock.Unlock()
if _, err = managedConn.Write(data); err != nil {
log.Debugw("Error while writing to connection", "Description", err)
if len(ctx) < maxVoteContext {
chunk[i] = ctx
return
}
for conflictID, voteCtx := range ctx {
counter++
if counter >= maxVoteContext {
counter = 0
i++
chunk = append(chunk, make(map[string]*vote.Context))
}
chunk[i][conflictID] = voteCtx
}
return
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment