pkg/server: remove dead code

Change-Id: I4501ac7de727e2ec6908a7624808b4e596a68a23
This commit is contained in:
Egon Elbre 2020-03-24 18:28:19 +02:00
parent 3a3648c80b
commit bd9a998abd
2 changed files with 7 additions and 69 deletions

View File

@ -1,53 +0,0 @@
// 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/common/identity"
"storj.io/common/peertls/extensions"
"storj.io/common/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)
}

View File

@ -22,11 +22,12 @@ import (
"storj.io/storj/private/grpctlsopts"
)
// Service represents a specific gRPC method collection to be registered
// on a shared gRPC server. Metainfo, OverlayCache, PieceStore,
// etc. are all examples of services.
type Service interface {
Run(ctx context.Context, server *Server) error
// 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"`
}
type public struct {
@ -47,7 +48,6 @@ type Server struct {
log *zap.Logger
public public
private private
next []Service
tlsOptions *tlsopts.Options
mu sync.Mutex
@ -58,10 +58,9 @@ type Server struct {
// New creates a Server out of an Identity, a net.Listener,
// a UnaryServerInterceptor, and a set of services.
func New(log *zap.Logger, tlsOptions *tlsopts.Options, publicAddr, privateAddr string, interceptor grpc.UnaryServerInterceptor, services ...Service) (*Server, error) {
func New(log *zap.Logger, tlsOptions *tlsopts.Options, publicAddr, privateAddr string, interceptor grpc.UnaryServerInterceptor) (*Server, error) {
server := &Server{
log: log,
next: services,
tlsOptions: tlsOptions,
done: make(chan struct{}),
}
@ -145,14 +144,6 @@ func (p *Server) Close() error {
func (p *Server) Run(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
// are there any unstarted services? start those first. the
// services should know to call Run again once they're ready.
if len(p.next) > 0 {
next := p.next[0]
p.next = p.next[1:]
return next.Run(ctx, p)
}
// Make sure the server isn't already closed. If it is, register
// ourselves in the wait group so that Close can wait on it.
p.mu.Lock()