forked from vguardbc/vguardbft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.go
44 lines (35 loc) · 1 KB
/
utilities.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"encoding/json"
"math/rand"
"time"
)
var seededRand = rand.New(rand.NewSource(time.Now().UnixNano()))
func mockRandomBytes(length int, charset string) []byte {
b := make([]byte, length)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return b
}
// txGenerator enqueues mock data entries to all message queues
func txGenerator(len int) {
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
for i := 0; i < NumOfValidators; i++ {
q := make(chan *Proposal, MaxQueue)
for i := int64(0); i < MsgLoad; i++ {
q <- &Proposal{
Timestamp: time.Now().UnixMicro(),
Transaction: mockRandomBytes(len, charset),
}
}
requestQueue = append(requestQueue, q)
}
log.Infof("%d request queue(s) loaded with %d requests of size %d bytes", NumOfValidators, MsgLoad, MsgSize)
}
func serialization(m interface{}) ([]byte, error) {
return json.Marshal(m)
}
func deserialization(b []byte, m interface{}) error {
return json.Unmarshal(b, m)
}