rubtella 0.0.0 → 0.0.1

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/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "rubtella"
5
+ gemspec.summary = "Library for Gnuttale in Ruby"
6
+ gemspec.description = "Library for Gnuttale in Ruby"
7
+ gemspec.email = "mateusz.zawisza@gmail.com"
8
+ gemspec.homepage = "http://github.com/mateuszzawisza/rubtella/"
9
+ gemspec.authors = ["Mateusz Zawisza"]
10
+ end
11
+ rescue LoadError
12
+ puts "Jeweler not available. Install it with: gem install jeweler"
13
+ end
14
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -9,7 +9,7 @@ module Rubtella
9
9
  guid
10
10
  end
11
11
 
12
- IP_ADDRESS = "195.150.93.207"
12
+ IP_ADDRESS = "127.0.0.1"
13
13
  PORT = 54321
14
14
  GUID = generate_guid
15
15
 
@@ -10,7 +10,8 @@ class RubtellaLogger
10
10
  end
11
11
 
12
12
  def init_logger
13
- log = Logger.new('log/rubtella.log')
13
+ Dir.mkdir(ENV['HOME'] + "/.rubtella") unless File.exist?(ENV['HOME'] + "/.rubtella")
14
+ log = Logger.new(ENV['HOME'] + "/.rubtella/rubtella.log")
14
15
  log.level = Logger::INFO
15
16
  log.formatter = proc{|s,t,p,m|"%5s [%s] (%s) %s :: %s\n" % [s, t.strftime("%Y-%m-%d %H:%M:%S"), $$, p, m]}
16
17
  return log
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/ruby
2
+ # ruby gnutella client
3
+
4
+ require 'socket'
5
+ require 'timeout'
6
+ require 'rubtella/logger'
7
+ require 'rubygems'
8
+ require 'ruby-debug'
9
+
10
+
11
+
12
+ module Rubtella
13
+
14
+ GNUTELLA_REQUEST = "GNUTELLA CONNECT/0.6"
15
+ GNUTELLA_RESPONSE_OK = "GNUTELLA/0.6 200 OK"
16
+
17
+
18
+
19
+ class Listener
20
+
21
+ include Socket::Constants
22
+
23
+ #listen for connection
24
+ def listen
25
+ server = TCPServer.new("0.0.0.0", PORT)
26
+
27
+
28
+ while (session = server.accept)
29
+
30
+
31
+ Thread.start do
32
+
33
+ begin
34
+ parse_request session
35
+ rescue => e
36
+ session.puts "Rubtella Server Error: " + e.to_s
37
+ puts "Rubtella Server Error: " + e.to_s
38
+ ensure
39
+ session.close
40
+ end
41
+
42
+ end
43
+ end #end loop
44
+
45
+ end
46
+
47
+ def parse_request request
48
+ req = request.recv 1000
49
+
50
+ puts req
51
+ request.send Sender.pong, 0
52
+ puts 'response send!'
53
+ req = request.recv 1000
54
+ puts 'received content:'
55
+
56
+ puts req
57
+ puts 'received!'
58
+ end
59
+
60
+ end
61
+
62
+ class Sender
63
+
64
+
65
+ attr_accessor :peer, :connected
66
+
67
+ def initialize peer
68
+ @peer = peer
69
+ @standard_headers = {"User-Agent" => "Rubtella",
70
+ "X-Ultrapeer" => "False",
71
+ "X-Query-Routing" => "0.1"}
72
+ end
73
+
74
+ def connect
75
+ begin
76
+ puts "connecting to: #{@peer.ip}:#{@peer.port}"
77
+ stream = TCPSocket.new @peer.ip, @peer.port
78
+ timeout(5) do
79
+ stream.send handshake_req, 0
80
+ end
81
+ @response = stream.recv 1000
82
+
83
+ resp = HTTPData::Parser.new @response
84
+ stream.send handshake_resp, 0
85
+
86
+ if resp.ok?
87
+ #connection established
88
+ puts 'connection established'
89
+ @connected = @peer
90
+ puts "Connected with #{@connected.ip} #{@connected.port}"
91
+ @@logger.info "Connected with #{@connected.ip} #{@connected.port}"
92
+
93
+ manage_connection stream
94
+ else
95
+ puts 'failed to connect'
96
+ @peer = resp.peers.shift
97
+ connect
98
+ end
99
+ rescue Timeout::Error
100
+ @peer = resp.peers.shift
101
+ connect
102
+ rescue => e
103
+ @@logger.info e.to_s
104
+ end
105
+ end
106
+
107
+ def handshake_req
108
+ req = HTTPData::Builder.new GNUTELLA_REQUEST, @standard_headers
109
+ req.build
110
+ end
111
+
112
+ def handshake_resp
113
+ resp = HTTPData::Builder.new GNUTELLA_RESPONSE_OK, @standard_headers
114
+ resp.build
115
+ end
116
+
117
+ def manage_connection stream
118
+ loop do
119
+ puts 'we\'re listening..'
120
+ resp = stream.recv 1000
121
+ if parse(resp) == "ping"
122
+ pong = TCPData::Builder::Pong.new
123
+ stream.send pong.build , 0
124
+ puts 'pong send..'
125
+ stream.close
126
+ puts 'connection closed'
127
+ break
128
+ end
129
+ end
130
+
131
+
132
+
133
+ end
134
+
135
+ def parse message
136
+ parsed = TCPData::Parser.new message
137
+ puts parsed.message
138
+
139
+ parsed.message
140
+
141
+ end
142
+
143
+ def send_query(text)
144
+ stream = TCPSocket.new @connected.ip, @connected.port
145
+ query = TCPData::Builder::Query.new(:criteria => text)
146
+ @@logger.info "sending query - #{text}"
147
+ stream.send query.build, 0
148
+ puts 'we\'re listening..'
149
+ resp = stream.recv 1000
150
+ parse(resp)
151
+ end
152
+ end
153
+
154
+ end
data/lib/rubtella.rb CHANGED
@@ -1,154 +1,6 @@
1
- #!/usr/bin/ruby
2
- # ruby gnutella client
3
-
4
- require 'socket'
5
- require 'timeout'
6
- require 'lib/logger'
7
- require 'rubygems'
8
- require 'ruby-debug'
9
-
10
-
11
-
12
- module Rubtella
13
-
14
- GNUTELLA_REQUEST = "GNUTELLA CONNECT/0.6"
15
- GNUTELLA_RESPONSE_OK = "GNUTELLA/0.6 200 OK"
16
-
17
-
18
-
19
- class Listener
20
-
21
- include Socket::Constants
22
-
23
- #listen for connection
24
- def listen
25
- server = TCPServer.new("0.0.0.0", PORT)
26
-
27
-
28
- while (session = server.accept)
29
-
30
-
31
- Thread.start do
32
-
33
- begin
34
- parse_request session
35
- rescue => e
36
- session.puts "Rubtella Server Error: " + e.to_s
37
- puts "Rubtella Server Error: " + e.to_s
38
- ensure
39
- session.close
40
- end
41
-
42
- end
43
- end #end loop
44
-
45
- end
46
-
47
- def parse_request request
48
- req = request.recv 1000
49
-
50
- puts req
51
- request.send Sender.pong, 0
52
- puts 'response send!'
53
- req = request.recv 1000
54
- puts 'received content:'
55
-
56
- puts req
57
- puts 'received!'
58
- end
59
-
60
- end
61
-
62
- class Sender
63
-
64
-
65
- attr_accessor :peer, :connected
66
-
67
- def initialize peer
68
- @peer = peer
69
- @standard_headers = {"User-Agent" => "Rubtella",
70
- "X-Ultrapeer" => "False",
71
- "X-Query-Routing" => "0.1"}
72
- end
73
-
74
- def connect
75
- begin
76
- puts "connecting to: #{@peer.ip}:#{@peer.port}"
77
- stream = TCPSocket.new @peer.ip, @peer.port
78
- timeout(5) do
79
- stream.send handshake_req, 0
80
- end
81
- @response = stream.recv 1000
82
-
83
- resp = HTTPData::Parser.new @response
84
- stream.send handshake_resp, 0
85
-
86
- if resp.ok?
87
- #connection established
88
- puts 'connection established'
89
- @connected = @peer
90
- puts "Connected with #{@connected.ip} #{@connected.port}"
91
- @@logger.info "Connected with #{@connected.ip} #{@connected.port}"
92
-
93
- manage_connection stream
94
- else
95
- puts 'failed to connect'
96
- @peer = resp.peers.shift
97
- connect
98
- end
99
- rescue Timeout::Error
100
- @peer = resp.peers.shift
101
- connect
102
- rescue => e
103
- @@logger.info e.to_s
104
- end
105
- end
106
-
107
- def handshake_req
108
- req = HTTPData::Builder.new GNUTELLA_REQUEST, @standard_headers
109
- req.build
110
- end
111
-
112
- def handshake_resp
113
- resp = HTTPData::Builder.new GNUTELLA_RESPONSE_OK, @standard_headers
114
- resp.build
115
- end
116
-
117
- def manage_connection stream
118
- loop do
119
- puts 'we\'re listening..'
120
- resp = stream.recv 1000
121
- if parse(resp) == "ping"
122
- pong = TCPData::Builder::Pong.new
123
- stream.send pong.build , 0
124
- puts 'pong send..'
125
- stream.close
126
- puts 'connection closed'
127
- break
128
- end
129
- end
130
-
131
-
132
-
133
- end
134
-
135
- def parse message
136
- parsed = TCPData::Parser.new message
137
- puts parsed.message
138
-
139
- parsed.message
140
-
141
- end
142
-
143
- def send_query(text)
144
- stream = TCPSocket.new @connected.ip, @connected.port
145
- query = TCPData::Builder::Query.new(:criteria => text)
146
- @@logger.info "sending query - #{text}"
147
- stream.send query.build, 0
148
- puts 'we\'re listening..'
149
- resp = stream.recv 1000
150
- parse(resp)
151
- end
152
- end
153
-
154
- end
1
+ require 'config/config'
2
+ require 'rubtella/errors'
3
+ require 'rubtella/peer'
4
+ require 'rubtella/tcp_data'
5
+ require 'rubtella/http_data'
6
+ require 'rubtella/rubtella'
data/rubtella.gemspec ADDED
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rubtella}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mateusz Zawisza"]
12
+ s.date = %q{2010-01-10}
13
+ s.default_executable = %q{rubtellad.rb}
14
+ s.description = %q{Library for Gnuttale in Ruby}
15
+ s.email = %q{mateusz.zawisza@gmail.com}
16
+ s.executables = ["rubtellad.rb"]
17
+ s.extra_rdoc_files = [
18
+ "README"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bin/rubtellad.rb",
26
+ "lib/config/config.rb",
27
+ "lib/rubtella.rb",
28
+ "lib/rubtella/errors.rb",
29
+ "lib/rubtella/http_data.rb",
30
+ "lib/rubtella/logger.rb",
31
+ "lib/rubtella/peer.rb",
32
+ "lib/rubtella/rubtella.rb",
33
+ "lib/rubtella/tcp_data.rb",
34
+ "rubtella.gemspec"
35
+ ]
36
+ s.homepage = %q{http://github.com/mateuszzawisza/rubtella/}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{Library for Gnuttale in Ruby}
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ else
48
+ end
49
+ else
50
+ end
51
+ end
52
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubtella
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Zawisza
@@ -10,13 +10,13 @@ bindir: bin
10
10
  cert_chain: []
11
11
 
12
12
  date: 2010-01-10 00:00:00 +01:00
13
- default_executable:
13
+ default_executable: rubtellad.rb
14
14
  dependencies: []
15
15
 
16
16
  description: Library for Gnuttale in Ruby
17
17
  email: mateusz.zawisza@gmail.com
18
- executables: []
19
-
18
+ executables:
19
+ - rubtellad.rb
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
@@ -24,16 +24,18 @@ extra_rdoc_files:
24
24
  files:
25
25
  - .gitignore
26
26
  - README
27
+ - Rakefile
27
28
  - VERSION
28
- - config/config.rb
29
- - lib/errors.rb
30
- - lib/http_data.rb
31
- - lib/logger.rb
32
- - lib/peer.rb
29
+ - bin/rubtellad.rb
30
+ - lib/config/config.rb
33
31
  - lib/rubtella.rb
34
- - lib/tcp_data.rb
35
- - rubtella.rb
36
- - rubtellad.rb
32
+ - lib/rubtella/errors.rb
33
+ - lib/rubtella/http_data.rb
34
+ - lib/rubtella/logger.rb
35
+ - lib/rubtella/peer.rb
36
+ - lib/rubtella/rubtella.rb
37
+ - lib/rubtella/tcp_data.rb
38
+ - rubtella.gemspec
37
39
  has_rdoc: true
38
40
  homepage: http://github.com/mateuszzawisza/rubtella/
39
41
  licenses: []
data/rubtella.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'config/config'
2
- require 'lib/errors'
3
- require 'lib/peer'
4
- require 'lib/tcp_data'
5
- require 'lib/http_data'
6
- require 'lib/rubtella'
File without changes
File without changes
File without changes
File without changes
File without changes