You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
958 B

  1. package core_grpc
  2. import (
  3. "net"
  4. "time"
  5. "google.golang.org/grpc"
  6. cmn "github.com/tendermint/tendermint/libs/common"
  7. )
  8. // Config is an gRPC server configuration.
  9. type Config struct {
  10. MaxOpenConnections int
  11. }
  12. // StartGRPCServer starts a new gRPC BroadcastAPIServer using the given net.Listener.
  13. // NOTE: This function blocks - you may want to call it in a go-routine.
  14. func StartGRPCServer(ln net.Listener) error {
  15. grpcServer := grpc.NewServer()
  16. RegisterBroadcastAPIServer(grpcServer, &broadcastAPI{})
  17. return grpcServer.Serve(ln)
  18. }
  19. // StartGRPCClient dials the gRPC server using protoAddr and returns a new
  20. // BroadcastAPIClient.
  21. func StartGRPCClient(protoAddr string) BroadcastAPIClient {
  22. conn, err := grpc.Dial(protoAddr, grpc.WithInsecure(), grpc.WithDialer(dialerFunc))
  23. if err != nil {
  24. panic(err)
  25. }
  26. return NewBroadcastAPIClient(conn)
  27. }
  28. func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) {
  29. return cmn.Connect(addr)
  30. }