Пример #1
0
// launches browser if it's enabled
func (c *Config) launchBrowser() {
	if c.WebInterface.LaunchBrowser == true {
		go func() {
			// TODO: wait is BS, is it really needed?
			//
			// Wait a moment just to make sure the http interface is up
			time.Sleep(time.Millisecond * 100)
			//

			logger.Info("Launching System Browser with %s", c.fullAddress())
			if err := util.OpenBrowser(c.fullAddress()); err != nil {
				logger.Error(err.Error())
			}
		}()
	}
}
Пример #2
0
// Run start the client service.
func (se *Service) Run() {
	// init wallet dir
	wallet.InitDir(se.cfg.WalletDir)

	// init account dir
	account.InitDir(se.cfg.AccountDir)

	// register coins
	r := router.New(se)
	addr := fmt.Sprintf("localhost:%d", se.cfg.Port)
	if err := gui.LaunchWebInterface(addr, se.cfg.GuiDir, r); err != nil {
		panic(err)
	}

	go func() {
		// Wait a moment just to make sure the http service is up
		time.Sleep(time.Millisecond * 100)
		fulladdress := fmt.Sprintf("http://%s", addr)
		logger.Info("Launching System Browser with %s", fulladdress)
		if err := util.OpenBrowser(fulladdress); err != nil {
			logger.Error(err.Error())
		}
	}()
}
Пример #3
0
func Run(c *Config) {

	c.GUIDirectory = util.ResolveResourceDirectory(c.GUIDirectory)

	scheme := "http"
	if c.WebInterfaceHTTPS {
		scheme = "https"
	}
	host := fmt.Sprintf("%s:%d", c.WebInterfaceAddr, c.WebInterfacePort)
	fullAddress := fmt.Sprintf("%s://%s", scheme, host)
	logger.Critical("Full address: %s", fullAddress)

	if c.PrintWebInterfaceAddress {
		fmt.Println(fullAddress)
		return
	}

	initProfiling(c.HTTPProf, c.ProfileCPU, c.ProfileCPUFile)

	logCfg := util.DevLogConfig(logModules)
	logCfg.Format = logFormat
	logCfg.InitLogger()

	// initLogging(c.LogLevel, c.ColorLog)

	// start the block db.
	blockdb.Start()
	defer blockdb.Stop()

	// start the transaction db.
	// transactiondb.Start()
	// defer transactiondb.Stop()

	// If the user Ctrl-C's, shutdown properly
	quit := make(chan int)
	go catchInterrupt(quit)
	// Watch for SIGUSR1
	go catchDebug()

	gui.InitWalletRPC(c.WalletDirectory)

	dconf := configureDaemon(c)
	d := daemon.NewDaemon(dconf)

	stopDaemon := make(chan int)
	go d.Start(stopDaemon)

	// start the webrpc
	closingC := make(chan struct{})
	if c.RPCInterface {
		go webrpc.Start(
			fmt.Sprintf("%v:%v", c.RPCInterfaceAddr, c.RPCInterfacePort),
			webrpc.ChanBuffSize(1000),
			webrpc.ThreadNum(1000),
			webrpc.Gateway(d.Gateway),
			webrpc.Quit(closingC))
	}

	// Debug only - forces connection on start.  Violates thread safety.
	if c.ConnectTo != "" {
		_, err := d.Pool.Pool.Connect(c.ConnectTo)
		if err != nil {
			log.Panic(err)
		}
	}

	if c.WebInterface {
		var err error
		if c.WebInterfaceHTTPS {
			// Verify cert/key parameters, and if neither exist, create them
			errs := util.CreateCertIfNotExists(host, c.WebInterfaceCert, c.WebInterfaceKey, "Skycoind")
			if len(errs) != 0 {
				for _, err := range errs {
					logger.Error(err.Error())
				}
				logger.Error("gui.CreateCertIfNotExists failure")
				os.Exit(1)
			}

			err = gui.LaunchWebInterfaceHTTPS(host, c.GUIDirectory, d, c.WebInterfaceCert, c.WebInterfaceKey)
		} else {
			err = gui.LaunchWebInterface(host, c.GUIDirectory, d)
		}

		if err != nil {
			logger.Error(err.Error())
			logger.Error("Failed to start web GUI")
			os.Exit(1)
		}

		if c.LaunchBrowser {
			go func() {
				// Wait a moment just to make sure the http interface is up
				time.Sleep(time.Millisecond * 100)

				logger.Info("Launching System Browser with %s", fullAddress)
				if err := util.OpenBrowser(fullAddress); err != nil {
					logger.Error(err.Error())
				}
			}()
		}
	}

	/*
		time.Sleep(5)
		tx := InitTransaction()
		_ = tx
		err, _ = d.Visor.Visor.InjectTxn(tx)
		if err != nil {
			log.Panic(err)
		}
	*/

	/*
		//first transaction
		if c.RunMaster == true {
			go func() {
				for d.Visor.Visor.Blockchain.Head().Seq() < 2 {
					time.Sleep(5)
					tx := InitTransaction()
					err, _ := d.Visor.Visor.InjectTxn(tx)
					if err != nil {
						//log.Panic(err)
					}
				}
			}()
		}
	*/

	<-quit
	stopDaemon <- 1
	close(closingC)

	logger.Info("Shutting down")
	d.Shutdown()
	logger.Info("Goodbye")
}
Пример #4
0
func Run(c *Config) {
	scheme := "http"
	if c.WebInterfaceHTTPS {
		scheme = "https"
	}
	host := fmt.Sprintf("%s:%d", c.WebInterfaceAddr, c.WebInterfacePort)
	fullAddress := fmt.Sprintf("%s://%s", scheme, host)
	logger.Critical("Full address: %s", fullAddress)

	if c.PrintWebInterfaceAddress {
		fmt.Println(fullAddress)
		return
	}

	initProfiling(c.HTTPProf, c.ProfileCPU, c.ProfileCPUFile)
	initLogging(c.LogLevel, c.ColorLog)

	// If the user Ctrl-C's, shutdown properly
	quit := make(chan int)
	go catchInterrupt(quit)
	// Watch for SIGUSR1
	go catchDebug()

	gui.InitWalletRPC(c.WalletDirectory)

	dconf := configureDaemon(c)
	d := daemon.NewDaemon(dconf)

	stopDaemon := make(chan int)
	go d.Start(stopDaemon)

	// Debug only - forces connection on start.  Violates thread safety.
	if c.ConnectTo != "" {
		_, err := d.Pool.Pool.Connect(c.ConnectTo)
		if err != nil {
			log.Panic(err)
		}
	}

	if c.WebInterface {
		var err error
		if c.WebInterfaceHTTPS {
			// Verify cert/key parameters, and if neither exist, create them
			errs := gui.CreateCertIfNotExists(host, c.WebInterfaceCert, c.WebInterfaceKey)
			if len(errs) != 0 {
				for _, err := range errs {
					logger.Error(err.Error())
				}
				logger.Error("gui.CreateCertIfNotExists failure")
				os.Exit(1)
			}

			err = gui.LaunchWebInterfaceHTTPS(host, c.GUIDirectory, d, c.WebInterfaceCert, c.WebInterfaceKey)
		} else {
			err = gui.LaunchWebInterface(host, c.GUIDirectory, d)
		}

		if err != nil {
			logger.Error(err.Error())
			logger.Error("Failed to start web GUI")
			os.Exit(1)
		}

		if c.LaunchBrowser {
			go func() {
				// Wait a moment just to make sure the http interface is up
				time.Sleep(time.Millisecond * 100)

				logger.Info("Launching System Browser with %s", fullAddress)
				if err := util.OpenBrowser(fullAddress); err != nil {
					logger.Error(err.Error())
				}
			}()
		}
	}

	/*
		time.Sleep(5)
		tx := InitTransaction()
		_ = tx
		err, _ = d.Visor.Visor.InjectTxn(tx)
		if err != nil {
			log.Panic(err)
		}
	*/

	<-quit
	stopDaemon <- 1

	logger.Info("Shutting down")
	d.Shutdown()
	logger.Info("Goodbye")
}