Exemple #1
0
func openDB() (t testDB, err error) {

	t.db, err = steward.OpenDatabase(db_path)

	t.Close()

	t.db, err = steward.OpenDatabase(db_path)

	return
}
func openDB() (t testDB, err error) {

	t.db, err = steward.OpenDatabase(db_path)
	if err != nil {
		return
	}

	err = steward.CleanDatabase(t.db)

	return
}
func TestParallelWebSocketConnect(*testing.T) {

	db, err := steward.OpenDatabase(db_path)
	if err != nil {
		log.Fatal(err)
	}

	db.SetMaxOpenConns(50) // default == 100

	err = steward.CleanDatabase(db)
	if err != nil {
		log.Fatal(err)
	}

	addr := ":8080"

	attackFlow := make(chan scoreboard.Attack, 100)

	go func() {
		err := scoreboard.Scoreboard(db, attackFlow, wwwPath, addr,
			time.Second, time.Now(), time.Minute, time.Minute,
			time.Second)
		if err != nil {
			log.Fatal(err)
		}
	}()

	time.Sleep(time.Second) // wait scoreboard launching

	connects := 1000

	log.Printf("%d parallel connects\n", connects)

	var wg sync.WaitGroup
	for i := 0; i < connects; i++ {
		wg.Add(1)
		go dialWebsocket(db, &wg, i)
	}

	wg.Wait()
}
Exemple #4
0
func main() {

	fmt.Println(buildInfo())

	kingpin.Parse()

	if *configPath == "" {
		*configPath = "/etc/tinfoilhat/tinfoilhat.toml"
	}

	config, err := config.ReadConfig(*configPath)
	if err != nil {
		log.Fatalln("Cannot open config:", err)
	}

	db, err := steward.OpenDatabase(config.Database.Connection)
	if err != nil {
		log.Fatalln("Open database fail:", err)
	}

	defer db.Close()

	db.SetMaxOpenConns(config.Database.MaxConnections)

	switch kingpin.Parse() {
	case "advisory list":
		advisoryList(db)

	case "advisory review":
		advisoryReview(db)

	case "advisory hide":
		advisoryHide(db)

	case "advisory unhide":
		advisoryUnhide(db)

	case "scoreboard":
		scoreboardShow(db)
	}
}
Exemple #5
0
func main() {

	fmt.Println(buildInfo())

	kingpin.Parse()

	if *configPath == "" {
		log.Println("Use default config path")
		*configPath = "/etc/tinfoilhat/tinfoilhat.toml"
	}

	config, err := config.ReadConfig(*configPath)
	if err != nil {
		log.Fatalln("Cannot open config:", err)
	}

	logFile, err := os.OpenFile(config.LogFile,
		os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		log.Fatalln("Cannot open file:", err)
	}
	defer logFile.Close()
	log.SetOutput(logFile)

	log.Println(buildInfo())

	var rlim syscall.Rlimit
	err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)
	if err != nil {
		log.Fatalln("Getrlimit fail:", err)
	}

	log.Println("RLIMIT_NOFILE CUR:", rlim.Cur, "MAX:", rlim.Max)

	db, err := steward.OpenDatabase(config.Database.Connection)
	if err != nil {
		log.Fatalln("Open database fail:", err)
	}

	defer db.Close()

	db.SetMaxOpenConns(config.Database.MaxConnections)

	if *dbReinit {
		reinitDatabase(db, config)
	}

	checker.SetTimeout(config.CheckerTimeout.Duration)

	if config.AdvisoryReceiver.Disabled {
		scoreboard.DisableAdvisory()
	}

	priv, err := vexillary.GenerateKey()
	if err != nil {
		log.Fatalln("Generate key fail:", err)
	}

	attackFlow := make(chan scoreboard.Attack, config.API.AttackBuffer)

	go receiver.FlagReceiver(db, priv, config.FlagReceiver.Addr,
		config.FlagReceiver.ReceiveTimeout.Duration,
		config.FlagReceiver.SocketTimeout.Duration,
		attackFlow)

	go receiver.AdvisoryReceiver(db, config.AdvisoryReceiver.Addr,
		config.AdvisoryReceiver.ReceiveTimeout.Duration,
		config.AdvisoryReceiver.SocketTimeout.Duration)

	go scoreboard.Scoreboard(db, attackFlow,
		config.Scoreboard.WwwPath,
		config.Scoreboard.Addr,
		config.Scoreboard.UpdateTimeout.Duration,
		config.Pulse.Start.Time,
		config.Pulse.Half.Duration,
		config.Pulse.Lunch.Duration,
		config.Pulse.DarkestTime.Duration)

	err = pulse.Pulse(db, priv,
		config.Pulse.Start.Time,
		config.Pulse.Half.Duration,
		config.Pulse.Lunch.Duration,
		config.Pulse.RoundLen.Duration,
		config.Pulse.CheckTimeout.Duration)
	if err != nil {
		log.Fatalln("Game error:", err)
	}

	log.Println("It's now safe to turn off you computer")
	for {
		time.Sleep(time.Hour)
	}
}