mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
cleanup to add linter grpc change: https://godoc.org/google.golang.org/grpc#WithContextDialer https://godoc.org/google.golang.org/grpc#WithDialer grpc/grpc-go#2627 prometheous change: due to UninstrumentedHandler, being deprecated in the future empty branch = empty if or else statement didn't delete them entirely but commented couldn't find a reason to have them could not replicate the issue #3406 but if want to keep it commented then we should comment out the if statement as well
39 lines
986 B
Go
39 lines
986 B
Go
package core_grpc
|
|
|
|
import (
|
|
"net"
|
|
|
|
"golang.org/x/net/context"
|
|
"google.golang.org/grpc"
|
|
|
|
cmn "github.com/tendermint/tendermint/libs/common"
|
|
)
|
|
|
|
// Config is an gRPC server configuration.
|
|
type Config struct {
|
|
MaxOpenConnections int
|
|
}
|
|
|
|
// StartGRPCServer starts a new gRPC BroadcastAPIServer using the given
|
|
// net.Listener.
|
|
// NOTE: This function blocks - you may want to call it in a go-routine.
|
|
func StartGRPCServer(ln net.Listener) error {
|
|
grpcServer := grpc.NewServer()
|
|
RegisterBroadcastAPIServer(grpcServer, &broadcastAPI{})
|
|
return grpcServer.Serve(ln)
|
|
}
|
|
|
|
// StartGRPCClient dials the gRPC server using protoAddr and returns a new
|
|
// BroadcastAPIClient.
|
|
func StartGRPCClient(protoAddr string) BroadcastAPIClient {
|
|
conn, err := grpc.Dial(protoAddr, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return NewBroadcastAPIClient(conn)
|
|
}
|
|
|
|
func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {
|
|
return cmn.Connect(addr)
|
|
}
|