edge

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: BSD-3-Clause Imports: 29 Imported by: 4

Documentation

Index

Constants

View Source
const (
	MethodWild    = "*"
	MethodGet     = "GET"     // RFC 7231, 4.3.1
	MethodHead    = "HEAD"    // RFC 7231, 4.3.2
	MethodPost    = "POST"    // RFC 7231, 4.3.3
	MethodPut     = "PUT"     // RFC 7231, 4.3.4
	MethodPatch   = "PATCH"   // RFC 5789
	MethodDelete  = "DELETE"  // RFC 7231, 4.3.5
	MethodConnect = "CONNECT" // RFC 7231, 4.3.6
	MethodOptions = "OPTIONS" // RFC 7231, 4.3.7
	MethodTrace   = "TRACE"   // RFC 7231, 4.3.8
)

HTTP methods were copied from net/http.

Variables

View Source
var (
	ErrClusterNotSet            = errors.New("cluster is not set")
	ErrGatewayNotSet            = errors.New("gateway is not set")
	ErrTunnelNotSet             = errors.New("tunnel is not set")
	ErrUnexpectedTunnelResponse = errors.New("unexpected tunnel response")
	ErrEmptyMemberList          = errors.New("member list is empty")
	ErrMemberNotFound           = errors.New("member not found")
	ErrNoTunnelAddrs            = errors.New("tunnel address does not found")
)

Functions

This section is empty.

Types

type Builtin added in v0.5.0

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

Builtin keep track of pages distribution over Edge servers.

func (*Builtin) GetAllNodes added in v0.7.4

func (pm *Builtin) GetAllNodes(ctx *RequestCtx, in *rony.MessageEnvelope)

func (*Builtin) GetNodes added in v0.5.0

func (pm *Builtin) GetNodes(ctx *RequestCtx, in *rony.MessageEnvelope)

func (*Builtin) GetPage added in v0.5.0

func (pm *Builtin) GetPage(ctx *RequestCtx, in *rony.MessageEnvelope)

type Cluster

type Cluster = cluster.Cluster

type DispatchCtx

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

DispatchCtx holds the context of the dispatcher's request. Each DispatchCtx could holds one or many RequestCtx. DispatchCtx lives until the last of its RequestCtx children.

func (*DispatchCtx) BufferPop added in v0.1.9

func (ctx *DispatchCtx) BufferPop() *rony.MessageEnvelope

func (*DispatchCtx) BufferPush added in v0.1.9

func (ctx *DispatchCtx) BufferPush(m *rony.MessageEnvelope)

func (*DispatchCtx) BufferSize added in v0.1.9

func (ctx *DispatchCtx) BufferSize() int32

func (*DispatchCtx) Conn

func (ctx *DispatchCtx) Conn() rony.Conn

func (*DispatchCtx) Debug

func (ctx *DispatchCtx) Debug()

func (*DispatchCtx) FillEnvelope

func (ctx *DispatchCtx) FillEnvelope(requestID uint64, constructor int64, payload []byte, auth []byte, kv ...*rony.KeyValue)

func (*DispatchCtx) Get

func (ctx *DispatchCtx) Get(key string) interface{}

func (*DispatchCtx) GetBool

func (ctx *DispatchCtx) GetBool(key string) bool

func (*DispatchCtx) GetBytes

func (ctx *DispatchCtx) GetBytes(key string, defaultValue []byte) []byte

func (*DispatchCtx) GetInt64

func (ctx *DispatchCtx) GetInt64(key string, defaultValue int64) int64

func (*DispatchCtx) GetString

func (ctx *DispatchCtx) GetString(key string, defaultValue string) string

func (*DispatchCtx) Kind added in v0.1.4

func (ctx *DispatchCtx) Kind() MessageKind

func (*DispatchCtx) ServerID added in v0.1.9

func (ctx *DispatchCtx) ServerID() string

func (*DispatchCtx) Set

func (ctx *DispatchCtx) Set(key string, v interface{})

func (*DispatchCtx) StreamID

func (ctx *DispatchCtx) StreamID() int64

func (*DispatchCtx) UnmarshalEnvelope

func (ctx *DispatchCtx) UnmarshalEnvelope(data []byte) error

type Dispatcher

type Dispatcher interface {
	// OnMessage is called on every message pushed to RequestCtx.
	// All the input arguments are valid in the function context, if you need to pass 'envelope' to other
	// async functions, make sure to hard copy (clone) it before sending it.
	// **NOTE**: This is not called on non-persistent connections, instead it is user's responsibility to check the
	// ctx.BufferSize() and ctx.BufferPop() functions
	OnMessage(ctx *DispatchCtx, envelope *rony.MessageEnvelope)
	// Interceptor is called before any handler called.
	// All the input arguments are valid in the function context, if you need to pass 'data' or 'envelope' to other
	// async functions, make sure to hard copy (clone) it before sending it. If 'err' is not nil then envelope will be
	// discarded, it is the user's responsibility to send back appropriate message using 'conn'
	// Note that conn IS NOT nil in any circumstances.
	Interceptor(ctx *DispatchCtx, data []byte) (err error)
	// Done will be called when the context has been finished, this lets cleaning up, or in case you need to flush the
	// messages and updates in one go.
	Done(ctx *DispatchCtx)
	// OnOpen will be called when a new connection has been opened
	OnOpen(conn rony.Conn, kvs ...*rony.KeyValue)
	// OnClose will be called when a connection is closed
	OnClose(conn rony.Conn)
}

type DummyGatewayConfig added in v0.1.8

type DummyGatewayConfig = dummyGateway.Config

type Gateway added in v0.5.20

type Gateway = gateway.Gateway

type GatewayProtocol added in v0.5.20

type GatewayProtocol = gateway.Protocol
const (
	Undefined GatewayProtocol = 0
	Dummy     GatewayProtocol = 1 << iota
	Http
	Websocket
	Quic
	Grpc
	TCP = Http | Websocket // Http & Websocket
)

Gateway Protocols

type GossipClusterConfig added in v0.1.8

type GossipClusterConfig = gossipCluster.Config

type Handler

type Handler = func(ctx *RequestCtx, in *rony.MessageEnvelope)

type HandlerOption added in v0.5.7

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

HandlerOption is a structure holds all the information required for a handler.

func NewHandlerOptions added in v0.3.12

func NewHandlerOptions() *HandlerOption

func (*HandlerOption) Append added in v0.5.7

func (ho *HandlerOption) Append(h ...Handler) *HandlerOption

Append adds the h handlers after already set handlers

func (*HandlerOption) GatewayOnly added in v0.5.7

func (ho *HandlerOption) GatewayOnly() *HandlerOption

GatewayOnly makes this method only available through gateway messages.

func (*HandlerOption) Prepend added in v0.5.7

func (ho *HandlerOption) Prepend(h ...Handler) *HandlerOption

Prepend adds the h handlers before already set handlers

func (*HandlerOption) SetConstructor added in v0.6.3

func (ho *HandlerOption) SetConstructor(constructors ...int64) *HandlerOption

func (*HandlerOption) SetHandler added in v0.6.3

func (ho *HandlerOption) SetHandler(h ...Handler) *HandlerOption

SetHandler replaces the handlers for this constructor with h

func (*HandlerOption) TunnelOnly added in v0.5.7

func (ho *HandlerOption) TunnelOnly() *HandlerOption

TunnelOnly makes this method only available through tunnel messages.

type HttpProxy added in v0.6.1

type HttpProxy = tcpGateway.HttpProxy

type HttpRequest added in v0.6.9

type HttpRequest = gateway.RequestCtx

type MessageKind added in v0.5.8

type MessageKind byte
const (
	GatewayMessage MessageKind
	TunnelMessage
)

func (MessageKind) String added in v0.5.8

func (c MessageKind) String() string

type Option

type Option func(edge *Server)

func WithDataDir added in v0.5.0

func WithDataDir(path string) Option

func WithDispatcher added in v0.1.9

func WithDispatcher(d Dispatcher) Option

WithDispatcher enables custom dispatcher to write your specific event handlers.

func WithGossipCluster added in v0.1.5

func WithGossipCluster(cfg GossipClusterConfig) Option

WithGossipCluster enables the cluster in gossip mode. This mod is eventually consistent mode but there is no need to a central key-value store or any other 3rd party service to run the cluster

func WithTcpGateway

func WithTcpGateway(config TcpGatewayConfig) Option

WithTcpGateway set the gateway to tcp which can support http and/or websocket Only one gateway could be set and if you set another gateway it panics on runtime.

func WithTestGateway

func WithTestGateway(config DummyGatewayConfig) Option

WithTestGateway set the gateway to a dummy gateway which is useful for writing tests. Only one gateway could be set and if you set another gateway it panics on runtime.

func WithUdpTunnel added in v0.1.8

func WithUdpTunnel(config UdpTunnelConfig) Option

WithUdpTunnel set the tunnel to a udp based tunnel which provides communication channel between edge servers.

type ProxyHandle added in v0.6.1

type ProxyHandle = gateway.ProxyHandle

type RequestCtx

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

RequestCtx holds the context of an RPC handler

func (*RequestCtx) Cluster added in v0.2.10

func (ctx *RequestCtx) Cluster() cluster.Cluster

func (*RequestCtx) ClusterView added in v0.6.38

func (ctx *RequestCtx) ClusterView(replicaSet uint64, edges *rony.Edges) (*rony.Edges, error)

func (*RequestCtx) Conn

func (ctx *RequestCtx) Conn() rony.Conn

func (*RequestCtx) ConnID

func (ctx *RequestCtx) ConnID() uint64

func (*RequestCtx) ExecuteRemote added in v0.1.9

func (ctx *RequestCtx) ExecuteRemote(replicaSet uint64, req, res *rony.MessageEnvelope) error

func (*RequestCtx) FindReplicaSet added in v0.5.8

func (ctx *RequestCtx) FindReplicaSet(pageID uint32) (uint64, error)

func (*RequestCtx) Get

func (ctx *RequestCtx) Get(key string) interface{}

func (*RequestCtx) GetBool

func (ctx *RequestCtx) GetBool(key string) bool

func (*RequestCtx) GetBytes

func (ctx *RequestCtx) GetBytes(key string, defaultValue []byte) []byte

func (*RequestCtx) GetInt64

func (ctx *RequestCtx) GetInt64(key string, defaultValue int64) int64

func (*RequestCtx) GetString

func (ctx *RequestCtx) GetString(key string, defaultValue string) string

func (*RequestCtx) Kind added in v0.1.4

func (ctx *RequestCtx) Kind() MessageKind

func (*RequestCtx) LocalReplicaSet added in v0.5.8

func (ctx *RequestCtx) LocalReplicaSet() uint64

func (*RequestCtx) Log added in v0.3.18

func (ctx *RequestCtx) Log() log.Logger

func (*RequestCtx) PushCustomError

func (ctx *RequestCtx) PushCustomError(code, item string, desc string)

func (*RequestCtx) PushCustomMessage

func (ctx *RequestCtx) PushCustomMessage(requestID uint64, constructor int64, message proto.Message, kvs ...*rony.KeyValue)

func (*RequestCtx) PushError

func (ctx *RequestCtx) PushError(err *rony.Error)

func (*RequestCtx) PushMessage

func (ctx *RequestCtx) PushMessage(constructor int64, proto proto.Message)

func (*RequestCtx) PushRedirectRequest added in v0.2.10

func (ctx *RequestCtx) PushRedirectRequest(replicaSet uint64)

func (*RequestCtx) PushRedirectSession added in v0.2.10

func (ctx *RequestCtx) PushRedirectSession(replicaSet uint64, wait time.Duration)

func (*RequestCtx) ReqID

func (ctx *RequestCtx) ReqID() uint64

func (*RequestCtx) Return

func (ctx *RequestCtx) Return()

func (*RequestCtx) ServerID added in v0.1.4

func (ctx *RequestCtx) ServerID() string

func (*RequestCtx) Set

func (ctx *RequestCtx) Set(key string, v interface{})

func (*RequestCtx) StopExecution

func (ctx *RequestCtx) StopExecution()

func (*RequestCtx) Stopped

func (ctx *RequestCtx) Stopped() bool

func (*RequestCtx) Store added in v0.7.2

func (ctx *RequestCtx) Store() store.Store

func (*RequestCtx) TryExecuteRemote added in v0.6.8

func (ctx *RequestCtx) TryExecuteRemote(attempts int, retryWait time.Duration, replicaSet uint64, req, res *rony.MessageEnvelope) error

type Server

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

func NewServer

func NewServer(serverID string, opts ...Option) *Server

func (*Server) Cluster added in v0.3.16

func (edge *Server) Cluster() cluster.Cluster

Cluster returns a reference to the underlying cluster of the Edge server

func (*Server) ExecuteRemote added in v0.6.13

func (edge *Server) ExecuteRemote(replicaSet uint64, req, res *rony.MessageEnvelope) error

ExecuteRemote sends and receives a request through the Tunnel interface of the receiver Edge node.

func (*Server) Gateway added in v0.5.18

func (edge *Server) Gateway() gateway.Gateway

Gateway returns a reference to the underlying gateway of the Edge server

func (*Server) GetGatewayConn added in v0.0.6

func (edge *Server) GetGatewayConn(connID uint64) rony.Conn

GetGatewayConn return the gateway connection identified by connID or returns nil if not found.

func (*Server) GetHandler added in v0.5.7

func (edge *Server) GetHandler(constructor int64) *HandlerOption

GetHandler returns the handlers of the constructor

func (*Server) GetServerID

func (edge *Server) GetServerID() string

GetServerID return this server id, which MUST be unique in the cluster otherwise the behaviour is unknown.

func (*Server) JoinCluster

func (edge *Server) JoinCluster(addr ...string) (int, error)

JoinCluster is used to take an existing Cluster and attempt to join a cluster by contacting all the given hosts and performing a state sync. This returns the number of hosts successfully contacted and an error if none could be reached. If an error is returned, the node did not successfully join the cluster.

func (*Server) SetGlobalPostHandlers added in v0.3.8

func (edge *Server) SetGlobalPostHandlers(handlers ...Handler)

SetGlobalPostHandlers set the handler which will be called after executing any request. These pre handlers are like middlewares which will be automatically triggered for each request. If you want to set post handler for specific request the your must use SetHandlers, PrependHandlers or AppendHandlers

func (*Server) SetGlobalPreHandlers added in v0.3.8

func (edge *Server) SetGlobalPreHandlers(handlers ...Handler)

SetGlobalPreHandlers set the handler which will be called before executing any request. These pre handlers are like middlewares which will be automatically triggered for each request. If you want to set pre handler for specific request the your must use SetHandlers, PrependHandlers or AppendHandlers

func (*Server) SetHandler added in v0.5.7

func (edge *Server) SetHandler(ho *HandlerOption)

SetHandler set the handlers for the constructor. 'leaderOnly' is applicable ONLY if the cluster is run with Raft support. If cluster is a Raft enabled cluster, then by setting 'leaderOnly' to TRUE, requests sent to a follower server will return redirect error to the client. For standalone servers 'leaderOnly' does not affect.

func (*Server) SetRestWrapper added in v0.6.40

func (edge *Server) SetRestWrapper(method string, path string, f *rest.Factory)

SetRestWrapper set a REST wrapper to expose RPCs in REST (Representational State Transfer) format

func (*Server) Shutdown

func (edge *Server) Shutdown()

Shutdown gracefully shutdown the services

func (*Server) ShutdownWithSignal

func (edge *Server) ShutdownWithSignal(signals ...os.Signal)

ShutdownWithSignal blocks until any of the signals has been called

func (*Server) Start added in v0.1.9

func (edge *Server) Start()

Start is a helper function which tries to start all three parts of the edge server This function does not return any error, if you need to make sure all the parts are started with no error, then you must start each section separately.

func (*Server) StartCluster

func (edge *Server) StartCluster() (err error)

StartCluster is non-blocking function which runs the gossip and raft if it is set

func (*Server) StartGateway

func (edge *Server) StartGateway() error

StartGateway is non-blocking function runs the gateway in background so we can accept clients requests

func (*Server) StartTunnel added in v0.1.9

func (edge *Server) StartTunnel() error

StartTunnel is non-blocking function runs the gateway in background so we can accept other servers requests

func (*Server) Stats

func (edge *Server) Stats() *Stats

Stats exports some internal metrics data packed in 'Stats' struct

func (*Server) Store added in v0.7.2

func (edge *Server) Store() store.Store

func (*Server) TryExecuteRemote added in v0.6.13

func (edge *Server) TryExecuteRemote(attempts int, retryWait time.Duration, replicaSet uint64, req, res *rony.MessageEnvelope) error

type Stats

type Stats struct {
	Address         string
	ReplicaSet      uint64
	Members         int
	MembershipScore int
	TunnelAddr      []string
	GatewayProtocol gateway.Protocol
	GatewayAddr     []string
}

Stats exports some internal metrics data

type TcpGatewayConfig added in v0.1.8

type TcpGatewayConfig = tcpGateway.Config

type Tunnel added in v0.5.20

type Tunnel = tunnel.Tunnel

type UdpTunnelConfig added in v0.1.8

type UdpTunnelConfig = udpTunnel.Config

Jump to

Keyboard shortcuts

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