mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-26 07:12:16 +00:00
Spell out the package explicitly. This commit is totally textual, and does not change any logic. The swiss-army knife package may serve a kick-start in early stage development. But as the codebase growing, we might want to retire it gradually: For simple wrapping functions, just inline it on the call site. For larger pice of code, make it an independent package.
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package server
|
|
|
|
import (
|
|
"net"
|
|
"strings"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/tendermint/abci/types"
|
|
common "github.com/tendermint/go-common"
|
|
)
|
|
|
|
// var maxNumberConnections = 2
|
|
|
|
type GRPCServer struct {
|
|
common.BaseService
|
|
|
|
proto string
|
|
addr string
|
|
listener net.Listener
|
|
server *grpc.Server
|
|
|
|
app types.ABCIApplicationServer
|
|
}
|
|
|
|
func NewGRPCServer(protoAddr string, app types.ABCIApplicationServer) (common.Service, error) {
|
|
parts := strings.SplitN(protoAddr, "://", 2)
|
|
proto, addr := parts[0], parts[1]
|
|
s := &GRPCServer{
|
|
proto: proto,
|
|
addr: addr,
|
|
listener: nil,
|
|
app: app,
|
|
}
|
|
s.BaseService = *common.NewBaseService(nil, "ABCIServer", s)
|
|
_, err := s.Start() // Just start it
|
|
return s, err
|
|
}
|
|
|
|
func (s *GRPCServer) OnStart() error {
|
|
s.BaseService.OnStart()
|
|
ln, err := net.Listen(s.proto, s.addr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
s.listener = ln
|
|
s.server = grpc.NewServer()
|
|
types.RegisterABCIApplicationServer(s.server, s.app)
|
|
go s.server.Serve(s.listener)
|
|
return nil
|
|
}
|
|
|
|
func (s *GRPCServer) OnStop() {
|
|
s.BaseService.OnStop()
|
|
s.server.Stop()
|
|
}
|