func initMemershipServices() { ca.CacheConfiguration() // Cache configuration eca = ca.NewECA(nil) tca = ca.NewTCA(eca) tlsca = ca.NewTLSCA(eca) var opts []grpc.ServerOption if viper.GetBool("peer.pki.tls.enabled") { // TLS configuration creds, err := credentials.NewServerTLSFromFile( filepath.Join(viper.GetString("server.rootpath"), "tlsca.cert"), filepath.Join(viper.GetString("server.rootpath"), "tlsca.priv"), ) if err != nil { panic("Failed creating credentials for OBC-CA: " + err.Error()) } opts = []grpc.ServerOption{grpc.Creds(creds)} } fmt.Printf("open socket...\n") sockp, err := net.Listen("tcp", viper.GetString("server.port")) if err != nil { panic("Cannot open port: " + err.Error()) } fmt.Printf("open socket...done\n") server = grpc.NewServer(opts...) eca.Start(server) tca.Start(server) tlsca.Start(server) fmt.Printf("start serving...\n") server.Serve(sockp) }
//initialize memberservices and startup func initMemSrvc() (net.Listener, error) { //start clean finitMemSrvc(nil) ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout) ca.CacheConfiguration() // Cache configuration aca := ca.NewACA() eca := ca.NewECA() tca := ca.NewTCA(eca) tlsca := ca.NewTLSCA(eca) sockp, err := net.Listen("tcp", viper.GetString("server.port")) if err != nil { return nil, err } var opts []grpc.ServerOption server := grpc.NewServer(opts...) aca.Start(server) eca.Start(server) tca.Start(server) tlsca.Start(server) go server.Serve(sockp) return sockp, nil }
func initMembershipSrvc() { // ca.LogInit seems to have been removed //ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout) ca.CacheConfiguration() // Cache configuration aca = ca.NewACA() eca = ca.NewECA(aca) tca = ca.NewTCA(eca) tlsca = ca.NewTLSCA(eca) var opts []grpc.ServerOption if viper.GetBool("peer.pki.tls.enabled") { // TLS configuration creds, err := credentials.NewServerTLSFromFile( filepath.Join(viper.GetString("server.rootpath"), "tlsca.cert"), filepath.Join(viper.GetString("server.rootpath"), "tlsca.priv"), ) if err != nil { panic("Failed creating credentials for Membersrvc: " + err.Error()) } opts = []grpc.ServerOption{grpc.Creds(creds)} } fmt.Printf("open socket...\n") sockp, err := net.Listen("tcp", viper.GetString("server.port")) if err != nil { panic("Cannot open port: " + err.Error()) } fmt.Printf("open socket...done\n") server = grpc.NewServer(opts...) aca.Start(server) eca.Start(server) tca.Start(server) tlsca.Start(server) fmt.Printf("start serving...\n") server.Serve(sockp) }
func main() { viper.SetEnvPrefix(envPrefix) viper.AutomaticEnv() replacer := strings.NewReplacer(".", "_") viper.SetEnvKeyReplacer(replacer) viper.SetConfigName("membersrvc") viper.SetConfigType("yaml") viper.AddConfigPath("./") // Path to look for the config file based on GOPATH gopath := os.Getenv("GOPATH") for _, p := range filepath.SplitList(gopath) { cfgpath := filepath.Join(p, "src/github.com/hyperledger/fabric/membersrvc") viper.AddConfigPath(cfgpath) } err := viper.ReadInConfig() if err != nil { panic(fmt.Errorf("Fatal error when reading %s config file: %s\n", "membersrvc", err)) } var iotrace, ioinfo, iowarning, ioerror, iopanic io.Writer if viper.GetInt("logging.trace") == 1 { iotrace = os.Stdout } else { iotrace = ioutil.Discard } if viper.GetInt("logging.info") == 1 { ioinfo = os.Stdout } else { ioinfo = ioutil.Discard } if viper.GetInt("logging.warning") == 1 { iowarning = os.Stdout } else { iowarning = ioutil.Discard } if viper.GetInt("logging.error") == 1 { ioerror = os.Stderr } else { ioerror = ioutil.Discard } if viper.GetInt("logging.panic") == 1 { iopanic = os.Stdout } else { iopanic = ioutil.Discard } // Init the crypto layer if err := crypto.Init(); err != nil { panic(fmt.Errorf("Failed initializing the crypto layer [%s]", err)) } ca.LogInit(iotrace, ioinfo, iowarning, ioerror, iopanic) // cache configure ca.CacheConfiguration() ca.Info.Println("CA Server (" + viper.GetString("server.version") + ")") aca := ca.NewACA() defer aca.Stop() eca := ca.NewECA() defer eca.Stop() tca := ca.NewTCA(eca) defer tca.Stop() tlsca := ca.NewTLSCA(eca) defer tlsca.Stop() runtime.GOMAXPROCS(viper.GetInt("server.gomaxprocs")) var opts []grpc.ServerOption if viper.GetString("server.tls.cert.file") != "" { creds, err := credentials.NewServerTLSFromFile(viper.GetString("server.tls.cert.file"), viper.GetString("server.tls.key.file")) if err != nil { panic(err) } opts = []grpc.ServerOption{grpc.Creds(creds)} } srv := grpc.NewServer(opts...) aca.Start(srv) eca.Start(srv) tca.Start(srv) tlsca.Start(srv) if sock, err := net.Listen("tcp", viper.GetString("server.port")); err != nil { ca.Error.Println("Fail to start CA Server: ", err) os.Exit(1) } else { srv.Serve(sock) sock.Close() } }
func main() { viper.SetEnvPrefix(envPrefix) viper.AutomaticEnv() replacer := strings.NewReplacer(".", "_") viper.SetEnvKeyReplacer(replacer) viper.SetConfigName("membersrvc") viper.SetConfigType("yaml") viper.AddConfigPath("./") // Path to look for the config file based on GOPATH gopath := os.Getenv("GOPATH") for _, p := range filepath.SplitList(gopath) { cfgpath := filepath.Join(p, "src/github.com/hyperledger/fabric/membersrvc") viper.AddConfigPath(cfgpath) } err := viper.ReadInConfig() if err != nil { logger.Panicf("Fatal error when reading %s config file: %s", "membersrvc", err) } flogging.LoggingInit("server") // Init the crypto layer if err := crypto.Init(); err != nil { logger.Panicf("Failed initializing the crypto layer [%s]", err) } // cache configure ca.CacheConfiguration() logger.Infof("CA Server (" + metadata.Version + ")") aca := ca.NewACA() defer aca.Stop() eca := ca.NewECA(aca) defer eca.Stop() tca := ca.NewTCA(eca) defer tca.Stop() tlsca := ca.NewTLSCA(eca) defer tlsca.Stop() runtime.GOMAXPROCS(viper.GetInt("server.gomaxprocs")) var opts []grpc.ServerOption if viper.GetString("server.tls.cert.file") != "" { creds, err := credentials.NewServerTLSFromFile(viper.GetString("server.tls.cert.file"), viper.GetString("server.tls.key.file")) if err != nil { logger.Panic(err) } opts = []grpc.ServerOption{grpc.Creds(creds)} } srv := grpc.NewServer(opts...) if viper.GetBool("aca.enabled") { aca.Start(srv) } eca.Start(srv) tca.Start(srv) tlsca.Start(srv) if sock, err := net.Listen("tcp", viper.GetString("server.port")); err != nil { logger.Errorf("Fail to start CA Server: %s", err) os.Exit(1) } else { srv.Serve(sock) sock.Close() } }