MEChat 1.2.5 → 1.5.0.pause
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Chat.rb +1 -1
- data/NodeDiscovery.rb +7 -0
- data/client.rb +25 -13
- data/lib/MEChat_pb.rb +1 -1
- data/lib/MEChat_services_pb.rb +1 -0
- data/main.rb +10 -1
- data/server.rb +1 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb92a5a7a909982b07131e2732e219b042a801759a2f9948f7f747699c2f6107
|
4
|
+
data.tar.gz: ae15bf6b528f057b9624bb73dc3ac58265d876d2a7cd94718a2e3f316841bd14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f6990020fd7846d1d6bcc2a981412bf514aa2b3599f4d070c8608ad671c8732c3f4f2ffc24edd053ffa3ce20236068779fbf55fa47b1f5583a573d3ed966b44
|
7
|
+
data.tar.gz: 3434d8fc144f53cd2081aff12dc6875510fc5d41b5b1df78f6c1b086b676569b37b4b79b7a5ac39a30772163b79a7ebcfdda9eb660cb42695ef3a92984190afd
|
data/Chat.rb
CHANGED
@@ -36,7 +36,7 @@ class Chat < DistributedChat::ChatService::Service
|
|
36
36
|
def request_critical_section(req,_call)
|
37
37
|
request = {:ip => Addrinfo.getaddrinfo(req.username.split(":")[0..-2].join(":"),req.username.split(":")[-1].to_i)[0], :message => req}
|
38
38
|
if $crit_section === 0
|
39
|
-
@logger.info "Sent reply to #{request[:ip].ip_address}:#{request[:ip].ip_port}, because I am not in critical section
|
39
|
+
@logger.info "Sent reply to #{request[:ip].ip_address}:#{request[:ip].ip_port}, because I am not in critical section"
|
40
40
|
send_reply ip: request[:ip]
|
41
41
|
elsif $crit_section < 2 && request[:message].timestamp < $alg.clock
|
42
42
|
@logger.info "Sent reply to #{request[:ip].ip_address}:#{request[:ip].ip_port}, because I am entering critical section but my request is newer"
|
data/NodeDiscovery.rb
CHANGED
@@ -61,6 +61,13 @@ class NodeDiscoveryImpl < DistributedChat::NodeDiscovery::Service
|
|
61
61
|
NodeInfoEnum.new($nodes).each
|
62
62
|
end
|
63
63
|
|
64
|
+
def deregister_node(node_info, _call)
|
65
|
+
$nodes.reject! { |x| x.address === node_info.address && x.port === node_info.port }
|
66
|
+
@logger.info "Deregistered node with ip:" + node_info.address + ":" + node_info.port.to_s
|
67
|
+
puts node_info.address + ":" + node_info.port.to_s + " left network"
|
68
|
+
DistributedChat::Response.new status_code: 0
|
69
|
+
end
|
70
|
+
|
64
71
|
def get_nodes_local
|
65
72
|
$nodes
|
66
73
|
end
|
data/client.rb
CHANGED
@@ -68,21 +68,33 @@ class Client
|
|
68
68
|
def run
|
69
69
|
new_msg = gets.chomp
|
70
70
|
while new_msg != "exit"
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
$crit_section = 1
|
72
|
+
request_critical_section
|
73
|
+
while $alg.replies.length < $nodes.length
|
74
|
+
sleep 0.1
|
75
|
+
end
|
76
|
+
$crit_section = 2
|
77
|
+
gets
|
78
|
+
$nodes.each do |node|
|
79
|
+
chat = DistributedChat::ChatService::Stub.new("#{node.address}:#{node.port}", :this_channel_is_insecure)
|
80
|
+
chat.send_message(DistributedChat::Request.new(username: "#{@ip.ip_address}:#{$port.to_s}", message: new_msg, timestamp: $alg.clock))
|
81
|
+
@logger.info "Sent message \"#{new_msg}\" to #{node.address}:#{node.port}"
|
82
|
+
end
|
83
|
+
$messages.push DistributedChat::Request.new(username: "#{@ip.ip_address}:#{$port.to_s}", message: new_msg, timestamp: $alg.clock)
|
84
|
+
release_critical_section
|
85
|
+
$crit_section = 0
|
86
|
+
new_msg = gets.chomp
|
75
87
|
end
|
76
|
-
$crit_section = 2
|
77
88
|
$nodes.each do |node|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
$crit_section = 0
|
85
|
-
new_msg = gets.chomp
|
89
|
+
begin
|
90
|
+
nodediscovery = DistributedChat::NodeDiscovery::Stub.new("#{node.address}:#{node.port}", :this_channel_is_insecure)
|
91
|
+
nodediscovery.deregister_node(DistributedChat::NodeInfo.new(address: @ip.ip_address, port: $port))
|
92
|
+
rescue GRPC::Unavailable
|
93
|
+
|
94
|
+
end
|
86
95
|
end
|
96
|
+
@logger.info "Disconnected from network"
|
97
|
+
puts "Disconnected from network"
|
98
|
+
$finished = true
|
87
99
|
end
|
88
100
|
end
|
data/lib/MEChat_pb.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
require 'google/protobuf'
|
6
6
|
|
7
7
|
|
8
|
-
descriptor_data = "\n\x0cMEChat.proto\x12\x10\x64istributed_chat\"?\n\x07Request\x12\x10\n\x08username\x18\x01 \x01(\t\x12\x0f\n\x07message\x18\x02 \x01(\t\x12\x11\n\ttimestamp\x18\x03 \x01(\x05\"\x1f\n\x08Response\x12\x13\n\x0bstatus_code\x18\x01 \x01(\x05\"O\n\x08NodeInfo\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\x12\x0c\n\x04port\x18\x02 \x01(\x05\x12\x16\n\ttimestamp\x18\x03 \x01(\x05H\x00\x88\x01\x01\x42\x0c\n\n_timestamp2\xf5\x01\n\x0b\x43hatService\x12\x44\n\x0bSendMessage\x12\x19.distributed_chat.Request\x1a\x1a.distributed_chat.Response\x12O\n\x16RequestCriticalSection\x12\x19.distributed_chat.Request\x1a\x1a.distributed_chat.Response\x12O\n\x16ReleaseCriticalSection\x12\x19.distributed_chat.Request\x1a\x1a.distributed_chat.Response2\
|
8
|
+
descriptor_data = "\n\x0cMEChat.proto\x12\x10\x64istributed_chat\"?\n\x07Request\x12\x10\n\x08username\x18\x01 \x01(\t\x12\x0f\n\x07message\x18\x02 \x01(\t\x12\x11\n\ttimestamp\x18\x03 \x01(\x05\"\x1f\n\x08Response\x12\x13\n\x0bstatus_code\x18\x01 \x01(\x05\"O\n\x08NodeInfo\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\x12\x0c\n\x04port\x18\x02 \x01(\x05\x12\x16\n\ttimestamp\x18\x03 \x01(\x05H\x00\x88\x01\x01\x42\x0c\n\n_timestamp2\xf5\x01\n\x0b\x43hatService\x12\x44\n\x0bSendMessage\x12\x19.distributed_chat.Request\x1a\x1a.distributed_chat.Response\x12O\n\x16RequestCriticalSection\x12\x19.distributed_chat.Request\x1a\x1a.distributed_chat.Response\x12O\n\x16ReleaseCriticalSection\x12\x19.distributed_chat.Request\x1a\x1a.distributed_chat.Response2\xe8\x01\n\rNodeDiscovery\x12H\n\x0cRegisterNode\x12\x1a.distributed_chat.NodeInfo\x1a\x1a.distributed_chat.NodeInfo0\x01\x12\x43\n\x08GetNodes\x12\x19.distributed_chat.Request\x1a\x1a.distributed_chat.NodeInfo0\x01\x12H\n\x0e\x44\x65registerNode\x12\x1a.distributed_chat.NodeInfo\x1a\x1a.distributed_chat.ResponseB\t\xaa\x02\x06MEChatb\x06proto3"
|
9
9
|
|
10
10
|
pool = Google::Protobuf::DescriptorPool.generated_pool
|
11
11
|
|
data/lib/MEChat_services_pb.rb
CHANGED
@@ -36,6 +36,7 @@ module DistributedChat
|
|
36
36
|
|
37
37
|
rpc :RegisterNode, ::DistributedChat::NodeInfo, stream(::DistributedChat::NodeInfo)
|
38
38
|
rpc :GetNodes, ::DistributedChat::Request, stream(::DistributedChat::NodeInfo)
|
39
|
+
rpc :DeregisterNode, ::DistributedChat::NodeInfo, ::DistributedChat::Response
|
39
40
|
end
|
40
41
|
|
41
42
|
Stub = Service.rpc_stub_class
|
data/main.rb
CHANGED
@@ -15,6 +15,7 @@ $nodes = []
|
|
15
15
|
$messages = []
|
16
16
|
$crit_section = 0
|
17
17
|
$alg = RicartAgrawala.new
|
18
|
+
$finished = false
|
18
19
|
|
19
20
|
class Main
|
20
21
|
|
@@ -53,6 +54,14 @@ class Main
|
|
53
54
|
end
|
54
55
|
server.join
|
55
56
|
client.join
|
57
|
+
checker = Thread.new do
|
58
|
+
until $finished
|
59
|
+
sleep 1
|
60
|
+
end
|
61
|
+
puts "Shutting down"
|
62
|
+
client.kill
|
63
|
+
server.kill
|
64
|
+
end
|
65
|
+
checker.join
|
56
66
|
end
|
57
|
-
|
58
67
|
end
|
data/server.rb
CHANGED
@@ -26,9 +26,7 @@ class Server
|
|
26
26
|
server.handle(chat)
|
27
27
|
puts "Server side running on " + $port.to_s
|
28
28
|
|
29
|
-
server.run_till_terminated_or_interrupted(['int', 'SIGTERM'])
|
29
|
+
server.run_till_terminated_or_interrupted(['int', 'SIGTERM', 'TERM', 'SIGINT'])
|
30
30
|
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
34
|
-
# Server.new.run
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: MEChat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0.pause
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Kaufmann
|
@@ -140,9 +140,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - ">"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 1.3.1
|
146
146
|
requirements: []
|
147
147
|
rubygems_version: 3.4.10
|
148
148
|
signing_key:
|