MEChat 1.2.5.pre.pause → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf2ec999b660eded80cb27be27389b5f5ed3cdbbb9413c794e349bfe743d6ec4
4
- data.tar.gz: 9c33f89aabb6acc8e801c833947c4c4cc917990a98fb63d9ce077e861f473fcf
3
+ metadata.gz: 7b0b0a773c231d57e3171ecf0470e072ff4f73822843033d6be17e3aa6964f8b
4
+ data.tar.gz: a85c124600569228418a949b486bf7eaf43d3aa4601f70e07ce3edace33b4c32
5
5
  SHA512:
6
- metadata.gz: 90018a9598629f8e7af04f2a874a715ef9fa4bd38e93194683edd7cd7f57fc6829384aefec9b260b4a7f093542067dd1e0b3056960a61c4152cfb01fbf8affc8
7
- data.tar.gz: 279a0a25e925d743405863dcbf68e392a579d469e2bb6d28b85a55a90dc66140ce7985c13fc3af08014779bf91df954c3a177aa054a780d304fdd3e4a53bc7be
6
+ metadata.gz: 88b6ba28024f7cdce8498be9de5cbff2f49f070a65f98ec5300860aa4bb063efdb35db2c0087416fe9315bdfdc4cde0616a41645351685dd3c35fbc5743ee9f9
7
+ data.tar.gz: e42a3ad6645f6bd32c24c44d63d76f414e6e02cdc353e3e0a06e354894c12e405c2e15484ff559e4994ee088860980ffa0e46f5e477bb8b67fc782e57b74bb5b
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,22 +68,33 @@ class Client
68
68
  def run
69
69
  new_msg = gets.chomp
70
70
  while new_msg != "exit"
71
- $crit_section = 1
72
- request_critical_section
73
- while $alg.replies.length < $nodes.length
74
- sleep 0.1
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
- gets
78
88
  $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
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
87
95
  end
96
+ @logger.info "Disconnected from network"
97
+ puts "Disconnected from network"
98
+ $finished = true
88
99
  end
89
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\x9e\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\x42\t\xaa\x02\x06MEChatb\x06proto3"
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
 
@@ -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.2.5.pre.pause
4
+ version: 1.5.0
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: 1.3.1
145
+ version: '0'
146
146
  requirements: []
147
147
  rubygems_version: 3.4.10
148
148
  signing_key: