예제 #1
0
파일: stamp.go 프로젝트: mlncn/cothority
func main() {
	conf := &app.ConfigColl{}
	app.ReadConfig(conf)

	switch app.RunFlags.Mode {
	case "server":
		RunServer(&app.RunFlags, conf)
	case "client":
		RunClient(&app.RunFlags, conf)
	}
}
예제 #2
0
파일: app_test.go 프로젝트: mlncn/cothority
func TestReadConfig(t *testing.T) {
	conf := app.ConfigColl{}

	dbg.DebugVisible = 5

	writeFile("/tmp/app.toml", testFileApp)
	writeFile("/tmp/deter.toml", testFileDeter)

	app.ReadConfig(&conf, "/tmp")

}
예제 #3
0
파일: naive.go 프로젝트: mlncn/cothority
func main() {

	conf := new(app.NaiveConfig)
	app.ReadConfig(conf)

	if app.RunFlags.Hostname == "" {
		log.Fatal("Hostname empty: Abort")
	}

	RunServer(conf)
	//monitor.End()
}
예제 #4
0
파일: shamir.go 프로젝트: mlncn/cothority
// Dispatch-function for running either client or server (mode-parameter)
func main() {
	conf := &app.ConfigShamir{}
	app.ReadConfig(conf)

	// we must know who we are
	if app.RunFlags.Hostname == "" {
		log.Fatal("Hostname empty: Abort")
	}

	dbg.Lvl2(app.RunFlags.Hostname, "Starting to run as", app.RunFlags.Mode)
	switch app.RunFlags.Mode {
	case "client":
		RunClient(conf)
	case "server":
		RunServer(conf)
	}
}
예제 #5
0
파일: ntree.go 프로젝트: mlncn/cothority
func main() {

	conf := new(app.NTreeConfig)
	app.ReadConfig(conf)

	// we must know who we are
	if app.RunFlags.Hostname == "" {
		log.Fatal("Hostname empty: Abort")
	}

	own, depth := conf.Tree.FindByName(app.RunFlags.Hostname, 0)
	if depth == 0 {
		// i.e. we are root
		conf.Root = true
	}
	if own == nil {
		dbg.Fatal("Could not find its name in the tree", app.RunFlags.Hostname)
	}
	conf.Tree = own
	conf.Name = own.Name
	// Wait for everybody to be ready before going on
	ioutil.WriteFile("coll_stamp_up/up"+app.RunFlags.Hostname, []byte("started"), 0666)
	for {
		_, err := os.Stat("coll_stamp_up")
		if err == nil {
			files, _ := ioutil.ReadDir("coll_stamp_up")
			dbg.Lvl4(app.RunFlags.Hostname, "waiting for others to finish", len(files))
			time.Sleep(time.Second)
		} else {
			break
		}
	}
	dbg.Lvl2(app.RunFlags.Hostname, "thinks everybody's here")

	switch app.RunFlags.Mode {
	case "client":
		log.Panic("No client mode")
	case "server":
		RunServer(conf)
	}

}
예제 #6
0
파일: sign.go 프로젝트: mlncn/cothority
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()
}
예제 #7
0
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()
}
예제 #8
0
파일: skeleton.go 프로젝트: mlncn/cothority
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()
}