rpcutils

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 18 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RPC Calls that do not require authentication or who handle authentication separately:
	NonAuthenticatingCalls = []string{
		"Master.AuthenticateHost",
		"Agent.BuildHost",
		"ControlCenterAgent.Ping",
		"Master.AddHostPrivate",
	}
	// RPC calls that do not require admin access:
	NonAdminRequiredCalls = map[string]struct{}{
		"Master.GetHost":                         struct{}{},
		"Master.GetHosts":                        struct{}{},
		"Master.GetEvaluatedService":             struct{}{},
		"Master.GetSystemUser":                   struct{}{},
		"Master.ReportHealthStatus":              struct{}{},
		"Master.ReportInstanceDead":              struct{}{},
		"Master.UpdateHost":                      struct{}{},
		"ControlCenterAgent.GetEvaluatedService": struct{}{},
		"ControlCenterAgent.GetHostID":           struct{}{},
		"ControlCenterAgent.GetZkInfo":           struct{}{},
		"ControlCenterAgent.GetISvcEndpoints":    struct{}{},
		"ControlCenterAgent.ReportHealthStatus":  struct{}{},
		"ControlCenterAgent.ReportInstanceDead":  struct{}{},
		"ControlCenterAgent.SendLogMessage":      struct{}{},
		"ControlCenterAgent.AddHostPrivate":      struct{}{},
	}

	ErrNoAdmin = errors.New("Delegate does not have admin access")
)
View Source
var DiscardClientTimeout = 30 * time.Second

DiscardClientTimeout timeout for removing client from pool if a call is taking too long. Does not interrupt call.

View Source
var RPCCertVerify = false

RPCCertVerify used to enable server certificate verification

View Source
var RPCDisableTLS = false

RPCDisableTLS used to disable TLS connections

View Source
var RPC_CLIENT_SIZE = 1

RPC_CLIENT_SIZE max number of rpc clients per address

Functions

func NewAuthClientCodec

func NewAuthClientCodec(conn io.ReadWriteCloser, createCodec ClientCodecCreator, headerBuilder auth.RPCHeaderBuilder) rpc.ClientCodec

func NewAuthServerCodec

func NewAuthServerCodec(conn io.ReadWriteCloser, createCodec ServerCodecCreator, parser auth.RPCHeaderParser) rpc.ServerCodec

func NewDefaultAuthClient

func NewDefaultAuthClient(conn io.ReadWriteCloser) *rpc.Client

NewDefaultAuthClient returns a new rpc.Client that uses our default client codec

func NewDefaultAuthClientCodec

func NewDefaultAuthClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec

func NewDefaultAuthServerCodec

func NewDefaultAuthServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec

func RegisterLocal

func RegisterLocal(name string, rcvr interface{}) error

func RegisterLocalAddress

func RegisterLocalAddress(addrs ...string)

func SetDialTimeout

func SetDialTimeout(timeout int)

SetDialTimeout time in seconds to timeout dialing a connection

Types

type AuthClientCodec

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

func (*AuthClientCodec) Close

func (a *AuthClientCodec) Close() error

Closes the connection on the client side

We don't change anything here, just let the underlying codec handle it.

func (*AuthClientCodec) ReadResponseBody

func (a *AuthClientCodec) ReadResponseBody(body interface{}) error

Decodes the body of the response and builds the body object. We don't change anything here, just let the underlying codec handle it.

func (*AuthClientCodec) ReadResponseHeader

func (a *AuthClientCodec) ReadResponseHeader(r *rpc.Response) error

Decodes the response and reads the header, building the rpc.Response object

We don't change anything here, just let the underlying codec handle it.

func (*AuthClientCodec) WriteRequest

func (a *AuthClientCodec) WriteRequest(r *rpc.Request, body interface{}) error

Encodes the request and sends it to the server. This implementation gets an auth header when appropriate, and writes it to the stream

before letting the underlying codec send the rest of the request.

type AuthServerCodec

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

Server Codec

func (*AuthServerCodec) Close

func (a *AuthServerCodec) Close() error

Closes the connection on the server side

We don't change anything here, just let the underlying codec handle it.

func (*AuthServerCodec) ReadRequestBody

func (a *AuthServerCodec) ReadRequestBody(body interface{}) error

Decodes the request and populates the body object with the body of the request

We don't change anything here, just let the underlying codec handle it.
This always gets called after ReadRequestHeader

func (*AuthServerCodec) ReadRequestHeader

func (a *AuthServerCodec) ReadRequestHeader(r *rpc.Request) error

Reads the request header and populates the rpc.Request object.

This implementation reads the auth header off the stream first, then
lets the underlying codec read the rest.
Finally, it validates the identity if necessary.

func (*AuthServerCodec) WriteResponse

func (a *AuthServerCodec) WriteResponse(r *rpc.Response, body interface{}) error

Encodes the response before sending it back down to the client. We don't change anything here, just let the underlying codec handle it.

type ByteBufferReadWriteCloser

type ByteBufferReadWriteCloser struct {
	ReadBuff  bytes.Buffer // Reads will happen from this buffer
	WriteBuff bytes.Buffer // Writes will happen to this buffer
}

We nead a ReadWriteCloser that we can pass to the underlying codec and use

To buffer requests and responses from the actual connection

func (*ByteBufferReadWriteCloser) Close

func (b *ByteBufferReadWriteCloser) Close() error

func (*ByteBufferReadWriteCloser) Read

func (b *ByteBufferReadWriteCloser) Read(p []byte) (int, error)

func (*ByteBufferReadWriteCloser) Write

func (b *ByteBufferReadWriteCloser) Write(p []byte) (int, error)

type Client

type Client interface {
	Close() error
	// TODO: CHANGE TIMEOUT TO MILLISECONDS, NOT SECONDS
	Call(serviceMethod string, args interface{}, reply interface{}, timeout time.Duration) error
}

Client for calling rpc methods

func GetCachedClient

func GetCachedClient(addr string) (Client, error)

GetCachedClient createa or gets a cached Client.

type ClientCodecCreator

type ClientCodecCreator func(io.ReadWriteCloser) rpc.ClientCodec

Client Codec

type ServerCodecCreator

type ServerCodecCreator func(io.ReadWriteCloser) rpc.ServerCodec

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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