itsi 0.1.14 → 0.1.18
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 +4 -4
- data/Cargo.lock +124 -109
- data/Cargo.toml +6 -0
- data/crates/itsi_error/Cargo.toml +1 -0
- data/crates/itsi_error/src/lib.rs +100 -10
- data/crates/itsi_scheduler/src/itsi_scheduler.rs +1 -1
- data/crates/itsi_server/Cargo.toml +8 -10
- data/crates/itsi_server/src/default_responses/html/401.html +68 -0
- data/crates/itsi_server/src/default_responses/html/403.html +68 -0
- data/crates/itsi_server/src/default_responses/html/404.html +68 -0
- data/crates/itsi_server/src/default_responses/html/413.html +71 -0
- data/crates/itsi_server/src/default_responses/html/429.html +68 -0
- data/crates/itsi_server/src/default_responses/html/500.html +71 -0
- data/crates/itsi_server/src/default_responses/html/502.html +71 -0
- data/crates/itsi_server/src/default_responses/html/503.html +68 -0
- data/crates/itsi_server/src/default_responses/html/504.html +69 -0
- data/crates/itsi_server/src/default_responses/html/index.html +238 -0
- data/crates/itsi_server/src/default_responses/json/401.json +6 -0
- data/crates/itsi_server/src/default_responses/json/403.json +6 -0
- data/crates/itsi_server/src/default_responses/json/404.json +6 -0
- data/crates/itsi_server/src/default_responses/json/413.json +6 -0
- data/crates/itsi_server/src/default_responses/json/429.json +6 -0
- data/crates/itsi_server/src/default_responses/json/500.json +6 -0
- data/crates/itsi_server/src/default_responses/json/502.json +6 -0
- data/crates/itsi_server/src/default_responses/json/503.json +6 -0
- data/crates/itsi_server/src/default_responses/json/504.json +6 -0
- data/crates/itsi_server/src/default_responses/mod.rs +11 -0
- data/crates/itsi_server/src/lib.rs +58 -26
- data/crates/itsi_server/src/prelude.rs +2 -0
- data/crates/itsi_server/src/ruby_types/README.md +21 -0
- data/crates/itsi_server/src/ruby_types/itsi_body_proxy/mod.rs +8 -6
- data/crates/itsi_server/src/ruby_types/itsi_grpc_call.rs +344 -0
- data/crates/itsi_server/src/ruby_types/{itsi_grpc_stream → itsi_grpc_response_stream}/mod.rs +121 -73
- data/crates/itsi_server/src/ruby_types/itsi_http_request.rs +103 -40
- data/crates/itsi_server/src/ruby_types/itsi_http_response.rs +8 -5
- data/crates/itsi_server/src/ruby_types/itsi_server/file_watcher.rs +4 -4
- data/crates/itsi_server/src/ruby_types/itsi_server/itsi_server_config.rs +37 -17
- data/crates/itsi_server/src/ruby_types/itsi_server.rs +4 -3
- data/crates/itsi_server/src/ruby_types/mod.rs +6 -13
- data/crates/itsi_server/src/server/{bind.rs → binds/bind.rs} +23 -4
- data/crates/itsi_server/src/server/{listener.rs → binds/listener.rs} +24 -10
- data/crates/itsi_server/src/server/binds/mod.rs +4 -0
- data/crates/itsi_server/src/server/{tls.rs → binds/tls.rs} +9 -4
- data/crates/itsi_server/src/server/http_message_types.rs +97 -0
- data/crates/itsi_server/src/server/io_stream.rs +2 -1
- data/crates/itsi_server/src/server/middleware_stack/middleware.rs +28 -16
- data/crates/itsi_server/src/server/middleware_stack/middlewares/allow_list.rs +17 -8
- data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_api_key.rs +47 -18
- data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_basic.rs +13 -9
- data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_jwt.rs +50 -29
- data/crates/itsi_server/src/server/middleware_stack/middlewares/cache_control.rs +5 -2
- data/crates/itsi_server/src/server/middleware_stack/middlewares/compression.rs +37 -48
- data/crates/itsi_server/src/server/middleware_stack/middlewares/cors.rs +25 -20
- data/crates/itsi_server/src/server/middleware_stack/middlewares/deny_list.rs +14 -7
- data/crates/itsi_server/src/server/middleware_stack/middlewares/error_response/default_responses.rs +190 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/error_response.rs +125 -95
- data/crates/itsi_server/src/server/middleware_stack/middlewares/etag.rs +9 -5
- data/crates/itsi_server/src/server/middleware_stack/middlewares/header_interpretation.rs +1 -4
- data/crates/itsi_server/src/server/middleware_stack/middlewares/intrusion_protection.rs +25 -19
- data/crates/itsi_server/src/server/middleware_stack/middlewares/log_requests.rs +4 -4
- data/crates/itsi_server/src/server/middleware_stack/middlewares/max_body.rs +47 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/mod.rs +9 -4
- data/crates/itsi_server/src/server/middleware_stack/middlewares/proxy.rs +260 -62
- data/crates/itsi_server/src/server/middleware_stack/middlewares/rate_limit.rs +29 -22
- data/crates/itsi_server/src/server/middleware_stack/middlewares/redirect.rs +6 -6
- data/crates/itsi_server/src/server/middleware_stack/middlewares/request_headers.rs +6 -5
- data/crates/itsi_server/src/server/middleware_stack/middlewares/response_headers.rs +4 -2
- data/crates/itsi_server/src/server/middleware_stack/middlewares/ruby_app.rs +51 -18
- data/crates/itsi_server/src/server/middleware_stack/middlewares/static_assets.rs +31 -13
- data/crates/itsi_server/src/server/middleware_stack/middlewares/static_response.rs +55 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/string_rewrite.rs +13 -8
- data/crates/itsi_server/src/server/middleware_stack/mod.rs +101 -69
- data/crates/itsi_server/src/server/mod.rs +3 -9
- data/crates/itsi_server/src/server/process_worker.rs +21 -3
- data/crates/itsi_server/src/server/request_job.rs +2 -2
- data/crates/itsi_server/src/server/serve_strategy/cluster_mode.rs +8 -3
- data/crates/itsi_server/src/server/serve_strategy/single_mode.rs +26 -26
- data/crates/itsi_server/src/server/signal.rs +24 -41
- data/crates/itsi_server/src/server/size_limited_incoming.rs +101 -0
- data/crates/itsi_server/src/server/thread_worker.rs +59 -28
- data/crates/itsi_server/src/services/itsi_http_service.rs +239 -0
- data/crates/itsi_server/src/services/mime_types.rs +1416 -0
- data/crates/itsi_server/src/services/mod.rs +6 -0
- data/crates/itsi_server/src/services/password_hasher.rs +83 -0
- data/crates/itsi_server/src/{server → services}/rate_limiter.rs +35 -31
- data/crates/itsi_server/src/{server → services}/static_file_server.rs +521 -181
- data/crates/itsi_tracing/src/lib.rs +145 -55
- data/{Itsi.rb → foo/Itsi.rb} +6 -9
- data/gems/scheduler/Cargo.lock +7 -0
- data/gems/scheduler/lib/itsi/scheduler/version.rb +1 -1
- data/gems/scheduler/test/helpers/test_helper.rb +0 -1
- data/gems/scheduler/test/test_address_resolve.rb +0 -1
- data/gems/scheduler/test/test_network_io.rb +1 -1
- data/gems/scheduler/test/test_process_wait.rb +0 -1
- data/gems/server/Cargo.lock +124 -109
- data/gems/server/exe/itsi +65 -19
- data/gems/server/itsi-server.gemspec +4 -3
- data/gems/server/lib/itsi/http_request/response_status_shortcodes.rb +74 -0
- data/gems/server/lib/itsi/http_request.rb +116 -17
- data/gems/server/lib/itsi/http_response.rb +2 -0
- data/gems/server/lib/itsi/passfile.rb +109 -0
- data/gems/server/lib/itsi/server/config/dsl.rb +160 -101
- data/gems/server/lib/itsi/server/config.rb +58 -23
- data/gems/server/lib/itsi/server/default_app/default_app.rb +25 -29
- data/gems/server/lib/itsi/server/default_app/index.html +113 -89
- data/gems/server/lib/itsi/server/{Itsi.rb → default_config/Itsi-rackup.rb} +1 -1
- data/gems/server/lib/itsi/server/default_config/Itsi.rb +107 -0
- data/gems/server/lib/itsi/server/grpc/grpc_call.rb +246 -0
- data/gems/server/lib/itsi/server/grpc/grpc_interface.rb +100 -0
- data/gems/server/lib/itsi/server/grpc/reflection/v1/reflection_pb.rb +26 -0
- data/gems/server/lib/itsi/server/grpc/reflection/v1/reflection_services_pb.rb +122 -0
- data/gems/server/lib/itsi/server/route_tester.rb +107 -0
- data/gems/server/lib/itsi/server/typed_handlers/param_parser.rb +200 -0
- data/gems/server/lib/itsi/server/typed_handlers/source_parser.rb +55 -0
- data/gems/server/lib/itsi/server/typed_handlers.rb +17 -0
- data/gems/server/lib/itsi/server/version.rb +1 -1
- data/gems/server/lib/itsi/server.rb +82 -12
- data/gems/server/lib/ruby_lsp/itsi/addon.rb +111 -0
- data/gems/server/lib/shell_completions/completions.rb +26 -0
- data/gems/server/test/helpers/test_helper.rb +2 -1
- data/lib/itsi/version.rb +1 -1
- data/sandbox/README.md +5 -0
- data/sandbox/itsi_file/Gemfile +4 -2
- data/sandbox/itsi_file/Gemfile.lock +48 -6
- data/sandbox/itsi_file/Itsi.rb +326 -129
- data/sandbox/itsi_file/call.json +1 -0
- data/sandbox/itsi_file/echo_client/Gemfile +10 -0
- data/sandbox/itsi_file/echo_client/Gemfile.lock +27 -0
- data/sandbox/itsi_file/echo_client/README.md +95 -0
- data/sandbox/itsi_file/echo_client/echo_client.rb +164 -0
- data/sandbox/itsi_file/echo_client/gen_proto.sh +17 -0
- data/sandbox/itsi_file/echo_client/lib/echo_pb.rb +16 -0
- data/sandbox/itsi_file/echo_client/lib/echo_services_pb.rb +29 -0
- data/sandbox/itsi_file/echo_client/run_client.rb +64 -0
- data/sandbox/itsi_file/echo_client/test_compressions.sh +20 -0
- data/sandbox/itsi_file/echo_service_nonitsi/Gemfile +10 -0
- data/sandbox/itsi_file/echo_service_nonitsi/Gemfile.lock +79 -0
- data/sandbox/itsi_file/echo_service_nonitsi/echo.proto +26 -0
- data/sandbox/itsi_file/echo_service_nonitsi/echo_pb.rb +16 -0
- data/sandbox/itsi_file/echo_service_nonitsi/echo_services_pb.rb +29 -0
- data/sandbox/itsi_file/echo_service_nonitsi/server.rb +52 -0
- data/sandbox/itsi_sandbox_async/config.ru +0 -1
- data/sandbox/itsi_sandbox_rack/Gemfile.lock +2 -2
- data/sandbox/itsi_sandbox_rails/Gemfile +2 -2
- data/sandbox/itsi_sandbox_rails/Gemfile.lock +76 -2
- data/sandbox/itsi_sandbox_rails/app/controllers/home_controller.rb +15 -0
- data/sandbox/itsi_sandbox_rails/config/environments/development.rb +1 -0
- data/sandbox/itsi_sandbox_rails/config/environments/production.rb +1 -0
- data/sandbox/itsi_sandbox_rails/config/routes.rb +2 -0
- data/sandbox/itsi_sinatra/app.rb +0 -1
- data/sandbox/static_files/.env +1 -0
- data/sandbox/static_files/404.html +25 -0
- data/sandbox/static_files/_DSC0102.NEF.jpg +0 -0
- data/sandbox/static_files/about.html +68 -0
- data/sandbox/static_files/tiny.html +1 -0
- data/sandbox/static_files/writebook.zip +0 -0
- data/tasks.txt +28 -33
- metadata +87 -26
- data/crates/itsi_error/src/from.rs +0 -68
- data/crates/itsi_server/src/ruby_types/itsi_grpc_request.rs +0 -147
- data/crates/itsi_server/src/ruby_types/itsi_grpc_response.rs +0 -19
- data/crates/itsi_server/src/server/itsi_service.rs +0 -172
- data/crates/itsi_server/src/server/middleware_stack/middlewares/grpc_service.rs +0 -72
- data/crates/itsi_server/src/server/types.rs +0 -43
- data/gems/server/lib/itsi/server/grpc_interface.rb +0 -213
- data/sandbox/itsi_file/public/assets/index.html +0 -1
- /data/crates/itsi_server/src/server/{bind_protocol.rs → binds/bind_protocol.rs} +0 -0
- /data/crates/itsi_server/src/server/{tls → binds/tls}/locked_dir_cache.rs +0 -0
- /data/crates/itsi_server/src/{server → services}/cache_store.rs +0 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
|
6
|
+
|
7
|
+
require 'bundler/setup'
|
8
|
+
require 'grpc'
|
9
|
+
require 'colorize'
|
10
|
+
require_relative 'lib/echo_pb'
|
11
|
+
require_relative 'lib/echo_services_pb'
|
12
|
+
|
13
|
+
class EchoClient
|
14
|
+
# Initialize the client with options to control compression
|
15
|
+
def initialize(host = 'localhost', port = 50051, compression: nil)
|
16
|
+
# Available compression options:
|
17
|
+
# nil - No compression (default)
|
18
|
+
# :gzip - Use gzip compression
|
19
|
+
# :deflate - Use deflate compression
|
20
|
+
@host = host
|
21
|
+
@port = port
|
22
|
+
@compression = compression
|
23
|
+
|
24
|
+
# Set up the channel and stub with compression options
|
25
|
+
channel_args = {}
|
26
|
+
if @compression
|
27
|
+
# Adding compression options to channel
|
28
|
+
channel_args = {
|
29
|
+
'grpc.default_compression_algorithm' => compression_algorithm,
|
30
|
+
'grpc.default_compression_level' => 2 # High compression level (0-2)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
@channel = GRPC::Core::Channel.new("#{host}:#{port}", channel_args, :this_channel_is_insecure)
|
35
|
+
@stub = Echo::EchoService::Stub.new("#{host}:#{port}", :this_channel_is_insecure, channel_args: channel_args)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Map compression symbol to GRPC compression algorithm constant
|
39
|
+
def compression_algorithm
|
40
|
+
case @compression
|
41
|
+
when :gzip
|
42
|
+
1 # GRPC::Core::CompressionAlgorithm::GZIP
|
43
|
+
when :deflate
|
44
|
+
2 # GRPC::Core::CompressionAlgorithm::DEFLATE
|
45
|
+
else
|
46
|
+
0 # GRPC::Core::CompressionAlgorithm::NONE
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Simple unary RPC
|
51
|
+
def echo(message)
|
52
|
+
puts "Calling echo with #{message.inspect}".blue
|
53
|
+
request = Echo::EchoRequest.new(message: message)
|
54
|
+
response = @stub.echo(request)
|
55
|
+
puts "Response: #{response.message.inspect}, Count: #{response.count}".green
|
56
|
+
response
|
57
|
+
end
|
58
|
+
|
59
|
+
# Server streaming RPC
|
60
|
+
def echo_stream(message)
|
61
|
+
puts "Calling echo_stream with #{message.inspect}".blue
|
62
|
+
request = Echo::EchoRequest.new(message: message)
|
63
|
+
responses = []
|
64
|
+
|
65
|
+
@stub.echo_stream(request).each do |response|
|
66
|
+
puts "Stream Response: #{response.message.inspect}, Count: #{response.count}".green
|
67
|
+
responses << response
|
68
|
+
end
|
69
|
+
|
70
|
+
responses
|
71
|
+
end
|
72
|
+
|
73
|
+
# Client streaming RPC
|
74
|
+
def echo_collect(messages)
|
75
|
+
puts "Calling echo_collect with #{messages.length} messages".blue
|
76
|
+
|
77
|
+
# Create a request enumerator
|
78
|
+
request_enum = Enumerator.new do |yielder|
|
79
|
+
messages.each do |message|
|
80
|
+
puts "Sending: #{message.inspect}".cyan
|
81
|
+
yielder << Echo::EchoRequest.new(message: message)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Call with the enumerator
|
86
|
+
response = @stub.echo_collect(request_enum)
|
87
|
+
|
88
|
+
puts "Collect Response: #{response.message.inspect}, Count: #{response.count}".green
|
89
|
+
response
|
90
|
+
end
|
91
|
+
|
92
|
+
# Bidirectional streaming RPC
|
93
|
+
def echo_bidirectional(messages)
|
94
|
+
puts "Calling echo_bidirectional with #{messages.length} messages".blue
|
95
|
+
responses = []
|
96
|
+
|
97
|
+
# Create a request enumerator
|
98
|
+
request_enum = Enumerator.new do |yielder|
|
99
|
+
messages.each do |message|
|
100
|
+
puts "Sending: #{message.inspect}".cyan
|
101
|
+
yielder << Echo::EchoRequest.new(message: message)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Call bidirectional with enumerator and collect responses
|
106
|
+
@stub.echo_bidirectional(request_enum).each do |response|
|
107
|
+
puts "Bidi Response: #{response.message.inspect}, Count: #{response.count}".green
|
108
|
+
responses << response
|
109
|
+
end
|
110
|
+
|
111
|
+
responses
|
112
|
+
end
|
113
|
+
|
114
|
+
# Get the current compression configuration
|
115
|
+
def compression_info
|
116
|
+
if @compression
|
117
|
+
"Using #{@compression} compression (algorithm: #{compression_algorithm}, level: 2)"
|
118
|
+
else
|
119
|
+
"No compression"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def close
|
124
|
+
@channel.close
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Only execute if this file is run directly
|
129
|
+
if __FILE__ == $PROGRAM_NAME
|
130
|
+
# Usage example
|
131
|
+
compression = ARGV[0]&.to_sym if ARGV[0]
|
132
|
+
|
133
|
+
# Show compression options if requested
|
134
|
+
if compression == :help
|
135
|
+
puts "Available compression options:".yellow
|
136
|
+
puts " none - No compression (default)"
|
137
|
+
puts " gzip - Use gzip compression"
|
138
|
+
puts " deflate - Use deflate compression"
|
139
|
+
puts "\nUsage: ruby echo_client.rb [compression]"
|
140
|
+
exit
|
141
|
+
end
|
142
|
+
|
143
|
+
client = EchoClient.new('localhost', 50051, compression: compression)
|
144
|
+
puts "Compression: #{client.compression_info}".yellow
|
145
|
+
|
146
|
+
begin
|
147
|
+
# Unary call
|
148
|
+
client.echo("Hello from Ruby client!")
|
149
|
+
|
150
|
+
# Server streaming
|
151
|
+
client.echo_stream("Stream me back!")
|
152
|
+
|
153
|
+
# Client streaming
|
154
|
+
client.echo_collect(["Message 1", "Message 2", "Message 3"])
|
155
|
+
|
156
|
+
# Bidirectional streaming
|
157
|
+
client.echo_bidirectional(["Bidi 1", "Bidi 2", "Bidi 3"])
|
158
|
+
|
159
|
+
rescue GRPC::BadStatus => e
|
160
|
+
puts "Error from server: #{e.message}".red
|
161
|
+
ensure
|
162
|
+
client.close
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# Create directory for generated code
|
4
|
+
mkdir -p lib
|
5
|
+
|
6
|
+
# Path to the proto file
|
7
|
+
PROTO_FILE="../echo.proto"
|
8
|
+
PROTO_DIR="$(dirname "$PROTO_FILE")"
|
9
|
+
|
10
|
+
# Generate Ruby code from proto file
|
11
|
+
grpc_tools_ruby_protoc \
|
12
|
+
--ruby_out=./lib \
|
13
|
+
--grpc_out=./lib \
|
14
|
+
--proto_path="$PROTO_DIR" \
|
15
|
+
"$PROTO_FILE"
|
16
|
+
|
17
|
+
echo "Ruby gRPC code generated successfully!"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# source: echo.proto
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
|
8
|
+
descriptor_data = "\n\necho.proto\x12\x04\x65\x63ho\"\x1e\n\x0b\x45\x63hoRequest\x12\x0f\n\x07message\x18\x01 \x01(\t\".\n\x0c\x45\x63hoResponse\x12\x0f\n\x07message\x18\x01 \x01(\t\x12\r\n\x05\x63ount\x18\x02 \x01(\x05\x32\xf3\x01\n\x0b\x45\x63hoService\x12/\n\x04\x45\x63ho\x12\x11.echo.EchoRequest\x1a\x12.echo.EchoResponse\"\x00\x12\x37\n\nEchoStream\x12\x11.echo.EchoRequest\x1a\x12.echo.EchoResponse\"\x00\x30\x01\x12\x38\n\x0b\x45\x63hoCollect\x12\x11.echo.EchoRequest\x1a\x12.echo.EchoResponse\"\x00(\x01\x12@\n\x11\x45\x63hoBidirectional\x12\x11.echo.EchoRequest\x1a\x12.echo.EchoResponse\"\x00(\x01\x30\x01\x62\x06proto3"
|
9
|
+
|
10
|
+
pool = Google::Protobuf::DescriptorPool.generated_pool
|
11
|
+
pool.add_serialized_file(descriptor_data)
|
12
|
+
|
13
|
+
module Echo
|
14
|
+
EchoRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("echo.EchoRequest").msgclass
|
15
|
+
EchoResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("echo.EchoResponse").msgclass
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# Source: echo.proto for package 'echo'
|
3
|
+
|
4
|
+
require 'grpc'
|
5
|
+
require_relative 'echo_pb'
|
6
|
+
|
7
|
+
module Echo
|
8
|
+
module EchoService
|
9
|
+
class Service
|
10
|
+
|
11
|
+
include ::GRPC::GenericService
|
12
|
+
|
13
|
+
self.marshal_class_method = :encode
|
14
|
+
self.unmarshal_class_method = :decode
|
15
|
+
self.service_name = 'echo.EchoService'
|
16
|
+
|
17
|
+
# Simple unary method
|
18
|
+
rpc :Echo, ::Echo::EchoRequest, ::Echo::EchoResponse
|
19
|
+
# Server streaming method
|
20
|
+
rpc :EchoStream, ::Echo::EchoRequest, stream(::Echo::EchoResponse)
|
21
|
+
# Client streaming method
|
22
|
+
rpc :EchoCollect, stream(::Echo::EchoRequest), ::Echo::EchoResponse
|
23
|
+
# Bidirectional streaming method
|
24
|
+
rpc :EchoBidirectional, stream(::Echo::EchoRequest), stream(::Echo::EchoResponse)
|
25
|
+
end
|
26
|
+
|
27
|
+
Stub = Service.rpc_stub_class
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative 'echo_client'
|
5
|
+
require 'optparse'
|
6
|
+
require 'colorize'
|
7
|
+
|
8
|
+
options = {
|
9
|
+
host: 'localhost',
|
10
|
+
port: 3000,
|
11
|
+
compression: nil
|
12
|
+
}
|
13
|
+
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
opts.banner = 'Usage: run_client.rb [options]'
|
16
|
+
|
17
|
+
opts.on('-h', '--host HOST', 'Server hostname') do |host|
|
18
|
+
options[:host] = host
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-p', '--port PORT', 'Server port') do |port|
|
22
|
+
options[:port] = port.to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on('-c', '--compression COMPRESSION', 'Compression (none, gzip, deflate)') do |comp|
|
26
|
+
options[:compression] = comp.to_sym unless comp == 'none'
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on('-m', '--message MESSAGE', 'Message to send') do |msg|
|
30
|
+
options[:message] = msg
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on('--help', 'Show this help message') do
|
34
|
+
puts opts
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
end.parse!
|
38
|
+
|
39
|
+
# Set default message if not provided
|
40
|
+
options[:message] ||= 'Hello from configurable Ruby client!'
|
41
|
+
|
42
|
+
puts "Connecting to #{options[:host]}:#{options[:port]}".yellow
|
43
|
+
puts "Compression: #{options[:compression] || 'none'}".yellow
|
44
|
+
puts "Message: #{options[:message]}".yellow
|
45
|
+
|
46
|
+
client = EchoClient.new(options[:host], options[:port], compression: options[:compression])
|
47
|
+
|
48
|
+
begin
|
49
|
+
# # Unary call
|
50
|
+
client.echo(options[:message])
|
51
|
+
|
52
|
+
# # Server streaming
|
53
|
+
client.echo_stream(options[:message])
|
54
|
+
|
55
|
+
# Client streaming
|
56
|
+
client.echo_collect([options[:message], "#{options[:message]} 2", "#{options[:message]} 3"])
|
57
|
+
|
58
|
+
# Bidirectional streaming
|
59
|
+
client.echo_bidirectional([options[:message], "#{options[:message]} B", "#{options[:message]} C"])
|
60
|
+
rescue GRPC::BadStatus => e
|
61
|
+
puts "Error from server: #{e.message}".red
|
62
|
+
ensure
|
63
|
+
client.close
|
64
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# This script tests the echo client with different compression settings
|
4
|
+
|
5
|
+
# Message to use for testing
|
6
|
+
MESSAGE="This is a test message that will be repeated multiple times to demonstrate compression. $(printf '%s' {1..10})"
|
7
|
+
|
8
|
+
echo "=== Testing with NO compression ==="
|
9
|
+
./run_client.rb -m "$MESSAGE" -c none
|
10
|
+
|
11
|
+
echo ""
|
12
|
+
echo "=== Testing with GZIP compression ==="
|
13
|
+
./run_client.rb -m "$MESSAGE" -c gzip
|
14
|
+
|
15
|
+
echo ""
|
16
|
+
echo "=== Testing with DEFLATE compression ==="
|
17
|
+
./run_client.rb -m "$MESSAGE" -c deflate
|
18
|
+
|
19
|
+
echo ""
|
20
|
+
echo "All compression tests completed."
|
@@ -0,0 +1,79 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
bigdecimal (3.1.9)
|
5
|
+
date (3.4.1)
|
6
|
+
debug (1.10.0)
|
7
|
+
irb (~> 1.10)
|
8
|
+
reline (>= 0.3.8)
|
9
|
+
google-protobuf (4.30.2)
|
10
|
+
bigdecimal
|
11
|
+
rake (>= 13)
|
12
|
+
google-protobuf (4.30.2-aarch64-linux)
|
13
|
+
bigdecimal
|
14
|
+
rake (>= 13)
|
15
|
+
google-protobuf (4.30.2-arm64-darwin)
|
16
|
+
bigdecimal
|
17
|
+
rake (>= 13)
|
18
|
+
google-protobuf (4.30.2-x86-linux)
|
19
|
+
bigdecimal
|
20
|
+
rake (>= 13)
|
21
|
+
google-protobuf (4.30.2-x86_64-darwin)
|
22
|
+
bigdecimal
|
23
|
+
rake (>= 13)
|
24
|
+
google-protobuf (4.30.2-x86_64-linux)
|
25
|
+
bigdecimal
|
26
|
+
rake (>= 13)
|
27
|
+
googleapis-common-protos-types (1.19.0)
|
28
|
+
google-protobuf (>= 3.18, < 5.a)
|
29
|
+
grpc (1.71.0)
|
30
|
+
google-protobuf (>= 3.25, < 5.0)
|
31
|
+
googleapis-common-protos-types (~> 1.0)
|
32
|
+
grpc (1.71.0-aarch64-linux)
|
33
|
+
google-protobuf (>= 3.25, < 5.0)
|
34
|
+
googleapis-common-protos-types (~> 1.0)
|
35
|
+
grpc (1.71.0-arm64-darwin)
|
36
|
+
google-protobuf (>= 3.25, < 5.0)
|
37
|
+
googleapis-common-protos-types (~> 1.0)
|
38
|
+
grpc (1.71.0-x86-linux)
|
39
|
+
google-protobuf (>= 3.25, < 5.0)
|
40
|
+
googleapis-common-protos-types (~> 1.0)
|
41
|
+
grpc (1.71.0-x86_64-darwin)
|
42
|
+
google-protobuf (>= 3.25, < 5.0)
|
43
|
+
googleapis-common-protos-types (~> 1.0)
|
44
|
+
grpc (1.71.0-x86_64-linux)
|
45
|
+
google-protobuf (>= 3.25, < 5.0)
|
46
|
+
googleapis-common-protos-types (~> 1.0)
|
47
|
+
io-console (0.8.0)
|
48
|
+
irb (1.15.1)
|
49
|
+
pp (>= 0.6.0)
|
50
|
+
rdoc (>= 4.0.0)
|
51
|
+
reline (>= 0.4.2)
|
52
|
+
pp (0.6.2)
|
53
|
+
prettyprint
|
54
|
+
prettyprint (0.2.0)
|
55
|
+
psych (5.2.3)
|
56
|
+
date
|
57
|
+
stringio
|
58
|
+
rake (13.2.1)
|
59
|
+
rdoc (6.13.0)
|
60
|
+
psych (>= 4.0.0)
|
61
|
+
reline (0.6.0)
|
62
|
+
io-console (~> 0.5)
|
63
|
+
stringio (3.1.6)
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
aarch64-linux
|
67
|
+
arm64-darwin
|
68
|
+
ruby
|
69
|
+
x86-linux
|
70
|
+
x86_64-darwin
|
71
|
+
x86_64-linux
|
72
|
+
|
73
|
+
DEPENDENCIES
|
74
|
+
debug
|
75
|
+
google-protobuf
|
76
|
+
grpc
|
77
|
+
|
78
|
+
BUNDLED WITH
|
79
|
+
2.6.3
|
@@ -0,0 +1,26 @@
|
|
1
|
+
syntax = "proto3";
|
2
|
+
|
3
|
+
package echo;
|
4
|
+
|
5
|
+
service EchoService {
|
6
|
+
// Simple unary method
|
7
|
+
rpc Echo(EchoRequest) returns (EchoResponse) {}
|
8
|
+
|
9
|
+
// Server streaming method
|
10
|
+
rpc EchoStream(EchoRequest) returns (stream EchoResponse) {}
|
11
|
+
|
12
|
+
// Client streaming method
|
13
|
+
rpc EchoCollect(stream EchoRequest) returns (EchoResponse) {}
|
14
|
+
|
15
|
+
// Bidirectional streaming method
|
16
|
+
rpc EchoBidirectional(stream EchoRequest) returns (stream EchoResponse) {}
|
17
|
+
}
|
18
|
+
|
19
|
+
message EchoRequest {
|
20
|
+
string message = 1;
|
21
|
+
}
|
22
|
+
|
23
|
+
message EchoResponse {
|
24
|
+
string message = 1;
|
25
|
+
int32 count = 2;
|
26
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# source: echo.proto
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
|
8
|
+
descriptor_data = "\n\necho.proto\x12\x04\x65\x63ho\"\x1e\n\x0b\x45\x63hoRequest\x12\x0f\n\x07message\x18\x01 \x01(\t\".\n\x0c\x45\x63hoResponse\x12\x0f\n\x07message\x18\x01 \x01(\t\x12\r\n\x05\x63ount\x18\x02 \x01(\x05\x32\xf3\x01\n\x0b\x45\x63hoService\x12/\n\x04\x45\x63ho\x12\x11.echo.EchoRequest\x1a\x12.echo.EchoResponse\"\x00\x12\x37\n\nEchoStream\x12\x11.echo.EchoRequest\x1a\x12.echo.EchoResponse\"\x00\x30\x01\x12\x38\n\x0b\x45\x63hoCollect\x12\x11.echo.EchoRequest\x1a\x12.echo.EchoResponse\"\x00(\x01\x12@\n\x11\x45\x63hoBidirectional\x12\x11.echo.EchoRequest\x1a\x12.echo.EchoResponse\"\x00(\x01\x30\x01\x62\x06proto3"
|
9
|
+
|
10
|
+
pool = Google::Protobuf::DescriptorPool.generated_pool
|
11
|
+
pool.add_serialized_file(descriptor_data)
|
12
|
+
|
13
|
+
module Echo
|
14
|
+
EchoRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("echo.EchoRequest").msgclass
|
15
|
+
EchoResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("echo.EchoResponse").msgclass
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# Source: echo.proto for package 'echo'
|
3
|
+
|
4
|
+
require 'grpc'
|
5
|
+
require_relative 'echo_pb'
|
6
|
+
|
7
|
+
module Echo
|
8
|
+
module EchoService
|
9
|
+
class Service
|
10
|
+
|
11
|
+
include ::GRPC::GenericService
|
12
|
+
|
13
|
+
self.marshal_class_method = :encode
|
14
|
+
self.unmarshal_class_method = :decode
|
15
|
+
self.service_name = 'echo.EchoService'
|
16
|
+
|
17
|
+
# Simple unary method
|
18
|
+
rpc :Echo, ::Echo::EchoRequest, ::Echo::EchoResponse
|
19
|
+
# Server streaming method
|
20
|
+
rpc :EchoStream, ::Echo::EchoRequest, stream(::Echo::EchoResponse)
|
21
|
+
# Client streaming method
|
22
|
+
rpc :EchoCollect, stream(::Echo::EchoRequest), ::Echo::EchoResponse
|
23
|
+
# Bidirectional streaming method
|
24
|
+
rpc :EchoBidirectional, stream(::Echo::EchoRequest), stream(::Echo::EchoResponse)
|
25
|
+
end
|
26
|
+
|
27
|
+
Stub = Service.rpc_stub_class
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'grpc'
|
2
|
+
require_relative 'echo_services_pb'
|
3
|
+
require_relative 'echo_pb' # Your generated file
|
4
|
+
|
5
|
+
# Define the EchoService implementation
|
6
|
+
class EchoService < Echo::EchoService::Service
|
7
|
+
# Implement the Echo method
|
8
|
+
def echo(request, _unused_call)
|
9
|
+
Echo::EchoResponse.new(message: "Echo: #{request.message}", count: 1)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Implement the EchoStream method (streaming response)
|
13
|
+
def echo_stream(request, _unused_call)
|
14
|
+
Enumerator.new do |yielder|
|
15
|
+
3.times do |i|
|
16
|
+
yielder << Echo::EchoResponse.new(message: "#{request.message} - part #{i + 1}", count: i + 1)
|
17
|
+
sleep 0.5 # Simulate processing time
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Implement the EchoCollect method (streaming request)
|
23
|
+
def echo_collect(call)
|
24
|
+
count = 0
|
25
|
+
message = ''
|
26
|
+
call.each_remote_read do |req|
|
27
|
+
count += 1
|
28
|
+
message += req.message + ' '
|
29
|
+
end
|
30
|
+
Echo::EchoResponse.new(message: message.strip, count: count)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Implement the EchoBidirectional method (bidirectional streaming)
|
34
|
+
def echo_bidirectional(requests, _unused_call)
|
35
|
+
Enumerator.new do |yielder|
|
36
|
+
requests.each do |req|
|
37
|
+
yielder << Echo::EchoResponse.new(message: "Echoing back: #{req.message}", count: req.message.length)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Create the gRPC server
|
44
|
+
def main
|
45
|
+
server = GRPC::RpcServer.new
|
46
|
+
server.add_http2_port('0.0.0.0:50051', :this_port_is_insecure)
|
47
|
+
server.handle(EchoService)
|
48
|
+
puts 'Server running on 0.0.0.0:50051'
|
49
|
+
server.run_till_terminated
|
50
|
+
end
|
51
|
+
|
52
|
+
main if __FILE__ == $PROGRAM_NAME
|
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../gems/scheduler
|
3
3
|
specs:
|
4
|
-
itsi-scheduler (0.1.
|
4
|
+
itsi-scheduler (0.1.14)
|
5
5
|
rb_sys (~> 0.9.91)
|
6
6
|
|
7
7
|
PATH
|
8
8
|
remote: ../../gems/server
|
9
9
|
specs:
|
10
|
-
itsi-server (0.1.
|
10
|
+
itsi-server (0.1.14)
|
11
11
|
rack (>= 1.6)
|
12
12
|
rb_sys (~> 0.9.91)
|
13
13
|
|