Author: Not specified Language: python
Description: Not specified Timestamp: 2017-09-22 21:01:59 +0000
View raw paste Reply
  1. class Client :
  2. # Setup class variables
  3.         client_keys = (public_key, private_key) # Public key private key tuple
  4.         operation = Operation('UPDATE ...') # Desired operation
  5.         message = Message(operation, retransmission = False) # Message containing operation and retransmission flag
  6.         message_handler = ClientMessageHandler(client_keys) # Handling messages and their signatures and calling timeout callbacks
  7.         olympus = Olympus() # Contains information about olympus e.g., how to send messages to olympus and its state
  8.         configuration = olympus.get_current_configuration() # Configuration consists of an ordered list of replicas and how to contact them
  9.         Timer.run(interval = 10, target = check_new_config(olympus)) # Check for new configuration every 10 seconds
  10.  
  11.         # Send operation to head
  12.         def send_operation(head, operation) :
  13.                 message_handler.send(receiver = head, message = operation)
  14.  
  15.         # Handle message time out
  16.         def message_timeout(message) :
  17.                 if message.retransmitted : # If already retransmissited, send reconfiguration request to olympus
  18.                         message_handler.send(receiver = olympus, message = reconfiguration_request())
  19.                 else : # Retransmit message
  20.                         retransmit(message)
  21.  
  22.         # Set message retransmitted flag and broadcast request to all nodes
  23.         def retransmit(message) :
  24.                 message.retransmitted = True
  25.                 message_handler.broadcast(configuration, message = operation)
  26.  
  27.         # Runs after receiving a message, presumably the result
  28.         def receive_result(message) :
  29.                 # Verification is done in ClientMessageHandler
  30.                 # If error, request reconfiguration
  31.                 if result == Error :
  32.                         message_handler.send(receiver = olympus, message = reconfiguration_request())
  33.                 else :
  34.                         # Done
  35.                         exit(0)
  36.  
  37.         # This method is called periodically to check for new configuration
  38.         def check_new_config(olympus) :
  39.                 config = olympus.get_current_configuration()
  40.                 if self.configuration != config :
  41.                         retransmit(operation)
  42.  
  43.         # Run the client and send its request
  44.         def run() :
  45.                 send_operation(configuration.Replicas.Head, operation)
  46.  
View raw paste Reply