app/models/server.rb
# receive verify comments response from other Gofreerev server
receive verify comments response from other Gofreerev server
receive verify comments response from other Gofreerev server
def receive_verify_comments_res (mid, request_mid, verify_comments, error)
    logger.debug2 "mid = #{mid}, request_mid = #{request_mid}"
    logger.debug2 "verify_comments = #{verify_comments}"
    logger.debug2 "error        = #{error} (#{error.class})"
    logger.debug2 "error.size = #{error.size}" if error.class == Array
    errors = []
    errors << "empty verify_comments response message was rejected" unless verify_comments or error
    errors << error if error
    if verify_comments
      server_seqs = verify_comments.collect { |hash| hash['seq'] }.uniq
      if server_seqs.size != verify_comments.size
        errors << "verify_comments response message was rejected. seq in verify_comments array must be unique"
        verify_comments = nil
      end
    end
    if !verify_comments or verify_comments.size == 0
      logger.debug2 "errors = #{errors.join(', ')}"
      return errors.size == 0 ? nil : errors.join(', ')
    end
    vcs = {}
    VerifyComment.where(:server_seq => server_seqs).each { |vc| vcs[vc.server_seq] = vc }
    unknown_seq = []
    invalid_server_id = []
    invalid_cid = []
    invalid_response = []
    identical_response = []
    ok_response = []
    verify_comments.each do |verify_comment|
      seq = verify_comment['seq']
      cid = verify_comment['cid']
      verified_at_server = verify_comment['verified_at_server']
      error = verify_comment['error']
      vc = vcs[seq]
      if !vc
        unknown_seq << verify_comment
      elsif vc.server_id != self.id
        invalid_server_id << verify_comment
      elsif vc.cid != cid
        invalid_cid << verify_comment
      elsif vc.verified_at_server.class != NilClass
        if (verified_at_server != vc.verified_at_server or error != vc.error)
          invalid_response << verify_comment
        else
          identical_response << verify_comment
        end
      else
        ok_response << verify_comment
        vc.verified_at_server = verified_at_server
        vc.error = error
        vc.save!
      end
    end 
    logger.debug2 "verify_comments.size = #{verify_comments.size}, unknown_seq.size = #{unknown_seq.size}, " +
                      "invalid_server_id.size = #{invalid_server_id.size}, invalid_cid.size = #{invalid_cid.size}, " +
                      "invalid_response.size = #{invalid_response.size}, identical_response.size = #{identical_response.size}, " +
                      "ok_response.size = #{ok_response.size}"
    ok_response.each do |verify_comment|
      seq = verify_comment['seq']
      vc = vcs[seq]
      vc.verified_at_server = verify_comment['verified_at_server']
      vc.error = verify_comment['error'] if verify_comment['error']
      vc.response_mid = mid
      vc.save!
    end
    if unknown_seq.size + invalid_server_id.size + invalid_cid.size + invalid_response.size > 0
      errors = [ "#{unknown_seq.size + invalid_server_id.size + invalid_cid.size + invalid_response.size} rows in verify gift response" ]
      errors << "Unknown or deleted seqs: " + unknown_seq.collect { |vg| vg['seq'] }.join(', ') if unknown_seq.size > 0
      errors << "Invalid seqs (other server): " + invalid_server_id.collect { |vg| vg['seq'] }.join(', ') if invalid_server_id.size > 0
      errors << "Invalid cids: " + invalid_cid.collect { |vg| vg['seq'] }.join(', ') if invalid_cid.size > 0
      errors << "Changed response: " + invalid_response.collect { |vg| vg['seq'] }.join(', ') if invalid_cid.size > 0
      message_hash = {
          :msgtype => 'error',
          :mid => Sequence.next_server_mid,
          :request_mid => request_mid,
          :response_mid => mid,
          :error => errors.join(', ')
      }
      logger.debug2 "error message = #{message_hash}"
      key, message = self.mix_encrypt_message_hash message_hash
      m = Message.new
      m.from_did = SystemParameter.did
      m.to_did = self.new_did
      m.server = true
      m.key = key
      m.message = message
      m.mid = message_hash.mid
      m.save!
      return errors.join(', ')
    end
    return nil
  end
def receive_verify_comments_res ( mid , request_mid , verify_comments , error ) logger . debug2 "mid = #{mid}, request_mid = #{request_mid}" logger . debug2 "verify_comments = #{verify_comments}" logger . debug2 "error        = #{error} (#{error.class})" logger . debug2 "error.size = #{error.size}" if error . class == Array errors = [ ] errors << "empty verify_comments response message was rejected" unless verify_comments or error errors << error if error if verify_comments server_seqs = verify_comments . collect { | hash | hash [ 'seq' ] } . uniq if server_seqs . size != verify_comments . size errors << "verify_comments response message was rejected. seq in verify_comments array must be unique" verify_comments = nil end end if ! verify_comments or verify_comments . size == 0 logger . debug2 "errors = #{errors.join(', ')}" return errors . size == 0 ? nil : errors . join ( ', ' ) end vcs = { } VerifyComment . where ( :server_seq => server_seqs ) . each { | vc | vcs [ vc . server_seq ] = vc } unknown_seq = [ ] invalid_server_id = [ ] invalid_cid = [ ] invalid_response = [ ] identical_response = [ ] ok_response = [ ] verify_comments . each do | verify_comment | seq = verify_comment [ 'seq' ] cid = verify_comment [ 'cid' ] verified_at_server = verify_comment [ 'verified_at_server' ] error = verify_comment [ 'error' ] vc = vcs [ seq ] if ! vc unknown_seq << verify_comment elsif vc . server_id != self . id invalid_server_id << verify_comment elsif vc . cid != cid invalid_cid << verify_comment elsif vc . verified_at_server . class != NilClass if ( verified_at_server != vc . verified_at_server or error != vc . error ) invalid_response << verify_comment else identical_response << verify_comment end else ok_response << verify_comment vc . verified_at_server = verified_at_server vc . error = error vc . save! end end logger . debug2 "verify_comments.size = #{verify_comments.size}, unknown_seq.size = #{unknown_seq.size}, " + "invalid_server_id.size = #{invalid_server_id.size}, invalid_cid.size = #{invalid_cid.size}, " + "invalid_response.size = #{invalid_response.size}, identical_response.size = #{identical_response.size}, " + "ok_response.size = #{ok_response.size}" ok_response . each do | verify_comment | seq = verify_comment [ 'seq' ] vc = vcs [ seq ] vc . verified_at_server = verify_comment [ 'verified_at_server' ] vc . error = verify_comment [ 'error' ] if verify_comment [ 'error' ] vc . response_mid = mid vc . save! end if unknown_seq . size + invalid_server_id . size + invalid_cid . size + invalid_response . size > 0 errors = [ "#{unknown_seq.size + invalid_server_id.size + invalid_cid.size + invalid_response.size} rows in verify gift response" ] errors << "Unknown or deleted seqs: " + unknown_seq . collect { | vg | vg [ 'seq' ] } . join ( ', ' ) if unknown_seq . size > 0 errors << "Invalid seqs (other server): " + invalid_server_id . collect { | vg | vg [ 'seq' ] } . join ( ', ' ) if invalid_server_id . size > 0 errors << "Invalid cids: " + invalid_cid . collect { | vg | vg [ 'seq' ] } . join ( ', ' ) if invalid_cid . size > 0 errors << "Changed response: " + invalid_response . collect { | vg | vg [ 'seq' ] } . join ( ', ' ) if invalid_cid . size > 0 message_hash = { :msgtype => 'error' , :mid => Sequence . next_server_mid , :request_mid => request_mid , :response_mid => mid , :error => errors . join ( ', ' ) } logger . debug2 "error message = #{message_hash}" key , message = self . mix_encrypt_message_hash message_hash m = Message . new m . from_did = SystemParameter . did m . to_did = self . new_did m . server = true m . key = key m . message = message m . mid = message_hash . mid m . save! return errors . join ( ', ' ) end return nil end
receive verify comments response from other Gofreerev server
receive verify comments response from other Gofreerev server
# seq in verify_comments must be unique # seq must be in verify_comments table (see Comment.verify_comments) # has already received a different response for this request # save response for remote gift verification. Response will be returned to client in next ping # each verify_gift # send server to server error message
mid
<not_specific>
request_mid
<not_specific>
verify_comments
<not_specific>
error
<not_specific>