onion 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,19 @@
1
1
  module Onion
2
+ # Onion::Router is a Ruby object representing a Tor router.
2
3
  class Router
3
4
  attr_reader :nick, :id_key_hash, :status_flags
4
5
  def initialize(nick, id_key_hash, status_flags)
5
- @nick = nick
6
- @id_key_hash = id_key_hash
7
- @status_flags = status_flags
6
+ @nick = nick # Nickname of the router.
7
+ @id_key_hash = id_key_hash # Hash of the router identity key.
8
+ @status_flags = status_flags # Array of strings with status flags.
8
9
  end
9
10
 
11
+ # Returns true if the rotuer is a guard router, false otherwise.
10
12
  def guard?
11
13
  @status_flags and @status_flags.include?("Guard")
12
14
  end
13
15
 
16
+ # Returns true if the router is an exit router, false otherwise.
14
17
  def exit?
15
18
  @status_flags and @status_flags.include?("Exit")
16
19
  end
@@ -1,4 +1,7 @@
1
1
  module Onion
2
+ # Onion::RouterList is a list of Onion::Router objects. On initialization,
3
+ # the text given is parsed with Onion::RouterListParser. The text should be
4
+ # in the router status format specified by the directory protocol 2.0 spec.
2
5
  class RouterList
3
6
  attr_reader :routers
4
7
  def initialize(text)
@@ -13,5 +16,20 @@ module Onion
13
16
  raise Exception "Couldn't parse #{text} b/c #{parser.failure_reason}."
14
17
  end
15
18
  end
19
+
20
+ # Returns the routers that are guard routers.
21
+ def guards
22
+ @routers.select { |r| r.guard? }
23
+ end
24
+
25
+ # Returns the routers that are exit routers.
26
+ def exits
27
+ @routers.select { |r| r.exit? }
28
+ end
29
+
30
+ # Returns the routers that are neither guard or exit routers.
31
+ def middlemen
32
+ @routers.filter { |r| r.guard? or r.exit? }
33
+ end
16
34
  end
17
35
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onion
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 0
10
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Poet (Tim Sally)
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-02 00:00:00 -05:00
17
+ date: 2010-10-03 00:00:00 -05:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 23
30
28
  segments:
31
29
  - 1
32
30
  - 4
@@ -65,7 +63,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
63
  requirements:
66
64
  - - ">="
67
65
  - !ruby/object:Gem::Version
68
- hash: 3
69
66
  segments:
70
67
  - 0
71
68
  version: "0"
@@ -74,7 +71,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
71
  requirements:
75
72
  - - ">="
76
73
  - !ruby/object:Gem::Version
77
- hash: 3
78
74
  segments:
79
75
  - 0
80
76
  version: "0"