-
Notifications
You must be signed in to change notification settings - Fork 390
/
config.go
48 lines (38 loc) · 1.28 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package server
import (
"context"
"github.com/zeebo/errs"
"go.uber.org/zap"
"google.golang.org/grpc"
"storj.io/storj/pkg/identity"
"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"`
}
// Run will run the given responsibilities with the configured identity.
func (sc Config) Run(ctx context.Context, identity *identity.FullIdentity, interceptor grpc.UnaryServerInterceptor, services ...Service) (err error) {
defer mon.Task()(&ctx)(&err)
opts, err := tlsopts.NewOptions(identity, sc.Config)
if err != nil {
return err
}
defer func() { err = errs.Combine(err, opts.RevDB.Close()) }()
server, err := New(opts, sc.Address, sc.PrivateAddress, interceptor, services...)
if err != nil {
return err
}
go func() {
<-ctx.Done()
if closeErr := server.Close(); closeErr != nil {
zap.S().Errorf("Failed to close server: %s", closeErr)
}
}()
zap.S().Infof("Node %s started on %s", server.Identity().ID, sc.Address)
return server.Run(ctx)
}