Пример #1
0
func (c *Client) getGroupClient() 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.gdirect != "" {
		c.gstore, err = api.NewGroupStore(c.gdirect, 10, tlsConfig, opts...)
	} else {
		c.gstore = api.NewReplGroupStore(&api.ReplGroupStoreConfig{
			AddressIndex:       2,
			StoreFTLSConfig:    tlsConfig,
			GRPCOpts:           opts,
			RingServerGRPCOpts: []grpc.DialOption{rOpts},
		})
		if err := c.gstore.Startup(context.Background()); err != nil {
			return fmt.Errorf("Unable to start group store client: %s", err)
		}
	}
	if err != nil {
		return fmt.Errorf("Unable to setup group store: %s", err.Error())
	}
	return nil
}
Пример #2
0
// main the control function
func main() {

	cfg := resolveConfig(nil)

	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 cOpts []grpc.DialOption
	tlsConfig := &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"),
	}
	rOpts, err := ftls.NewGRPCClientDialOpt(&ftls.Config{
		MutualTLS:          false,
		InsecureSkipVerify: cfg.insecureSkipVerify,
		CAFile:             path.Join(cfg.path, "ca.pem"),
	})
	if err != nil {
		grpclog.Fatalln("Cannot setup tls config for synd client:", err)
	}

	clientID, _ := os.Hostname()
	if clientID != "" {
		clientID += "/oohhc-filesysd"
	}

	gstore := api.NewReplGroupStore(&api.ReplGroupStoreConfig{
		AddressIndex:       2,
		StoreFTLSConfig:    tlsConfig,
		GRPCOpts:           cOpts,
		RingServer:         cfg.oortGroupSyndicate,
		RingCachePath:      path.Join(cfg.path, "ring/groupstore.ring"),
		RingServerGRPCOpts: []grpc.DialOption{rOpts},
		RingClientID:       clientID,
	})
	if gerr := gstore.Startup(context.Background()); gerr != nil {
		grpclog.Fatalln("Cannot start valuestore connector:", gerr)
	}

	fs, err := NewFileSystemWS(gstore)
	if err != nil {
		grpclog.Fatalln(err)
	}
	l, err := net.Listen("tcp", fmt.Sprintf(":%d", cfg.port))
	FatalIf(err, "Failed to bind to port")
	fb.RegisterFileSystemAPIServer(s, NewFileSystemAPIServer(fs))
	grpclog.Printf("Starting up on %d...\n", cfg.port)
	s.Serve(l)
}
Пример #3
0
func (stor *groupStore) startup() error {
	if stor.conn != nil {
		return nil
	}
	var err error
	creds, err := ftls.NewGRPCClientDialOpt(stor.ftlsc)
	if err != nil {
		stor.conn = nil
		return err
	}
	opts := make([]grpc.DialOption, len(stor.opts))
	copy(opts, stor.opts)
	opts = append(opts, creds)
	stor.conn, err = grpc.Dial(stor.addr, opts...)
	if err != nil {
		stor.conn = nil
		return err
	}
	stor.client = pb.NewGroupStoreClient(stor.conn)
	return nil
}
Пример #4
0
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)
}