Elko: Director Protocols

The Elko Director Protocols

The Director

The Director is an Elko server that coordinates the operation of a collection of Context Servers. In particular, the Context Servers that a Director is working for keep it informed of their relative load factors, the opening and closing of contexts, the coming and going of users, and their availability for providing context services to arriving users.

The Director acts as a first contact point for users seeking entry to a particular context. Rather than contacting a Context Server directly, a user client instead contacts a Director (indeed, the client may not even know the network address of any Context Server). The client seeking entry informs the director of the ref of the context they wish to enter and the ref of the user as whom they wish to enter. The Director then checks to see if the requested context is already loaded on one of the Context Servers it knows about. If it is, the Director directs the user client to that Context Server. If it is not, the Director picks a suitable Context Server and requests it to open the desired context, and directs the user client to to this newly chosen Context Server. In either case, when the Director directs a client to a Context Server, it does not merely give the client the address of the Context Server, but also provides a reservation, an unguessable token that the Director also forwards to the chosen Context Server along with the context ref of the context being entered and the user ref of the user. When the client contacts the Context Server, it provides this reservation token along with its other entry credentials. The Context Server only permits a given client to enter a given context if it also provides the appropriate reservation token to do so. Reservations also expire after a short time (currently 30 seconds). This scheme allows the Director to act as a load balancer for a server farm full of Context Servers.

Since a Director keeps track of the active users on its collection of Context Servers, it can also enable users to rendezvous with each other, by directing a user to the appropriate context containing another user whom they wish to meet. This is especially important in highly scalable contexts, since context cloning may result in more than one instance of a particular context being active at any given time. The Director keeps track of which users are in which clone instances. In a similar vein, the Director can act as a message relay between users and contexts on different Context Servers.

Finally, since a Director is in contact with the entire collection of Context Servers, it can act as a centralized administration contact point for the server farm, enabling the whole farm or selected servers to be reinitialized, shutdown, or directed to take other specific actions.

A Director understands three different JSON message protocols. These correspond to the three kinds of actors who may wish to communicate with a Director: Context Servers providing context services, clients seeking reservations for entry into contexts, and administrators. Each of the ports that a Director listens for connections on can be configured to support any or all of these protocols.

Each of these protocols is associated with a particular object ref to which messages should be addressed:

Common Protocols

While there are three different message protocols, they share a common set of messages pertaining to connection housekeeping. These messages may be targeted at any of the three protocol objects described above.

auth

→ { to:REF, op:"auth", auth:?AUTHDESC, label:?STR}

This message begins a new session with the Director, providing whatever authorization credentials as may be appropriate (according to the Director's server configuration) to gain access to services.

An auth message must be the first message sent to director, provider, or admin on any new connection to the Director. Any other message to these objects will result in immediate termination of the connection.

If the auth operation fails, the connection will be terminated by the Director. Otherwise, the client is thereafter free to send messages according to the protocol of the REF that was authorized.

Authorization information

The auth parameter of the auth message describes a bundle of authorization information to authorize access. Its general form is:

{ type:"auth", mode:STR, code:?STR, id:?STR }

where:

disconnect

→ { to:REF, op:"disconnect" }

This message requests the server to terminate its connection to the sender. The connection to the server is broken.

ping

→ { to:REF, op:"ping", tag:?STR }

This message tests connectivity to the server.

If the message is successfully received by the server, it will reply with:

← { to:REF, op:"pong", tag:?STR }

debug

→ { to:REF, op:"debug", msg:STR }

This message delivers debugging information to the server. If the server is configured to permit this, the string given in the msg parameter will be written to the server's log. If the server is not configured to permit this, this message will simply be ignored.

User Protocol

The Director user protocol is used by user clients requesting reservations for entry to contexts. There is only one message beyond the basic protocol:

reserve

→ { to:"director", op:"reserve", protocol:STR, context:CONTEXTREF_STR, user:?USERREF_STR }

This message requests a reservation for entry into a context.

If the reservation is successful, the reply will take the form:

← { to:"director", op:"reserve", context:CONTEXTREF_STR, user:?USERREF_STR, hostport:STR, reservation:STR }

where:

If the reservation fails, the reply will take the form:

← { to:"director", op:"reserve", context:CONTEXTREF_STR, user:?USERREF_STR, deny:STR }

where:

Provider Protocol

The Director provider protocol is used by providers of context services, that is, by Context Servers, to aprise the Director of their availability.

address

→ { to:"provider", op:"address", protocol:STR, hostport:STR }

This message informs the Director of the sender's availability to speak some protocol at some network address.

where:

context

→ { to:"provider", op:"context", context:CONTEXTREF_STR, open:BOOL, yours:BOOL, maxcap:?INT, basecap:?INT, restricted:?BOOL }

This message informs the Director of the opening or closing of a context by the sending Context Server.

where:

load

→ { to:"provider", op:"load", factor:FLOAT }

This message informs the Director of sender's current load.

where:

relay

→ { to:"provider", op:"relay", context:?CONTEXTREF_STR, user:?USERREF_STR, msg:JSONOBJ }

This message requests the Director to relay a message to a user or context on a different Context Server from the sender.

where:

The context and user parameters are mutually exclusive, and one or the other must be provided. If the base ref of a cloned context or user is specified, the message will be relayed to all Context Servers (other than the sender) who host clones of the indicated recipient context or user.

The relay message will result in the corresponding relay message being sent to all relevant Context Servers (i.e., those serving the context or user indicated). It takes the same form as the inbound request:

← { to:"provider", op:"relay", context:?CONTEXTREF_STR, user:?USERREF_STR, msg:JSONOBJ }

user

→ { to:"provider", op:"user", context:CONTEXTREF_STR, user:USERREF_STR, on:BOOL }

This message informs the Director of the entry or exit of a user to or from a context hosted by the sender.

where:

willserve

→ { to:"provider", op:"willserve", context:STR, capacity:?INT }

This message informs the Director of the sender's availability to serve some family of contexts.

where:

close

This message may be sent by the Director to the Context Server. It instructs the Context Server to force the closure of a context or the disconnection of a user.

← { to:"provider", op:"close", context:?CONTEXTREF_STR, user:?USERREF_STR, dup:?BOOL }

where:

The context and user parameters are mutually exclusive.

reinit

This message may be sent by the Director to the Context Server. It instructs the Context Server to reinitialize itself.

← { to:"provider", op:"reinit" }

shutdown

This message may be sent by the Director to the Context Server. It instructs the Context Server to shut itself down.

← { to:"provider", op:"shutdown", kill:?BOOL }

where:

say

This message may be sent by the Director to the Context Server. It requests the Context Server to deliver a say message to a particular user or to the users in a particular context.

← { to:"provider", op:"say", context:?CONTEXTREF_STR, user:?USERREF_STR, text:STR }

where:

The context and user parameters are mutually exclusive, and one or the other must be provided. If the base ref of a cloned context or user is specified, all clones of the indicated context or user will be spoken to.

Admin Protocol

The Director admin protocol is used to administer the Director and, indirectly, the entire collection of Context Servers it is in contact with.

close

→ { to:"admin", op:"close", context:?CONTEXTREF_STR, user:?USERREF_STR }

This message instructs the Director to force the closure of a context or the disconnection of a user.

where:

The context and user parameters are mutually exclusive, and one or the other must be provided. If the base ref of a cloned context or user is specified, all clones of the indicated context or user will be closed.

If the indicated context is open or the indicated user is connected, the Director will send a provider close message to each relevant connected Context Server instructing it to take the requested action.

dump

→ { to:"admin", op:"dump", depth:INT, provider:?STR, context:?CONTEXTREF_STR }

This message requests the Director to provide a dump of its state to the requesting administrator.

where:

The Director will reply with a message of the form:

← { to:"admin", op:"dump", numproviders:INT, numcontexts:INT, numusers:INT, providers:[PROVIDERDUMP] }

where:

The provider dump descriptor takes the form:

{ type:"providerdesc", provider:STR, numcontexts:INT, numusers:INT, load:FLOAT, capacity:INT, hostports:[STR], protocols:[STR], serving:[STR], contexts:[OPENCONTEXTDUMP] }

where:

The open context dump descriptor takes the form:

{ type:"contextdesc", context:CONTEXTREF_STR, numusers:INT, users:[USERREF_STR] }

where:

find

→ { to:"admin", op:"find", context:?CONTEXTREF_STR, user:?USERREF_STR }

This message requests the Director to provide the location of a context or user.

where:

The context and user parameters are mutually exclusive, and one or the other must be provided. If the base ref of a cloned context or user is specified, the locations of all clones of the indicated context or user will be returned.

If a context location was requested, the Director will reply with:

← { to:"admin", op:"context", context:?CONTEXTREF_STR, open:BOOL, provider:?STR, clones:[CONTEXTREF_STR] }

where:

If a user location was requested, the Director will reply with:

← { to:"admin", op:"user", user:?USERREF_STR, on:BOOL, contexts:[CONTEXTREF_STR] }

where:

listcontexts

→ { to:"admin", op:"listcontexts" }

This message requests the Director to provide a list of currently open contexts.

The Director will reply with:

← { to:"admin", op:"listcontexts", contexts:[CONTEXTREF_STR] }

where:

listproviders

→ { to:"admin", op:"listproviders" }

This message requests the Director to provide a list of known providers (i.e., Context Servers).

The Director will reply with:

← { to:"admin", op:"listproviders", providers:[STR] }

where:

listusers

→ { to:"admin", op:"listusers" }

This message requests the Director to provide a list of currently connected users.

The Director will reply with:

← { to:"admin", op:"listusers", users:[USERREF_STR] }

where:

reinit

→ { to:"admin", op:"reinit", provider:?STR, director:?BOOL }

This message instructs the Director to reinitialize one or more servers.

where:

If any providers are to be reinitialized, each will be sent a corresponding reinit message on its provider connection.

relay

→ { to:"admin", op:"relay", context:?CONTEXTREF_STR, user:?USERREF_STR, msg:JSONOBJ }

This message requests the Director to relay a message to a user or context on whatever Context Server is appropriate. It takes the exact same form and has the same behavior as the corresponding message in the provider protocol, except of course that it is targeted at "admin" instead of "provider".

say

→ { to:"admin", op:"say", context:?CONTEXTREF_STR, user:?USERREF_STR, text:STR }

This message requests the Director to deliver a say message to a particular user or to the users in a particular context.

where:

The context and user parameters are mutually exclusive, and one or the other must be provided. If the base ref of a cloned context or user is specified, all clones of the indicated context or user will be spoken to.

The Director will send a corresponding say message to each relevant Context Server.

shutdown

→ { to:"admin", op:"shutdown", provider:?STR, director:?BOOL, kill:?BOOL }

This message instructs the Director to shut down one or more servers.

where:

If any providers are to be shut down, each will be sent a corresponding shutdown message on its provider connection.

watch

→ { to:"admin", op:"watch", context:?CONTEXTREF_STR, user:?USERREF_STR }

This message requests the Director to begin providing ongoing updates as to the location of a context or user.

where:

The context and user parameters are mutually exclusive, and one or the other must be provided. If the base ref of a cloned context or user is specified, the locations of all clones of the indicated context or user will be watched.

The operation of watch is similar to find, except that the Director maintains continuous surveillance of the context or user indicated. Each time the context is opened or close, or the user enters or exits, a context or user message will be sent to the administrator. These messages take the same form as they do in the replies to the find request; the only difference is that the behavior is spontaneous and asynchronous.

unwatch

→ { to:"admin", op:"unwatch", context:?CONTEXTREF_STR, user:?USERREF_STR }

This message requests the Director to cease providing ongoing updates as to the location of a context or user. It undoes the effect of an earlier watch request.

where:

The context and user parameters are mutually exclusive, and one or the other must be provided. For this request to be useful, the parameters should match those of an earlier watch request. However, requesting an unwatch of a context or user that was not actually being watched is a benign operation with no effect.