gopkg.in/dedis/onet.v2@v2.0.0-20181115163211-c8f3724038a7/simul/simul.go (about)

     1  /*
     2  Package simul allows for easy simulation on different platforms. THe following platforms
     3  are available:
     4  
     5  	- localhost - for up to 100 nodes
     6  	- mininet - for up to 1'000 nodes
     7  	- deterlab - for up to 50'000 nodes
     8  
     9  Usually you start small, then work your way up to the full potential of your
    10  protocol!
    11  */
    12  package simul
    13  
    14  import (
    15  	"flag"
    16  	"os"
    17  
    18  	"gopkg.in/dedis/onet.v2/log"
    19  	"gopkg.in/dedis/onet.v2/simul/platform"
    20  )
    21  
    22  // The address of this server - if there is only one server in the config
    23  // file, it will be derived from it automatically
    24  var serverAddress string
    25  
    26  // ip addr of the logger to connect to
    27  var monitorAddress string
    28  
    29  // Simul is != "" if this node needs to start a simulation of that protocol
    30  var simul string
    31  
    32  // suite is Ed25519 by default
    33  var suite string
    34  
    35  // Initialize before 'init' so we can directly use the fields as parameters
    36  // to 'Flag'
    37  func init() {
    38  	flag.StringVar(&serverAddress, "address", "", "our address to use")
    39  	flag.StringVar(&simul, "simul", "", "start simulating that protocol")
    40  	flag.StringVar(&monitorAddress, "monitor", "", "remote monitor")
    41  	flag.StringVar(&suite, "suite", "Ed25519", "cryptographic suite to use")
    42  
    43  }
    44  
    45  // Start has to be called by the main-file that imports the protocol and/or the
    46  // service. If a user calls the simulation-file, `simul` is empty, and the
    47  // build is started.
    48  // Only the platform will call this binary with a simul-flag set to the name of the
    49  // simulation to run.
    50  // If given an array of rcs, each element will be interpreted as a .toml-file
    51  // to load and simulate.
    52  func Start(rcs ...string) {
    53  	wd, err := os.Getwd()
    54  	if len(rcs) > 0 {
    55  		log.ErrFatal(err)
    56  		for _, rc := range rcs {
    57  			log.Lvl1("Running toml-file:", rc)
    58  			os.Args = []string{os.Args[0], rc}
    59  			Start()
    60  		}
    61  		return
    62  	}
    63  	flag.Parse()
    64  	if simul == "" {
    65  		startBuild()
    66  	} else {
    67  		err := platform.Simulate(suite, serverAddress, simul, monitorAddress)
    68  		log.ErrFatal(err)
    69  	}
    70  	os.Chdir(wd)
    71  }