jls-lumberjack 0.0.18 → 0.0.19
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.
- data/lib/lumberjack/server2.rb +82 -0
- metadata +15 -15
@@ -0,0 +1,82 @@
|
|
1
|
+
require "ffi-rzmq"
|
2
|
+
require "zlib"
|
3
|
+
require "rbnacl"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Lumberjack
|
7
|
+
class Server2
|
8
|
+
# Create a new Lumberjack server.
|
9
|
+
#
|
10
|
+
# - options is a hash. Valid options are:
|
11
|
+
#
|
12
|
+
# * :port - the port to listen on
|
13
|
+
# * :address - the host/address to bind to
|
14
|
+
def initialize(options={})
|
15
|
+
@options = {
|
16
|
+
:endpoint => "tcp://0.0.0.0:3333",
|
17
|
+
:my_secret_key => nil,
|
18
|
+
:their_public_key => nil,
|
19
|
+
}.merge(options)
|
20
|
+
|
21
|
+
[:my_secret_key, :their_public_key].each do |k|
|
22
|
+
if @options[k].nil?
|
23
|
+
raise "You must specify #{k} in Lumberjack::Server.new(...)"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
@context = ZMQ::Context.new
|
28
|
+
@socket = @context.socket(ZMQ::REP)
|
29
|
+
@socket.bind(@options[:endpoint])
|
30
|
+
|
31
|
+
@cryptobox = Crypto::Box.new(
|
32
|
+
Crypto::PublicKey.new(@options[:their_public_key]),
|
33
|
+
Crypto::PrivateKey.new(@options[:my_secret_key]))
|
34
|
+
end # def initialize
|
35
|
+
|
36
|
+
def run(&block)
|
37
|
+
ciphertext = ""
|
38
|
+
ciphertext.force_encoding("BINARY")
|
39
|
+
nonce = ""
|
40
|
+
nonce.force_encoding("BINARY")
|
41
|
+
count = 0
|
42
|
+
start = Time.now
|
43
|
+
while true
|
44
|
+
@socket.recv_string(nonce)
|
45
|
+
@socket.recv_string(ciphertext)
|
46
|
+
|
47
|
+
# Decrypt
|
48
|
+
plaintext = @cryptobox.open(nonce, ciphertext)
|
49
|
+
|
50
|
+
# decompress
|
51
|
+
inflated = Zlib::Inflate.inflate(plaintext)
|
52
|
+
|
53
|
+
# JSON
|
54
|
+
events = JSON.parse(inflated)
|
55
|
+
events.each do |event|
|
56
|
+
yield event
|
57
|
+
end
|
58
|
+
|
59
|
+
# TODO(sissel): yield each event
|
60
|
+
count += events.count
|
61
|
+
@socket.send_string("")
|
62
|
+
#count += 4096
|
63
|
+
|
64
|
+
if count > 100000
|
65
|
+
puts :rate => (count / (Time.now - start))
|
66
|
+
count = 0
|
67
|
+
start = Time.now
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end # def run
|
71
|
+
end # class Server2
|
72
|
+
end # module Lumberjack
|
73
|
+
|
74
|
+
if __FILE__ == $0
|
75
|
+
a = Lumberjack::Server2.new(
|
76
|
+
:their_public_key => File.read("../../nacl.public").force_encoding("BINARY"),
|
77
|
+
:my_secret_key => File.read("../../nacl.secret").force_encoding("BINARY"))
|
78
|
+
|
79
|
+
a.run do |e|
|
80
|
+
p :event => e
|
81
|
+
end
|
82
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jls-lumberjack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.19
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jordan Sissel
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: lumberjack log transport library
|
15
15
|
email:
|
@@ -19,31 +19,31 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- lib/lumberjack/server.rb
|
22
|
+
- lib/lumberjack/server2.rb
|
22
23
|
- lib/lumberjack/client.rb
|
23
24
|
homepage: https://github.com/jordansissel/lumberjack
|
24
25
|
licenses: []
|
25
|
-
post_install_message:
|
26
|
+
post_install_message:
|
26
27
|
rdoc_options: []
|
27
28
|
require_paths:
|
28
29
|
- lib
|
29
30
|
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
30
32
|
requirements:
|
31
|
-
- -
|
33
|
+
- - ! '>='
|
32
34
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
MA==
|
35
|
-
none: false
|
35
|
+
version: '0'
|
36
36
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
37
38
|
requirements:
|
38
|
-
- -
|
39
|
+
- - ! '>='
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
MA==
|
42
|
-
none: false
|
41
|
+
version: '0'
|
43
42
|
requirements: []
|
44
|
-
rubyforge_project:
|
43
|
+
rubyforge_project:
|
45
44
|
rubygems_version: 1.8.24
|
46
|
-
signing_key:
|
45
|
+
signing_key:
|
47
46
|
specification_version: 3
|
48
47
|
summary: lumberjack log transport library
|
49
48
|
test_files: []
|
49
|
+
has_rdoc:
|