mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 05:46:32 +00:00
* libs/common: Refactor libs/common 5 - move mathematical functions and types out of `libs/common` to math pkg - move net functions out of `libs/common` to net pkg - move string functions out of `libs/common` to strings pkg - move async functions out of `libs/common` to async pkg - move bit functions out of `libs/common` to bits pkg - move cmap functions out of `libs/common` to cmap pkg - move os functions out of `libs/common` to os pkg Signed-off-by: Marko Baricevic <marbar3778@yahoo.com> * fix testing issues * fix tests closes #41417 woooooooooooooooooo kill the cmn pkg Signed-off-by: Marko Baricevic <marbar3778@yahoo.com> * add changelog entry * fix goimport issues * run gofmt
39 lines
986 B
Go
39 lines
986 B
Go
package coregrpc
|
|
|
|
import (
|
|
"net"
|
|
|
|
"golang.org/x/net/context"
|
|
"google.golang.org/grpc"
|
|
|
|
tmnet "github.com/tendermint/tendermint/libs/net"
|
|
)
|
|
|
|
// 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 tmnet.Connect(addr)
|
|
}
|