forked from adrianco/spigo
/
spigo.go
35 lines (31 loc) · 972 Bytes
/
spigo.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
// simulate protocol interactions in go - spigo
// terminology is a mix of promise theory and flying spaghetti monster lore
package main
import (
"fmt"
"flag"
"time"
"github.com/adrianco/spigo/gotocol"
"github.com/adrianco/spigo/fsm"
"github.com/adrianco/spigo/pirate"
"github.com/adrianco/spigo/graphml"
)
var Population, duration int
func main() {
flag.IntVar(&Population,"p", 100, "Pirate population")
flag.IntVar(&duration,"d", 10, "Simulation duration in seconds")
flag.BoolVar(&graphml.Enabled, "g", false, "Enable GraphML logging")
flag.Parse()
fmt.Println("Spigo population", Population, "pirates")
graphml.Setup()
noodles := make(map[string]chan gotocol.Message, Population)
for i := 1; i <= Population; i++ {
name := fmt.Sprintf("Pirate%d", i)
graphml.Node(name)
noodles[name] = make(chan gotocol.Message)
go pirate.Listen(noodles[name])
}
fsm.ChatSleep = time.Duration(duration) * time.Second
fsm.Touch(noodles)
graphml.Close()
}