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
Branches
No related tags found
No related merge requests found
...@@ -29,6 +29,8 @@ const ( ...@@ -29,6 +29,8 @@ const (
CfgServerAddress = "analysis.client.serverAddress" CfgServerAddress = "analysis.client.serverAddress"
// defines the report interval of the reporting in seconds. // defines the report interval of the reporting in seconds.
reportIntervalSec = 5 reportIntervalSec = 5
// maxVoteContext defines the maximum number of vote context to fit into an FPC update
maxVoteContext = 50
) )
func init() { func init() {
...@@ -148,29 +150,57 @@ func onRoundExecuted(roundStats *vote.RoundStats) { ...@@ -148,29 +150,57 @@ func onRoundExecuted(roundStats *vote.RoundStats) {
nodeID = local.GetInstance().ID().Bytes() nodeID = local.GetInstance().ID().Bytes()
} }
rs := vote.RoundStats{ chunks := splitFPCVoteContext(roundStats.ActiveVoteContexts)
Duration: roundStats.Duration,
RandUsed: roundStats.RandUsed,
ActiveVoteContexts: roundStats.ActiveVoteContexts,
}
hb := &packet.FPCHeartbeat{ connLock.Lock()
OwnID: nodeID, defer connLock.Unlock()
RoundStats: rs,
}
data, err := packet.NewFPCHeartbeatMessage(hb) for _, chunk := range chunks {
if err != nil { rs := vote.RoundStats{
log.Info(err, " - FPC heartbeat message skipped") Duration: roundStats.Duration,
return 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() if len(ctx) < maxVoteContext {
defer connLock.Unlock() chunk[i] = ctx
if _, err = managedConn.Write(data); err != nil {
log.Debugw("Error while writing to connection", "Description", err)
return 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.
Please register or to comment