publicrpc: move runnable to cmd/guardiand
This matches the adminrpc implementation, removing the runnable and socket listener from pkg/publicrpc API surface. Change-Id: Ia6461c2ff839f39462391c5afd2694b1619b30b6
This commit is contained in:
parent
a897166a0c
commit
54b2e51379
|
@ -3,6 +3,7 @@ package guardiand
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
|
@ -352,6 +353,7 @@ func runBridge(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
|
||||
// local admin service socket
|
||||
adminService, err := adminServiceRunnable(logger, *adminSocketPath, injectC)
|
||||
if err != nil {
|
||||
logger.Fatal("failed to create admin service socket", zap.Error(err))
|
||||
|
@ -359,6 +361,10 @@ func runBridge(cmd *cobra.Command, args []string) {
|
|||
|
||||
// subscriber channel multiplexing for public gPRC streams
|
||||
rawHeartbeatListeners := publicrpc.HeartbeatStreamMultiplexer(logger)
|
||||
publicrpcService, err := publicrpcServiceRunnable(logger, *publicRPC, rawHeartbeatListeners)
|
||||
if err != nil {
|
||||
log.Fatal("failed to create publicrpc service socket", zap.Error(err))
|
||||
}
|
||||
|
||||
// Run supervisor.
|
||||
supervisor.New(rootCtx, logger, func(ctx context.Context) error {
|
||||
|
@ -407,8 +413,7 @@ func runBridge(cmd *cobra.Command, args []string) {
|
|||
return err
|
||||
}
|
||||
if *publicRPC != "" {
|
||||
if err := supervisor.Run(ctx, "publicrpc",
|
||||
publicrpc.PublicrpcServiceRunnable(logger, *publicRPC, rawHeartbeatListeners)); err != nil {
|
||||
if err := supervisor.Run(ctx, "publicrpc", publicrpcService); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package guardiand
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
publicrpcv1 "github.com/certusone/wormhole/bridge/pkg/proto/publicrpc/v1"
|
||||
"github.com/certusone/wormhole/bridge/pkg/publicrpc"
|
||||
"github.com/certusone/wormhole/bridge/pkg/supervisor"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
)
|
||||
|
||||
func publicrpcServiceRunnable(logger *zap.Logger, listenAddr string, hl *publicrpc.RawHeartbeatConns) (supervisor.Runnable, error) {
|
||||
l, err := net.Listen("tcp", listenAddr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to listen: %w", err)
|
||||
}
|
||||
|
||||
logger.Info("publicrpc server listening", zap.String("addr", l.Addr().String()))
|
||||
|
||||
rpcServer := publicrpc.NewPublicrpcServer(logger, hl)
|
||||
grpcServer := grpc.NewServer()
|
||||
publicrpcv1.RegisterPublicrpcServer(grpcServer, rpcServer)
|
||||
|
||||
return supervisor.GRPCServer(grpcServer, l, false), nil
|
||||
}
|
|
@ -1,14 +1,8 @@
|
|||
package publicrpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
publicrpcv1 "github.com/certusone/wormhole/bridge/pkg/proto/publicrpc/v1"
|
||||
"github.com/certusone/wormhole/bridge/pkg/supervisor"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// PublicrpcServer implements the publicrpc gRPC service.
|
||||
|
@ -45,17 +39,3 @@ func (s *PublicrpcServer) GetRawHeartbeats(req *publicrpcv1.GetRawHeartbeatsRequ
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func PublicrpcServiceRunnable(logger *zap.Logger, listenAddr string, rawHeartbeatListeners *RawHeartbeatConns) supervisor.Runnable {
|
||||
l, err := net.Listen("tcp", listenAddr)
|
||||
if err != nil {
|
||||
logger.Fatal("failed to listen for publicrpc service", zap.Error(err))
|
||||
}
|
||||
logger.Info(fmt.Sprintf("publicrpc server listening on %s", listenAddr))
|
||||
|
||||
rpcServer := NewPublicrpcServer(logger, rawHeartbeatListeners)
|
||||
|
||||
grpcServer := grpc.NewServer()
|
||||
publicrpcv1.RegisterPublicrpcServer(grpcServer, rpcServer)
|
||||
return supervisor.GRPCServer(grpcServer, l, false)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue