MEChat 1.5.0.pause → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Chat.rb +23 -0
- data/client.rb +7 -2
- data/lib/MEChat_pb.rb +2 -1
- data/lib/MEChat_services_pb.rb +2 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d426f918814c8eb2cc7af86875db57cbad6f157e777d010fc97b356691fa06f
|
4
|
+
data.tar.gz: 64fc48ba5502998be586249b1406db537bf517e306cd7204cb2982f1d2dfc011
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43225895cd00f342aa8aff09802ae836713dd456b0957025ee124f745bfb18c96fa7b75d2ec4d47c7c27971fab1e97735f669f0331fe7df17079795cca76718e
|
7
|
+
data.tar.gz: c5883d554e758f17c3b97cbd158acd2dd39555a1e5e86d14d2d194b88f43558ee6b6df6112905c002ea702127506a7e1bf482287b9b474f23e35c5bd92314f21
|
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
|
@@ -74,7 +80,6 @@ class Client
|
|
74
80
|
sleep 0.1
|
75
81
|
end
|
76
82
|
$crit_section = 2
|
77
|
-
gets
|
78
83
|
$nodes.each do |node|
|
79
84
|
chat = DistributedChat::ChatService::Stub.new("#{node.address}:#{node.port}", :this_channel_is_insecure)
|
80
85
|
chat.send_message(DistributedChat::Request.new(username: "#{@ip.ip_address}:#{$port.to_s}", message: new_msg, timestamp: $alg.clock))
|
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\
|
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
|
data/lib/MEChat_services_pb.rb
CHANGED
@@ -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.
|
4
|
+
version: 1.6.0
|
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-
|
11
|
+
date: 2024-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|
@@ -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: '0'
|
146
146
|
requirements: []
|
147
147
|
rubygems_version: 3.4.10
|
148
148
|
signing_key:
|