rpc25519

package
v1.0.78 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Defaults used by HandleHTTP
	DefaultRPCPath   = "/_goRPC25519_"
	DefaultDebugPath = "/debug/rpc25519"
)

Variables

View Source
var DefaultNetServer = NewNetServer()

DefaultNetServer is the default instance of *NetServer.

View Source
var ErrIsShutdown = errors.New("connection is shut down")

Functions

func Accept

func Accept(lis net.Listener)

Accept accepts connections on the listener and serves requests to [DefaultServer] for each incoming connection. Accept blocks; the caller typically invokes it in a go statement.

func HandleHTTP

func HandleHTTP()

HandleHTTP registers an HTTP handler for RPC messages to DefaultNetServer on DefaultRPCPath and a debugging handler on DefaultDebugPath. It is still necessary to invoke http.Serve(), typically in a go statement.

func Register

func Register(rcvr any) error

Register publishes the receiver's methods in the [DefaultServer].

func RegisterName

func RegisterName(name string, rcvr any) error

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

func ServeCodec

func ServeCodec(codec ServerCodec)

ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.

func ServeConn

func ServeConn(conn io.ReadWriteCloser)

ServeConn runs the DefaultNetServer on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement. ServeConn uses the gob wire format (see package gob) on the connection. To use an alternate codec, use ServeCodec. See [NewClient]'s comment for information about concurrent access.

func ServeRequest

func ServeRequest(codec ServerCodec) error

ServeRequest is like ServeCodec but synchronously serves a single request. It does not close the codec upon completion.

Types

type Call

type Call struct {
	ServiceMethod string     // The name of the service and method to call.
	Args          any        // The argument to the function (*struct).
	Reply         any        // The reply from the function (*struct).
	Error         error      // After completion, the error status.
	Done          chan *Call // Receives *Call when Go is complete.
}

Call represents an active RPC.

type ClientCodec

type ClientCodec interface {
	WriteRequest(*Request, any) error
	ReadResponseHeader(*Response) error
	ReadResponseBody(any) error

	Close() error
}

A ClientCodec implements writing of RPC requests and reading of RPC responses for the client side of an RPC session. The client calls [ClientCodec.WriteRequest] to write a request to the connection and calls [ClientCodec.ReadResponseHeader] and [ClientCodec.ReadResponseBody] in pairs to read responses. The client calls [ClientCodec.Close] when finished with the connection. ReadResponseBody may be called with a nil argument to force the body of the response to be read and then discarded. See [NewClient]'s comment for information about concurrent access.

type NetClient

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

NetClient represents an RPC Client. There may be multiple outstanding Calls associated with a single NetClient, and a NetClient may be used by multiple goroutines simultaneously.

func Dial

func Dial(network, address string) (*NetClient, error)

Dial connects to an RPC server at the specified network address.

func DialHTTP

func DialHTTP(network, address string) (*NetClient, error)

DialHTTP connects to an HTTP RPC server at the specified network address listening on the default HTTP RPC path.

func DialHTTPPath

func DialHTTPPath(network, address, path string) (*NetClient, error)

DialHTTPPath connects to an HTTP RPC server at the specified network address and path.

func NewNetClient

func NewNetClient(conn io.ReadWriteCloser) *NetClient

NewClient returns a new [Client] to handle requests to the set of services at the other end of the connection. It adds a buffer to the write side of the connection so the header and payload are sent as a unit.

The read and write halves of the connection are serialized independently, so no interlocking is required. However each half may be accessed concurrently so the implementation of conn should protect against concurrent reads or concurrent writes.

func NewNetClientWithCodec

func NewNetClientWithCodec(codec ClientCodec) *NetClient

NewNetClientWithCodec is like NewNetClient but uses the specified codec to encode requests and decode responses.

func (*NetClient) Call

func (client *NetClient) Call(serviceMethod string, args any, reply any) error

Call invokes the named function, waits for it to complete, and returns its error status.

func (*NetClient) Close

func (client *NetClient) Close() error

Close calls the underlying codec's Close method. If the connection is already shutting down, ErrIsShutdown is returned.

func (*NetClient) Go

func (client *NetClient) Go(serviceMethod string, args any, reply any, done chan *Call) *Call

Go invokes the function asynchronously. It returns the Call structure representing the invocation. The done channel will signal when the call is complete by returning the same Call object. If done is nil, Go will allocate a new channel. If non-nil, done must be buffered or Go will deliberately crash.

type NetServer

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

NetServer represents an RPC Server, using the Go standard lib's net/rpc API.

func NewNetServer

func NewNetServer() *NetServer

NewNetServer returns a new NetServer.

func (*NetServer) Accept

func (server *NetServer) Accept(lis net.Listener)

Accept accepts connections on the listener and serves requests for each incoming connection. Accept blocks until the listener returns a non-nil error. The caller typically invokes Accept in a go statement.

func (*NetServer) HandleHTTP

func (server *NetServer) HandleHTTP(rpcPath, debugPath string)

HandleHTTP registers an HTTP handler for RPC messages on rpcPath, and a debugging handler on debugPath. It is still necessary to invoke http.Serve(), typically in a go statement.

func (*NetServer) Register

func (server *NetServer) Register(rcvr any) error

Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:

  • exported method of exported type
  • two arguments, both of exported type
  • the second argument is a pointer
  • one return value, of type error

It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.

func (*NetServer) RegisterName

func (server *NetServer) RegisterName(name string, rcvr any) error

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

func (*NetServer) ServeCodec

func (server *NetServer) ServeCodec(codec ServerCodec)

ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.

func (*NetServer) ServeConn

func (server *NetServer) ServeConn(conn io.ReadWriteCloser)

ServeConn runs the server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement. ServeConn uses the gob wire format (see package gob) on the connection. To use an alternate codec, use ServeCodec. See [NewClient]'s comment for information about concurrent access.

func (*NetServer) ServeHTTP

func (server *NetServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements an http.Handler that answers RPC requests.

func (*NetServer) ServeRequest

func (server *NetServer) ServeRequest(codec ServerCodec) error

ServeRequest is like ServeCodec but synchronously serves a single request. It does not close the codec upon completion.

type Request

type Request struct {
	ServiceMethod string // format: "Service.Method"
	Seq           uint64 // sequence number chosen by client
	// contains filtered or unexported fields
}

Request is a header written before every RPC call. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.

func (*Request) DecodeMsg

func (z *Request) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.

func (Request) EncodeMsg

func (z Request) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Request) MarshalMsg

func (z Request) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Request) Msgsize

func (z Request) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Request) UnmarshalMsg

func (z *Request) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Request) UnmarshalMsgWithCfg

func (z *Request) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)

type Response

type Response struct {
	ServiceMethod string // echoes that of the Request
	Seq           uint64 // echoes that of the request
	Error         string // error, if any.
	// contains filtered or unexported fields
}

Response is a header written before every RPC return. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.

func (*Response) DecodeMsg

func (z *Response) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.

func (Response) EncodeMsg

func (z Response) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Response) MarshalMsg

func (z Response) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Response) Msgsize

func (z Response) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Response) UnmarshalMsg

func (z *Response) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Response) UnmarshalMsgWithCfg

func (z *Response) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)

type ServerCodec

type ServerCodec interface {
	ReadRequestHeader(*Request) error
	ReadRequestBody(any) error
	WriteResponse(*Response, any) error

	// Close can be called multiple times and must be idempotent.
	Close() error
}

A ServerCodec implements reading of RPC requests and writing of RPC responses for the server side of an RPC session. The server calls [ServerCodec.ReadRequestHeader] and [ServerCodec.ReadRequestBody] in pairs to read requests from the connection, and it calls [ServerCodec.WriteResponse] to write a response back. The server calls [ServerCodec.Close] when finished with the connection. ReadRequestBody may be called with a nil argument to force the body of the request to be read and discarded. See [NewClient]'s comment for information about concurrent access.

type ServerError

type ServerError string

ServerError represents an error that has been returned from the remote side of the RPC connection.

func (ServerError) Error

func (e ServerError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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