rpc

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package rpc implements SCION Infra RPC calls over QUIC.

Index

Constants

View Source
const (
	// CtxTimedOutError is a custom QUIC error code that is used when canceling
	// writes due to context expiration.
	CtxTimedOutError = iota + 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Conn is the connection to initiate QUIC Sessions on. It can be shared
	// with Servers, because QUIC connection IDs are used to demux the packets.
	Conn net.PacketConn
	// TLSConfig is the client's TLS configuration for starting QUIC connections.
	TLSConfig *tls.Config
	// QUICConfig is the client's QUIC configuration.
	QUICConfig *quic.Config
}

func (*Client) Request

func (c *Client) Request(ctx context.Context, request *Request, address net.Addr) (*Reply, error)

Request sends the request to the host described by address, and blocks until a reply is received (or the context times out). If a reply is received, it is returned.

type Handler

type Handler interface {
	ServeRPC(rw ReplyWriter, request *Request)
}

Handler is called by RPC servers whenever a new request arrives. Implementations should write replies to rw.

type Reply

type Reply struct {
	Message *capnp.Message
}

type ReplyWriter

type ReplyWriter interface {
	// WriteReply blocks until the Reply is sent back to the peer. The
	// underlying connection is always closed before WriteReply returns.
	WriteReply(*Reply) error
	// Close closes any connections kept open by this writer, and unblocks an
	// ongoing WriteReply. It is safe to call Close concurrently with
	// WriteReply. Close can be safely called multiple times.
	io.Closer
}

ReplyWriter provides handlers a way to respond to requests. ReplyWriter keeps a connection alive for replying. Method WriteReply can block; to unblock the method (and to close the connection ahead of time), call Close. ReplyWriter implementations must also close the connection whenever they return from WriteReply.

type Request

type Request struct {
	Message *capnp.Message
	// Address records the network address that sent the request. It will
	// usually be used for logging.
	Address net.Addr
}

type Server

type Server struct {
	// Conn is the connection to listen on. It can be shared with Clients,
	// because QUIC connection IDs are used to demux the packets.
	Conn net.PacketConn
	// TLSConfig is the server's TLS configuration for starting QUIC connections.
	TLSConfig *tls.Config
	// QUICConfig is the server's QUIC configuration.
	QUICConfig *quic.Config
	// Handler is called for every RPC Request receivd by the server.
	Handler Handler
	// contains filtered or unexported fields
}

Server is the configuration for a QUIC RPC server. Messages are SCION Infra Signed Control Payloads. For each accepted connection, the server parses the message from the client and passes it to the handler.

func (*Server) Close

func (s *Server) Close() error

Close closes the Server's listener. All active QUIC connections are immediately torn down. It is safe to call close multiple times.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

Jump to

Keyboard shortcuts

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