Router
From Croquet Consortium
Contents |
Router Common
TConnectionDispatcher
This class takes incoming Croquet connection requests and transfers them to the appropriate router. Subclasses must implement the specific mapping required.
Instance variables:
socket <Socket> The server socket accepting the incoming connections. server <Process> The process handling incoming connections. mutex <TMutex> Mutex to get exclusive access to the dispatcher. sessions <Dictionary> The mapping from session ID to router. autoCreate <Boolean> If true, non-existing sessions are automatically created.
Class variables: Default <TSessionDispatcher> The default session dispatcher (if any) Port <Integer> The port for the default session dispatcher
TDataGram
I am a simple datagram representation that allows to decouple the facet and the argument data (and reuse the data in many datagrams).
Instance variables:
facet <TObjectID> The facet to invoke. data <ByteArray> The arguments for the invocation.
TMessageRelay
I relay messages on a socket.
Instance variables:
address <ByteArray> The ip address of the connection. port <Integer> The port for the connection. socket <Socket> The relay socket. stream <SocketStream> The socket stream for easier decoding. buffer <ByteArray> The buffer for send operations. eventQueue <SharedQueue> The queue for scheduling further messages. outQueue <SharedQueue> The queue for outgoing messages. reader <Process> The reader process writer <Process> The writer process recvCypher <StreamCypher> The stream cypher for receiving messages sendCypher <StreamCypher> The stream cypher for sending messages facets <Dictionary> The facets defined for this relay. recvCount <Integer> Number of messages received. sendCount <Integer> Number of messages sent. recvAmount <Integer> Overall number of bytes received. sendAmount <Integer> Overall number of bytes sent.
TMessageRouter
I route incoming messages from croquet clients.
Instance variables:
log <Stream> My log stream. socket <Socket> The server socket. clients <Array of TMessageClient> My Croquet clients that I handle. eventQueue <SharedQueue> The event queue for handling messages. eventLoop <Process> The process executing the event queue. server <Process> The server process connecting incoming clients. facets <Dictionary> The facets defined for the router. lastTick <Integer> The millisecond clock value for the last message sent timeStamp <Float> The current time stamp for the island. autoStop <Boolean> If true, close the router when the last client goes away.
TMessageRouterClient
Instance variables:
router <TMessageRouter> The router recvFacet <TObjectID> The recv: facet which allows me to receive msgs. syncFacet <TObjectID> The sync: facet which allows me to act as a server. serveFacet <TObjectID> The serve: facet which allows me to recv a snapshot. tickFacet <TObjectID> The tick facet which allows me to get time information. listFacet <TObjectID> The list: facet that allows me to list other facets.
TMessageRouterTests
Tests for message routers
Router Controller
TRemoteController
This island controller uses a remote message router. For security reasons, a controller is generally set up with two bits of information: a "session key" (used for encryption with the router) and a "list facet" which the controller can use to list other available facets. How to actually transfer those two bits of information is what makes my subclasses and the associated routers special. In the simplest case, we might just use no encryption (no session key) and a well-known list facet. In a more realistic case, however, we would use either encryption or out-of-band techniques (email, https) to get this information across. However, since in general we expect there to be *some* form of authentication, TRemoteController provides the method login:password: as a generic entry point (which then needs to be implemented by the subclasses properly).
Instance variables:
connection <TMessageRelay> The connection to the router loginPromise <TPromise> Signaled when login completes. joinPromise <TPromise> Signaled when join completes. syncPromise <TPromise> Signaled when sync completes. sentMessages <Dictionary> Measuring the start time of messages. sentCounter <SmallInteger> A message ID counter. latencyStats <Bag> A bag full of latency stats. messageStats <Bag> A bag full of message stats. cacheManager <TCacheManager> A cache manager to deliver the resources for this island backDoor <TMessageRouter> The back-door to the message router if hosted on the same machine.
TRemoteControllerConnection
A message relay used as remote controller connection.
Instance variables:
.controller <TRemoteController> The remote controller.
TSessionController
TSessionController provides authentication based on the fact that both router and controller share a secret (the password hash) which can be used to initiate a secure connection. To log in, the controller only sends the user name to which the router responds with a challenge - namely an encrypted version of the session key and the list facet (both of which are XORed against the password hash). The controller then requests a list of the available facets which, once the router responds to it, completes the authentication phase. Some interesting notes:
- this scheme never transfers either plain or hashes of passwords over the wire
- the only way to determine whether you responded correctly to the challenge by the router is to see whether the facets are actually listed - if the controller just closes the connection you must assume that password is incorrect
Instance variables: password <TSecureID> The password hash.
TSimpleController
I am a simplified controller making use of the simplified router.
Router Example
TExampleDispatcher
An example connection dispatcher. Uses a set of existing routers or creates new example routers.
Instance variables: routers <Dictionary> Maps session IDs to routers. autoCreate <Boolean> If true, create new routers on demand. defaultRouterClass <Behavior> The default router class to use.
TExampleRouter
An example router doing no authentication whatsoever and providing everyone with full access. Nice for testing but not much else.
Router Simple
TSimpleRouter
I am a simplified router, which exposes all the facets if provided with the right login facet. I can be used for testing Croquet in an environment where actual authorization schemes haven't been chosen. For now, TSimpleRouter can be provided with a set of user names/passwords or their md5 hashes for authentication.
The model provided here is overly simplified since we NEVER want to give unrestricted access to anything in a real-life use. But for now it is convenient while we're looking for better ways of doing it.
