fargo 0.3.0 → 0.4.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.
@@ -1,5 +1,5 @@
1
1
  require 'bzip2'
2
- require 'libxml'
2
+ require 'nokogiri'
3
3
 
4
4
  module Fargo
5
5
  class Listing < Struct.new(:tth, :size, :name, :nick, :mtime, :root); end
@@ -39,6 +39,11 @@ module Fargo
39
39
 
40
40
  @getting_file_list[nick] = true
41
41
  download nick, 'files.xml.bz2'
42
+
43
+ EventMachine.add_timer 60 do
44
+ @file_list.delete nick
45
+ @getting_file_list.delete nick
46
+ end
42
47
  end
43
48
 
44
49
  # Wait for the results to arrive, timed out after some time
@@ -68,7 +73,7 @@ module Fargo
68
73
  if file && File.exists?(file)
69
74
  Fargo.logger.debug "Parsing file list for: '#{nick}' at '#{file}'"
70
75
  xml = Bzip2::Reader.open(file).read
71
- doc = LibXML::XML::Document.string xml
76
+ doc = Nokogiri::XML::Document.parse xml
72
77
 
73
78
  construct_file_list doc.root, nil, nick
74
79
  else
@@ -79,17 +84,14 @@ module Fargo
79
84
  def construct_file_list node, prefix, nick
80
85
  list = {}
81
86
 
82
- node.each_element do |element|
87
+ node.element_children.each do |element|
83
88
  path = prefix ? prefix + "\\" + element['Name'] : element['Name']
84
89
 
85
90
  if element.name =~ /directory/i
86
91
  list[element['Name']] = construct_file_list element, path, nick
87
92
  else
88
- # Why does this consistently segfault ruby 1.8.7 when I convert
89
- # element['Size'] to an integer before the struct is created?!
90
93
  element = list[element['Name']] = Listing.new(element['TTH'],
91
- element['Size'], path, nick)
92
- element.size = element.size.to_i
94
+ element['Size'].to_i, path, nick)
93
95
  end
94
96
  end
95
97
 
@@ -26,9 +26,15 @@ module Fargo
26
26
  @searches[search.to_s] = []
27
27
  @search_objects[search.to_s] = search
28
28
  search_hub search
29
+
30
+ EventMachine.add_timer(600) { remove_search search }
29
31
  end
30
32
 
31
33
  def searches
34
+ search_objects.map{ |s| s.query }
35
+ end
36
+
37
+ def search_objects
32
38
  @searches.keys.map { |k| @search_objects[k] }
33
39
  end
34
40
 
@@ -1,3 +1,3 @@
1
1
  module Fargo
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -9,7 +9,7 @@ describe Fargo::Protocol::Hub do
9
9
  }
10
10
  include Fargo::TTH
11
11
 
12
- context "searches" do
12
+ context "searches", :type => :emsync do
13
13
  let(:file1) { Fargo.config.download_dir + '/file12' }
14
14
  let(:file2) { Fargo.config.download_dir + '/file23' }
15
15
  let(:file3) { Fargo.config.download_dir + '/file34' }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Fargo::Protocol::PeerUpload do
3
+ describe Fargo::Protocol::PeerUpload, :type => :emsync do
4
4
  let(:conn) {
5
5
  helper_object(Fargo::Protocol::Peer).tap do |conn|
6
6
  conn.client = Fargo::Client.new
@@ -62,7 +62,12 @@ describe Fargo::Search do
62
62
  subject.should_not match_hash(:tth => 'foobar')
63
63
  end
64
64
 
65
- it "only matches anything with a filetype of ANY" do
65
+ it "extracts the query from the pattern specified" do
66
+ subject.pattern = 'a$b$c'
67
+ subject.query.should == 'a b c'
68
+ end
69
+
70
+ it "matches valid file names with a filetype of ANY" do
66
71
  subject.query = 'foo bar baz'
67
72
  subject.filetype = Fargo::Search::ANY
68
73
 
@@ -30,4 +30,11 @@ describe Fargo::Supports::Chat, :type => :em do
30
30
  client.messages.should == []
31
31
  client.messages_with('foo').should == []
32
32
  end
33
+
34
+ it "sends the correct message when chatting" do
35
+ client.instance_variable_set('@hub', hub = mock)
36
+ hub.should_receive(:send_data).with('<fargo> hello world!|')
37
+
38
+ client.send_chat 'hello world!'
39
+ end
33
40
  end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Fargo::Supports::LocalFileList do
3
+ describe Fargo::Supports::LocalFileList, :type => :emsync do
4
+
5
+ include Fargo::TTH
4
6
 
5
7
  before :each do
6
8
  @root = Fargo.config.download_dir + '/shared'
@@ -29,6 +31,16 @@ describe Fargo::Supports::LocalFileList do
29
31
  hash['shared']['c']['d'].name.should == 'shared/c/d'
30
32
  end
31
33
 
34
+ it "caches the file list so that another client can come along" do
35
+ @client.share_directory @root
36
+
37
+ client2 = Fargo::Client.new
38
+ client2.config.override_share_size = nil
39
+ client2.local_file_list.should == @client.local_file_list
40
+ client2.share_size.should == @client.share_size
41
+ client2.shared_directories.should == @client.shared_directories
42
+ end
43
+
32
44
  it "caches the size of each file shared" do
33
45
  @client.share_directory @root
34
46
 
@@ -67,4 +79,23 @@ describe Fargo::Supports::LocalFileList do
67
79
 
68
80
  @client.listing_for('TTH/' + listing.tth).should == listing
69
81
  end
82
+
83
+ it "generates a correct file list" do
84
+ @client.share_directory @root
85
+ file = Bzip2::Reader.open(@client.config.config_dir + '/files.xml.bz2')
86
+ xml = file.read
87
+
88
+ xml.should == <<-XML
89
+ <?xml version="1.0" encoding="utf-8"?>
90
+ <FileListing Base="/" Version="1" Generator="fargo #{Fargo::VERSION}">
91
+ <Directory Name="shared">
92
+ <File Name="a" Size="1" TTH="#{file_tth(@root + '/a')}"/>
93
+ <File Name="b" Size="1" TTH="#{file_tth(@root + '/b')}"/>
94
+ <Directory Name="c">
95
+ <File Name="d" Size="1" TTH="#{file_tth(@root + '/c/d')}"/>
96
+ </Directory>
97
+ </Directory>
98
+ </FileListing>
99
+ XML
100
+ end
70
101
  end
@@ -28,12 +28,15 @@ RSpec.configure do |c|
28
28
  end
29
29
 
30
30
  c.around :each, :type => :em do |example|
31
- EventMachine.run {
31
+ EventMachine.run_block {
32
32
  example.run
33
-
34
- EventMachine.stop_event_loop
35
33
  }
36
34
  end
35
+
36
+ c.before :each, :type => :emsync do
37
+ EM.stub(:schedule).and_yield
38
+ EM.stub(:defer).and_yield
39
+ end
37
40
  end
38
41
 
39
42
  Dir[File.dirname(__FILE__) + '/support/*.rb'].each { |f| load f }
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fargo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 3
7
+ - 4
9
8
  - 0
10
- version: 0.3.0
9
+ version: 0.4.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Alex Crichton
@@ -15,76 +14,100 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-04 00:00:00 -04:00
17
+ date: 2010-11-18 00:00:00 -05:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
21
+ name: eventmachine
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: em-websocket
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: em-http-request
48
+ requirement: &id003 !ruby/object:Gem::Requirement
23
49
  none: false
24
50
  requirements:
25
51
  - - ">="
26
52
  - !ruby/object:Gem::Version
27
- hash: 3
28
53
  segments:
29
54
  - 0
30
55
  version: "0"
31
- requirement: *id001
32
56
  type: :runtime
33
- name: eventmachine
34
57
  prerelease: false
58
+ version_requirements: *id003
35
59
  - !ruby/object:Gem::Dependency
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
60
+ name: activesupport
61
+ requirement: &id004 !ruby/object:Gem::Requirement
37
62
  none: false
38
63
  requirements:
39
64
  - - ">="
40
65
  - !ruby/object:Gem::Version
41
- hash: 7
42
66
  segments:
43
67
  - 3
44
68
  - 0
45
69
  - 0
46
70
  version: 3.0.0
47
- requirement: *id002
48
71
  type: :runtime
49
- name: activesupport
50
72
  prerelease: false
73
+ version_requirements: *id004
51
74
  - !ruby/object:Gem::Dependency
52
- version_requirements: &id003 !ruby/object:Gem::Requirement
75
+ name: nokogiri
76
+ requirement: &id005 !ruby/object:Gem::Requirement
53
77
  none: false
54
78
  requirements:
55
79
  - - ">="
56
80
  - !ruby/object:Gem::Version
57
- hash: 3
58
81
  segments:
59
82
  - 0
60
83
  version: "0"
61
- requirement: *id003
62
84
  type: :runtime
63
- name: libxml-ruby
64
85
  prerelease: false
86
+ version_requirements: *id005
65
87
  - !ruby/object:Gem::Dependency
66
- version_requirements: &id004 !ruby/object:Gem::Requirement
88
+ name: bzip2-ruby
89
+ requirement: &id006 !ruby/object:Gem::Requirement
67
90
  none: false
68
91
  requirements:
69
92
  - - ">="
70
93
  - !ruby/object:Gem::Version
71
- hash: 3
72
94
  segments:
73
95
  - 0
74
96
  version: "0"
75
- requirement: *id004
76
97
  type: :runtime
77
- name: bzip2-ruby
78
98
  prerelease: false
99
+ version_requirements: *id006
79
100
  description: Direct Connect (DC) Client implemented in pure Ruby
80
101
  email: alex@alexcrichton.com
81
- executables: []
82
-
102
+ executables:
103
+ - fargo
83
104
  extensions:
84
105
  - ext/fargo/extconf.rb
106
+ - ext/readline/extconf.rb
85
107
  extra_rdoc_files: []
86
108
 
87
109
  files:
110
+ - bin/fargo
88
111
  - ext/fargo/base32.c
89
112
  - ext/fargo/base32.h
90
113
  - ext/fargo/extconf.rb
@@ -96,8 +119,24 @@ files:
96
119
  - ext/fargo/tigertree.h
97
120
  - ext/fargo/tth.c
98
121
  - ext/fargo/tth.h
122
+ - ext/readline/extconf.rb
123
+ - ext/readline/fargo_cli.c
124
+ - ext/readline/screen.c
125
+ - ext/readline/screen.h
99
126
  - lib/fargo.rb
127
+ - lib/fargo/cli.rb
128
+ - lib/fargo/cli/completion.rb
129
+ - lib/fargo/cli/downloads.rb
130
+ - lib/fargo/cli/help.rb
131
+ - lib/fargo/cli/info.rb
132
+ - lib/fargo/cli/logging.rb
133
+ - lib/fargo/cli/nick_browser.rb
134
+ - lib/fargo/cli/searches.rb
135
+ - lib/fargo/cli/stats.rb
100
136
  - lib/fargo/client.rb
137
+ - lib/fargo/ext/irb.rb
138
+ - lib/fargo/ext/readline.rb
139
+ - lib/fargo/ext/struct.rb
101
140
  - lib/fargo/parser.rb
102
141
  - lib/fargo/protocol/dc.rb
103
142
  - lib/fargo/protocol/hub.rb
@@ -135,8 +174,8 @@ homepage: http://github.com/alexcrichton/fargo
135
174
  licenses: []
136
175
 
137
176
  post_install_message:
138
- rdoc_options:
139
- - --charset=UTF-8
177
+ rdoc_options: []
178
+
140
179
  require_paths:
141
180
  - lib
142
181
  - ext
@@ -145,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
184
  requirements:
146
185
  - - ">="
147
186
  - !ruby/object:Gem::Version
148
- hash: 3
187
+ hash: 4279216489116306912
149
188
  segments:
150
189
  - 0
151
190
  version: "0"
@@ -154,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
193
  requirements:
155
194
  - - ">="
156
195
  - !ruby/object:Gem::Version
157
- hash: 3
196
+ hash: 4279216489116306912
158
197
  segments:
159
198
  - 0
160
199
  version: "0"