github.com/number571/tendermint@v0.34.11-gost/rpc/grpc/client_server.go (about) 1 package coregrpc 2 3 import ( 4 "context" 5 "net" 6 7 "google.golang.org/grpc" 8 9 tmnet "github.com/number571/tendermint/libs/net" 10 "github.com/number571/tendermint/rpc/core" 11 ) 12 13 // Config is an gRPC server configuration. 14 type Config struct { 15 MaxOpenConnections int 16 } 17 18 // StartGRPCServer starts a new gRPC BroadcastAPIServer using the given 19 // net.Listener. 20 // NOTE: This function blocks - you may want to call it in a go-routine. 21 // Deprecated: gRPC in the RPC layer of Tendermint will be removed in 0.36 22 func StartGRPCServer(env *core.Environment, ln net.Listener) error { 23 grpcServer := grpc.NewServer() 24 RegisterBroadcastAPIServer(grpcServer, &broadcastAPI{env: env}) 25 return grpcServer.Serve(ln) 26 } 27 28 // StartGRPCClient dials the gRPC server using protoAddr and returns a new 29 // BroadcastAPIClient. 30 func StartGRPCClient(protoAddr string) BroadcastAPIClient { 31 conn, err := grpc.Dial(protoAddr, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc)) 32 if err != nil { 33 panic(err) 34 } 35 return NewBroadcastAPIClient(conn) 36 } 37 38 func dialerFunc(ctx context.Context, addr string) (net.Conn, error) { 39 return tmnet.Connect(addr) 40 }