From f5600225c33f35978f8bd0f2e4ad357bc58ddc64 Mon Sep 17 00:00:00 2001
From: Sean Young <sean.young@monax.io>
Date: Tue, 8 May 2018 11:47:01 +0100
Subject: [PATCH] Add config to create generic grpc server

This is so we can add a grpc keys server in a later commit

Signed-off-by: Sean Young <sean.young@monax.io>
---
 core/kernel.go | 18 ++++++++++++++++++
 rpc/config.go  | 14 ++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/core/kernel.go b/core/kernel.go
index 4f3df68b..faab16fc 100644
--- a/core/kernel.go
+++ b/core/kernel.go
@@ -17,6 +17,7 @@ package core
 import (
 	"context"
 	"fmt"
+	"net"
 	"net/http"
 	_ "net/http/pprof"
 	"os"
@@ -44,6 +45,7 @@ import (
 	tm_config "github.com/tendermint/tendermint/config"
 	tm_types "github.com/tendermint/tendermint/types"
 	dbm "github.com/tendermint/tmlibs/db"
+	"google.golang.org/grpc"
 )
 
 const (
@@ -199,6 +201,22 @@ func NewKernel(ctx context.Context, keyClient keys.KeyClient, privValidator tm_t
 				return serveProcess, nil
 			},
 		},
+		{
+			Name:     "grpc service",
+			Disabled: rpcConfig.GRPC.Disabled,
+			Launch: func() (process.Process, error) {
+				listen, err := net.Listen("tcp", rpcConfig.GRPC.ListenAddress)
+				if err != nil {
+					return nil, err
+				}
+
+				grpcServer := grpc.NewServer()
+
+				go grpcServer.Serve(listen)
+
+				return process.FromListeners(listen), nil
+			},
+		},
 	}
 
 	return &Kernel{
diff --git a/rpc/config.go b/rpc/config.go
index eba0b7ed..796b7f65 100644
--- a/rpc/config.go
+++ b/rpc/config.go
@@ -6,6 +6,7 @@ type RPCConfig struct {
 	V0       *V0Config       `json:",omitempty" toml:",omitempty"`
 	TM       *TMConfig       `json:",omitempty" toml:",omitempty"`
 	Profiler *ProfilerConfig `json:",omitempty" toml:",omitempty"`
+	GRPC     *GRPCConfig     `json:",omitempty" toml:",omitempty"`
 }
 
 type TMConfig struct {
@@ -23,13 +24,20 @@ type ProfilerConfig struct {
 	ListenAddress string
 }
 
+type GRPCConfig struct {
+	Disabled      bool
+	ListenAddress string
+}
+
 func DefaultRPCConfig() *RPCConfig {
 	return &RPCConfig{
 		TM:       DefaultTMConfig(),
 		V0:       DefaultV0Config(),
 		Profiler: DefaultProfilerConfig(),
+		GRPC:     DefaultGRPCConfig(),
 	}
 }
+
 func DefaultV0Config() *V0Config {
 	return &V0Config{
 		Server: server.DefaultServerConfig(),
@@ -42,6 +50,12 @@ func DefaultTMConfig() *TMConfig {
 	}
 }
 
+func DefaultGRPCConfig() *GRPCConfig {
+	return &GRPCConfig{
+		ListenAddress: "localhost:46659",
+	}
+}
+
 func DefaultProfilerConfig() *ProfilerConfig {
 	return &ProfilerConfig{
 		Disabled:      true,
-- 
GitLab