ruby-fcp 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3688159009b019973149954a320bd03b6c17764c
4
- data.tar.gz: dd51314afb436cf9d0d0644be086afde15dfc67b
3
+ metadata.gz: c1155d73ac1fae96727ec974cd20478c07b37fe3
4
+ data.tar.gz: 6473e4a1b4fb1e1b2bdc16d05294cd1c8ba8869b
5
5
  SHA512:
6
- metadata.gz: 862c30d01f87c9b7b86a372b8f277f42248ed653d64208155c28cb1b7a0f077cd68283b2b97a1a39c39197a6cbddf7ad2ea9346e86ba25fa3caff6a072541483
7
- data.tar.gz: 66d413e5bae0929a2024f550ace7ab62b20d69e4ac17c0f1c64784df9903a21507fe631febfd14565b0901e40096d28369fa633f7adda0ce285e827fa48c713d
6
+ metadata.gz: 9283b3058d5ff46d336ba3ab00084a6e548328fe702b4c58defc0101c8b324097c3c9f85171632b457b3e306c45a70d3d727b2e0cc6421435ba1b9dbce079254
7
+ data.tar.gz: dc8cff53b6c29c12eedb8fd3edbed5bb188b2a92f8b9fb6403025fe96c69a2ae2d14619fbd865f154f879d9fe0aad147d94c6b0a93cf2fc69984bca5e1ffec9e
@@ -4,10 +4,12 @@ require 'ruby-fcp/utils'
4
4
 
5
5
  class Communicator
6
6
  attr_reader :ConnectionIdentifier
7
- attr_accessor :responses, :heartbeat
7
+ attr_accessor :responses, :heartbeat, :utils
8
8
 
9
- def initialize(client,host, port, version = 2.0)
10
- @utils = Utils.new
9
+ # clients name must be unique
10
+ # This performs NodeHello operations upon initialization.
11
+ # Communicator handles packet sending and recieving and sorting
12
+ def initialize(client, host='127.0.0.1', port=9481, version = 2.0)
11
13
  @version = version
12
14
  @ConnectionIdentifier = ""
13
15
  @host = host
@@ -18,6 +20,7 @@ class Communicator
18
20
  @state = false
19
21
  @queue = Queue.new
20
22
  @heartbeat = 300
23
+ @utils = Utils.new
21
24
  connect
22
25
  end
23
26
 
@@ -125,6 +128,7 @@ class Communicator
125
128
  end
126
129
  end
127
130
 
131
+ # Send disconnect message and close the socket
128
132
  def close
129
133
  @tex.synchronize{@sock.write "Disconnect EndMessage\n"}
130
134
  @sock.close
@@ -5,31 +5,16 @@ require 'digest'
5
5
  require 'base64'
6
6
  require 'ruby-fcp/communicator'
7
7
 
8
- class FCPClient
9
-
10
- attr_accessor :utils, :com
11
-
12
- # clients name must be unique
13
- # This performs NodeHello operations upon initialization.
14
- # Communicator handles packet sending and recieving and sorting
15
- def initialize(client, host = "127.0.0.1", port = 9481)
16
- @utils = Utils.new
17
- @com = Communicator.new(client,host,port)
18
- end
8
+ class FCPClient < Communicator
19
9
 
20
10
  # Simple attribute reader for you ConnectionIdentifier
21
11
  def identifier
22
- @com.ConnectionIdentifier
23
- end
24
-
25
- # Simple attribute reader to display all responses recieved
26
- def responses
27
- @com.responses
12
+ @ConnectionIdentifier
28
13
  end
29
14
 
30
15
  # return last response from request defined by Identifier
31
16
  def last_response(id)
32
- @com.responses[id].last
17
+ @responses[id].last
33
18
  end
34
19
 
35
20
  # Simple interface to put a single file onto freenet from your disk uses ClientPut message
@@ -41,7 +26,7 @@ class FCPClient
41
26
  id = @utils.id_generate
42
27
  options = { "URI" => uri, "Identifier" => id, "UploadFrom" => 'disk', "Filename" => filename, "FileHash" => @utils.filehash_maker(id, filename,identifier), "Verbosity" => "111111111" }.merge(opts)
43
28
  options["TargetFilename"] = filename.split(File::SEPARATOR)[-1] if uri =~ /CHK@/
44
- @com.send_packet @utils.packet_mangler(options,"ClientPut")
29
+ send_packet @utils.packet_mangler(options,"ClientPut")
45
30
  #@com.fcpackets.client_put uri, id, options
46
31
  if wait
47
32
  wait_for id, /PutFailed|PutSuccessful/
@@ -59,7 +44,7 @@ class FCPClient
59
44
  def direct_put(uri,data, wait = true, opts = {})
60
45
  id = @utils.id_generate
61
46
  options = {"Identifier" => id, "URI" => uri ,"UploadFrom" => "direct", "DataLength" => data.bytesize }.merge(opts)
62
- @com.send_packet @utils.packet_mangler(options,"ClientPut").sub! "EndMessage\n", "Data\n#{data}"
47
+ send_packet @utils.packet_mangler(options,"ClientPut").sub! "EndMessage\n", "Data\n#{data}"
63
48
  if wait
64
49
  wait_for id,/PutFailed|PutSuccessful/
65
50
  else
@@ -77,7 +62,7 @@ class FCPClient
77
62
  id = @utils.id_generate
78
63
  ddarun(dir,true,false)
79
64
  options = {"Identifier" => id,"URI" => uri,"Filename" => dir, "Global" => 'true', "AllowUnreadableFiles" => 'true', "IncludeHiddenValues" => 'false'}.merge(opts)
80
- @com.send_packet @utils.packet_mangler(options,"ClientPutDiskDir")
65
+ send_packet @utils.packet_mangler(options,"ClientPutDiskDir")
81
66
  if wait
82
67
  wait_for(id,/PutFailed|PutSuccessful/)
83
68
  else
@@ -115,7 +100,7 @@ class FCPClient
115
100
  message = @utils.packet_mangler(options,"ClientPutComplexDir")
116
101
  files.each { |f| message << f[:data] if f.has_key? :data}
117
102
  puts message
118
- @com.send_packet message
103
+ send_packet message
119
104
  if wait
120
105
  wait_for(id,/PutFailed|PutSuccessful/)
121
106
  else
@@ -126,7 +111,7 @@ class FCPClient
126
111
  # performs TestDDARequest and TestDDAResponse automagically
127
112
  # read and write are true or false values
128
113
  def ddarun(directory,read, write)
129
- @com.send_packet @utils.packet_mangler({"Directory" => directory,"WantReadDirectory" => read, "WantWriteDirectory" => write} ,"TestDDARequest")
114
+ send_packet @utils.packet_mangler({"Directory" => directory,"WantReadDirectory" => read, "WantWriteDirectory" => write} ,"TestDDARequest")
130
115
  res = wait_for(:dda, /TestDDAReply/).pop
131
116
  content = nil
132
117
  if write
@@ -136,7 +121,7 @@ class FCPClient
136
121
  elsif read
137
122
  content = File.open(res["ReadFilename"],'r').read
138
123
  end
139
- @com.send_packet @utils.packet_mangler({"Directory" => directory,"ReadContent" => content}, "TestDDAResponse")
124
+ send_packet @utils.packet_mangler({"Directory" => directory,"ReadContent" => content}, "TestDDAResponse")
140
125
  response = wait_for(:dda ,/TestDDAComplete/).pop
141
126
  File.delete(res["WriteFilename"]) if write
142
127
  response
@@ -149,7 +134,7 @@ class FCPClient
149
134
  saveloc = File.join directory, uri.split('/')[-1]
150
135
  ddarun(directory,false, true)
151
136
  options = {"URI" => uri, "Identifier" => id, "ReturnType" => 'disk', "Filename" => saveloc, "TempFilename" => saveloc+".tmp" , "Persistence" => 'forever', "Global" => false, "Verbosity" => 1111111}.merge(opts)
152
- @com.send_packet @utils.packet_mangler(options,"ClientGet")
137
+ send_packet @utils.packet_mangler(options,"ClientGet")
153
138
  if wait
154
139
  wait_for(id,/GetFailed|DataFound/)
155
140
  else
@@ -160,7 +145,7 @@ class FCPClient
160
145
  def direct_get(uri ,wait = true, opts={})
161
146
  id = @utils.id_generate
162
147
  options = {"URI" => uri, "Identifier" => id, "ReturnType" => 'direct', "Global" => false}.merge(opts)
163
- @com.send_packet @utils.packet_mangler(options,"ClientGet")
148
+ send_packet @utils.packet_mangler(options,"ClientGet")
164
149
  if wait
165
150
  wait_for(id,/AllData|GetFailed/)
166
151
  else
@@ -171,45 +156,45 @@ class FCPClient
171
156
  # Implements GetPluginInfo
172
157
  def get_plugin_info(pluginname, detailed = false)
173
158
  id = @utils.id_generate
174
- @com.send_packet @utils.packet_mangler({"PluginName" => pluginname, "Identifier" => id, "Detailed" => detailed },"GetPluginInfo")
159
+ send_packet @utils.packet_mangler({"PluginName" => pluginname, "Identifier" => id, "Detailed" => detailed },"GetPluginInfo")
175
160
  wait_for id, /PluginInfo/
176
161
  end
177
162
 
178
163
  # Straigt forward, ListPeers, sometimes it may choke up and give you end list peers before your peers, in that case check the id
179
164
  def listpeers
180
165
  id = @utils.id_generate
181
- @com.send_packet @utils.packet_mangler({"Identifier" => id, "WithMetaData" => true, "WithVolatile" => false},"ListPeers")
166
+ send_packet @utils.packet_mangler({"Identifier" => id, "WithMetaData" => true, "WithVolatile" => false},"ListPeers")
182
167
  wait_for id, /EndListPeers/
183
168
  end
184
169
 
185
170
  #Uses GenerateSSK
186
171
  def new_ssk_pair
187
172
  id = @utils.id_generate
188
- @com.send_packet @utils.packet_mangler({"Identifier" => id}, "GenerateSSK")
173
+ send_packet @utils.packet_mangler({"Identifier" => id}, "GenerateSSK")
189
174
  wait_for id, /SSKKeypair/
190
175
  end
191
176
 
192
177
  # returns information on a given peer not peers implements ListPeer
193
178
  def peerinfo(peer)
194
- @com.send_packet @utils.packet_mangler({"NodeIdentifier" => peer,"WithVolatile" => false,"WithMetadata" => true}, "ListPeer")
179
+ send_packet @utils.packet_mangler({"NodeIdentifier" => peer,"WithVolatile" => false,"WithMetadata" => true}, "ListPeer")
195
180
  wait_for :peer, /Peer/
196
181
  end
197
182
 
198
183
  # List all persistent request just implements ListPersistentRequest
199
184
  def list_persistent_requests
200
- @com.send_packet "ListPersistentRequests\nEndMessage\n"
185
+ send_packet "ListPersistentRequests\nEndMessage\n"
201
186
  wait_for :default ,/EndListPersistentRequests/
202
187
  end
203
188
 
204
189
  def modify_persistent_request(id,clienttoken,priorityclass)
205
- @com.send_packet @utils.packet_mangler({"Identifier" => id,"ClientToken" => clienttoken, "PriorityClass" => priorityclass}, "ModifyPersistentRequest")
190
+ send_packet @utils.packet_mangler({"Identifier" => id,"ClientToken" => clienttoken, "PriorityClass" => priorityclass}, "ModifyPersistentRequest")
206
191
  wait_for id, /PersistentRequestModified/
207
192
  end
208
193
 
209
194
  #subscirbe to a usk, have to poll it yourself by using responses[id]
210
195
  def subscribe_usk(uri, wait = false ,opts ={})
211
196
  id = @utils.id_generate
212
- @com.send_packet @utils.packet_mangler({"URI" => uri, "Identifier" => id} ,"SubscribeUSK")
197
+ send_packet @utils.packet_mangler({"URI" => uri, "Identifier" => id} ,"SubscribeUSK")
213
198
  id
214
199
  end
215
200
 
@@ -221,13 +206,13 @@ class FCPClient
221
206
  end
222
207
 
223
208
  def unsubscribe_usk(id)
224
- @com.send_packet "UnsubscribeUSK\nIdentifier=#{id}\nEndMessage\n"
209
+ send_packet "UnsubscribeUSK\nIdentifier=#{id}\nEndMessage\n"
225
210
  id
226
211
  end
227
212
 
228
213
  def proberequest(type,hopstolive=25,wait = true)
229
214
  id = @utils.id_generate
230
- @com.send_packet @utils.packet_mangler({"Identifier" => id,"Type" => type,"HopsToLive" => hopstolive}, "ProbeRequest")
215
+ send_packet @utils.packet_mangler({"Identifier" => id,"Type" => type,"HopsToLive" => hopstolive}, "ProbeRequest")
231
216
  if wait
232
217
  wait_for id,/Probe/
233
218
  else
@@ -240,8 +225,8 @@ class FCPClient
240
225
  response = [ ]
241
226
  loop do
242
227
  begin
243
- x = @com.responses[id].pop
244
- print @com.responses[:error].pop
228
+ x = @responses[id].pop
229
+ print @responses[:error].pop
245
230
  rescue
246
231
  sleep(2)
247
232
  end
@@ -269,30 +254,25 @@ class FCPClient
269
254
  def wait_for_ever(id)
270
255
  loop do
271
256
  begin
272
- x = @com.responses[id].pop
257
+ x = @responses[id].pop
273
258
  rescue
274
259
  print '.'
275
260
  sleep(2)
276
- print @com.responses[:error]
277
- print @com.responses[:default]
261
+ print @responses[:error]
262
+ print @responses[:default]
278
263
  end
279
264
  unless x.nil?
280
265
  x.each { |key, value| puts "#{key}=#{value}" }
281
266
  else
282
267
  print '.'
283
268
  sleep(1)
284
- puts @com.responses[:error]
285
- print @com.responses[:default]
269
+ puts @responses[:error]
270
+ print @responses[:default]
286
271
  end
287
272
  end
288
273
  end
289
274
 
290
- # Send disconnect message and close the socket
291
- def close
292
- @com.close
293
- end
294
-
295
275
  def killswitch
296
- @com.send_packet "Shutdown\nEndMessage\n"
276
+ send_packet "Shutdown\nEndMessage\n"
297
277
  end
298
278
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-fcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - hikiko