Sha256: ca3b9e135ac5e811dcfd45329e78f6c7a5d612ebaf40e021ab7e0c06e013a718

Contents?: true

Size: 1.51 KB

Versions: 34

Compression:

Stored size: 1.51 KB

Contents

#!/usr/bin/env ruby   
# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

require 'digest'

path = ARGV

def usage
  $stderr.puts "Usage: path_hash.rb '<app_name>;<txn_name>' ['<app_name>;<txn_name>'...]"
  exit
end

usage unless path.size > 0

path_hash = 0
path.each do |hop|
  app_name, transaction_name = hop.split(';')

  if !app_name || !transaction_name
    $stderr.puts ''
    $stderr.puts "Error: Malformed transaction identifier '#{hop}'."
    usage
  end

  identifier = "#{app_name};#{transaction_name}"
  md5sum = Digest::MD5.digest(identifier)
  low4_of_md5 = md5sum.unpack("@12N").first

  rotated_path_hash = ((path_hash << 1) | (path_hash >> 31)) & 0xffffffff

  xor_result = rotated_path_hash ^ low4_of_md5

  puts '--'
  puts "A: txnIdentifier:       '#{identifier}'"
  puts "B: MD5(A):              #{Digest::MD5.hexdigest(identifier)}"
  puts "C: Low 4 bytes of B:    0x#{low4_of_md5.to_s(16).rjust(8, '0')} (0b#{low4_of_md5.to_s(2).rjust(32, '0')})"
  puts ''
  puts "D: Input path_hash:     0x#{path_hash.to_s(16).rjust(8, '0')} (0b#{path_hash.to_s(2).rjust(32, '0')})"
  puts "E: Rotated E:           0x#{rotated_path_hash.to_s(16).rjust(8, '0')} (0b#{rotated_path_hash.to_s(2).rjust(32, '0')})"
  puts ""
  puts "F: XOR(D, F):           0x#{xor_result.to_s(16).rjust(8, '0')} (0b#{xor_result.to_s(2).rjust(32, '0')})"
  puts '--'

  path_hash = xor_result
end

puts "Final result: #{path_hash.to_s(16).rjust(8, '0')}"

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
newrelic_rpm-4.1.0.333 test/script/path_hash.rb
newrelic_rpm-4.0.0.332 test/script/path_hash.rb
newrelic_rpm-3.18.1.330 test/script/path_hash.rb
newrelic_rpm-3.18.0.329 test/script/path_hash.rb
newrelic_rpm-3.17.2.327 test/script/path_hash.rb
newrelic_rpm-3.17.1.326 test/script/path_hash.rb
newrelic_rpm-3.17.0.325 test/script/path_hash.rb
newrelic_rpm-3.16.3.323 test/script/path_hash.rb
newrelic_rpm-3.16.2.321 test/script/path_hash.rb
newrelic_rpm-3.16.1.320 test/script/path_hash.rb
newrelic_rpm-3.16.0.318 test/script/path_hash.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.15.2.317/test/script/path_hash.rb
newrelic_rpm-3.15.2.317 test/script/path_hash.rb
newrelic_rpm-3.15.1.316 test/script/path_hash.rb
newrelic_rpm-3.15.0.314 test/script/path_hash.rb
newrelic_rpm-3.14.3.313 test/script/path_hash.rb
newrelic_rpm-3.14.2.312 test/script/path_hash.rb
newrelic_rpm-3.14.1.311 test/script/path_hash.rb
newrelic_rpm-3.14.0.305 test/script/path_hash.rb
newrelic_rpm-3.13.2.302 test/script/path_hash.rb