modules/rcore/lib/wrangle/peer.rb
# handle pack/unpack of all PR6 messages
handle pack/unpack of all PR6 messages
handle pack / unpack of all PR6 messages
def processMessage
                loop do
                    input = @processMessageQueue.pop
                    Log::debug "#{__method__}: #{input}"
                    case input[:type]
                    when :send
                        id = input[:id]
                        to = input[:to]
                        from = input[:from]
                        output = packMessage(to, input[:message])
                        if output
                            @processJobQueue.push({
                                :type=>:notifyPacked,
                                :id=>id,
                                :time => Time.now,
                                :counter => output[:counter],
                                :message => {
                                    :to => to,
                                    :from => from,
                                    :message => output[:data],
                                    :ip => input[:ip],
                                    :port => input[:port]
                                }                                
                            })
                        else
                            @processJobQueue.push({
                                :type=>:notifyNotSent,
                                :id=>id,
                                :time => Time.now
                            })
                        end
                    when :receive
                        id = input[:id]
                        result = unpackMessage(input[:data])
                        if result
                            case result[:recipient]
                            when :PR6_RECIPIENT_CLIENT
                                @processJobQueue.push({
                                    :type => :processMessage,
                                    :from => result[:from],
                                    :to => result[:to],
                                    :message => result[:data]                                    
                                })
                            when :PR6_RECIPIENT_SERVER
                                association = AssociationRecord.read(result[:to], result[:to], result[:from])
                                if association
                                    output = packMessage(result[:from], Server.new(association, @objects).input(result[:counter], result[:data]))
                                    if output.size > 0
                                        @outputQueue.push({
                                            :to => result[:from],
                                            :from => result[:to],
                                            :ip => input[:ip],
                                            :port => input[:port],
                                            :message => output[:data]
                                        })
                                    end
                                else
                                    Log::warning "#{__method__}: assocation record removed since last read"
                                end
                            else
                                raise
                            end
                        end
                    else
                        raise "unknown message type"
                    end
                end
            end
def processMessage loop do input = @processMessageQueue . pop Log :: debug "#{__method__}: #{input}" case input [ :type ] when :send id = input [ :id ] to = input [ :to ] from = input [ :from ] output = packMessage ( to , input [ :message ] ) if output @processJobQueue . push ( { :type => :notifyPacked , :id => id , :time => Time . now , :counter => output [ :counter ] , :message => { :to => to , :from => from , :message => output [ :data ] , :ip => input [ :ip ] , :port => input [ :port ] } } ) else @processJobQueue . push ( { :type => :notifyNotSent , :id => id , :time => Time . now } ) end when :receive id = input [ :id ] result = unpackMessage ( input [ :data ] ) if result case result [ :recipient ] when :PR6_RECIPIENT_CLIENT @processJobQueue . push ( { :type => :processMessage , :from => result [ :from ] , :to => result [ :to ] , :message => result [ :data ] } ) when :PR6_RECIPIENT_SERVER association = AssociationRecord . read ( result [ :to ] , result [ :to ] , result [ :from ] ) if association output = packMessage ( result [ :from ] , Server . new ( association , @objects ) . input ( result [ :counter ] , result [ :data ] ) ) if output . size > 0 @outputQueue . push ( { :to => result [ :from ] , :from => result [ :to ] , :ip => input [ :ip ] , :port => input [ :port ] , :message => output [ :data ] } ) end else Log :: warning "#{__method__}: assocation record removed since last read" end else raise end end else raise "unknown message type" end end end
handle pack/unpack of all PR6 messages
handle pack / unpack of all PR6 messages