MEChat 1.5.0.pause → 1.6.0.pause

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: cb92a5a7a909982b07131e2732e219b042a801759a2f9948f7f747699c2f6107
4
- data.tar.gz: ae15bf6b528f057b9624bb73dc3ac58265d876d2a7cd94718a2e3f316841bd14
3
+ metadata.gz: 71e92ad15261f15b1f4d74e8ab720f0d399c57abd3a94bcc6643e4b32bab2578
4
+ data.tar.gz: 62716c4cc5f1bd8f1ae0edcbf9edfe3f1e0f3991bf452ba2e44ff6471d5a12fb
5
5
  SHA512:
6
- metadata.gz: 2f6990020fd7846d1d6bcc2a981412bf514aa2b3599f4d070c8608ad671c8732c3f4f2ffc24edd053ffa3ce20236068779fbf55fa47b1f5583a573d3ed966b44
7
- data.tar.gz: 3434d8fc144f53cd2081aff12dc6875510fc5d41b5b1df78f6c1b086b676569b37b4b79b7a5ac39a30772163b79a7ebcfdda9eb660cb42695ef3a92984190afd
6
+ metadata.gz: 588731e2988ca901578acd960b64c7df3e40e4549ce70c9d89db2f21b59bf138786a93323a3bfe524bc91df2f176f916b25a8cfdfff57932c560288bec345eda
7
+ data.tar.gz: eed9ab10ed384570471f6f157521dcc1cb5b810c6df5e237ef599b3d6ed5b02c62258330166b7b96b710396363b664b0e8c3c6cb13c89f6c2a68b6370d143a9c
data/Chat.rb CHANGED
@@ -8,6 +8,25 @@ this_dir = File.expand_path(File.dirname(__FILE__))
8
8
  lib_dir = File.join(this_dir, 'lib')
9
9
  $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
10
10
 
11
+ class MessagesEnum
12
+ def initialize(messages)
13
+ @messages = messages
14
+ end
15
+
16
+ def each
17
+ if block_given?
18
+ @messages.each do |msg|
19
+ yield DistributedChat::Request.new(
20
+ username: msg.username,
21
+ message: msg.message,
22
+ timestamp: msg.timestamp
23
+ )
24
+ end
25
+ else
26
+ enum_for(:each)
27
+ end
28
+ end
29
+ end
11
30
  class Chat < DistributedChat::ChatService::Service
12
31
 
13
32
  def initialize ip,port,node_service
@@ -61,4 +80,8 @@ class Chat < DistributedChat::ChatService::Service
61
80
  $alg.clock = [req.timestamp,$alg.clock].max + 1
62
81
  DistributedChat::Response.new status_code: 0
63
82
  end
83
+
84
+ def get_messages(req,_call)
85
+ MessagesEnum.new($messages).each
86
+ end
64
87
  end
data/client.rb CHANGED
@@ -21,7 +21,13 @@ class Client
21
21
  nodediscovery.register_node(DistributedChat::NodeInfo.new(address: @ip.ip_address, port: $port)).each do |node|
22
22
  $nodes.push node
23
23
  end
24
-
24
+ chat = DistributedChat::ChatService::Stub.new("#{ip.ip_address}:#{ip.ip_port}", :this_channel_is_insecure)
25
+ chat.get_messages(DistributedChat::Empty.new).each do |msg|
26
+ $messages << msg
27
+ end
28
+ $messages.each do |msg|
29
+ puts "#{msg.username}: #{msg.message}"
30
+ end
25
31
  end
26
32
 
27
33
  private def request_critical_section
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\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"
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\"\x07\n\x05\x45mpty\"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\xba\x02\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.Response\x12\x43\n\x0bGetMessages\x12\x17.distributed_chat.Empty\x1a\x19.distributed_chat.Request0\x01\x32\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
 
@@ -34,5 +34,6 @@ end
34
34
  module DistributedChat
35
35
  Request = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("distributed_chat.Request").msgclass
36
36
  Response = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("distributed_chat.Response").msgclass
37
+ Empty = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("distributed_chat.Empty").msgclass
37
38
  NodeInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("distributed_chat.NodeInfo").msgclass
38
39
  end
@@ -20,6 +20,8 @@ module DistributedChat
20
20
  rpc :RequestCriticalSection, ::DistributedChat::Request, ::DistributedChat::Response
21
21
  # Method to release access to the critical section
22
22
  rpc :ReleaseCriticalSection, ::DistributedChat::Request, ::DistributedChat::Response
23
+ # Method to request the current chat log
24
+ rpc :GetMessages, ::DistributedChat::Empty, stream(::DistributedChat::Request)
23
25
  end
24
26
 
25
27
  Stub = Service.rpc_stub_class
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MEChat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0.pause
4
+ version: 1.6.0.pause
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Kaufmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-09 00:00:00.000000000 Z
11
+ date: 2024-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc