func (c *Client) getValueClient() error { var err error var opts []grpc.DialOption tlsConfig := &ftls.Config{ MutualTLS: *mutualtls, InsecureSkipVerify: *insecureSkipVerify, CertFile: *certfile, KeyFile: *keyfile, CAFile: *cafile, } rOpts, err := ftls.NewGRPCClientDialOpt(&ftls.Config{ MutualTLS: false, CAFile: *cafile, }) if err != nil { return err } if c.vdirect != "" { c.vstore, err = api.NewValueStore(c.vdirect, 10, tlsConfig, opts...) } else { c.vstore = api.NewReplValueStore(&api.ReplValueStoreConfig{ AddressIndex: 2, StoreFTLSConfig: tlsConfig, GRPCOpts: opts, RingServerGRPCOpts: []grpc.DialOption{rOpts}, }) if err := c.vstore.Startup(context.Background()); err != nil { return fmt.Errorf("Unable to start value store client: %s", err) } } if err != nil { return fmt.Errorf("Unable to setup value store: %s", err.Error()) } return nil }
func main() { flag.Parse() if *printVersionInfo { fmt.Println("formicd version:", formicdVersion) fmt.Println("build date:", buildDate) fmt.Println("go version:", goVersion) return } cfg := resolveConfig(nil) setupMetrics(cfg.metricsAddr, cfg.metricsCollectors) var opts []grpc.ServerOption creds, err := credentials.NewServerTLSFromFile(path.Join(cfg.path, "server.crt"), path.Join(cfg.path, "server.key")) FatalIf(err, "Couldn't load cert from file") opts = []grpc.ServerOption{grpc.Creds(creds)} s := grpc.NewServer(opts...) var vcOpts []grpc.DialOption vtlsConfig := &ftls.Config{ MutualTLS: !cfg.skipMutualTLS, InsecureSkipVerify: cfg.insecureSkipVerify, CertFile: path.Join(cfg.path, "client.crt"), KeyFile: path.Join(cfg.path, "client.key"), CAFile: path.Join(cfg.path, "ca.pem"), } vrOpts, err := ftls.NewGRPCClientDialOpt(&ftls.Config{ MutualTLS: false, InsecureSkipVerify: cfg.insecureSkipVerify, CAFile: path.Join(cfg.path, "ca.pem"), }) if err != nil { grpclog.Fatalln("Cannot setup value store tls config for synd client:", err) } var gcOpts []grpc.DialOption gtlsConfig := &ftls.Config{ MutualTLS: !cfg.skipMutualTLS, InsecureSkipVerify: cfg.insecureSkipVerify, CertFile: path.Join(cfg.path, "client.crt"), KeyFile: path.Join(cfg.path, "client.key"), CAFile: path.Join(cfg.path, "ca.pem"), } grOpts, err := ftls.NewGRPCClientDialOpt(&ftls.Config{ MutualTLS: false, InsecureSkipVerify: cfg.insecureSkipVerify, CAFile: path.Join(cfg.path, "ca.pem"), }) if err != nil { grpclog.Fatalln("Cannot setup group store tls config for synd client:", err) } clientID, _ := os.Hostname() if clientID != "" { clientID += "/formicd" } vstore := api.NewReplValueStore(&api.ReplValueStoreConfig{ AddressIndex: 2, StoreFTLSConfig: vtlsConfig, GRPCOpts: vcOpts, RingServer: cfg.oortValueSyndicate, RingCachePath: path.Join(cfg.path, "ring/valuestore.ring"), RingServerGRPCOpts: []grpc.DialOption{vrOpts}, RingClientID: clientID, ConcurrentRequestsPerStore: cfg.concurrentRequestsPerStore, }) if verr := vstore.Startup(context.Background()); verr != nil { grpclog.Fatalln("Cannot start valuestore connector:", verr) } gstore := api.NewReplGroupStore(&api.ReplGroupStoreConfig{ AddressIndex: 2, StoreFTLSConfig: gtlsConfig, GRPCOpts: gcOpts, RingServer: cfg.oortGroupSyndicate, RingCachePath: path.Join(cfg.path, "ring/groupstore.ring"), RingServerGRPCOpts: []grpc.DialOption{grOpts}, RingClientID: clientID, ConcurrentRequestsPerStore: cfg.concurrentRequestsPerStore, }) if gerr := gstore.Startup(context.Background()); gerr != nil { grpclog.Fatalln("Cannot start valuestore connector:", gerr) } fs, err := NewOortFS(vstore, gstore) if err != nil { grpclog.Fatalln(err) } l, err := net.Listen("tcp", fmt.Sprintf(":%d", cfg.port)) FatalIf(err, "Failed to bind to port") pb.RegisterApiServer(s, NewApiServer(fs, cfg.nodeId)) grpclog.Printf("Starting up on %d...\n", cfg.port) s.Serve(l) }