rncp 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.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rncp'
4
+
5
+ RNCP::Cli::CommandLineRunner.run
@@ -0,0 +1,39 @@
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/version'
15
+
16
+ require 'clamp'
17
+
18
+ require 'rncp/listen_cmd'
19
+ require 'rncp/send_cmd'
20
+ require 'rncp/poll_cmd'
21
+ require 'rncp/push_cmd'
22
+
23
+ module RNCP
24
+ def self.version_string
25
+ "RNCP version #{RNCP::VERSION}"
26
+ end
27
+
28
+ module Cli
29
+ class CommandLineRunner < Clamp::Command
30
+ self.default_subcommand = "listen"
31
+
32
+ subcommand 'listen', "runs in listener mode, waits for connection", ListenCommand
33
+ subcommand 'send', "sends files to a listener mode receiver", SendCommand
34
+ subcommand 'push', "broadcasts for clients, waits for connection", PushCommand
35
+ subcommand 'poll', "waits for broadcast, connects to broadcaster", PollCommand
36
+ end
37
+ end # Cli
38
+ end
39
+
@@ -0,0 +1,65 @@
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'zlib'
15
+ require 'archive/tar/minitar'
16
+ require 'stringio'
17
+
18
+ module RNCP
19
+ module Files
20
+ def directory_list(path)
21
+ return [path].flatten if File.directory?(path) == false
22
+
23
+ data = []
24
+ Dir["#{path}**/*", "#{path}**/.*"].each do |entry|
25
+ next if entry[/^.*\/\.+$/]
26
+ data << directory_list(entry)
27
+ end
28
+ return data.flatten
29
+ end # directory_list
30
+
31
+ def tar(files)
32
+ data = StringIO.new("")
33
+ sgz = Zlib::GzipWriter.new(data)
34
+ tar = Archive::Tar::Minitar::Output.new sgz
35
+
36
+ puts "[#] start writing files"
37
+ files.each do |f|
38
+ directory_list(f).each do |entry|
39
+ puts "[*] adding: #{entry}"
40
+ Archive::Tar::Minitar.pack_file(entry, tar)
41
+ end
42
+ end
43
+
44
+ sgz.flush
45
+ sgz.close
46
+ sgz = nil
47
+
48
+ data.rewind
49
+ return data
50
+ end # tar
51
+
52
+ def untar(data)
53
+ sgz = Zlib::GzipReader.new(StringIO.new(data))
54
+ tar = Archive::Tar::Minitar::Input.new sgz
55
+
56
+ tar.each do |entry|
57
+ puts "[*] #{entry.name}"
58
+ tar.extract_entry "./", entry
59
+ end
60
+
61
+ sgz.close
62
+ end # untar
63
+
64
+ end # Files
65
+ end # RNCP
@@ -0,0 +1,26 @@
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/listener'
15
+
16
+ module RNCP
17
+ module Cli
18
+ class ListenCommand < Clamp::Command
19
+
20
+ def execute
21
+ RNCP::NcpListener.new.listen
22
+ end
23
+
24
+ end # ListenCommand
25
+ end # Cli
26
+ end # RNCP
@@ -0,0 +1,84 @@
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/networking'
15
+ require 'rncp/files'
16
+
17
+ module RNCP
18
+ class NcpListener
19
+ include RNCP::Networking
20
+ include RNCP::Files
21
+
22
+ def initialize
23
+ end
24
+
25
+ def listen
26
+ puts "[#] rncp Listener: creating new connection"
27
+ l = bind_tcp
28
+ puts "[*] waiting for connections"
29
+
30
+ sock, info = l.accept
31
+ printf "[*] connection from %s:%s\n", info.ip_address, info.ip_port
32
+ puts "[*] receiving..."
33
+
34
+ data = ""
35
+ while (sock.eof? == false)
36
+ data += sock.gets()
37
+ end
38
+
39
+ untar data
40
+ puts "[*] received: "
41
+
42
+ puts "[#] finished"
43
+ sock.close
44
+ l.close
45
+ end # listen
46
+
47
+ def poll
48
+ addr = nil
49
+ msock = join_multicast
50
+ puts "[*] waiting for something-cast"
51
+ loop do
52
+ begin
53
+ data, addr = msock.recvfrom 1024
54
+ if addr[1] == RNCP::PORT
55
+ puts "[*] found pusher at #{addr[3]}:#{addr[1]}"
56
+ puts "[#] Anouncement: #{data}"
57
+ break
58
+ else
59
+ puts "[?] received garbase from #{addr}"
60
+ end
61
+ rescue Execeptione => e
62
+ puts "exception #{e}"
63
+ end # begin
64
+ end #loop
65
+
66
+ msock.close if msock.nil? == false
67
+
68
+ sock = TCPSocket::new addr[3], addr[1]
69
+ sock.send "I am ready!", 0
70
+
71
+ data = ""
72
+ while (sock.eof? == false)
73
+ data += sock.gets()
74
+ end
75
+
76
+ untar data
77
+ puts "[*] received: "
78
+
79
+ puts "[#] finished"
80
+ sock.close
81
+ end # poll
82
+
83
+ end # NcpListener
84
+ end # RNCP
@@ -0,0 +1,54 @@
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'socket'
15
+ require 'ipaddr'
16
+ require 'rncp/params'
17
+
18
+ module RNCP
19
+ module Networking
20
+ def bind_tcp
21
+ sock = Socket::new Socket::AF_INET, Socket::SOCK_STREAM, 0
22
+ opts = [1].pack("i")
23
+ addr = [Socket::AF_INET, RNCP::PORT, 0, 0, 0, 0, 0, 0]
24
+ .pack("snCCCCNN")
25
+
26
+ sock.setsockopt Socket::SOL_SOCKET, Socket::SO_REUSEADDR, opts
27
+ sock.bind addr
28
+ sock.listen 1
29
+ return sock
30
+ end # bind_tcp
31
+
32
+ def join_multicast
33
+ msock = UDPSocket.new
34
+ membership = IPAddr.new(RNCP::IPV4_GROUP).hton +
35
+ IPAddr.new("0.0.0.0").hton
36
+
37
+ puts "[#] Joining Multicast group"
38
+ msock.setsockopt :IPPROTO_IP, :IP_ADD_MEMBERSHIP, membership
39
+ msock.setsockopt :SOL_SOCKET, :SO_REUSEADDR, 1
40
+ msock.bind "0.0.0.0", RNCP::PORT
41
+
42
+ return msock
43
+ end # join_multicast
44
+
45
+ def bind_multicast
46
+ msock = UDPSocket.open
47
+ msock.setsockopt :IPPROTO_IP, :IP_MULTICAST_TTL, [32].pack("i")
48
+ msock.setsockopt :SOL_SOCKET, :SO_REUSEADDR, 1
49
+ msock.bind '', RNCP::PORT
50
+ msock.setsockopt :IPPROTO_IP, :IP_MULTICAST_LOOP, 1
51
+ return msock
52
+ end # bind_multicast
53
+ end # Networking
54
+ end # RNCP
@@ -0,0 +1,22 @@
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/version'
15
+
16
+ module RNCP
17
+ IPV4_GROUP = '224.110.99.112'
18
+ IPV4_BC = '255.255.255.255'
19
+ PORT = 8002
20
+ MC_MSG = "Multicasting for rncp Version #{RNCP::VERSION}"
21
+ BC_MSG = "Broadcasting for rncp Version #{RNCP::VERSION}"
22
+ end
@@ -0,0 +1,27 @@
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/listener'
15
+
16
+ module RNCP
17
+ module Cli
18
+ class PollCommand < Clamp::Command
19
+
20
+ def execute
21
+ RNCP::NcpListener.new.poll
22
+ end
23
+
24
+ end # PollCommand
25
+ end # Cli
26
+ end # RNCP
27
+
@@ -0,0 +1,29 @@
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/pusher'
15
+
16
+ module RNCP
17
+ module Cli
18
+ class PushCommand < Clamp::Command
19
+
20
+ parameter "FILE ...", "Files to send"
21
+
22
+ def execute
23
+ RNCP::NcpPusher.new.push file_list
24
+ end
25
+
26
+ end # PushCommand
27
+ end # Cli
28
+ end # RNCP
29
+
@@ -0,0 +1,109 @@
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/networking'
15
+ require 'stringio'
16
+ require 'fileutils'
17
+ require 'zlib'
18
+ require 'archive/tar/minitar'
19
+ require 'tempfile'
20
+
21
+ module RNCP
22
+ class NcpPusher
23
+ include RNCP::Networking
24
+ include RNCP::Files
25
+
26
+ def initialize
27
+ end
28
+
29
+ def send_to(ip, files)
30
+ begin
31
+ puts "[*] copying #{files} to ip : #{ip}"
32
+ sock = TCPSocket::new ip, RNCP::PORT
33
+ sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
34
+
35
+ data = tar files
36
+
37
+ sock.send data.string, 0
38
+ sock.flush
39
+
40
+ rescue Exception => e
41
+ puts "[!] cannot create connection to host, bailing out"
42
+ puts e
43
+ ensure
44
+ sock.close if sock.nil? == false
45
+ puts "[#] finished"
46
+ end
47
+ end # send_to
48
+
49
+ def push(files)
50
+ begin
51
+ sock = nil
52
+ addr = nil
53
+ msock = bind_multicast
54
+
55
+ # check broadcast
56
+
57
+ if msock.nil? == true
58
+ puts "[!] cannot continue without atleast one announcement socket!"
59
+ return 1
60
+ end
61
+
62
+ dsock = bind_tcp
63
+
64
+ if dsock.nil? == true
65
+ puts "[!] cannot continue without data socket"
66
+ return -1
67
+ end
68
+
69
+ puts "[*] starting X-Casting, waiting for TCP connect"
70
+ while sock.nil? == true
71
+ if msock.nil? == false
72
+ msock.send RNCP::MC_MSG, 0, RNCP::IPV4_GROUP, RNCP::PORT
73
+ end
74
+ # Broadcast
75
+ puts "."
76
+ result = select( [dsock], nil, nil, 2 )
77
+
78
+ next if result.nil? == true
79
+ for inp in result[0]
80
+ if inp == dsock
81
+ sock, addr = dsock.accept
82
+ printf "[*] connection from %s:%s\n",
83
+ addr.ip_address, addr.ip_port
84
+ puts "[*] Client answer: #{sock.recv 1024}"
85
+ end # if
86
+ end # for inp
87
+ end # while sock.nil?
88
+
89
+ msock.close if msock.nil? == false
90
+ msock = nil
91
+ dsock.close if dsock.nil? == false
92
+ dsock = nil
93
+
94
+ data = tar files
95
+
96
+ sock.send data.string, 0
97
+ sock.flush
98
+ rescue Exception => e
99
+ puts "[!] cannot push data, bailing out"
100
+ puts e
101
+ ensure
102
+ sock.close if sock.nil? == false
103
+ puts "[*] finished"
104
+ msock.close if msock.nil? == false
105
+ dsock.close if dsock.nil? == false
106
+ end # begin
107
+ end # push
108
+ end # NcpPusher
109
+ end # RNCP
@@ -0,0 +1,30 @@
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/pusher'
15
+
16
+ module RNCP
17
+ module Cli
18
+ class SendCommand < Clamp::Command
19
+
20
+ parameter "IP", "Destination IP Address"
21
+ parameter "FILE ...", "Files to send"
22
+
23
+ def execute
24
+ RNCP::NcpPusher.new.send_to ip, file_list
25
+ end
26
+
27
+ end # ListenCommand
28
+ end # Cli
29
+ end # RNCP
30
+
@@ -0,0 +1,17 @@
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ module RNCP
16
+ VERSION = '0.0.1'
17
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rncp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Parent
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitar
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.5.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.5.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: clamp
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.3'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.3'
46
+ description: A port of NCP written in Ruby
47
+ email:
48
+ - jecxjo@sdf.lonestar.org
49
+ executables:
50
+ - rncp
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - lib/rncp.rb
55
+ - lib/rncp/params.rb
56
+ - lib/rncp/listener.rb
57
+ - lib/rncp/files.rb
58
+ - lib/rncp/pusher.rb
59
+ - lib/rncp/listen_cmd.rb
60
+ - lib/rncp/poll_cmd.rb
61
+ - lib/rncp/version.rb
62
+ - lib/rncp/send_cmd.rb
63
+ - lib/rncp/networking.rb
64
+ - lib/rncp/push_cmd.rb
65
+ - bin/rncp
66
+ homepage: http://github.com/jecxjo/rncp
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.23
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: a fast file copy tool for LANs
90
+ test_files: []