DIY-pcap 0.2.3 → 0.2.4

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/diy/builder.rb CHANGED
@@ -31,33 +31,26 @@ module DIY
31
31
  end
32
32
 
33
33
  def client(ip_or_iport)
34
- default_port = "7878"
35
- if ! ip_or_iport.include?(':')
36
- iport = ip_or_iport + ':' + default_port
37
- else
38
- iport = ip_or_iport
39
- end
40
- @curi = ip2druby(iport)
34
+ @curi = ip_or_iport_with_default(ip_or_iport, 7878)
41
35
  end
42
36
 
43
37
  def server(ip_or_iport)
44
- default_port = "7879"
45
- if ! ip_or_iport.include?(':')
46
- iport = ip_or_iport + ':' + default_port
47
- else
48
- iport = ip_or_iport
49
- end
50
- @suri = ip2druby(iport)
38
+ @suri = ip_or_iport_with_default(ip_or_iport, 7879)
51
39
  end
52
40
 
53
41
  def me(ip_or_iport)
54
- default_port = "7880"
42
+ @me = ip_or_iport_with_default(ip_or_iport, 7880)
43
+ end
44
+ alias controller me
45
+
46
+ def ip_or_iport_with_default(ip_or_iport, default_port)
47
+ default_port = default_port.to_s
55
48
  if ! ip_or_iport.include?(':')
56
49
  iport = ip_or_iport + ':' + default_port
57
50
  else
58
51
  iport = ip_or_iport
59
52
  end
60
- @me = ip2druby(iport)
53
+ ip2druby(iport)
61
54
  end
62
55
 
63
56
  def ip2druby(ip)
data/lib/diy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module DIY
2
2
  class PCAP
3
- VERSION = "0.2.3"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
data/lib/diy/worker.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # encoding : utf-8
2
2
  require 'diy/packet'
3
3
  require 'drb'
4
+ require 'thread'
5
+
4
6
  module DIY
5
7
  include DRbUndumped
6
8
  class Worker
@@ -8,6 +10,7 @@ module DIY
8
10
  @live = live
9
11
  @recv_t = nil
10
12
  @start = false
13
+ @m = Mutex.new
11
14
  loop_recv
12
15
  end
13
16
 
@@ -25,8 +28,10 @@ module DIY
25
28
  @live.loop do |this, pkt|
26
29
  next unless @start
27
30
  begin
28
- @block.call(pkt.body) if @block
29
- rescue DRb::DRbconnError
31
+ @m.synchronize do
32
+ @block.call(pkt.body) if @block
33
+ end
34
+ rescue DRb::DRbConnError
30
35
  DIY::Logger.info "closed connection by controller"
31
36
  end
32
37
  end
data/simple/pcap.rb CHANGED
@@ -10,7 +10,7 @@ a = DIY::Builder.new do
10
10
  pcapfile Dir["pcaps/*.pcap"]
11
11
  client "127.0.0.1"
12
12
  server "127.0.0.1"
13
- me "127.0.0.1"
13
+ controller "127.0.0.1"
14
14
  end
15
15
 
16
16
  a.run
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: DIY-pcap
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 31
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 3
9
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
10
11
  platform: ruby
11
12
  authors:
12
13
  - yafei Lee
@@ -14,8 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2012-09-29 00:00:00 +08:00
18
- default_executable:
18
+ date: 2012-10-08 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: ffi-pcap
@@ -25,6 +25,7 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
+ hash: 23
28
29
  segments:
29
30
  - 0
30
31
  - 2
@@ -110,7 +111,6 @@ files:
110
111
  - spec/spec_helper.rb
111
112
  - spec/utils_spec.rb
112
113
  - spec/worker_spec.rb
113
- has_rdoc: true
114
114
  homepage: ""
115
115
  licenses: []
116
116
 
@@ -124,6 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
+ hash: 3
127
128
  segments:
128
129
  - 0
129
130
  version: "0"
@@ -132,13 +133,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  requirements:
133
134
  - - ">="
134
135
  - !ruby/object:Gem::Version
136
+ hash: 3
135
137
  segments:
136
138
  - 0
137
139
  version: "0"
138
140
  requirements: []
139
141
 
140
142
  rubyforge_project:
141
- rubygems_version: 1.3.7
143
+ rubygems_version: 1.8.24
142
144
  signing_key:
143
145
  specification_version: 3
144
146
  summary: DIY pcap send and recv