-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
80 lines (64 loc) · 1.95 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"runtime"
"sync"
"time"
"github.com/fewstera/contact-tracing-crypto/pkg/tracing"
)
func main() {
numberOfPeople := 81000
numberOfKeysPerPerson := 14
dailyKeys, err := generateDailyKeysForPeople(numberOfPeople, numberOfKeysPerPerson)
if err != nil {
panic(fmt.Errorf("Error generating daily keys: %w", err))
}
dividedDailyKeys := [][]tracing.DailyTracingKey{}
numProcesses := runtime.NumCPU()
chunkSize := (len(dailyKeys) + numProcesses - 1) / numProcesses
for i := 0; i < len(dailyKeys); i += chunkSize {
end := i + chunkSize
if end > len(dailyKeys) {
end = len(dailyKeys)
}
dividedDailyKeys = append(dividedDailyKeys, dailyKeys[i:end])
}
startTime := time.Now()
var wg sync.WaitGroup
for _, dKeys := range dividedDailyKeys {
wg.Add(1)
go func(dKeys []tracing.DailyTracingKey) {
// Generate proximity tokens for each daily key
for _, dailyKey := range dKeys {
dailyKey.AllProximityIdentifiers()
}
wg.Done()
}(dKeys)
}
wg.Wait()
duration := time.Now().Sub(startTime)
fmt.Printf("Took %.2f seconds\n", float64(duration.Milliseconds())/1000)
}
func generateDailyKeysForPeople(numberOfPeople, numberOfKeysPerPerson int) ([]tracing.DailyTracingKey, error) {
todayDayNumber := uint32(time.Now().Unix() / (60 * 60 * 24))
dayNumbers := []uint32{}
// Generate day numbers for past 10 days
for x := 0; x < numberOfKeysPerPerson; x++ {
dayNumbers = append(dayNumbers, todayDayNumber-uint32(x))
}
dailyKeys := []tracing.DailyTracingKey{}
for i := 0; i < numberOfPeople; i++ {
p, err := tracing.GeneratePerson()
if err != nil {
return nil, fmt.Errorf("generating new person %d: %w", i, err)
}
for _, dayNumber := range dayNumbers {
dailyTracingKey, err := p.DailyTracingKey(dayNumber)
if err != nil {
return nil, fmt.Errorf("generating new person %d, daily key %d: %w", i, dayNumber, err)
}
dailyKeys = append(dailyKeys, dailyTracingKey)
}
}
return dailyKeys, nil
}