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