Module: RSMP::Proxy::Modules::Versions

Included in:
RSMP::Proxy
Defined in:
lib/rsmp/proxy/modules/versions.rb

Overview

Version negotiation and handling Manages RSMP version handshake between sites and supervisors

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.version_meets_requirement?(version, requirement) ⇒ Boolean

Use Gem class to check version requirement Requirement must be a string like ‘1.1’, ‘>=1.0.3’ or ‘<2.1.4’, or list of strings, like [‘<=1.4’,‘<1.5’]

Returns:

  • (Boolean)


63
64
65
# File 'lib/rsmp/proxy/modules/versions.rb', line 63

def self.version_meets_requirement?(version, requirement)
  Gem::Requirement.new(requirement).satisfied_by?(Gem::Version.new(version))
end

Instance Method Details

#check_core_version(message) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rsmp/proxy/modules/versions.rb', line 18

def check_core_version(message)
  versions = core_versions
  # find versions that both we and the client support
  candidates = message.versions & versions
  if candidates.any?
    @core_version = candidates.max_by { |v| Gem::Version.new(v) } # pick latest version
  else
    reason = "RSMP versions [#{message.versions.join(', ')}] requested, " \
             "but only [#{versions.join(', ')}] supported."
    dont_acknowledge message, 'Version message rejected', reason, force: true
    raise HandshakeError, reason
  end
end

#core_versionsObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/rsmp/proxy/modules/versions.rb', line 7

def core_versions
  version = @site_settings['core_version']
  if version == 'latest'
    [RSMP::Schema.latest_core_version]
  elsif version
    [version]
  else
    RSMP::Schema.core_versions
  end
end

#extraneous_version(message) ⇒ Object



34
35
36
# File 'lib/rsmp/proxy/modules/versions.rb', line 34

def extraneous_version(message)
  dont_acknowledge message, 'Received', 'extraneous Version message'
end

#process_version(message) ⇒ Object



32
# File 'lib/rsmp/proxy/modules/versions.rb', line 32

def process_version(message); end

#send_version(site_id, core_versions) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rsmp/proxy/modules/versions.rb', line 38

def send_version(site_id, core_versions)
  versions = if core_versions == 'latest'
               [RSMP::Schema.latest_core_version]
             elsif core_versions == 'all'
               RSMP::Schema.core_versions
             else
               [core_versions].flatten
             end
  versions_array = versions.map { |v| { 'vers' => v } }

  site_id_array = [site_id].flatten.map { |id| { 'sId' => id } }

  version_response = Version.new({
                                   'RSMP' => versions_array,
                                   'siteId' => site_id_array,
                                   'SXL' => sxl_version.to_s
                                 })
  send_message version_response
end

#version_acknowledgedObject



58
# File 'lib/rsmp/proxy/modules/versions.rb', line 58

def version_acknowledged; end