Python Manual User Manual

Page of 124
Authorisation of Clients
75
Overriding this method can be useful purely for logging purposes, but might also be used in a client
process to trigger an announcement to activate the function of the process upon a connection becoming
active. Consequently, the operation of a client process could be suspended or the process shutdown
when no active connection could be established or the connection lost.
This latter mode of operation would be necessary when a retry delay is not specified when connecting
a message exchange client to a server. In this situation the retry delay defaults to the value of "
-1
",
indicating that one and only one connection attempt should be made. If this is used, a client should
monitor to see if the connection fails and shutdown the process if it does. Similarly, if it does manage
to connect to the server, when that connection is subsequently lost the process should again be shut-
down.
Note that creation of a one off connection will currently consume resources that cannot be reclaimed.
This is a limitation of the Python interface and is not present when using the OSE C++ class library
directly which has a way of reclaiming the resources. As the intent is that the message exchange frame-
work is for permanent connections, this is not seen as too problematic at this time and will only be ad-
dressed at some time in the future.
Authorisation of Clients
As the message exchange framework provides direct access into an application, it may be desirable to
restrict which hosts can connect in to an application. If this type of control is required, it can be imple-
mented by creating a new derived version of the
Exchange
class and overriding the member function
"
authorise()
". For each client connection that a server gets, this member function will be called
with the IP address of the host the client is located on. A server may then reject or accept the connec-
tion.
class Exchange(netsvc.Exchange):
def __init__(self,type,hosts=[]):
netsvc.Exchange.__init__(self,type)
self._allow = hosts
def authorise(self,host):
return host in self._allow
To accept a connection the member function should return a true value and false otherwise. When a
connection is rejected, the client will see it as a failed connection attempt.
Distributed Exchange Server
When an application is distributed across multiple machines, it may not be desirable that processes on
one machine must connect to the message exchange server located on another machine. The problem
here is that if the machine hosting the message exchange server is shutdown, none of the processes lo-
cated on remote machines will be able to communicate with each other. In essence there is a single
point of failure.