func init() { store.AddDegradedCallback(handleDegraded) store.AddDeletingCallback(handleDeleting) store.AddAppliedCallback(handleApplied) }
func init() { store.AddAppliedCallback(handleApplied) store.AddChosenCallback(handleChosen) store.AddDegradedCallback(handleDegraded) store.AddProposalCallback(handleProposalChange) }
func main() { haltChan = make(chan struct{}) // Define and parse flags. id := flag.Uint("id", 0, "Set the node ID of this unanimity instance.") memprof = flag.Uint("memprof", 0, "Generate a memory profile and "+ "halt after the given instruction slot is applied.") cpuprof = flag.Uint("cpuprof", 0, "Generate a CPU profile and halt "+ "after the given instruction slot is applied.") flag.Parse() // Validate flags. if *id == 0 || *id > 0xFFFF { log.Fatal("Invalid node ID specified.") } // If both memprof and cpuprof are set, they need to be the same. if *memprof != 0 && *cpuprof != 0 && *memprof != *cpuprof { log.Fatal("If both memprof and cpuprof are set they must " + "match.") } // If either memprof or cpuprof are set, hook up the callback // responsible for terminating the node at the right time. if *memprof != 0 || *cpuprof != 0 { store.AddAppliedCallback(handleProfileTime) // If generating a CPU profile, start it now. if *cpuprof != 0 { f, err := os.Create("cpuprofile.prof") if err != nil { log.Fatal(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } } // Load configuration from config file. loadConfig() config.SetId(uint16(*id)) // Load our TLS certificate. idStr := strconv.FormatUint(uint64(config.Id()), 10) cert, err := tls.LoadX509KeyPair(idStr+".crt", idStr+".key") if err != nil { log.Fatalf("error loading our TLS certificate: %s", err) } config.SetCertificate(&cert) fmt.Printf("Loaded configuration, our ID is %d.\n", config.Id()) if config.IsCore() { core.Startup() } else { client.Startup() } <-haltChan // If we're to generate a memory profile before terminating, do so. if *memprof != 0 { f, err := os.Create("memprofile.mprof") if err != nil { log.Fatal(err) } defer f.Close() pprof.WriteHeapProfile(f) } }