storj/cmd/netstate/main.go
Natalie Villasana 6723064bfb
Enables netstate service to save pointers (#49)
* adds pointer to netstate proto file

* generated updated netstate proto

* changes boltdb netstate to save pointers as values

* updates netstate Put to save Pointers, updates client example to put a pointer, adds grpc status errors, updates tests, changes boltdb 'File' struct to 'PointerEntry'

* updates netstate client example and client test to save pointers, updates netstate List and Delete

* begins adding netstate-http tests

* removes netstate http service

* re-adds netstate auth

* updates boltdb netstate test

* changes encrypted_unencrypted_size from int64 to bytes in netstate proto

* updates READMEs
2018-05-29 22:47:40 -04:00

67 lines
1.4 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"flag"
"fmt"
"net"
"go.uber.org/zap"
"google.golang.org/grpc"
"storj.io/storj/pkg/netstate"
proto "storj.io/storj/protos/netstate"
"storj.io/storj/storage/boltdb"
)
var (
port int
dbPath string
prod bool
)
func initializeFlags() {
flag.IntVar(&port, "port", 8080, "port")
flag.StringVar(&dbPath, "db", "netstate.db", "db path")
flag.BoolVar(&prod, "prod", false, "type of environment where this service runs")
flag.Parse()
}
func main() {
initializeFlags()
// No err here because no vars passed into NewDevelopment().
// The default won't return an error, but if args are passed in,
// then there will need to be error handling.
logger, _ := zap.NewDevelopment()
if prod {
logger, _ = zap.NewProduction()
}
defer logger.Sync()
bdb, err := boltdb.New(logger, dbPath)
if err != nil {
logger.Fatal("failed to initiate boltdb", zap.Error(err))
return
}
defer bdb.Close()
// start grpc server
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
logger.Fatal("failed to listen", zap.Error(err))
}
grpcServer := grpc.NewServer()
proto.RegisterNetStateServer(grpcServer, netstate.NewServer(bdb, logger))
logger.Debug(fmt.Sprintf("server listening on port %d", port))
defer grpcServer.GracefulStop()
err = grpcServer.Serve(lis)
if err != nil {
logger.Error("Failed to serve:", zap.Error(err))
}
}