pixelflut 0.0.5 → 0.0.6

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: bc5f965ac963380d9f086a9d8fc8ae155fed8eda6e2a2466a57fc5ed9f38773c
4
- data.tar.gz: 6350e684e3a17f65e3eb045f9d3ff0a8a988bce93f91460949441cd433194d96
3
+ metadata.gz: bbd5e580104dccc3e1a1123ccc063dde0ae530d7443129bc044e9b73a9c71293
4
+ data.tar.gz: 6590f3d4f9491a10aec353701cde1f53a26158ba8c655be0952ea3be0129d500
5
5
  SHA512:
6
- metadata.gz: 92ea11881a51b23d2ba8cc3e79ce4eca85107c2640917875ab42022169a88fe22a3e5ec4875830e4dcd0a4266e03596f30528f0ee05c8b6fff001103c18a8926
7
- data.tar.gz: c9037c48b74adf490248b186a0a29a7b54bc7cdf7f361031336bec2e6b25c96db303700facb64831ebc466b697f5f172132543f174cdc6ede7e9d5d383cfa879
6
+ metadata.gz: ac78e76fc92be0e1891012cd1d1fe5b0cb5f388f736f75c2a4a193a294ce339cd1763ce2d1dcc055fa997b6feed20a0fba30d57447695cf8512db229fdcd6306
7
+ data.tar.gz: 20efde215a0528fc028980fa8edc3c8d40a3acff446aeb3f3599ca7cbd69a87dcc1eac135a5d844e2746a58651c011f8f64a38b2c35733029d382d5c832fe8a0
data/TODO.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Todo
4
4
 
5
- - [ ] limit connections to _*one* per IP_
5
+ - [x] limit connections _per IP_
6
6
  - [x] allow 10 (pixel-)actions per client
7
+ - [ ] extend `pxf generate`
8
+ - [ ] add a pre-processor for images
7
9
  - [ ] mention the Gosu gem in the README
data/bin/pxf-server CHANGED
@@ -8,10 +8,10 @@ def options(cfg)
8
8
  opts.banner = 'usage: pxf server [options]'
9
9
  opts.separator(nil)
10
10
  opts.separator('valid options:')
11
- opts.on('-b', '--bind ADDR', String, 'bind to given address') do |v|
11
+ opts.on('-b', '--bind ADDR', String, 'bind address') do |v|
12
12
  cfg.server.host = v
13
13
  end
14
- opts.on('-p', '--port PORT', Integer, 'select port(default: 1234)') do |v|
14
+ opts.on('-p', '--port PORT', Integer, 'bind port(default: 1234)') do |v|
15
15
  cfg.server.port = v
16
16
  end
17
17
  opts.on('-k', '--keep-alive', Float, 'set maximum keep-alive time') do |v|
@@ -20,8 +20,11 @@ def options(cfg)
20
20
  opts.on('-r', '--read_buffer SIZE', Integer, 'set read buffer size (default: 1024)') do |v|
21
21
  cfg.server.read_buffer_size = v
22
22
  end
23
- opts.on('-c', '--commands NUMBER', Integer, 'set number of continious processed commands (default: 10)') do |v|
24
- cfg.server.max_commands_at_once = v
23
+ opts.on('-l', '--peer-limit NUMBER', Integer, 'limit number connections per peer (default: 8)') do |v|
24
+ cfg.server.peer_limit = v
25
+ end
26
+ opts.on('-c', '--command-limit NUMBER', Integer, 'limit of continious processed commands (default: 10)') do |v|
27
+ cfg.server.command_limit = v
25
28
  end
26
29
  opts.on('-w', '--width WIDTH', Integer, 'set canvas width (default: 800)') do |v|
27
30
  cfg.width = v
data/lib/pixelflut/app.rb CHANGED
@@ -26,6 +26,7 @@ module Pixelflut
26
26
  @image = TextImage.new(width, height)
27
27
  @server = Server.new(@image, configuration.server)
28
28
  log(self.caption = "Pixelflut@#{configuration.server.host}:#{configuration.server.port}")
29
+ log(configuration.server)
29
30
  reset!
30
31
  end
31
32
 
@@ -9,10 +9,19 @@ module Pixelflut
9
9
  :port,
10
10
  :keep_alive_time,
11
11
  :read_buffer_size,
12
- :max_commands_at_once
12
+ :command_limit,
13
+ :peer_limit
13
14
  ) do
14
15
  def self.default
15
- new(nil, 1234, 1, 1024, 10)
16
+ new(nil, 1234, 1, 1024, 10, 8)
17
+ end
18
+
19
+ def to_s
20
+ "bind: #{host}:#{port}"\
21
+ ", keep-alive-time: #{keep_alive_time}"\
22
+ ", read-buffer-size: #{read_buffer_size}"\
23
+ ", command-limit: #{command_limit}"\
24
+ ", peer-limit: #{peer_limit}"
16
25
  end
17
26
  end
18
27
 
@@ -21,13 +30,14 @@ module Pixelflut
21
30
  def initialize(canvas, config = Configuration.default)
22
31
  @canvas, @config = canvas, config
23
32
  @socket, @connections = nil, {}
33
+ @peers = Hash.new{ |h, k| h[k] = 0 }
24
34
  @ccfg = Connection::Configuration.new(
25
35
  keep_alive_time: config.keep_alive_time,
26
36
  read_buffer_size: config.read_buffer_size,
27
- max_commands_at_once: config.max_commands_at_once,
37
+ command_limit: config.command_limit,
28
38
  canvas: canvas,
29
39
  size_result: "SIZE #{canvas.width} #{canvas.height}\n".freeze,
30
- on_end: ->(conn){ @connections.delete(conn) }
40
+ on_end: ->(conn){ @peers[conn.peeraddr] -= 1 if @connections.delete(conn) }
31
41
  ).freeze
32
42
  end
33
43
 
@@ -50,8 +60,12 @@ module Pixelflut
50
60
 
51
61
  private
52
62
 
53
- def create_connection(incoming)
54
- con = Connection.new(incoming, @ccfg)
63
+ def create_connection(socket)
64
+ peeraddr = socket.peeraddr(false)[-1]
65
+ count = @peers[peeraddr] + 1
66
+ return socket.close if count > @config.peer_limit
67
+ @peers[peeraddr] = count
68
+ con = Connection.new(socket, peeraddr, @ccfg)
55
69
  @connections[con] = con
56
70
  end
57
71
 
@@ -64,16 +78,17 @@ module Pixelflut
64
78
  Configuration = Struct.new(
65
79
  :keep_alive_time,
66
80
  :read_buffer_size,
67
- :max_commands_at_once,
81
+ :command_limit,
68
82
  :canvas,
69
83
  :size_result,
70
84
  :on_end,
71
85
  keyword_init: true
72
86
  )
73
87
 
74
- def initialize(socket, config)
75
- @socket, @config = socket, config
76
- # socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
88
+ attr_reader :peeraddr
89
+
90
+ def initialize(socket, peeraddr, config)
91
+ @socket, @peeraddr, @config = socket, peeraddr, config
77
92
  @last_tm, @buffer = Time.now.to_f, ''
78
93
  end
79
94
 
@@ -126,7 +141,7 @@ module Pixelflut
126
141
  end
127
142
 
128
143
  def process_loop(index)
129
- command_count = @config.max_commands_at_once
144
+ command_count = @config.command_limit
130
145
  while process_buffer(index)
131
146
  index = @buffer.index("\n") or return
132
147
  command_count -= 1
@@ -1,3 +1,3 @@
1
1
  module Pixelflut
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.0.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixelflut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt