Skip to content

Commit

Permalink
Break out functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed May 28, 2024
1 parent cf2c669 commit 611c6da
Showing 1 changed file with 67 additions and 31 deletions.
98 changes: 67 additions & 31 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
prometheusmetrics "github.com/attestantio/dirk/services/metrics/prometheus"
"github.com/attestantio/dirk/services/peers"
staticpeers "github.com/attestantio/dirk/services/peers/static"
"github.com/attestantio/dirk/services/process"
standardprocess "github.com/attestantio/dirk/services/process/standard"
"github.com/attestantio/dirk/services/ruler"
goruler "github.com/attestantio/dirk/services/ruler/golang"
Expand Down Expand Up @@ -587,45 +588,22 @@ func startSender(ctx context.Context,
return senderSvc, nil
}

func startGrpcServer(ctx context.Context,
func startProcess(ctx context.Context,
monitor metrics.Service,
majordomoSvc majordomo.Service,
serverID uint64,
stores []e2wtypes.Store,
unlockerSvc unlocker.Service,
checkerSvc checker.Service,
fetcherSvc fetcher.Service,
rulerSvc ruler.Service,
peersSvc peers.Service,
certPEMBlock []byte,
keyPEMBlock []byte,
caPEMBlock []byte,
) (
*grpcapi.Service,
process.Service,
error,
) {
// Set up the lister.
listerSvc, err := startLister(ctx, monitor, fetcherSvc, checkerSvc, rulerSvc)
if err != nil {
return nil, err
}

// Set up the signec.
signerSvc, err := startSigner(ctx, monitor, fetcherSvc, checkerSvc, unlockerSvc, rulerSvc)
if err != nil {
return nil, err
}

peersSvc, err := startPeers(ctx, monitor)
if err != nil {
return nil, err
}

serverID, err := strconv.ParseUint(viper.GetString("server.id"), 10, 64)
if err != nil {
return nil, errors.Wrap(err, "failed to obtain server ID")
}

certPEMBlock, keyPEMBlock, caPEMBlock, err := obtainCerts(ctx, majordomoSvc)
if err != nil {
return nil, err
}

sender, err := startSender(ctx, monitor, certPEMBlock, keyPEMBlock, caPEMBlock)
if err != nil {
return nil, err
Expand Down Expand Up @@ -661,6 +639,65 @@ func startGrpcServer(ctx context.Context,
return nil, errors.Wrap(err, "failed to create process service")
}

return processSvc, nil
}

func startGrpcServer(ctx context.Context,
monitor metrics.Service,
majordomoSvc majordomo.Service,
stores []e2wtypes.Store,
unlockerSvc unlocker.Service,
checkerSvc checker.Service,
fetcherSvc fetcher.Service,
rulerSvc ruler.Service,
) (
*grpcapi.Service,
error,
) {
// Set up the lister.
listerSvc, err := startLister(ctx, monitor, fetcherSvc, checkerSvc, rulerSvc)
if err != nil {
return nil, err
}

// Set up the signec.
signerSvc, err := startSigner(ctx, monitor, fetcherSvc, checkerSvc, unlockerSvc, rulerSvc)
if err != nil {
return nil, err
}

peersSvc, err := startPeers(ctx, monitor)
if err != nil {
return nil, err
}

serverID, err := strconv.ParseUint(viper.GetString("server.id"), 10, 64)
if err != nil {
return nil, errors.Wrap(err, "failed to obtain server ID")
}

certPEMBlock, keyPEMBlock, caPEMBlock, err := obtainCerts(ctx, majordomoSvc)
if err != nil {
return nil, err
}

processSvc, err := startProcess(ctx,
monitor,
majordomoSvc,
serverID,
stores,
unlockerSvc,
checkerSvc,
fetcherSvc,
peersSvc,
certPEMBlock,
keyPEMBlock,
caPEMBlock,
)
if err != nil {
return nil, err
}

var accountManagerMonitor metrics.AccountManagerMonitor
if monitor, isMonitor := monitor.(metrics.AccountManagerMonitor); isMonitor {
accountManagerMonitor = monitor
Expand Down Expand Up @@ -698,7 +735,6 @@ func startGrpcServer(ctx context.Context,
if monitor, isMonitor := monitor.(metrics.APIMonitor); isMonitor {
apiMonitor = monitor
}

svc, err := grpcapi.New(ctx,
grpcapi.WithLogLevel(util.LogLevel("api")),
grpcapi.WithMonitor(apiMonitor),
Expand Down

0 comments on commit 611c6da

Please sign in to comment.