tendermint/rpc/grpc/client_server.go

38 lines
958 B
Go
Raw Normal View History

2016-06-21 13:19:49 -04:00
package core_grpc
import (
"net"
"time"
"google.golang.org/grpc"
2018-07-01 22:36:49 -04:00
cmn "github.com/tendermint/tendermint/libs/common"
2016-06-21 13:19:49 -04:00
)
// 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 {
2016-06-21 13:19:49 -04:00
grpcServer := grpc.NewServer()
RegisterBroadcastAPIServer(grpcServer, &broadcastAPI{})
return grpcServer.Serve(ln)
2016-06-21 13:19:49 -04:00
}
// StartGRPCClient dials the gRPC server using protoAddr and returns a new
// BroadcastAPIClient.
2016-06-21 13:19:49 -04:00
func StartGRPCClient(protoAddr string) BroadcastAPIClient {
conn, err := grpc.Dial(protoAddr, grpc.WithInsecure(), grpc.WithDialer(dialerFunc))
if err != nil {
panic(err)
}
return NewBroadcastAPIClient(conn)
}
func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) {
2017-10-04 16:40:45 -04:00
return cmn.Connect(addr)
2016-06-21 13:19:49 -04:00
}