Skip to content

Commit

Permalink
Fix protocol discrepency between Go Log Courier and Ruby Log Courier
Browse files Browse the repository at this point in the history
  • Loading branch information
driskell committed Oct 21, 2021
1 parent 86a2e74 commit 6e9d898
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
16 changes: 11 additions & 5 deletions docs/Protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,30 @@ Data for this message is currently defined as follows:

```text
+---+---+---+---+
| F | M | m | p |
| Flags |
+---+---+---+---+
| Major Version |
+---+---+---+---+
| Minor Version |
+---+---+---+---+
| Patch Version |
+---+---+---+---+
| Client |
+---+---+---+---+
| 28-bytes Reserved...
+
```

F = 1-byte of Bit Flags defined as follows:
Flags = 1-byte of Bit Flags defined as follows:

- Bit 1: EVNT message stream is supported
- Bits 2-8: Reserved

M = Major version of client
Major Version = Major version of client

m = minor version of client
Minor Version = Minor version of client

p = patch version of client
Patch Version = Patch version of client

Client = 4-character ASCII identifier of the client. All "LC" prefix are reserved. See [Known Clients](#known-clients).

Expand Down
2 changes: 1 addition & 1 deletion ruby/log-courier/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
log-courier (2.7.0)
log-courier (2.7.2)
cabin (~> 0.6)
multi_json (~> 1.10)

Expand Down
2 changes: 1 addition & 1 deletion ruby/log-courier/lib/log-courier/client_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def resume_send
def handshake(io_control)
return true if @options[:disable_handshake]

@socket.write ['HELO', 8, 0, 2, 7, 0, 'RYLC'].pack('A4NCCCCA4')
@socket.write ['HELO', 20, 0, 2, 7, 2, 'RYLC'].pack('A4NNNNNA4')

signature, data = receive
if signature != 'VERS'
Expand Down
4 changes: 2 additions & 2 deletions ruby/log-courier/lib/log-courier/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ module LogCourier
# Protocol
module Protocol
def self.parse_helo_vers(data)
data = "\x00\x00\x00\x00\x00\x00\x00\x00" if data.length < 8
data = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" if data.length < 8

flags, major_version, minor_version, patch_version, client = data.unpack('CCCCA4')
flags, major_version, minor_version, patch_version, client = data.unpack('NNNNA4')
client = case client
when 'LCOR'
'Log Courier'
Expand Down
10 changes: 5 additions & 5 deletions ruby/log-courier/lib/log-courier/server_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@ def handshake
@helo = Protocol.parse_helo_vers(data)
@logger&.info 'Remote identified', peer: @peer, client_version: @helo[:client_version]

# Flags 1 byte - EVNT flag = 0
# Flags 4 bytes - EVNT flag = 0
# (Significant rewrite would be required to support streaming messages as currently we read
# first and then yield for processing. To support EVNT we have to move protocol parsing to
# the connection layer here so we can keep reading until we reach the end of the stream)
# Major Version 1 byte
# Minor Version 1 byte
# Patch Version 1 byte
# Major Version 4 bytes
# Minor Version 4 bytes
# Patch Version 4 bytes
# Client String 4 bytes
data = [1, 2, 7, 0, 'RYLC'].pack('CCCCA4')
data = [0, 2, 7, 2, 'RYLC'].pack('NNNNA4')
send 'VERS', data
end

Expand Down
2 changes: 1 addition & 1 deletion ruby/log-courier/log-courier.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |gem|
gem.name = 'log-courier'
gem.version = '2.7.1'
gem.version = '2.7.2'
gem.description = 'Log Courier library'
gem.summary = 'Ruby implementation of the Courier protocol'
gem.homepage = 'https://github.com/driskell/ruby-log-courier'
Expand Down
6 changes: 3 additions & 3 deletions ruby/logstash-input-courier/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
PATH
remote: ../log-courier
specs:
log-courier (2.7.0)
log-courier (2.7.2)
cabin (~> 0.6)
multi_json (~> 1.10)

PATH
remote: .
specs:
logstash-input-courier (2.7.0-java)
log-courier (~> 2.7.0)
logstash-input-courier (2.7.2-java)
log-courier (~> 2.7.2)
logstash-codec-plain
logstash-core-plugin-api (>= 1.60, <= 2.99)

Expand Down
4 changes: 2 additions & 2 deletions ruby/logstash-input-courier/logstash-input-courier.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Add platform conditions around java-only dependencies so GitHub dependency chart that is MRI only (I think) still works
Gem::Specification.new do |gem|
gem.name = 'logstash-input-courier'
gem.version = '2.7.0'
gem.version = '2.7.2'
gem.description = 'Courier Input Logstash Plugin'
gem.summary =
'Receive events from Log Courier and Logstash using the Courier protocol'
Expand All @@ -18,7 +18,7 @@ Gem::Specification.new do |gem|

gem.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'input' }

gem.add_runtime_dependency 'log-courier', '~> 2.7.0'
gem.add_runtime_dependency 'log-courier', '~> 2.7.2'
gem.add_runtime_dependency 'logstash-codec-plain' if RUBY_PLATFORM == 'java'
gem.add_runtime_dependency 'logstash-core-plugin-api', '>= 1.60', '<= 2.99' if RUBY_PLATFORM == 'java'
end

0 comments on commit 6e9d898

Please sign in to comment.