distribustream 0.1.0 → 0.2.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,66 +0,0 @@
1
- #--
2
- # Copyright (C) 2006-07 ClickCaster, Inc. (info@clickcaster.com)
3
- # All rights reserved. See COPYING for permissions.
4
- #
5
- # This source file is distributed as part of the
6
- # DistribuStream file transfer system.
7
- #
8
- # See http://distribustream.rubyforge.org/
9
- #++
10
-
11
- module PDTP
12
- class Client < Mongrel::HttpHandler
13
- # Implementation of a ruby test client for the pdtp protocol
14
- class Protocol < PDTP::Protocol
15
- def initialize *args
16
- super
17
- end
18
-
19
- # Called after a connection to the server has been established
20
- def connection_completed
21
- begin
22
- listen_port = @@config[:listen_port]
23
-
24
- #create the client
25
- client = PDTP::Client.new
26
- PDTP::Protocol.listener = client
27
- client.server_connection = self
28
- client.generate_client_id listen_port
29
- client.file_service = PDTP::Client::FileService.new
30
-
31
- # Start a mongrel server on the specified port. If it isnt available, keep trying higher ports
32
- begin
33
- mongrel_server = Mongrel::HttpServer.new('0.0.0.0', listen_port)
34
- rescue Exception => e
35
- listen_port += 1
36
- retry
37
- end
38
-
39
- @@log.info "listening on port #{listen_port}"
40
- mongrel_server.register '/', client
41
- mongrel_server.run
42
-
43
- # Tell the server about ourself
44
- send_message :client_info, :listen_port => listen_port, :client_id => client.my_id
45
-
46
- # Ask the server for some information on the file we want
47
- send_message :ask_info, :url => @@config[:request_url]
48
-
49
- # Request the file
50
- send_message :request, :url => @@config[:request_url]
51
-
52
- @@log.info "This client is requesting"
53
- rescue Exception=>e
54
- puts "Exception in connection_completed: #{e}"
55
- puts e.backtrace.join("\n")
56
- exit
57
- end
58
- end
59
-
60
- def unbind
61
- super
62
- puts 'Disconnected from PDTP server.'
63
- end
64
- end
65
- end
66
- end
@@ -1,91 +0,0 @@
1
- #--
2
- # Copyright (C) 2006-07 ClickCaster, Inc. (info@clickcaster.com)
3
- # All rights reserved. See COPYING for permissions.
4
- #
5
- # This source file is distributed as part of the
6
- # DistribuStream file transfer system.
7
- #
8
- # See http://distribustream.rubyforge.org/
9
- #++
10
-
11
- require File.dirname(__FILE__) + '/file_service'
12
-
13
- describe "A FileInfo with chunk_size=1" do
14
- before(:each) do
15
- @fi=PDTP::FileInfo.new
16
- @fi.file_size=5
17
- @fi.base_chunk_size=1
18
- end
19
-
20
- it "chunk_size works" do
21
- @fi.chunk_size(0).should == 1
22
- @fi.chunk_size(3).should == 1
23
- @fi.chunk_size(4).should == 1
24
-
25
- proc{ @fi.chunk_size(-1)}.should raise_error
26
- proc{ @fi.chunk_size(5)}.should raise_error
27
- end
28
-
29
- it "num_chunks works" do
30
- @fi.num_chunks.should == 5
31
- end
32
-
33
- it "chunk_from_offset works" do
34
- @fi.chunk_from_offset(0).should == 0
35
- @fi.chunk_from_offset(4).should == 4
36
- proc{@fi.chunk_from_offset(5)}.should raise_error
37
- end
38
-
39
- it "chunk_range_from_byte_range works" do
40
- @fi.chunk_range_from_byte_range(0..4,false).should == (0..4)
41
- @fi.chunk_range_from_byte_range(0..4,true).should == (0..4)
42
- proc{@fi.chunk_range_from_byte_range(-1..3,true)}.should raise_error
43
- end
44
-
45
- end
46
-
47
- describe "A FileInfo with chunk_size=256 and file_size=768" do
48
- before(:each) do
49
- @fi=PDTP::FileInfo.new
50
- @fi.base_chunk_size=256
51
- @fi.file_size=768
52
- end
53
-
54
- it "chunk_size works" do
55
- @fi.chunk_size(0).should == 256
56
- @fi.chunk_size(2).should == 256
57
- proc{@fi.chunk_size(3)}.should raise_error
58
- end
59
-
60
- it "num_chunks works" do
61
- @fi.num_chunks.should == 3
62
- end
63
-
64
- it "chunk_from_offset works" do
65
- @fi.chunk_from_offset(256).should == 1
66
- @fi.chunk_from_offset(255).should == 0
67
- end
68
-
69
- it "chunk_range_from_byte_range works" do
70
- @fi.chunk_range_from_byte_range(256..511,true).should == (1..1)
71
- @fi.chunk_range_from_byte_range(256..511,false).should == (1..1)
72
- @fi.chunk_range_from_byte_range(255..512,true).should == (1..1)
73
- @fi.chunk_range_from_byte_range(255..512,false).should == (0..2)
74
- end
75
- end
76
-
77
- describe "A FileInfo with chunk_size=256 and file_size=255" do
78
- before(:each) do
79
- @fi=PDTP::FileInfo.new
80
- @fi.base_chunk_size=256
81
- @fi.file_size=255
82
- end
83
-
84
- it "num_chunks works" do
85
- @fi.num_chunks.should ==1
86
- end
87
-
88
- it "chunk_from_offset works" do
89
- @fi.chunk_from_offset(254).should == 0
90
- end
91
- end
@@ -1,68 +0,0 @@
1
- #--
2
- # Copyright (C) 2006-07 ClickCaster, Inc. (info@clickcaster.com)
3
- # All rights reserved. See COPYING for permissions.
4
- #
5
- # This source file is distributed as part of the
6
- # DistribuStream file transfer system.
7
- #
8
- # See http://distribustream.rubyforge.org/
9
- #++
10
-
11
- require File.dirname(__FILE__) + '/protocol'
12
-
13
- describe PDTP::Protocol, 'obj_matches_type?' do
14
- it "identifies :url objects" do
15
- PDTP::Protocol.obj_matches_type?("http://bla.com/test3.mp3",:url).should == true
16
- PDTP::Protocol.obj_matches_type?(4,:url).should == false
17
- end
18
-
19
- it "identifies :range objects" do
20
- PDTP::Protocol.obj_matches_type?(0..4,:range).should == true
21
- PDTP::Protocol.obj_matches_type?(4,:range).should == false
22
- PDTP::Protocol.obj_matches_type?( {"min"=>0,"max"=>4} , :range ).should == true
23
- end
24
-
25
- it "identifies :ip objects" do
26
- PDTP::Protocol.obj_matches_type?("127.0.0.1", :ip).should == true
27
- PDTP::Protocol.obj_matches_type?("127.0.0.1.1", :ip).should == false
28
- end
29
-
30
- it "identifies :int objects" do
31
- PDTP::Protocol.obj_matches_type?(4,:int).should == true
32
- PDTP::Protocol.obj_matches_type?("hi",:int).should == false
33
- end
34
-
35
- it "identifies :bool objects" do
36
- PDTP::Protocol.obj_matches_type?(true, :bool).should == true
37
- PDTP::Protocol.obj_matches_type?(0,:bool).should == false
38
- end
39
-
40
- it "identifies :string objects" do
41
- PDTP::Protocol.obj_matches_type?("hi", :string).should == true
42
- PDTP::Protocol.obj_matches_type?(6, :string).should == false
43
- end
44
-
45
- end
46
-
47
- describe PDTP::Protocol, 'validate_message' do
48
- it "supports optional parameters" do
49
- msg1 = ["request", {"url"=>"pdtp://bla.com/test.txt", "range"=>0..4 }]
50
- msg2 = ["request", {"url"=>"pdtp://bla.com/test.txt" }]
51
- msg3 = ["request", {"range"=> "hi", "url"=>"pdtp://bla.com/test.txt" }]
52
-
53
- proc { PDTP::Protocol.validate_message(msg1)}.should_not raise_error
54
- proc { PDTP::Protocol.validate_message(msg2)}.should_not raise_error
55
- proc { PDTP::Protocol.validate_message(msg3)}.should raise_error
56
- end
57
-
58
- it "validates required parameters" do
59
- msg1 = ["ask_info"]
60
- msg2 = ["ask_info", {"url"=>"pdtp://bla.com/test.txt"}]
61
- msg3 = ["ask_info", {"url"=>42 }]
62
-
63
- proc { PDTP::Protocol.validate_message(msg1)}.should raise_error
64
- proc { PDTP::Protocol.validate_message(msg2)}.should_not raise_error
65
- proc { PDTP::Protocol.validate_message(msg3)}.should raise_error
66
- end
67
-
68
- end
@@ -1,40 +0,0 @@
1
- #--
2
- # Copyright (C) 2006-07 ClickCaster, Inc. (info@clickcaster.com)
3
- # All rights reserved. See COPYING for permissions.
4
- #
5
- # This source file is distributed as part of the
6
- # DistribuStream file transfer system.
7
- #
8
- # See http://distribustream.rubyforge.org/
9
- #++
10
-
11
- require File.dirname(__FILE__) + '/trust'
12
-
13
- describe 'A new trust node' do
14
- before(:each) do
15
- @node = PDTP::Trust.new
16
- @other = PDTP::Trust.new
17
- @distant = PDTP::Trust.new
18
- end
19
-
20
- it 'should be empty' do
21
- @node.outgoing.should be_empty
22
- @node.implicit.should be_empty
23
- end
24
-
25
- it 'should trust a node after a good transfer' do
26
- @node.success(@other)
27
- @node.outgoing.should_not be_empty
28
- end
29
-
30
- it 'should normalize trusts across outgoing edges' do
31
- @node.success(@other)
32
- trust = @node.weight(@other)
33
-
34
- @node.success(@distant)
35
- @node.outgoing.size.should == 2
36
-
37
- @node.weight(@other).should < trust
38
- (@node.weight(@other) + @node.weight(@distant)).should be_close(1.0, 0.00001)
39
- end
40
- end