storj/pkg/server/config.go
Jeff Wendling 098cbc9c67 all: use pkg/rpc instead of pkg/transport
all of the packages and tests work with both grpc and
drpc. we'll probably need to do some jenkins pipelines
to run the tests with drpc as well.

most of the changes are really due to a bit of cleanup
of the pkg/transport.Client api into an rpc.Dialer in
the spirit of a net.Dialer. now that we don't need
observers, we can pass around stateless configuration
to everything rather than stateful things that issue
observations. it also adds a DialAddressID for the
case where we don't have a pb.Node, but we do have an
address and want to assert some ID. this happened
pretty frequently, and now there's no more weird
contortions creating custom tls options, etc.

a lot of the other changes are being consistent/using
the abstractions in the rpc package to do rpc style
things like finding peer information, or checking
status codes.

Change-Id: Ief62875e21d80a21b3c56a5a37f45887679f9412
2019-09-25 15:37:06 -06:00

55 lines
1.6 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package server
import (
"context"
"go.uber.org/zap"
"google.golang.org/grpc"
"storj.io/storj/pkg/identity"
"storj.io/storj/pkg/peertls/extensions"
"storj.io/storj/pkg/peertls/tlsopts"
)
// Config holds server specific configuration parameters
type Config struct {
tlsopts.Config
Address string `user:"true" help:"public address to listen on" default:":7777"`
PrivateAddress string `user:"true" help:"private address to listen on" default:"127.0.0.1:7778"`
DebugLogTraffic bool `user:"true" help:"log all GRPC traffic to zap logger" default:"false"`
}
// Run will run the given responsibilities with the configured identity.
func (sc Config) Run(ctx context.Context, log *zap.Logger, identity *identity.FullIdentity, revDB extensions.RevocationDB, interceptor grpc.UnaryServerInterceptor, services ...Service) (err error) {
defer mon.Task()(&ctx)(&err)
// Ensure revDB is not nil, since we call Close() below we do not want a
// panic
if revDB == nil {
return Error.New("revDB cannot be nil in call to Run")
}
tlsOptions, err := tlsopts.NewOptions(identity, sc.Config, revDB)
if err != nil {
return err
}
server, err := New(log.Named("server"), tlsOptions, sc.Address, sc.PrivateAddress, interceptor, services...)
if err != nil {
return err
}
go func() {
<-ctx.Done()
if closeErr := server.Close(); closeErr != nil {
log.Sugar().Errorf("Failed to close server: %s", closeErr)
}
}()
log.Sugar().Infof("Node %s started on %s", server.Identity().ID, sc.Address)
return server.Run(ctx)
}