net-ntp 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bbc7ec55a142eb7a087a849c5ad9c0c918f864c
4
+ data.tar.gz: 42cbee4bfc9aa3e62d4306982d29f782639d53f1
5
+ SHA512:
6
+ metadata.gz: a6c4fda6c182d1dfa46a26b95a61cb5a68aab34ae634ed1fe2bb1e5ec56e5afe05f37827e07c56076f6cfd7ef4c7e340e231c522964347b5ae9dbf9651c7bdb9
7
+ data.tar.gz: 1afe43476aae8eb8336ef31c55a9b4ae0f4c91a06cd1f2098c63d0f98936a27597284f2740a9cc77322438d7442bca25cb7c6174371565f2536455371a8c6e52
@@ -67,8 +67,7 @@ module Net #:nodoc:
67
67
  sock = UDPSocket.new
68
68
  sock.connect(host, port)
69
69
 
70
- client_time_send = Time.new.to_i
71
- client_localtime = client_time_send
70
+ client_localtime = Time.now.to_f
72
71
  client_adj_localtime = client_localtime + NTP_ADJ
73
72
  client_frac_localtime = frac2bin(client_adj_localtime)
74
73
 
@@ -77,12 +76,16 @@ module Net #:nodoc:
77
76
  sock.print ntp_msg
78
77
  sock.flush
79
78
 
80
- data = nil
81
- Timeout::timeout(timeout) do |t|
82
- data = sock.recvfrom(960)[0]
79
+ read, write, error = IO.select [sock], nil, nil, timeout
80
+ if read[0]
81
+ client_time_receive = Time.now.to_f
82
+ data, _ = sock.recvfrom(960)
83
+ Response.new(data, client_time_receive)
84
+ else
85
+ # For backwards compatibility we throw a Timeout error, even
86
+ # though the timeout is being controlled by select()
87
+ raise Timeout::Error
83
88
  end
84
-
85
- Response.new(data)
86
89
  end
87
90
 
88
91
  def self.frac2bin(frac) #:nodoc:
@@ -98,14 +101,17 @@ module Net #:nodoc:
98
101
  private_class_method :frac2bin
99
102
 
100
103
  class Response
101
- def initialize(raw_data)
104
+
105
+ attr_reader :client_time_receive
106
+
107
+ def initialize(raw_data, client_time_receive)
102
108
  @raw_data = raw_data
103
- @client_time_receive = Time.new.to_i
109
+ @client_time_receive = client_time_receive
104
110
  @packet_data_by_field = nil
105
111
  end
106
112
 
107
113
  def leap_indicator
108
- @leap_indicator ||= (packet_data_by_field[:byte1][0] & 0xC0) >> 6
114
+ @leap_indicator ||= (packet_data_by_field[:byte1].bytes.first & 0xC0) >> 6
109
115
  end
110
116
 
111
117
  def leap_indicator_text
@@ -113,11 +119,11 @@ module Net #:nodoc:
113
119
  end
114
120
 
115
121
  def version_number
116
- @version_number ||= (packet_data_by_field[:byte1][0] & 0x38) >> 3
122
+ @version_number ||= (packet_data_by_field[:byte1].bytes.first & 0x38) >> 3
117
123
  end
118
124
 
119
125
  def mode
120
- @mode ||= (packet_data_by_field[:byte1][0] & 0x07)
126
+ @mode ||= (packet_data_by_field[:byte1].bytes.first & 0x07)
121
127
  end
122
128
 
123
129
  def mode_text
@@ -176,12 +182,16 @@ module Net #:nodoc:
176
182
  @time ||= Time.at(receive_timestamp)
177
183
  end
178
184
 
185
+ # As described in http://tools.ietf.org/html/rfc958
186
+ def offset
187
+ @offset ||= (receive_timestamp - originate_timestamp + transmit_timestamp - client_time_receive) / 2.0
188
+ end
179
189
 
180
190
  protected
181
191
 
182
192
  def packet_data_by_field #:nodoc:
183
193
  if !@packet_data_by_field
184
- @packetdata = @raw_data.unpack("a C3 n B16 n B16 H8 N B32 N B32 N B32 N B32");
194
+ @packetdata = @raw_data.unpack("a C3 n B16 n B16 H8 N B32 N B32 N B32 N B32")
185
195
  @packet_data_by_field = {}
186
196
  NTP_FIELDS.each do |field|
187
197
  @packet_data_by_field[field] = @packetdata.shift
@@ -203,7 +213,7 @@ module Net #:nodoc:
203
213
 
204
214
  def unpack_ip(stratum, tmp_ip) #:nodoc:
205
215
  if stratum < 2
206
- [tmp_ip].pack("H8").unpack("A4")[0]
216
+ [tmp_ip].pack("H8").unpack("A4").bytes.first
207
217
  else
208
218
  ipbytes = [tmp_ip].pack("H8").unpack("C4")
209
219
  sprintf("%d.%d.%d.%d", ipbytes[0], ipbytes[1], ipbytes[2], ipbytes[3])
@@ -1,5 +1,5 @@
1
1
  module Net
2
2
  module NTP
3
- VERSION = '2.1.1'
3
+ VERSION = '2.1.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,74 +1,54 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: net-ntp
3
- version: !ruby/object:Gem::Version
4
- hash: 9
5
- prerelease:
6
- segments:
7
- - 2
8
- - 1
9
- - 1
10
- version: 2.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.2
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Jerome Waibel
14
8
  - Nathan Sutton
15
9
  - Brandon Arbini
16
10
  autorequire:
17
11
  bindir: bin
18
12
  cert_chain: []
19
-
20
- date: 2012-04-23 00:00:00 Z
13
+ date: 2014-04-19 00:00:00.000000000 Z
21
14
  dependencies: []
22
-
23
- description: This project was a rubyfied version of perl's Net::NTP module, (C) 2004 by James G. Willmore. It provides a method to query an NTP server as specified in RFC1305 and RFC2030. Updated and re-released in 2010 by Zencoder.
24
- email:
15
+ description: This project was a rubyfied version of perl's Net::NTP module, (C) 2004
16
+ by James G. Willmore. It provides a method to query an NTP server as specified in
17
+ RFC1305 and RFC2030. Updated and re-released in 2010 by Zencoder.
18
+ email:
25
19
  - nate@zencoder.com
26
20
  - brandon@zencoder.com
27
21
  executables: []
28
-
29
22
  extensions: []
30
-
31
23
  extra_rdoc_files: []
32
-
33
- files:
34
- - lib/net/ntp/ntp.rb
35
- - lib/net/ntp/version.rb
36
- - lib/net/ntp.rb
24
+ files:
37
25
  - LICENSE
38
26
  - README.markdown
39
27
  - Rakefile
28
+ - lib/net/ntp.rb
29
+ - lib/net/ntp/ntp.rb
30
+ - lib/net/ntp/version.rb
40
31
  homepage: http://github.com/zencoder/net-ntp
41
32
  licenses: []
42
-
33
+ metadata: {}
43
34
  post_install_message:
44
35
  rdoc_options: []
45
-
46
- require_paths:
36
+ require_paths:
47
37
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
51
40
  - - ">="
52
- - !ruby/object:Gem::Version
53
- hash: 3
54
- segments:
55
- - 0
56
- version: "0"
57
- required_rubygems_version: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
60
45
  - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
- version: "0"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
66
48
  requirements: []
67
-
68
49
  rubyforge_project:
69
- rubygems_version: 1.8.17
50
+ rubygems_version: 2.2.2
70
51
  signing_key:
71
- specification_version: 3
52
+ specification_version: 4
72
53
  summary: NTP client for ruby.
73
54
  test_files: []
74
-