2019-01-02 10:23:25 +00:00
|
|
|
// 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"
|
2019-02-11 11:17:32 +00:00
|
|
|
"storj.io/storj/pkg/peertls/tlsopts"
|
2019-01-02 10:23:25 +00:00
|
|
|
"storj.io/storj/pkg/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config holds server specific configuration parameters
|
|
|
|
type Config struct {
|
2019-02-11 11:17:32 +00:00
|
|
|
tlsopts.Config
|
2019-03-07 18:19:37 +00:00
|
|
|
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"`
|
2019-01-02 10:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run will run the given responsibilities with the configured identity.
|
2019-01-25 14:54:54 +00:00
|
|
|
func (sc Config) Run(ctx context.Context, identity *identity.FullIdentity, interceptor grpc.UnaryServerInterceptor, services ...Service) (err error) {
|
2019-01-02 10:23:25 +00:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
2019-02-11 11:17:32 +00:00
|
|
|
opts, err := tlsopts.NewOptions(identity, sc.Config)
|
2019-01-02 10:23:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer func() { err = utils.CombineErrors(err, opts.RevDB.Close()) }()
|
|
|
|
|
2019-03-07 18:19:37 +00:00
|
|
|
server, err := New(opts, sc.Address, sc.PrivateAddress, interceptor, services...)
|
2019-01-02 10:23:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-01-17 21:08:05 +00:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
<-ctx.Done()
|
2019-01-28 15:04:53 +00:00
|
|
|
if closeErr := server.Close(); closeErr != nil {
|
2019-01-17 21:08:05 +00:00
|
|
|
zap.S().Errorf("Failed to close server: %s", closeErr)
|
|
|
|
}
|
|
|
|
}()
|
2019-01-02 10:23:25 +00:00
|
|
|
|
2019-01-28 15:04:53 +00:00
|
|
|
zap.S().Infof("Node %s started on %s", server.Identity().ID, sc.Address)
|
|
|
|
return server.Run(ctx)
|
2019-01-02 10:23:25 +00:00
|
|
|
}
|