func RunServer(flags *app.Flags, conf *app.ConfigColl) { hostname := flags.Hostname if hostname == conf.Hosts[0] { dbg.Lvlf3("Tree is %+v", conf.Tree) } dbg.Lvl3(hostname, "Starting to run") app.RunFlags.StartedUp(len(conf.Hosts)) peer := conode.NewPeer(hostname, conf.ConfigConode) if app.RunFlags.AmRoot { for { setupRound := sign.NewRoundSetup(peer.Node) peer.StartAnnouncementWithWait(setupRound, 5*time.Second) counted := <-setupRound.Counted dbg.Lvl1("Number of peers counted:", counted) if counted == len(conf.Hosts) { dbg.Lvl1("All hosts replied") break } time.Sleep(time.Second) } } RegisterRoundMeasure(peer.Node.LastRound()) peer.LoopRounds(RoundMeasureType, conf.Rounds) dbg.Lvlf3("Done - flags are %+v", app.RunFlags) monitor.End() }
func RunServer(conf *app.NTreeConfig) { if conf.Root { RunRoot(conf) monitor.End() } else { RunPeer(conf) //RunServer2(conf) } }
// Searches for the index in the hostlist and decides if we're the leader // or one of the clients func RunServer(conf *app.NaiveConfig) { indexPeer := -1 for i, h := range conf.Hosts { if h == app.RunFlags.Hostname { indexPeer = i } } if indexPeer == -1 { dbg.Fatal("Could not find its own hostname. Abort") } if indexPeer == 0 { dbg.Lvl3("Launching a naiv_sign.: Leader", app.RunFlags.Hostname) GoLeader(conf) monitor.End() } else { dbg.Lvl3("Launching a naiv_sign: Signer", app.RunFlags.Hostname) GoSigner(conf) } }
func main() { conf := &app.ConfigColl{} app.ReadConfig(conf) // we must know who we are if app.RunFlags.Hostname == "" { dbg.Fatal("Hostname empty: Abort") } // Do some common setup if app.RunFlags.Mode == "client" { app.RunFlags.Hostname = app.RunFlags.Name } hostname := app.RunFlags.Hostname if hostname == conf.Hosts[0] { dbg.Lvlf3("Tree is %+v", conf.Tree) } dbg.Lvl3(hostname, "Starting to run") app.RunFlags.StartedUp(len(conf.Hosts)) peer := conode.NewPeer(hostname, conf.ConfigConode) if app.RunFlags.AmRoot { for { time.Sleep(time.Second) setupRound := sign.NewRoundSetup(peer.Node) peer.StartAnnouncementWithWait(setupRound, 5*time.Second) counted := <-setupRound.Counted dbg.Lvl1("Number of peers counted:", counted) if counted == len(conf.Hosts) { dbg.Lvl1("All hosts replied") break } } } RegisterRoundMeasure(peer.Node.LastRound()) peer.LoopRounds(RoundMeasureType, conf.Rounds) dbg.Lvlf3("Done - flags are %+v", app.RunFlags) monitor.End() }
func main() { conf := &app.ConfigColl{} app.ReadConfig(conf) // we must know who we are if app.RunFlags.Hostname == "" { dbg.Fatal("Hostname empty: Abort") } // Do some common setup if app.RunFlags.Mode == "client" { app.RunFlags.Hostname = app.RunFlags.Name } hostname := app.RunFlags.Hostname if hostname == conf.Hosts[0] { dbg.Lvlf3("Tree is %+v", conf.Tree) } dbg.Lvl3(hostname, "Starting to run") app.RunFlags.StartedUp(len(conf.Hosts)) peer := conode.NewPeer(hostname, conf.ConfigConode) Releases = make(map[string]CommitEntry) //ReleaseInformation() ReadRelease(PolicyFile, SignaturesFile, CommitIdFile) if app.RunFlags.AmRoot { err := peer.WaitRoundSetup(len(conf.Hosts), 5, 2) if err != nil { dbg.Fatal(err) } dbg.Lvl1("Starting the rounds") } if app.RunFlags.AmRoot { for round := 0; round < conf.Rounds; round++ { dbg.Lvl1("Doing round", round, "of", conf.Rounds) wallTime := monitor.NewMeasure("round") hashToSign, _ := CommitScanner(CommitIdFile) // retrieve commitid/hash that the root is willing to get signed entry := Releases[hashToSign] if entry.policy != "" && entry.signatures != "" { rootpgpTime := monitor.NewMeasure("rootpgp") decision, err := ApprovalCheck(entry.policy, entry.signatures, hashToSign) rootpgpTime.Measure() if decision && err == nil { round := NewRoundSwsign(peer.Node) round.Hash = []byte(hashToSign) // passing hash of the file that we want to produce a signature for peer.StartAnnouncement(round) wallTime.Measure() Signature := <-round.Signature dbg.Lvlf1("Received signature %+v", Signature) } else { dbg.Fatal("Developers related to the root haven't approved the release so the root didn't start signing process") } } else { dbg.Error("There is no input with such commitid", hashToSign) } } peer.SendCloseAll() } else { peer.LoopRounds(RoundSwsignType, conf.Rounds) } dbg.Lvlf3("Done - flags are %+v", app.RunFlags) monitor.End() }
func RunServer(conf *app.ConfigShamir) { flags := app.RunFlags s := edwards.NewAES128SHA256Ed25519(false) n := len(conf.Hosts) info := poly.Threshold{ N: n, R: n, T: n, } indexPeer := -1 for i, h := range conf.Hosts { if h == flags.Hostname { indexPeer = i break } } if indexPeer == -1 { log.Fatal("Peer", flags.Hostname, "(", flags.PhysAddr, ") did not find any match for its name.Abort") } dbg.Lvl3("Creating new peer", flags.Hostname, "(", flags.PhysAddr, ") ...") // indexPeer == 0 <==> peer is root p := NewPeer(indexPeer, flags.Hostname, s, info, indexPeer == 0) // make it listen setup := monitor.NewMeasure("setup") dbg.Lvl3("Peer", flags.Hostname, "is now listening for incoming connections") go p.Listen() // then connect it to its successor in the list for _, h := range conf.Hosts[indexPeer+1:] { dbg.Lvl3("Peer", flags.Hostname, "will connect to", h) // will connect and SYN with the remote peer p.ConnectTo(h) } // Wait until this peer is connected / SYN'd with each other peer p.WaitSYNs() // Setup the schnorr system amongst peers p.SetupDistributedSchnorr() p.SendACKs() p.WaitACKs() dbg.Lvl3(p.String(), "completed Schnorr setup") // send setup time if we're root if p.IsRoot() { setup.Measure() } roundm := monitor.NewMeasure("round") for round := 1; round <= conf.Rounds; round++ { calc := monitor.NewMeasure("calc") // Then issue a signature ! //sys, usr := app.GetRTime() msg := "hello world" // Only root calculates if it's OK and sends a log-message if p.IsRoot() { dbg.Lvl1("Starting round", round) sig := p.SchnorrSigRoot([]byte(msg)) calc.Measure() verify := monitor.NewMeasure("verify") err := p.VerifySchnorrSig(sig, []byte(msg)) if err != nil { dbg.Fatal(p.String(), "could not verify schnorr signature:/", err) } verify.Measure() roundm.Measure() dbg.Lvl3(p.String(), "verified the schnorr sig !") } else { // Compute the partial sig and send it to the root p.SchnorrSigPeer([]byte(msg)) } } p.WaitFins() dbg.Lvl3(p.String(), "is leaving ...") if p.IsRoot() { monitor.End() } }
func main() { // First, let's read our config // You should create your own config in lib/app. // TOML is a pretty simple and readable format // Whatever information needed, supply it in the simulation/.toml file that // will be parsed into your ConfigSkeleton struct. conf := &app.ConfigSkeleton{} app.ReadConfig(conf) // we must know who we are if app.RunFlags.Hostname == "" { dbg.Fatal("Hostname empty: Abort") } // Do some common setup if app.RunFlags.Mode == "client" { app.RunFlags.Hostname = app.RunFlags.Name } hostname := app.RunFlags.Hostname // i.e. we are root if hostname == conf.Hosts[0] { dbg.Lvlf3("Tree is %+v", conf.Tree) } dbg.Lvl3(hostname, "Starting to run") // Connect to the monitor process. This monitor process is run on your // machine and accepts connections from any node, usually you only connect // with the root for readability and performance reasons (don't connect to // your machine from 8000 nodes .. !) if app.RunFlags.Logger != "" { monitor.ConnectSink(app.RunFlags.Logger) } else { dbg.Fatal("No logger specified") } // Here you create a "Peer",that's the struct that will create a new round // each seconds and handle other subtleties for you peer := conode.NewPeer(hostname, conf.ConfigConode) // The root waits everyone's to be up if app.RunFlags.AmRoot { for { time.Sleep(time.Second) setupRound := sign.NewRoundSetup(peer.Node) peer.StartAnnouncementWithWait(setupRound, 5*time.Second) counted := <-setupRound.Counted dbg.Lvl1("Number of peers counted:", counted) if counted == len(conf.Hosts) { dbg.Lvl1("All hosts replied") break } } } // You register by giving the type, and a function that takes a sign.Node in // input (basically the underlying protocol) and returns a Round. sign.RegisterRoundFactory(RoundSkeletonType, func(node *sign.Node) sign.Round { return NewRoundSkeleton(node) }) // Here it will create a new round each seconds automatically. // If you need more fined grained control, you must implement yourself the // conode.Peer struct (it's quite easy). peer.LoopRounds(RoundSkeletonType, conf.Rounds) // Notify the monitor that we finished so that the simulation can be stopped monitor.End() }