Skip to content

Commit

Permalink
Merge pull request #58 from TRON-US/BTFS-1156-Enhanced
Browse files Browse the repository at this point in the history
[BTFS-1156-Enhanced] - added grcoptions, enabled startime in runtime,…
  • Loading branch information
laipogo authored Dec 20, 2019
2 parents 971cccb + eacd9f6 commit c5b3cdd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions utils/grpc/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type RuntimeServer struct {
sharedpb.UnimplementedRuntimeServiceServer
}

var Startime = time.Now()

//implementation of the shared helper function
func (s *RuntimeServer) CheckRuntime(ctx context.Context, req *sharedpb.SignedRuntimeInfoRequest) (*sharedpb.RuntimeInfoReport, error) {
//get connection object
Expand All @@ -52,6 +54,7 @@ func (s *RuntimeServer) CheckRuntime(ctx context.Context, req *sharedpb.SignedRu
res.Extra = []byte(nil)
res.PeerId = []byte(nil)
res.ServiceName = []byte(s.serviceName)
res.StartTime = Startime
res.CurentTime = time.Now()
res.GitHash = []byte(nil)
res.Version = []byte(nil)
Expand Down
14 changes: 9 additions & 5 deletions utils/grpc/setup_server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package grpc

import (
"fmt"
"log"
"net"

Expand Down Expand Up @@ -36,15 +37,17 @@ func (s *GrpcServer) serverTypeToServerName(server interface{}) {
case escrow.EscrowServiceServer:
s.serverName = "escrow"
case guard.GuardServiceServer:
s.serverName = "guard"
s.serverName = "guard-interceptor"
case hub.HubQueryServiceServer:
s.serverName = "hub"
case string:
s.serverName = fmt.Sprintf("%v", server)
default:
s.serverName = "unknown"
}
}

func (s *GrpcServer) GrpcServer(port string, dbURL string, rdURL string, server interface{}) *GrpcServer {
func (s *GrpcServer) GrpcServer(port string, dbURL string, rdURL string, server interface{}, options ...grpc.ServerOption) *GrpcServer {

s.serverTypeToServerName(server)

Expand All @@ -58,7 +61,7 @@ func (s *GrpcServer) GrpcServer(port string, dbURL string, rdURL string, server

s.lis = lis

s.CreateServer(s.serverName).
s.CreateServer(s.serverName, options...).
CreateHealthServer().
RegisterServer(server).
RegisterHealthServer().
Expand All @@ -76,10 +79,11 @@ func (s *GrpcServer) AcceptConnection() *GrpcServer {
return s
}

func (s *GrpcServer) CreateServer(serverName string) *GrpcServer {
func (s *GrpcServer) CreateServer(serverName string, options ...grpc.ServerOption) *GrpcServer {
//create grpc server
s.serverName = serverName
s.server = grpc.NewServer(middleware.GrpcServerOption)
options = append(options, middleware.GrpcServerOption)
s.server = grpc.NewServer(options...)
return s
}

Expand Down

0 comments on commit c5b3cdd

Please sign in to comment.