grpctransport

package
v0.0.0-...-bd4e2c0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_grpctransport_grpctransport_proto protoreflect.FileDescriptor
View Source
var GrpcTransport_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "grpctransport.GrpcTransport",
	HandlerType: (*GrpcTransportServer)(nil),
	Methods:     []grpc.MethodDesc{},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "Listen",
			Handler:       _GrpcTransport_Listen_Handler,
			ClientStreams: true,
		},
	},
	Metadata: "grpctransport/grpctransport.proto",
}

GrpcTransport_ServiceDesc is the grpc.ServiceDesc for GrpcTransport service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func RegisterGrpcTransportServer

func RegisterGrpcTransportServer(s grpc.ServiceRegistrar, srv GrpcTransportServer)

Types

type ByeBye

type ByeBye struct {
	// contains filtered or unexported fields
}

func (*ByeBye) Descriptor deprecated

func (*ByeBye) Descriptor() ([]byte, []int)

Deprecated: Use ByeBye.ProtoReflect.Descriptor instead.

func (*ByeBye) ProtoMessage

func (*ByeBye) ProtoMessage()

func (*ByeBye) ProtoReflect

func (x *ByeBye) ProtoReflect() protoreflect.Message

func (*ByeBye) Reset

func (x *ByeBye) Reset()

func (*ByeBye) String

func (x *ByeBye) String() string

type GrpcMessage

type GrpcMessage struct {
	Sender uint64             `protobuf:"varint,1,opt,name=sender,proto3" json:"sender,omitempty"`
	Msg    *messagepb.Message `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"`
	// contains filtered or unexported fields
}

func (*GrpcMessage) Descriptor deprecated

func (*GrpcMessage) Descriptor() ([]byte, []int)

Deprecated: Use GrpcMessage.ProtoReflect.Descriptor instead.

func (*GrpcMessage) GetMsg

func (x *GrpcMessage) GetMsg() *messagepb.Message

func (*GrpcMessage) GetSender

func (x *GrpcMessage) GetSender() uint64

func (*GrpcMessage) ProtoMessage

func (*GrpcMessage) ProtoMessage()

func (*GrpcMessage) ProtoReflect

func (x *GrpcMessage) ProtoReflect() protoreflect.Message

func (*GrpcMessage) Reset

func (x *GrpcMessage) Reset()

func (*GrpcMessage) String

func (x *GrpcMessage) String() string

type GrpcTransport

type GrpcTransport struct {
	UnimplementedGrpcTransportServer
	// contains filtered or unexported fields
}

GrpcTransport represents a networking module that is based on gRPC. Each node's networking module contains one gRPC server, to which other nodes' modules connect. The type of gRPC connection is multi-request-single-response, where each module contains one instance of a gRPC client per node. A message to a node is sent as request to that node's gRPC server.

func NewGrpcTransport

func NewGrpcTransport(membership map[t.NodeID]string, ownId t.NodeID, l logging.Logger) *GrpcTransport

NewGrpcTransport returns a pointer to a new initialized GrpcTransport networking module. The membership parameter must represent the complete static membership of the system. It maps the numeric node ID of each node in the system to a string representation of its network address with the format "IPAddress:port". The ownId parameter is the numeric ID of the node that will use the returned networking module. The returned GrpcTransport is not yet running (able to receive messages), nor is it connected to any nodes (able to send messages). This needs to be done explicitly by calling the respective Start() and Connect() methods.

func (*GrpcTransport) Connect

func (gt *GrpcTransport) Connect()

Connect establishes (in parallel) network connections to all nodes in the system. The other nodes' GrpcTransport modules must be running. Only after Connect() returns, sending messages over this GrpcTransport is possible. TODO: Deal with errors, e.g. when the connection times out (make sure the RPC call in connectToNode() has a timeout).

func (*GrpcTransport) Listen

Listen implements the gRPC Listen service (multi-request-single-response). It receives messages from the gRPC client running on the other node and writes them to a channel that the user can access through ReceiveChan(). This function is called by the gRPC system on every new connection from another node's Net module's gRPC client.

func (*GrpcTransport) ReceiveChan

func (gt *GrpcTransport) ReceiveChan() <-chan modules.ReceivedMessage

ReceiveChan returns a channel to which the Net module writes all received messages and sender IDs (Both the message itself and the sender ID are part of the ReceivedMessage struct.)

func (*GrpcTransport) Send

func (gt *GrpcTransport) Send(dest t.NodeID, msg *messagepb.Message) error

Send sends msg to the node with ID dest. Concurrent calls to Send are not (yet? TODO) supported.

func (*GrpcTransport) ServerError

func (gt *GrpcTransport) ServerError() error

ServerError returns the error returned by the gRPC server's Serve() call. ServerError() must not be called before the GrpcTransport is stopped and its Stop() method has returned.

func (*GrpcTransport) Start

func (gt *GrpcTransport) Start() error

Start starts the networking module by initializing and starting the internal gRPC server, listening on the port determined by the membership and own ID. Before ths method is called, no other GrpcTransports can connect to this one.

func (*GrpcTransport) Stop

func (gt *GrpcTransport) Stop()

Stop closes all open connections to other nodes and stops the own gRPC server (preventing further incoming connections). After Stop() returns, the error returned by the gRPC server's Serve() call can be obtained through the ServerError() method.

type GrpcTransportClient

type GrpcTransportClient interface {
	Listen(ctx context.Context, opts ...grpc.CallOption) (GrpcTransport_ListenClient, error)
}

GrpcTransportClient is the client API for GrpcTransport service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

type GrpcTransportServer

type GrpcTransportServer interface {
	Listen(GrpcTransport_ListenServer) error
	// contains filtered or unexported methods
}

GrpcTransportServer is the server API for GrpcTransport service. All implementations must embed UnimplementedGrpcTransportServer for forward compatibility

type GrpcTransport_ListenClient

type GrpcTransport_ListenClient interface {
	Send(*GrpcMessage) error
	CloseAndRecv() (*ByeBye, error)
	grpc.ClientStream
}

type GrpcTransport_ListenServer

type GrpcTransport_ListenServer interface {
	SendAndClose(*ByeBye) error
	Recv() (*GrpcMessage, error)
	grpc.ServerStream
}

type UnimplementedGrpcTransportServer

type UnimplementedGrpcTransportServer struct {
}

UnimplementedGrpcTransportServer must be embedded to have forward compatible implementations.

func (UnimplementedGrpcTransportServer) Listen

type UnsafeGrpcTransportServer

type UnsafeGrpcTransportServer interface {
	// contains filtered or unexported methods
}

UnsafeGrpcTransportServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to GrpcTransportServer will result in compilation errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL