<commit_before>/*
* Prifi-app starts a cothority node in either trustee, relay or client mode.
 */
package main

import (
	"fmt"
	"github.com/dedis/cothority/app/lib/config"
	"github.com/dedis/cothority/app/lib/server"
	"github.com/dedis/cothority/log"
	"github.com/dedis/cothority/sda"
	"github.com/lbarman/prifi_dev/sda/services"
	"gopkg.in/urfave/cli.v1"
	"os"
	"os/user"
	"path"
	"runtime"
)

// DefaultName is the name of the binary we produce and is used to create a directory
// folder with this name
const DefaultName = "prifi"

// Default names of configuration files
const DefaultServerConfig = "config.toml"
const DefaultGroupConfig = "group.toml"

// This app can launch the prifi service in either client, trustee or relay mode
func main() {
	app := cli.NewApp()
	app.Name = "prifi"
	app.Usage = "Starts PriFi in either Trustee, Relay or Client mode."
	app.Version = "0.1"
	app.Commands = []cli.Command{
		{
			Name:    "setup",
			Aliases: []string{"s"},
			Usage:   "setup the configuration for the server",
			Action:  setupCothorityd,
		},
		{
			Name:    "trustee",
			Usage:   "start in trustee mode",
			Aliases: []string{"t"},
			Action:  trustee,
		},
		{
			Name:      "relay",
			Usage:     "start in relay mode",
			ArgsUsage: "group [id-name]",
			Aliases:   []string{"r"},
			Action:    relay,
		},
		{
			Name:    "client",
			Usage:   "start in client mode",
			Aliases: []string{"c"},
			Action:  client,
		},
	}
	app.Flags = []cli.Flag{
		cli.IntFlag{
			Name:  "debug, d",
			Value: 0,
			Usage: "debug-level: 1 for terse, 5 for maximal",
		},
		cli.StringFlag{
			Name:  "config, c",
			Value: getDefaultFile(DefaultServerConfig),
			Usage: "configuration-file",
		},
		cli.StringFlag{
			Name:  "group, g",
			Value: getDefaultFile(DefaultGroupConfig),
			Usage: "Group file",
		},
		cli.BoolFlag{
			Name:  "nowait",
			Usage: "Return immediately",
		},
	}
	app.Before = func(c *cli.Context) error {
		log.SetDebugVisible(c.Int("debug"))
		return nil
	}
	app.Run(os.Args)
}

// Start the cothority in trustee-mode using the already stored configuration.
func trustee(c *cli.Context) error {
	log.Info("Starting trustee")
	host, err := cothorityd(c)
	log.ErrFatal(err)
	service := host.GetService(prifi.ServiceName).(*prifi.Service)
	// Do other setups
	log.ErrFatal(service.StartTrustee())

	host.Start()
	return nil
}

// Start the cothority in relay-mode using the already stored configuration.
func relay(c *cli.Context) error {
	log.Info("Starting relay")
	host, err := cothorityd(c)
	log.ErrFatal(err)
	service := host.GetService(prifi.ServiceName).(*prifi.Service)
	// Do other setups
	group := getGroup(c)
	log.ErrFatal(service.StartRelay(group))

	host.Start()
	return nil
}

// Start the cothority in client-mode using the already stored configuration.
func client(c *cli.Context) error {
	log.Info("Starting client")
	host, err := cothorityd(c)
	log.ErrFatal(err)
	service := host.GetService(prifi.ServiceName).(*prifi.Service)
	// Do other setups
	log.ErrFatal(service.StartClient())

	host.Start()
	return nil
}

// Sets up a new cothority node configuration (used by all prifi modes)
func setupCothorityd(c *cli.Context) error {
	server.InteractiveConfig("cothorityd")
	return nil
}

// Starts the cothority node to enable communication with the prifi-service.
// Returns the prifi-service.
func cothorityd(c *cli.Context) (*sda.Conode, error) {
	// first check the options
	cfile := c.GlobalString("config")

	if _, err := os.Stat(cfile); os.IsNotExist(err) {
		return nil, err
	}
	// Let's read the config
	_, host, err := config.ParseCothorityd(cfile)
	if err != nil {
		return nil, err
	}
	return host, nil
}<commit_msg>Setup uses correct name for default configuration folder<commit_after>/*
* Prifi-app starts a cothority node in either trustee, relay or client mode.
 */
package main

import (
	"fmt"
	"github.com/dedis/cothority/app/lib/config"
	"github.com/dedis/cothority/app/lib/server"
	"github.com/dedis/cothority/log"
	"github.com/dedis/cothority/sda"
	"github.com/lbarman/prifi_dev/sda/services"
	"gopkg.in/urfave/cli.v1"
	"os"
	"os/user"
	"path"
	"runtime"
)

// DefaultName is the name of the binary we produce and is used to create a directory
// folder with this name
const DefaultName = "prifi"

// Default names of configuration files
const DefaultServerConfig = "config.toml"
const DefaultGroupConfig = "group.toml"

// This app can launch the prifi service in either client, trustee or relay mode
func main() {
	app := cli.NewApp()
	app.Name = "prifi"
	app.Usage = "Starts PriFi in either Trustee, Relay or Client mode."
	app.Version = "0.1"
	app.Commands = []cli.Command{
		{
			Name:    "setup",
			Aliases: []string{"s"},
			Usage:   "setup the configuration for the server",
			Action:  setupCothorityd,
		},
		{
			Name:    "trustee",
			Usage:   "start in trustee mode",
			Aliases: []string{"t"},
			Action:  trustee,
		},
		{
			Name:      "relay",
			Usage:     "start in relay mode",
			ArgsUsage: "group [id-name]",
			Aliases:   []string{"r"},
			Action:    relay,
		},
		{
			Name:    "client",
			Usage:   "start in client mode",
			Aliases: []string{"c"},
			Action:  client,
		},
	}
	app.Flags = []cli.Flag{
		cli.IntFlag{
			Name:  "debug, d",
			Value: 0,
			Usage: "debug-level: 1 for terse, 5 for maximal",
		},
		cli.StringFlag{
			Name:  "config, c",
			Value: getDefaultFile(DefaultServerConfig),
			Usage: "configuration-file",
		},
		cli.StringFlag{
			Name:  "group, g",
			Value: getDefaultFile(DefaultGroupConfig),
			Usage: "Group file",
		},
		cli.BoolFlag{
			Name:  "nowait",
			Usage: "Return immediately",
		},
	}
	app.Before = func(c *cli.Context) error {
		log.SetDebugVisible(c.Int("debug"))
		return nil
	}
	app.Run(os.Args)
}

// Start the cothority in trustee-mode using the already stored configuration.
func trustee(c *cli.Context) error {
	log.Info("Starting trustee")
	host, err := cothorityd(c)
	log.ErrFatal(err)
	service := host.GetService(prifi.ServiceName).(*prifi.Service)
	// Do other setups
	log.ErrFatal(service.StartTrustee())

	host.Start()
	return nil
}

// Start the cothority in relay-mode using the already stored configuration.
func relay(c *cli.Context) error {
	log.Info("Starting relay")
	host, err := cothorityd(c)
	log.ErrFatal(err)
	service := host.GetService(prifi.ServiceName).(*prifi.Service)
	// Do other setups
	group := getGroup(c)
	log.ErrFatal(service.StartRelay(group))

	host.Start()
	return nil
}

// Start the cothority in client-mode using the already stored configuration.
func client(c *cli.Context) error {
	log.Info("Starting client")
	host, err := cothorityd(c)
	log.ErrFatal(err)
	service := host.GetService(prifi.ServiceName).(*prifi.Service)
	// Do other setups
	log.ErrFatal(service.StartClient())

	host.Start()
	return nil
}

// Sets up a new cothority node configuration (used by all prifi modes)
func setupCothorityd(c *cli.Context) error {
	server.InteractiveConfig(DefaultName)
	return nil
}

// Starts the cothority node to enable communication with the prifi-service.
// Returns the prifi-service.
func cothorityd(c *cli.Context) (*sda.Conode, error) {
	// first check the options
	cfile := c.GlobalString("config")

	if _, err := os.Stat(cfile); os.IsNotExist(err) {
		return nil, err
	}
	// Let's read the config
	_, host, err := config.ParseCothorityd(cfile)
	if err != nil {
		return nil, err
	}
	return host, nil
}
{'fraction_non_alphanumeric': 0.13782832385594368, 'fraction_numerical': 0.0016246953696181965, 'mean_word_length': 3.663510101010101, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2528181', 'n_tokens_mistral': 2849, 'n_tokens_neox': 2612, 'n_words': 699}