MEChat 1.2.5 → 1.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 970e7269319bf1254409794849e9a886384b0ac615c58732413cfb0fbaffdb26
4
- data.tar.gz: 6fbe3b25ef02df8ddd82a5d3de0c49eba494468212d6bffdeb33f3c3e2288575
3
+ metadata.gz: 7b0b0a773c231d57e3171ecf0470e072ff4f73822843033d6be17e3aa6964f8b
4
+ data.tar.gz: a85c124600569228418a949b486bf7eaf43d3aa4601f70e07ce3edace33b4c32
5
5
  SHA512:
6
- metadata.gz: ffedf600eedfa4bed9334fbafae153135bc288869f1b349598c704c9ca8f166d3992e2581fa8184a5f3280ab5a114114e9fecbafbc74409ac34a7ee2cd1f339e
7
- data.tar.gz: 1c596f8b598b325f42afbecf91528d3dcfe9779398722c09e38242c9d44a4c9391fd36e05d1989e241917aac66059e403a77a50bb2c80269433864efef0fb9ea
6
+ metadata.gz: 88b6ba28024f7cdce8498be9de5cbff2f49f070a65f98ec5300860aa4bb063efdb35db2c0087416fe9315bdfdc4cde0616a41645351685dd3c35fbc5743ee9f9
7
+ data.tar.gz: e42a3ad6645f6bd32c24c44d63d76f414e6e02cdc353e3e0a06e354894c12e405c2e15484ff559e4994ee088860980ffa0e46f5e477bb8b67fc782e57b74bb5b
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 | #{_call}"
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
- $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
88
  $nodes.each do |node|
78
- chat = DistributedChat::ChatService::Stub.new("#{node.address}:#{node.port}", :this_channel_is_insecure)
79
- chat.send_message(DistributedChat::Request.new(username: "#{@ip.ip_address}:#{$port.to_s}", message: new_msg, timestamp: $alg.clock))
80
- @logger.info "Sent message \"#{new_msg}\" to #{node.address}:#{node.port}"
81
- end
82
- $messages.push DistributedChat::Request.new(username: "#{@ip.ip_address}:#{$port.to_s}", message: new_msg, timestamp: $alg.clock)
83
- release_critical_section
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\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
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Kaufmann