fiverr_copy 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/fiverr_copy +11 -1
- data/lib/fiverr_copy/client.rb +19 -21
- data/lib/fiverr_copy/server.rb +13 -10
- data/lib/fiverr_copy/version.rb +1 -1
- metadata +3 -3
data/bin/fiverr_copy
CHANGED
@@ -35,6 +35,16 @@ optparse = OptionParser.new do |opts|
|
|
35
35
|
options[:next_hop] = next_hop
|
36
36
|
end
|
37
37
|
|
38
|
+
options[:filename] = "fiverr_copy_compressed_#{Time.now}.tgz"
|
39
|
+
opts.on( '-f', '--filename FILENAME', 'Specify filename' ) do |filename|
|
40
|
+
options[:filename] = filename
|
41
|
+
end
|
42
|
+
|
43
|
+
options[:chunk_size] = 1024
|
44
|
+
opts.on( '-w', '--chunk CHUNK_SIZE', 'specify chunk size' ) do |chunk_size|
|
45
|
+
options[:chunk_size] = chunk_size
|
46
|
+
end
|
47
|
+
|
38
48
|
# This displays the help screen, all programs are
|
39
49
|
# assumed to have this option.
|
40
50
|
opts.on( '-h', '--help', 'Display this screen' ) do
|
@@ -55,6 +65,6 @@ if options[:mode] == :server
|
|
55
65
|
FiverrCopy::Server.run!
|
56
66
|
end
|
57
67
|
else
|
58
|
-
FiverrCopy::Client.run!(options[:port], options[:next_hop])
|
68
|
+
FiverrCopy::Client.run!(options[:port], options[:next_hop], options[:filename], options[:chunk_size])
|
59
69
|
end
|
60
70
|
|
data/lib/fiverr_copy/client.rb
CHANGED
@@ -41,39 +41,37 @@ class FiverrCopy::Client
|
|
41
41
|
end
|
42
42
|
|
43
43
|
|
44
|
-
def self.run!(port, next_client)
|
44
|
+
def self.run!(port, next_client, filename, chunk)
|
45
|
+
puts "FiverrCopy client initializing"
|
45
46
|
server = TCPServer.new(port)
|
47
|
+
|
48
|
+
session = server.accept
|
49
|
+
|
46
50
|
client_session = nil
|
47
51
|
if !(next_client.nil?)
|
48
|
-
puts "
|
52
|
+
puts "Connecting to next hop at #{next_client}:#{port}"
|
49
53
|
client_session = TCPSocket.new(next_client, port)
|
50
54
|
else
|
51
|
-
puts "
|
55
|
+
puts "Last hop mode"
|
52
56
|
end
|
53
57
|
|
54
|
-
@real_file_name = ""
|
55
58
|
temp_file = Tempfile.new("fiverr_copy_#{Time.now.to_i}.tgz")
|
56
59
|
Tempfile.open(temp_file) do |f|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
Thread.start do
|
61
|
+
while (stream = session.read(chunk)) do
|
62
|
+
|
63
|
+
puts "Connection from #{session.peeraddr[2]} at #{session.peeraddr[3]}"
|
64
|
+
|
62
65
|
|
63
|
-
|
66
|
+
puts "Got #{stream.size} bytes"
|
67
|
+
f.write stream
|
64
68
|
|
65
|
-
|
66
|
-
@real_file_name = stream.chomp.split(":").last
|
67
|
-
puts "log: Recieving #{@real_file_name}"
|
68
|
-
else
|
69
|
-
puts "log: got #{stream.size} bytes"
|
70
|
-
f.write stream
|
71
|
-
end
|
72
|
-
client_session.puts(stream) if !(next_client.nil?)
|
69
|
+
client_session.write(stream) if !(next_client.nil?)
|
73
70
|
session.puts "OK:#{stream.size}"
|
74
|
-
end
|
75
|
-
end
|
71
|
+
end
|
72
|
+
end #end thread conversation
|
76
73
|
end
|
77
|
-
|
74
|
+
puts "Done."
|
75
|
+
FileUtils.mv(temp_file, "#{Dir.pwd}/#{filename}")
|
78
76
|
end
|
79
77
|
end
|
data/lib/fiverr_copy/server.rb
CHANGED
@@ -14,6 +14,8 @@ class FiverrCopy::Server
|
|
14
14
|
threads = []
|
15
15
|
files_to_sync = Dir[self.recipe.filter]
|
16
16
|
|
17
|
+
compressed_file_name = "fiverr_copy_compressed_#{Time.now.to_i}.tgz"
|
18
|
+
|
17
19
|
if !(self.recipe.manual_client_activation?)
|
18
20
|
self.recipe.initialized_clients.each do |client|
|
19
21
|
threads << Thread.new(client) do |current_client|
|
@@ -22,22 +24,22 @@ class FiverrCopy::Server
|
|
22
24
|
Net::SSH.start(current_client.client_ip, current_client.username) do |ssh|
|
23
25
|
ssh.exec("killall fiverr_copy")
|
24
26
|
next_client = "--nexthop #{current_client.next_client}" if current_client.next_client
|
25
|
-
puts "
|
26
|
-
ssh.exec("fiverr_copy --client --port #{self.recipe.port} #{next_client} \&")
|
27
|
+
puts "#{current_client}: fiverr_copy --client --port #{self.recipe.port} --filename #{compressed_file_name} --chunk #{self.recipe.chunk_size} #{next_client} \&"
|
28
|
+
ssh.exec("fiverr_copy --client --port #{self.recipe.port} --filename #{compressed_file_name} --chunk #{self.recipe.chunk_size} #{next_client} \&")
|
27
29
|
end
|
28
30
|
end
|
29
31
|
sleep 10
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
|
35
|
+
|
34
36
|
|
35
37
|
attempts = 1
|
36
38
|
begin
|
37
39
|
puts "Attempting Connection to #{self.recipe.initialized_clients.first.client_ip}:#{self.recipe.port}"
|
38
40
|
client_session = TCPSocket.new(self.recipe.initialized_clients.first.client_ip, self.recipe.port)
|
39
|
-
puts "Compressing: tar cvzf #{compressed_file_name}
|
40
|
-
`tar cvzf #{compressed_file_name}
|
41
|
+
puts "Compressing: tar cvzf #{compressed_file_name} #{self.recipe.filter}"
|
42
|
+
`tar cvzf #{compressed_file_name} #{self.recipe.filter}`
|
41
43
|
rescue Errno::ECONNREFUSED => e
|
42
44
|
if attempts < 10
|
43
45
|
attempts += 1
|
@@ -51,7 +53,7 @@ class FiverrCopy::Server
|
|
51
53
|
end
|
52
54
|
|
53
55
|
puts "Validating Compressed file"
|
54
|
-
if !(FileTest.exists?("#{compressed_file_name}
|
56
|
+
if !(FileTest.exists?("#{compressed_file_name}"))
|
55
57
|
puts "Could not find the compressed file to transfer:"
|
56
58
|
puts `ls *.tgz`
|
57
59
|
puts "exiting"
|
@@ -60,13 +62,14 @@ class FiverrCopy::Server
|
|
60
62
|
|
61
63
|
puts "Transmitting..."
|
62
64
|
|
63
|
-
File.open("#{compressed_file_name}
|
64
|
-
client_session.puts "FILENAME:#{"#{compressed_file_name}
|
65
|
+
File.open("#{compressed_file_name}") do |transmitted_file|
|
66
|
+
client_session.puts "FILENAME:#{"#{compressed_file_name}"}"
|
65
67
|
puts "Transmitting #{transmitted_file.to_s} (#{File.size(transmitted_file)})"
|
66
|
-
while (buffer = transmitted_file.read(self.recipe.chunk_size)) do
|
68
|
+
while !(client_session.closed?) && (client_response = client_session.gets) && (buffer = transmitted_file.read(self.recipe.chunk_size)) do
|
67
69
|
puts "Sending #{buffer.size}B"
|
68
|
-
client_session.
|
70
|
+
client_session.puts buffer
|
69
71
|
end
|
72
|
+
puts "Done!"
|
70
73
|
end
|
71
74
|
|
72
75
|
end
|
data/lib/fiverr_copy/version.rb
CHANGED
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:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 13
|
10
|
+
version: 0.0.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Elad Meidar
|