DIY-pcap 0.2.8 → 0.3.0

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.
@@ -24,14 +24,15 @@ module DIY
24
24
 
25
25
  loop do
26
26
  begin
27
- pkts = @offline.nexts
28
- one_round( client, server, pkts )
29
- client, server = server, client
27
+ pkts = @offline.nexts
28
+ one_round( client, server, pkts )
29
+ client, server = server, client
30
30
  rescue HopePacketTimeoutError, UserError, FFI::PCap::LibError => e
31
31
  DIY::Logger.warn( "Timeout: Hope packet is #{pkts[0].pretty_print} ") if e.kind_of?(HopePacketTimeoutError)
32
32
  @fail_count += 1
33
33
  begin
34
- @offline.next_pcap
34
+ @offline.next_pcap
35
+ server.terminal
35
36
  rescue EOFError
36
37
  client.terminal
37
38
  server.terminal
@@ -62,7 +63,7 @@ module DIY
62
63
  recv_pkt = Packet.new(recv_pkt)
63
64
  begin
64
65
  @strategy.call(pkts.first, recv_pkt, pkts)
65
- rescue DIY::StrategyCallError =>e
66
+ rescue DIY::UserError =>e
66
67
  DIY::Logger.warn("UserError Catch: " + e.inspect)
67
68
  e.backtrace.each do |msg|
68
69
  DIY::Logger.info(msg)
@@ -9,12 +9,8 @@ module DIY
9
9
  # 没有报文被指定时
10
10
  class ZeroOfflineError < Error; end
11
11
 
12
- # 不可能出现的报文出现
13
- class UnExpectPacketError < Error; end
14
-
15
12
  class UserError < Error
16
13
  def initialize(real_exception)
17
- puts "new..."
18
14
  @real_exception = real_exception
19
15
  @name = real_exception.class
20
16
  @message = real_exception.message
@@ -26,6 +22,9 @@ module DIY
26
22
  end
27
23
  end
28
24
 
25
+ # 不可能出现的报文出现
26
+ class UnExpectPacketError < UserError; end
27
+
29
28
  # 策略执行异常
30
29
  class StrategyCallError < UserError; end
31
30
  # before_send 异常
@@ -42,10 +42,11 @@ module DIY
42
42
  return
43
43
  elsif ret == Strategy::FAIL
44
44
  logger.warn("pkt fail:")
45
- logger.warn("pkt fail: hope_pkt is #{Utils.pp(hope_pkt)}")
46
- logger.warn("pkt fail: recv_pkt is #{Utils.pp(recv_pkt)}")
47
- #TODO 也许需要将Queue输出?
48
- raise UnExpectPacketError, "strategy FAIL"
45
+ logger.warn("pkt fail: hope_pkt is #{hope_pkt.pretty_print}")
46
+ logger.warn("pkt fail: recv_pkt is #{recv_pkt.pretty_print}")
47
+ e = RuntimeError.new("Strategy FAIL: hope #{hope_pkt.pretty_print} but get #{recv_pkt.pretty_print}")
48
+ e.set_backtrace(caller) # not used
49
+ raise UnExpectPacketError.new(e)
49
50
  elsif ret == Strategy::NONE
50
51
  #~ logger.debug("pkt jumpped:")
51
52
  next
data/lib/diy/utils.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding : utf-8
1
2
  module DIY
2
3
  module Utils
3
4
  class << self
@@ -5,12 +6,13 @@ module DIY
5
6
  def pp(pkt, size_print = true)
6
7
  pkt = pkt.content if pkt.kind_of?(DIY::Packet)
7
8
  return nil if pkt.nil?
8
- #~ ( pkt[0..10] + "..." ).dump + "(#{pkt.size} sizes)"
9
9
  size = pkt.size
10
10
  size_print_str = ""
11
+
11
12
  if size_print
12
13
  size_print_str = "(#{size} sizes)"
13
14
  end
15
+
14
16
  begin
15
17
  new_pkt = pkt.dup
16
18
  Mu::Pcap::Ethernet.from_bytes(new_pkt).to_s + size_print_str
@@ -46,7 +48,6 @@ module DIY
46
48
  if ! Utils.ary_match(filter_ary, msg)
47
49
  new_bt << msg
48
50
  else
49
- puts "break"
50
51
  break
51
52
  end
52
53
  end
data/lib/diy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module DIY
2
2
  class PCAP
3
- VERSION = "0.2.8"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -84,5 +84,21 @@ describe "Controller" do
84
84
  end
85
85
  lambda { build2.run }.should_not raise_error
86
86
  end
87
+
88
+ it "#run stragety fail" do
89
+
90
+ def return_fail
91
+ DIY::Strategy::FAIL
92
+ end
93
+
94
+ fail = lambda { |h,r,q|
95
+ return_fail
96
+ }
97
+ build2 = DIY::Builder.new do
98
+ use fail
99
+ pcapfiles "helper/http.pcap"
100
+ end
101
+ lambda { build2.run }.should_not raise_error
102
+ end
87
103
 
88
104
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: DIY-pcap
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 2
9
- - 8
10
- version: 0.2.8
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - yafei Lee
@@ -15,7 +14,8 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2012-10-11 00:00:00 Z
17
+ date: 2012-10-11 00:00:00 +08:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: ffi-pcap
@@ -25,7 +25,6 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- hash: 23
29
28
  segments:
30
29
  - 0
31
30
  - 2
@@ -146,6 +145,7 @@ files:
146
145
  - spec/spec_helper.rb
147
146
  - spec/utils_spec.rb
148
147
  - spec/worker_spec.rb
148
+ has_rdoc: true
149
149
  homepage: ""
150
150
  licenses: []
151
151
 
@@ -159,7 +159,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
159
  requirements:
160
160
  - - ">="
161
161
  - !ruby/object:Gem::Version
162
- hash: 3
163
162
  segments:
164
163
  - 0
165
164
  version: "0"
@@ -168,14 +167,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
167
  requirements:
169
168
  - - ">="
170
169
  - !ruby/object:Gem::Version
171
- hash: 3
172
170
  segments:
173
171
  - 0
174
172
  version: "0"
175
173
  requirements: []
176
174
 
177
175
  rubyforge_project:
178
- rubygems_version: 1.8.24
176
+ rubygems_version: 1.3.7
179
177
  signing_key:
180
178
  specification_version: 3
181
179
  summary: DIY pcap send and recv