Class: Meshchat::Network::Incoming::MessageProcessor
- Inherits:
-
Object
- Object
- Meshchat::Network::Incoming::MessageProcessor
- Defined in:
- lib/meshchat/network/incoming/message_processor.rb
Overview
decodes an encrypted message and handles it. also update’s the info of the sender
Instance Attribute Summary collapse
-
#_location ⇒ Object
readonly
Returns the value of attribute _location.
-
#_message_dispatcher ⇒ Object
readonly
Returns the value of attribute _message_dispatcher.
-
#_message_factory ⇒ Object
readonly
Returns the value of attribute _message_factory.
-
#_network ⇒ Object
readonly
Returns the value of attribute _network.
Instance Method Summary collapse
-
#initialize(network: NETWORK_LOCAL, message_dispatcher: nil, location: nil) ⇒ MessageProcessor
constructor
A new instance of MessageProcessor.
- #is_processing_for_local? ⇒ Boolean
- #is_processing_for_relay? ⇒ Boolean
- #process(encoded_message) ⇒ Object
- #update_sender_info(json) ⇒ Object
Constructor Details
#initialize(network: NETWORK_LOCAL, message_dispatcher: nil, location: nil) ⇒ MessageProcessor
Returns a new instance of MessageProcessor.
11 12 13 14 15 16 |
# File 'lib/meshchat/network/incoming/message_processor.rb', line 11 def initialize(network: NETWORK_LOCAL, message_dispatcher: nil, location: nil) @_network = network @_message_dispatcher = @_message_factory = . @_location = location end |
Instance Attribute Details
#_location ⇒ Object (readonly)
Returns the value of attribute _location.
8 9 10 |
# File 'lib/meshchat/network/incoming/message_processor.rb', line 8 def _location @_location end |
#_message_dispatcher ⇒ Object (readonly)
Returns the value of attribute _message_dispatcher.
9 10 11 |
# File 'lib/meshchat/network/incoming/message_processor.rb', line 9 def @_message_dispatcher end |
#_message_factory ⇒ Object (readonly)
Returns the value of attribute _message_factory.
9 10 11 |
# File 'lib/meshchat/network/incoming/message_processor.rb', line 9 def @_message_factory end |
#_network ⇒ Object (readonly)
Returns the value of attribute _network.
8 9 10 |
# File 'lib/meshchat/network/incoming/message_processor.rb', line 8 def _network @_network end |
Instance Method Details
#is_processing_for_local? ⇒ Boolean
69 70 71 |
# File 'lib/meshchat/network/incoming/message_processor.rb', line 69 def is_processing_for_local? _network != NETWORK_RELAY end |
#is_processing_for_relay? ⇒ Boolean
65 66 67 |
# File 'lib/meshchat/network/incoming/message_processor.rb', line 65 def is_processing_for_relay? _network == NETWORK_RELAY end |
#process(encoded_message) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/meshchat/network/incoming/message_processor.rb', line 19 def process() request = MessageDecryptor.new(, ) = request. Debug.() # show the message to the user, and update the information # we have on the sender, so that we may reply to the # correct location update_sender_info(request._json) Display. end |
#update_sender_info(json) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/meshchat/network/incoming/message_processor.rb', line 33 def update_sender_info(json) sender = json['sender'] # Note that sender['location'] should always reference # the sender's local network address network_location = sender['location'] # if the sender isn't currently marked as active, # perform the server list exchange node = Node.find_by_uid(sender['uid']) raise Errors::Forbidden, 'node not found' if node.nil? # if we are receiving a message from a node we had previously # known to be offline, we need to do the node list hash dance # with them to see if they know of any new members to the network unless node.online? node.update(on_local_network: true) if is_processing_for_local? node.update(on_relay: true) if is_processing_for_relay? nlh = .create(Message::NODE_LIST_HASH) .(node: node, message: nlh) end # update the node's location/alias # as they can change this info willy nilly attributes = { location_on_network: network_location, alias_name: sender['alias'] } attributes[:location_of_relay] = _location if is_processing_for_relay? node.update(attributes) end |