fiverr_copy 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -52,7 +52,7 @@ class FiverrCopy::Client
52
52
  end
53
53
 
54
54
  @real_file_name = ""
55
- temp_file = "fiverr_copy_#{Time.now.to_i}.tgz"
55
+ temp_file = Tempfile.new("fiverr_copy_#{Time.now.to_i}.tgz")
56
56
  Tempfile.open(temp_file) do |f|
57
57
  while (session = server.accept)
58
58
  Thread.start do
@@ -1,5 +1,12 @@
1
1
  class FiverrCopy::Recipe
2
- attr_accessor :name, :description, :filter, :clients, :username, :port, :chunk_size
2
+ attr_accessor :name,
3
+ :description,
4
+ :filter,
5
+ :clients,
6
+ :username,
7
+ :port,
8
+ :chunk_size,
9
+ :manual
3
10
 
4
11
  attr_reader :initialized_clients
5
12
 
@@ -9,11 +16,16 @@ class FiverrCopy::Recipe
9
16
  self.description = description
10
17
  self.port = 1234
11
18
  self.chunk_size = 1024
19
+ self.manual = false
12
20
  @initialized_clients = []
13
21
  yield(self)
14
22
  self
15
23
  end
16
24
 
25
+ def manual_client_activation?
26
+ self.manual == true
27
+ end
28
+
17
29
  def clients=(clients_array = [])
18
30
  raise "No clients specified" if clients_array.empty?
19
31
  clients_array.uniq!
@@ -36,6 +48,7 @@ class FiverrCopy::Recipe
36
48
  puts "Clients : #{self.initialized_clients.size}"
37
49
  puts "Port : #{self.port}"
38
50
  puts "Chunk : #{self.chunk_size}"
51
+ puts "Manual : #{self.manual_client_activation?}"
39
52
  puts "---------------------"
40
53
  end
41
54
  end
@@ -13,29 +13,41 @@ class FiverrCopy::Server
13
13
  def self.run!
14
14
  threads = []
15
15
  files_to_sync = Dir[self.recipe.filter]
16
- self.recipe.initialized_clients.each do |client|
17
- threads << Thread.new(client) do |current_client|
18
- current_client.setup!
19
- puts "Connecting to #{current_client.client_ip}:#{self.recipe.port}"
20
- Net::SSH.start(current_client.client_ip, current_client.username) do |ssh|
21
- ssh.exec("killall fiverr_copy")
22
- next_client = "--nexthop #{current_client.next_client}" if current_client.next_client
23
- puts "Running: fiverr_copy --client --port #{self.recipe.port} #{next_client} @ #{current_client.client_ip}"
24
- ssh.exec("fiverr_copy --client --port #{self.recipe.port} #{next_client} \&")
16
+
17
+ if !(self.recipe.manual_client_activation?)
18
+ self.recipe.initialized_clients.each do |client|
19
+ threads << Thread.new(client) do |current_client|
20
+ current_client.setup!
21
+ puts "Connecting to #{current_client.client_ip}:#{self.recipe.port}"
22
+ Net::SSH.start(current_client.client_ip, current_client.username) do |ssh|
23
+ ssh.exec("killall fiverr_copy")
24
+ next_client = "--nexthop #{current_client.next_client}" if current_client.next_client
25
+ puts "Running: fiverr_copy --client --port #{self.recipe.port} #{next_client} @ #{current_client.client_ip}"
26
+ ssh.exec("fiverr_copy --client --port #{self.recipe.port} #{next_client} \&")
27
+ end
25
28
  end
29
+ sleep 10
26
30
  end
27
- sleep 10
28
31
  end
29
32
 
30
33
  compressed_file_name = "fiverr_copy_compressed_#{Time.now.to_i}"
31
34
 
35
+ attempts = 1
32
36
  begin
33
37
  puts "Attempting Connection to #{self.recipe.initialized_clients.first.client_ip}:#{self.recipe.port}"
34
38
  client_session = TCPSocket.new(self.recipe.initialized_clients.first.client_ip, self.recipe.port)
35
39
  puts "Compressing: tar cvzf #{compressed_file_name}.tgz #{self.recipe.filter}"
36
40
  `tar cvzf #{compressed_file_name}.tgz #{self.recipe.filter}`
37
41
  rescue Errno::ECONNREFUSED => e
38
- puts "ERROR: unable to connect to #{self.recipe.initialized_clients.first.client_ip} => #{e.to_s}"
42
+ if attempts < 10
43
+ attempts += 1
44
+ sleep 1.5
45
+ print "Retry #{attempts}: "
46
+ retry
47
+ else
48
+ puts "ERROR: unable to connect to #{self.recipe.initialized_clients.first.client_ip} => #{e.to_s}"
49
+ exit 0
50
+ end
39
51
  end
40
52
 
41
53
  puts "Validating Compressed file"
@@ -49,8 +61,8 @@ class FiverrCopy::Server
49
61
  puts "Transmitting..."
50
62
 
51
63
  File.open("#{compressed_file_name}.tgz") do |transmitted_file|
52
- client_session.write "FILENAME:#{"#{compressed_file_name}.tgz"}"
53
- puts "Transmitting #{transmitted_file.basename} (#{transmitted_file.size})"
64
+ client_session.puts "FILENAME:#{"#{compressed_file_name}.tgz"}"
65
+ puts "Transmitting #{transmitted_file.to_s} (#{File.size(transmitted_file)})"
54
66
  while (buffer = transmitted_file.read(self.recipe.chunk_size)) do
55
67
  puts "Sending #{buffer.size}B"
56
68
  client_session.write buffer
@@ -1,3 +1,3 @@
1
1
  module FiverrCopy
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fiverr_copy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 11
10
- version: 0.0.11
9
+ - 12
10
+ version: 0.0.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Elad Meidar
@@ -64,7 +64,6 @@ files:
64
64
  - bin/fiverr_copy
65
65
  - elad.sql
66
66
  - fiverr_copy.gemspec
67
- - fiverr_copy_compressed_1333352437.tgz
68
67
  - lib/fiverr_copy.rb
69
68
  - lib/fiverr_copy/client.rb
70
69
  - lib/fiverr_copy/recipe.rb
Binary file