Exemple #1
0
// BuildProxy create new proxy builder
func BuildProxy(proxy Proxy) *ProxyBuilder {
	gStr := gsconfig.String("gsproxy.dhkey.G", "6849211231874234332173554215962568648211715948614349192108760170867674332076420634857278025209099493881977517436387566623834457627945222750416199306671083")

	pStr := gsconfig.String("gsproxy.dhkey.P", "13196520348498300509170571968898643110806720751219744788129636326922565480984492185368038375211941297871289403061486510064429072584259746910423138674192557")

	G, _ := new(big.Int).SetString(gStr, 0)

	P, _ := new(big.Int).SetString(pStr, 0)

	return &ProxyBuilder{

		laddrF: gsconfig.String("gsproxy.frontend.laddr", ":13512"),

		laddrE: gsconfig.String("gsproxy.backend.laddr", ":15827"),

		timeout: gsconfig.Seconds("gsproxy.rpc.timeout", 5),

		dhkeyResolver: handler.DHKeyResolve(func(device *gorpc.Device) (*handler.DHKey, error) {
			return handler.NewDHKey(G, P), nil
		}),

		proxy: proxy,
	}
}
Exemple #2
0
func (runner *_Runner) Run(main func(runner Runner)) {
	defer func() {
		if e := recover(); e != nil {
			runner.E("catch unknown exception\n\t%s", e)
		}

		runner.I("service stopped.")

		gslogger.Join()
	}()

	flag.Parse()

	configpath := *runner.flagString["config"]

	runner.D("config file path :%s", configpath)

	if configpath != "" {
		switch filepath.Ext(configpath) {
		case ".json":
			if err := gsconfig.LoadJSON(configpath); err != nil {
				gserrors.Panicf(ErrConfig, "load config file error :%s", configpath)
			}
		default:
			runner.W("can't load config file :%s", configpath)
		}
	}

	for k, v := range runner.flagString {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagInt {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagUint {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagFloat32 {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagFloat64 {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagSecond {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagMilliseconds {
		gsconfig.Update(runner.fullname[k], *v)
	}

	logroot := gsconfig.String("gsrunner.log", "")
	runner.D("log root path :%s", logroot)
	loglevel := gsconfig.String("gsrunner.log.level", "")
	runner.D("log level :%s", loglevel)
	registryFile := gsconfig.String("gsrunner.registry", "")
	runner.D("registry file:%s", registryFile)

	if logroot != "" {

		fullpath, _ := filepath.Abs(logroot)

		dir := filepath.Dir(fullpath)

		name := filepath.Base(fullpath)

		gslogger.SetLogDir(dir)

		gslogger.NewSink(gslogger.NewFilelog("gschat-mailhub", name, gsconfig.Int64("gschat.mailhub.log.maxsize", 0)))
	}

	if loglevel != "" {
		gslogger.NewFlags(gslogger.ParseLevel(loglevel))
	}

	if registryFile != "" {

		runner.I("load gsrpc services registry file :%s", registryFile)

		file, err := os.Open(registryFile)

		if err != nil {
			gserrors.Panicf(err, "open registry file error :%s", registryFile)
		}

		gorpc.RegistryLoad(file, registryFile)

		runner.I("load gsrpc services registry file :%s -- success", registryFile)
	}

	runner.I("service started.")

	main(runner)
}