apiotics 0.1.87 → 0.1.91
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apiotics.rb +1 -0
- data/lib/apiotics/configuration.rb +3 -1
- data/lib/apiotics/connection_error.rb +9 -0
- data/lib/apiotics/server.rb +41 -7
- data/lib/apiotics/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b31ad466b84f50973745b403b4ac5ddec4ed902b
|
4
|
+
data.tar.gz: b73a87608753aa15394f2e4b0e9cf780628f7163
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d87a3c583ef9038958d6b8505f947ee86a7e649f7933ec35be4f245f15dd10829ba3085899eb3845111ed73d35ba6bbcd9eb5cb57f1ec37ae56191957ed5c4d
|
7
|
+
data.tar.gz: a39ec503fa05723a6969ea3e85abdcd1c8376e740373094c02080545477e90303e89e6e134b698e115f4ab41b3077e414f739e8b475bf7b074463e0764484670
|
data/lib/apiotics.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Apiotics
|
2
2
|
class Configuration
|
3
3
|
|
4
|
-
attr_accessor :public_key, :private_key, :local_logging, :targets, :local_port, :server, :server_port, :portal, :push, :tls, :verify_peer, :handshake, :parents, :reduced_metadata, :redis_comms_connection, :interface_kinds
|
4
|
+
attr_accessor :public_key, :private_key, :local_logging, :targets, :local_port, :server, :server_port, :portal, :push, :tls, :verify_peer, :handshake, :parents, :reduced_metadata, :redis_comms_connection, :interface_kinds, :max_missed_heartbeats, :heartbeat_interval
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@public_key = nil
|
@@ -19,6 +19,8 @@ module Apiotics
|
|
19
19
|
@parents = {}
|
20
20
|
@reduced_metadata = false
|
21
21
|
@redis_comms_connection = false
|
22
|
+
@max_missed_heartbeats = 3
|
23
|
+
@heartbeat_interval = 5
|
22
24
|
@interface_kinds = {
|
23
25
|
"string" => "string",
|
24
26
|
"text" => "string",
|
data/lib/apiotics/server.rb
CHANGED
@@ -70,6 +70,15 @@ module Apiotics
|
|
70
70
|
@localport = Apiotics.configuration.local_port
|
71
71
|
listen_remote
|
72
72
|
listen_local
|
73
|
+
@heartbeat_state = Hash.new
|
74
|
+
heartbeat = {
|
75
|
+
"action" => "set-request",
|
76
|
+
"instance" => "0000000000000000000000000000000000000000000000000000000000000000",
|
77
|
+
"driver" => "Core::Heartbeat",
|
78
|
+
"interface" => nil
|
79
|
+
}
|
80
|
+
send_heartbeat(heartbeat)
|
81
|
+
# need to write a loop that throws an error if the heartbeat is not received back.
|
73
82
|
end
|
74
83
|
|
75
84
|
def send(msg)
|
@@ -88,17 +97,22 @@ module Apiotics
|
|
88
97
|
msg = @server.gets
|
89
98
|
puts msg
|
90
99
|
msg_hash = Apiotics::Parse.message(msg)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
if r.
|
95
|
-
r.
|
96
|
-
|
97
|
-
|
100
|
+
unless msg_hash["driver"] == "Core::Heartbeat"
|
101
|
+
r = Apiotics::Insert.new(msg_hash)
|
102
|
+
puts "Message received": msg_hash
|
103
|
+
if r.valid == true
|
104
|
+
if r.action == "set-request-ack" || r.action == "set-complete" || r.action == "get-ack"
|
105
|
+
r.save
|
106
|
+
unless Apiotics.configuration.local_logging == false
|
107
|
+
r.save_log
|
108
|
+
end
|
98
109
|
end
|
99
110
|
end
|
111
|
+
else
|
112
|
+
monitor_heartbeat(msg_hash)
|
100
113
|
end
|
101
114
|
end
|
115
|
+
ActiveRecord::Base.connection.close
|
102
116
|
end
|
103
117
|
rescue => e
|
104
118
|
puts e
|
@@ -147,6 +161,26 @@ module Apiotics
|
|
147
161
|
end
|
148
162
|
end
|
149
163
|
|
164
|
+
def send_heartbeat(heartbeat)
|
165
|
+
loop do
|
166
|
+
heartbeat["interface"] = DateTime.now.to_i
|
167
|
+
self.send(heartbeat)
|
168
|
+
self.monitor_heartbeat(heartbeat)
|
169
|
+
sleep Apiotics.configuration.heartbeat_interval
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def monitor_heartbeat(heartbeat)
|
174
|
+
if heartbeat["action"] = "set-request"
|
175
|
+
@heartbeat_state[heartbeat["interface"]] = heartbeat
|
176
|
+
elsif heartbeat["action"] = "set-request-ack"
|
177
|
+
@heartbeat_state.delete(heartbeat["interface"])
|
178
|
+
end
|
179
|
+
if @heartbeat_state.length > Apiotics.configuration.max_missed_heartbeats
|
180
|
+
raise Apiotics::ConnectionError
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
150
184
|
def self.lookup
|
151
185
|
if Apiotics.configuration.tls == true
|
152
186
|
socket = TCPSocket.new(Apiotics.configuration.server, Apiotics.configuration.server_port)
|
data/lib/apiotics/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiotics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.91
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MicroArx Corporation
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- lib/apiotics.rb
|
163
163
|
- lib/apiotics/client.rb
|
164
164
|
- lib/apiotics/configuration.rb
|
165
|
+
- lib/apiotics/connection_error.rb
|
165
166
|
- lib/apiotics/extract.rb
|
166
167
|
- lib/apiotics/hardware.rb
|
167
168
|
- lib/apiotics/insert.rb
|