Documentation ¶
Overview ¶
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Index ¶
- Constants
- Variables
- func Accept(lis net.Listener)
- func AlwaysPrintf(format string, a ...interface{})
- func Caller(upStack int) string
- func DirExists(name string) bool
- func FileExists(name string) bool
- func FileLine(depth int) string
- func FileSize(name string) (int64, error)
- func GenAddress() string
- func GetAvailPort() int
- func GetExternalIP() string
- func GetExternalIPAsInt() int
- func HandleHTTP()
- func HostKeyVerifies(knownKeysPath string, connState *tls.ConnectionState, remoteAddr string) (good, bad []string, wasNew bool, err0 error)
- func IsLocalhost(ipStr string) (isLocal bool, hostOnlyNoPort string)
- func IsRoutableIPv4(ip string) bool
- func IsWritable(path string) bool
- func LoadClientTLSConfig(embedded bool, sslCA, sslCert, sslCertKey string) (*tls.Config, error)
- func LoadClientTLSConfigFilesystem(sslCA, sslCert, sslCertKey string) (*tls.Config, error)
- func LoadServerTLSConfig(embedded bool, sslCA, sslClientCA, sslCert, sslCertKey string) (*tls.Config, error)
- func LoadServerTLSConfigFilesystem(sslCA, sslClientCA, sslCert, sslCertKey string) (*tls.Config, error)
- func LocalAddrMatching(addr string) (local string, err error)
- func P(format string, a ...interface{})
- func PB(w io.Writer, format string, a ...interface{})
- func PP(format string, a ...interface{})
- func PPP(format string, a ...interface{})
- func Printf(format string, a ...interface{}) (n int, err error)
- func QPrintf(format string, a ...interface{}) (n int, err error)
- func Register(rcvr any) error
- func RegisterName(name string, rcvr any) error
- func SelfyNewKey(createKeyPairNamed, odir string) error
- func ServeCodec(codec ServerCodec)
- func ServeConn(conn io.ReadWriteCloser)
- func ServeRequest(codec ServerCodec) error
- func StripNanomsgAddressPrefix(nanomsgAddr string) (suffix string, err error)
- func TSPrintf(format string, a ...interface{})
- func VPrintf(format string, a ...interface{}) (n int, err error)
- func VV(format string, a ...interface{})
- func WaitUntilCanConnect(addr string)
- func WrapWithBrackets(local string) string
- type Call
- type Client
- func (c *Client) Call(serviceMethod string, args any, reply any) error
- func (c *Client) Close() error
- func (c *Client) Err() error
- func (c *Client) GetOneRead(seqno uint64, ch chan *Message)
- func (c *Client) GetReadIncomingCh() (ch chan *Message)
- func (c *Client) GetReads(ch chan *Message)
- func (c *Client) Go(serviceMethod string, args any, reply any, done chan *Call) *Call
- func (c *Client) LocalAddr() string
- func (c *Client) Name() string
- func (c *Client) OneWaySend(msg *Message, doneCh <-chan struct{}) (err error)
- func (c *Client) RunClientMain(serverAddr string, tcp_only bool, certPath string)
- func (c *Client) RunClientTCP(serverAddr string)
- func (c *Client) RunQUIC(localHostPort, quicServerAddr string, tlsConfig *tls.Config)
- func (c *Client) RunReadLoop(conn net.Conn)
- func (c *Client) RunSendLoop(conn net.Conn)
- func (c *Client) SendAndGetReply(req *Message, doneCh <-chan struct{}) (reply *Message, err error)
- func (c *Client) SendAndGetReplyWithTimeout(timeout time.Duration, req *Message) (reply *Message, err error)
- func (c *Client) SetLocalAddr(local string)
- func (c *Client) UngetReads(ch chan *Message)
- type ClientCodec
- type Config
- type HDR
- func (mid *HDR) AsGreenpack(scratch []byte) (o []byte, err error)
- func (m *HDR) Bytes() []byte
- func (m *HDR) Compact() string
- func (z *HDR) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *HDR) EncodeMsg(en *msgp.Writer) (err error)
- func (a *HDR) Equal(b *HDR) bool
- func (m *HDR) JSON() []byte
- func (z *HDR) MarshalMsg(b []byte) (o []byte, err error)
- func (z *HDR) Msgsize() (s int)
- func (m *HDR) OpaqueURLFriendly() string
- func (m *HDR) Pretty() string
- func (m *HDR) String() string
- func (z *HDR) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *HDR) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)
- type Known
- type KnownKey
- type Message
- func (m *Message) AsGreenpack(scratch []byte) (o []byte, err error)
- func (z *Message) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Message) EncodeMsg(en *msgp.Writer) (err error)
- func (z *Message) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Message) Msgsize() (s int)
- func (msg *Message) String() string
- func (z *Message) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *Message) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)
- type NetClient
- type NetConnWrapper
- type NetServer
- func (server *NetServer) Accept(lis net.Listener)
- func (server *NetServer) HandleHTTP(rpcPath, debugPath string)
- func (server *NetServer) Register(rcvr any) error
- func (server *NetServer) RegisterName(name string, rcvr any) error
- func (server *NetServer) ServeCodec(codec ServerCodec)
- func (server *NetServer) ServeConn(conn io.ReadWriteCloser)
- func (server *NetServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (server *NetServer) ServeRequest(codec ServerCodec) error
- type OneWayFunc
- type Request
- func (z *Request) DecodeMsg(dc *msgp.Reader) (err error)
- func (z Request) EncodeMsg(en *msgp.Writer) (err error)
- func (z Request) MarshalMsg(b []byte) (o []byte, err error)
- func (z Request) Msgsize() (s int)
- func (z *Request) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *Request) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)
- type Response
- func (z *Response) DecodeMsg(dc *msgp.Reader) (err error)
- func (z Response) EncodeMsg(en *msgp.Writer) (err error)
- func (z Response) MarshalMsg(b []byte) (o []byte, err error)
- func (z Response) Msgsize() (s int)
- func (z *Response) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *Response) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)
- type Server
- func (s *Server) Close() error
- func (s *Server) Register(rcvr any) error
- func (s *Server) Register1Func(callme1 OneWayFunc)
- func (s *Server) Register2Func(callme2 TwoWayFunc)
- func (s *Server) RegisterName(name string, rcvr any) error
- func (s *Server) RunQUICServer(quicServerAddr string, tlsConfig *tls.Config, boundCh chan net.Addr)
- func (s *Server) RunServerMain(serverAddress string, tcp_only bool, certPath string, boundCh chan net.Addr)
- func (s *Server) RunTCP(serverAddress string, boundCh chan net.Addr)
- func (s *Server) SendMessage(callID, subject, destAddr string, by []byte, seqno uint64) error
- func (s *Server) Start() (serverAddr net.Addr, err error)
- type ServerCodec
- type ServerError
- type TwoWayFunc
Constants ¶
const ( // Defaults used by HandleHTTP DefaultRPCPath = "/_goRPC25519_" DefaultDebugPath = "/debug/rpc25519" )
const RFC3339MsecTz0 = "2006-01-02T15:04:05.000Z07:00"
const RFC3339NanoNumericTZ0pad = "2006-01-02T15:04:05.000000000-07:00"
const VersionByteBase59Checked byte = 255
we always use 255, which is -1 in 8-bit 2's compliment.
Variables ¶
var Chicago *time.Location
var DefaultNetServer = NewNetServer()
DefaultNetServer is the default instance of *NetServer.
var ErrDone = fmt.Errorf("done channel closed")
var ErrIsShutdown = errors.New("connection is shut down")
var ErrNetConnectionNotFound = fmt.Errorf("error: net.Conn not found")
var ErrNotFound = fmt.Errorf("known_tls_hosts file not found")
var ErrPubKeyMismath = fmt.Errorf("remote host pubkey does not match that on file!")
var ErrPubKeyUnknown = fmt.Errorf("remote host pubkey is not on file, and TOFU is off!")
var ErrShutdown = fmt.Errorf("shutting down")
var ForceQuiet = false
useful during git bisect
var Frankfurt *time.Location
var GTZ *time.Location
var London *time.Location
var MyPid = os.Getpid()
var NYC *time.Location
var OurStdout io.Writer = os.Stdout
so we can multi write easily, use our own printf
var ShowPid bool
var UtcTz *time.Location
var Verbose bool = false
for tons of debug output
var VerboseVerbose bool = false
Functions ¶
func Accept ¶ added in v1.0.42
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 AlwaysPrintf ¶
func AlwaysPrintf(format string, a ...interface{})
func FileExists ¶
func GenAddress ¶
func GenAddress() string
GenAddress generates a local address by calling GetAvailPort() and GetExternalIP(), then prefixing them with 'tcp://'.
func GetAvailPort ¶
func GetAvailPort() int
GetAvailPort asks the OS for an unused port. There's a race here, where the port could be grabbed by someone else before the caller gets to Listen on it, but in practice such races are rare. Uses net.Listen("tcp", ":0") to determine a free port, then releases it back to the OS with Listener.Close().
func GetExternalIP ¶
func GetExternalIP() string
GetExternalIP tries to determine the external IP address used on this host.
func GetExternalIPAsInt ¶
func GetExternalIPAsInt() int
GetExternalIPAsInt calls GetExternalIP() and then converts the resulting IPv4 string into an integer.
func HandleHTTP ¶ added in v1.0.42
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 HostKeyVerifies ¶
func HostKeyVerifies( knownKeysPath string, connState *tls.ConnectionState, remoteAddr string) (good, bad []string, wasNew bool, err0 error)
server will want stripPort true since client's port will change all the time. tofu true means we add any unknown cert to our knownKeysPath. We don't really care what the IP or hostname is, as long as we recognized a certified public key (in one of the identities), we accept. The IP or port could change, we don't care.
NB only ed25519 keys are permitted, any others will result in an immediate error and no further keys will be evaluated.
func IsLocalhost ¶ added in v1.0.12
func IsRoutableIPv4 ¶
IsRoutableIPv4 returns true if the string in ip represents an IPv4 address that is not private. See http://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces for the numeric ranges that are private. 127.0.0.1, 192.168.0.1, and 172.16.0.1 are examples of non-routables IP addresses.
func IsWritable ¶
IsWritable returns true if the file does not exist. Otherwise it checks the write bits. If any write bits (owner, group, others) are set, then we return true. Otherwise false.
func LoadClientTLSConfig ¶
LoadClientTLSConfig creates a client TLSConfig by loading the CA and client certs. The following paths must be passed: - sslCA: path to the CA certificate - sslCert: path to the client certificate - sslCertKey: path to the client key If the path is prefixed with "embedded=", load the embedded certs.
embedded true means load from the static embedded files, created at compile time. If embedded is false, then we read from the filesystem.
func LoadServerTLSConfig ¶
func LoadServerTLSConfig(embedded bool, sslCA, sslClientCA, sslCert, sslCertKey string) (*tls.Config, error)
LoadServerTLSConfig creates a server TLSConfig by loading the CA and server certs. The following paths must be passed:
- sslCA: path to the CA certificate
- sslClientCA: path to the CA certificate to verify client certificates, can be the same as sslCA
- sslCert: path to the server certificate
- sslCertKey: path to the server key
embedded true means load from the static embedded files, created at compile time. If embedded is false, then we read from the filesystem.
func LocalAddrMatching ¶ added in v1.0.7
LocalAddrMatching finds a matching interface IP to a server destination address
addr should b "host:port" of server, we'll find the local IP to use.
func PPP ¶
func PPP(format string, a ...interface{})
without the file/line, otherwise the same as PP
func Printf ¶
Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.
func RegisterName ¶ added in v1.0.42
RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.
func SelfyNewKey ¶ added in v1.0.3
SelfyNewKey will generate a self-signed certificate authority, a new ed25519 key pair, sign the public key to create a cert, and write these four new files to disk. The directories odir/my-keep-private-dir and odir/certs will be created.
func ServeCodec ¶ added in v1.0.42
func ServeCodec(codec ServerCodec)
ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.
func ServeConn ¶ added in v1.0.42
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 ¶ added in v1.0.42
func ServeRequest(codec ServerCodec) error
ServeRequest is like ServeCodec but synchronously serves a single request. It does not close the codec upon completion.
func StripNanomsgAddressPrefix ¶
StripNanomsgAddressPrefix removes the 'tcp://' prefix from nanomsgAddr.
func WaitUntilCanConnect ¶
func WaitUntilCanConnect(addr string)
func WrapWithBrackets ¶ added in v1.0.7
if it needs [] ipv6 brackets, add them
Types ¶
type Call ¶ added in v1.0.42
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 Client ¶
type Client struct { Conn uConnLR // Conn net.Conn // the default. QuicConn quic.Connection // if connecting suceeds, a nil will be sent; else the error. Connected chan error // contains filtered or unexported fields }
Clients write requests, and maybe wait for responses.
func NewClient ¶
NewClient attemps to connect to config.ClientDialToHostPort; err will come back with any problems encountered. The name setting allows users to track multiple instances of Clients, and the Client.Name() method will retreive it.
func (*Client) Call ¶ added in v1.0.42
Call implements the net/rpc Client.Call() API; its docs:
Call invokes the named function, waits for it to complete, and returns its error status.
func (*Client) GetOneRead ¶
GetOneRead responds on ch with the first incoming message whose Seqno matches seqno, then auto unregisters itself after that single send on ch.
func (*Client) GetReadIncomingCh ¶
GetReadIncomingCh creates and returns a buffered channel that reads incoming messages that are server-pushed (not associated with a round-trip rpc call request/response pair.
func (*Client) Go ¶ added in v1.0.42
Go implements the net/rpc Client.Go() API; its docs:
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.
func (*Client) OneWaySend ¶
OneWaySend sends a message without expecting or waiting for a response. The doneCh is optional, and can be nil.
func (*Client) RunClientMain ¶
eg. serverAddr = "localhost:8443" serverAddr = "192.168.254.151:8443"
func (*Client) RunClientTCP ¶
func (*Client) RunReadLoop ¶
func (*Client) RunSendLoop ¶
func (*Client) SendAndGetReply ¶
SendAndGetReply starts a round-trip RPC call. We will wait for a response before retuning. The doneCh is optional; it can be nil. A context.Done() like channel can be supplied there to stop waiting before a reply comes back.
func (*Client) SendAndGetReplyWithTimeout ¶
func (c *Client) SendAndGetReplyWithTimeout(timeout time.Duration, req *Message) (reply *Message, err error)
SendAndGetReplyWithTimeout expires the call after timeout.
func (*Client) SetLocalAddr ¶ added in v1.0.17
func (*Client) UngetReads ¶
UngetReads reverses what GetReads does: un-register and have ch be deaf from now on. Idempotent: if ch is already gone, no foul is reported.
type ClientCodec ¶ added in v1.0.42
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 Config ¶
type Config struct { // ServerAddr host:port that the rpc25519.Server should bind to. ServerAddr string // optional. Can be used to force client to use a specific host:port; // say for port sharing with a server. ClientHostPort string // Who the client should contact ClientDialToHostPort string // TCP false means TLS-1.3 secured. true here means do TCP only. TCPonly_no_TLS bool // UseQUIC cannot be true if TCPonly_no_TLS is true. UseQUIC bool // path to certs/ like certificate // directory on the live filesystem. If left // empty then the embedded certs/ from build-time, those // copied from the on-disk certs/ directory and baked // into the executable as a virtual file system with // the go:embed directive are used. CertPath string // SkipVerifyKeys true allows any incoming // key to be signed by // any CA; it does not have to be ours. Obviously // this discards almost all access control; it // should rarely be used unless communication // with the any random agent/hacker/public person // is desired. SkipVerifyKeys bool ClientKeyPairName string // default "client" means use certs/client.crt and certs/client.key ServerKeyPairName string // default "node" means use certs/node.crt and certs/node.key // These are timeouts for connection and transport tuning. // The defaults of 0 mean wait forever. ConnectTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration LocalAddress string // contains filtered or unexported fields }
Config says who to contact (for a client), or where to listen (for a server); and sets how strong a security posture we adopt.
Copying a Config is fine, but it should be a simple shallow copy to preserve the shared *SharedTransport struct.
This shared pointer is the basis of port (and file handle) reuse where a single process can maintain a server and multiple clients in a "star" pattern. This only works with QUIC of course, and is one of the main reasons to use QUIC. The shared pointer is reference counted and the underlying net.UDPConn is only closed when the last instance in use is Close()-ed.
type HDR ¶ added in v1.0.42
type HDR struct { Nc net.Conn `msg:"-"` Created string `zid:"0"` From string `zid:"1"` To string `zid:"2"` Subject string `zid:"3"` IsRPC bool `zid:"4"` IsLeg2 bool `zid:"5"` Serial int64 `zid:"6"` CallID string `zid:"7"` // able to match call and response on this alone. PID int64 `zid:"8"` Seqno uint64 `zid:"9"` IsNetRPC bool `zid:"10"` }
The Multiverse Identitifer: for when there are multiple universes and so a UUID just won't do.
func HDRFromBytes ¶ added in v1.0.42
func HDRFromGreenpack ¶ added in v1.0.42
workspace can be nil or reused to avoid allocation.
func HDRFromOpaqueURLFriendly ¶ added in v1.0.42
func (*HDR) AsGreenpack ¶ added in v1.0.42
the scrach workspace can be nil or reused to avoid allocation.
func (*HDR) DecodeMsg ¶ added in v1.0.42
DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.
func (*HDR) Equal ¶ added in v1.0.42
Equal compares two *HDR structs field by field for structural equality
func (*HDR) MarshalMsg ¶ added in v1.0.42
MarshalMsg implements msgp.Marshaler
func (*HDR) Msgsize ¶ added in v1.0.42
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*HDR) OpaqueURLFriendly ¶ added in v1.0.42
func (*HDR) UnmarshalMsg ¶ added in v1.0.42
UnmarshalMsg implements msgp.Unmarshaler
func (*HDR) UnmarshalMsgWithCfg ¶ added in v1.0.42
type Known ¶
type KnownKey ¶
type KnownKey struct { Addr string // 192.168.254.151:8443 KeyType string // ed25519 PubKey string // 9aTjVYv1K7vj3WYX3EktjaGPycNwym5Rn5Vo1WuxLdF7bxpMDV6 Emails string Line int }
KnownKey saved to a file results in lines like 127.0.0.1 pubkey@edwardsRPC-ed25519-b58c-9ZrrEXxvoqmj9UkgiPjHNZP41N9wuLyQTEUCg5S7VjPuJbXXL8a:froggy@example.com
func (*KnownKey) IdentityString ¶
e.g. "pubkey@edwardsRPC-ed25519-b58c-9ZrrEXxvoqmj9UkgiPjHNZP41N9wuLyQTEUCg5S7VjPuJbXXL8a:froggy@example.com"
type Message ¶
type Message struct { // HDR contains header information. HDR HDR `zid:"0"` JobSerz []byte `zid:"1"` JobErrs string `zid:"2"` // Err is not serialized on the wire by the server, // so communicates only local information. Callback // functions should convey errors in-band within // JobSerz. Err error `msg:"-"` DoneCh chan *Message `msg:"-"` }
Message basic substrate.
func MessageFromGreenpack ¶ added in v1.0.28
func NewMessage ¶
func NewMessage() *Message
func NewMessageFromBytes ¶
func (*Message) AsGreenpack ¶ added in v1.0.29
the scrach workspace can be nil or reused to avoid allocation.
func (*Message) DecodeMsg ¶ added in v1.0.26
DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.
func (*Message) MarshalMsg ¶ added in v1.0.26
MarshalMsg implements msgp.Marshaler
func (*Message) Msgsize ¶ added in v1.0.26
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Message) UnmarshalMsg ¶ added in v1.0.26
UnmarshalMsg implements msgp.Unmarshaler
func (*Message) UnmarshalMsgWithCfg ¶ added in v1.0.26
type NetClient ¶ added in v1.0.42
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 DialHTTP ¶ added in v1.0.42
DialHTTP connects to an HTTP RPC server at the specified network address listening on the default HTTP RPC path.
func DialHTTPPath ¶ added in v1.0.42
DialHTTPPath connects to an HTTP RPC server at the specified network address and path.
func NewNetClient ¶ added in v1.0.42
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 ¶ added in v1.0.42
func NewNetClientWithCodec(codec ClientCodec) *NetClient
NewNetClientWithCodec is like NewNetClient but uses the specified codec to encode requests and decode responses.
func (*NetClient) Call ¶ added in v1.0.42
Call invokes the named function, waits for it to complete, and returns its error status.
func (*NetClient) Close ¶ added in v1.0.42
Close calls the underlying codec's Close method. If the connection is already shutting down, ErrIsShutdown is returned.
func (*NetClient) Go ¶ added in v1.0.42
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 NetConnWrapper ¶ added in v1.0.5
type NetConnWrapper struct { quic.Stream quic.Connection }
type NetServer ¶ added in v1.0.42
type NetServer struct {
// contains filtered or unexported fields
}
NetServer represents an RPC Server, using the Go standard lib's net/rpc API.
func NewNetServer ¶ added in v1.0.42
func NewNetServer() *NetServer
NewNetServer returns a new NetServer.
func (*NetServer) Accept ¶ added in v1.0.42
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 ¶ added in v1.0.42
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 ¶ added in v1.0.42
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 ¶ added in v1.0.42
RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.
func (*NetServer) ServeCodec ¶ added in v1.0.42
func (server *NetServer) ServeCodec(codec ServerCodec)
ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.
func (*NetServer) ServeConn ¶ added in v1.0.42
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 ¶ added in v1.0.42
func (server *NetServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements an http.Handler that answers RPC requests.
func (*NetServer) ServeRequest ¶ added in v1.0.42
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 OneWayFunc ¶ added in v1.0.39
type OneWayFunc func(req *Message)
OneWayFunc is the simpler sibling to the above. A OneWayFunc will not return anything to the sender.
As above req.JobSerz [] byte contains the job payload.
type Request ¶ added in v1.0.42
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 ¶ added in v1.0.42
DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.
func (Request) MarshalMsg ¶ added in v1.0.42
MarshalMsg implements msgp.Marshaler
func (Request) Msgsize ¶ added in v1.0.42
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Request) UnmarshalMsg ¶ added in v1.0.42
UnmarshalMsg implements msgp.Unmarshaler
func (*Request) UnmarshalMsgWithCfg ¶ added in v1.0.42
type Response ¶ added in v1.0.42
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 ¶ added in v1.0.42
DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.
func (Response) MarshalMsg ¶ added in v1.0.42
MarshalMsg implements msgp.Marshaler
func (Response) Msgsize ¶ added in v1.0.42
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Response) UnmarshalMsg ¶ added in v1.0.42
UnmarshalMsg implements msgp.Unmarshaler
func (*Response) UnmarshalMsgWithCfg ¶ added in v1.0.42
type Server ¶
type Server struct { // remote when server gets a new client, // So test 004 can avoid a race/panic. RemoteConnectedCh chan string // contains filtered or unexported fields }
Servers read and respond to requests. Two APIs are available.
Using the rpc25519.Message based API:
Register1Func() and Register2Func() register callbacks.
Using the net/rpc API:
Server.Register() registers structs with callback methods on them.
The net/rpc API is implemented as a layer on top of the rpc25519.Message based API. Both can be used concurrently if desired.
func NewServer ¶
NewServer will keep its own copy of config. If config is nil, the server will make its own upon Start().
func (*Server) Register ¶ added in v1.0.42
Register implements the net/rpc Server.Register() API. Its docs:
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 (*Server) Register1Func ¶ added in v1.0.39
func (s *Server) Register1Func(callme1 OneWayFunc)
func (*Server) Register2Func ¶ added in v1.0.39
func (s *Server) Register2Func(callme2 TwoWayFunc)
func (*Server) RegisterName ¶ added in v1.0.42
RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.
func (*Server) RunQUICServer ¶ added in v1.0.5
func (*Server) RunServerMain ¶
func (s *Server) RunServerMain(serverAddress string, tcp_only bool, certPath string, boundCh chan net.Addr)
boundCh should be buffered, at least 1, if it is not nil. If not nil, we will send the bound net.Addr back on it after we have started listening.
func (*Server) SendMessage ¶
type ServerCodec ¶ added in v1.0.42
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 ¶ added in v1.0.42
type ServerError string
ServerError represents an error that has been returned from the remote side of the RPC connection.
func (ServerError) Error ¶ added in v1.0.42
func (e ServerError) Error() string
type TwoWayFunc ¶ added in v1.0.39
TwoWayFunc is the user's own function that they register with the server for remote procedure calls.
The user's Func may not want to return anything. In that case they should register a OneWayFunc instead.
req.JobSerz []byte contains the job payload.
Implementers of TwoWayFunc should assign their return []byte to reply.JobSerz. reply.Jobserz can also be left nil, of course.
Any errors can be returned on reply.JobErrs; this is optional. Not that JobErrs is a string value.
The system will overwrite the reply.HDR field when sending the reply, so the user should not bother trying to alter it.