BotnetV2 1.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b511120a79c8dfb4146818da5f14c7c83b0fe440
4
- data.tar.gz: 360c51c97647b13819c9588d18d8201122c1f074
3
+ metadata.gz: b7e73d7fbd098e9930c730c8983980ed1f831efc
4
+ data.tar.gz: 970cc0f1a5f27dea9bd5b76d04925a58b5ae0bdf
5
5
  SHA512:
6
- metadata.gz: b7341772937b5c9486ad63b925f9ed66f05cf8802a6df17e4f2b70857d04f7ef0116033793ca76f7e56ddf0bc0bef9bcabb87c04e8c8128cffacf60d12e47f7f
7
- data.tar.gz: 33f04c08ca82956da34879ddc3955feb2f02784dbb4d77cf0723f8ffe5c8c645d03d0e85476ccea97105037b82aa5affcde0afe4cdd680161ddf08cd6be404f4
6
+ metadata.gz: 5236d40fb87dbdfe04810f8fbb88927793bc11f9058eac5f530b3f76af09f9ed067dd178c6f8ae99c3b19b9a43fea472f2e85be29d0927583d117b87310942f1
7
+ data.tar.gz: e9fa0084cd5384a8a0f401982e6a43b4d8d59d8c5e18211c869c3ca964ff60584f8bffb217a1b79d0fe63e65edaf13e21992001eba513eb1b006e2db2426d259
data/BotnetV2.gemspec CHANGED
@@ -14,12 +14,12 @@ require 'securerandom'
14
14
  Gem::Specification.new do |spec|
15
15
  spec.name = "BotnetV2"
16
16
  spec.version = BotnetV2::VERSION
17
- spec.authors = ["Michael Fürst"]
17
+ spec.authors = ["Penguinmenac3"]
18
18
  spec.email = ["penguinmenac3@gmail.com"]
19
19
  spec.summary = %q{A bot net to calculate intense tasks on remote machines.}
20
20
  spec.description = %q{A bot net to calculate intense tasks on remote machines.}
21
21
  spec.homepage = "https://fuersts1.homeip.net/penguinmenac3/botnetv2"
22
- spec.license = "MIT"
22
+ spec.license = "GPL"
23
23
 
24
24
  spec.files = `git ls-files -z`.split("\x0")
25
25
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -27,6 +27,13 @@ module BotnetV2
27
27
  @connection.send @onReady
28
28
  end
29
29
 
30
+ def net_status(callback)
31
+ message = Hash.new
32
+ message['status'] = SecureRandom.hex
33
+ @callbacks[message['status']] = callback
34
+ @connection.send message
35
+ end
36
+
30
37
  def execute (task_src, callback)
31
38
  message = Hash.new
32
39
  message['onWork'] = Hash.new
@@ -47,6 +54,9 @@ module BotnetV2
47
54
  end
48
55
  @callbacks[message['onResult']['task_id']].call(res, error)
49
56
  end
57
+ if message['status'] != nil
58
+ @callbacks[message['status']['task_id']].call(message['status'])
59
+ end
50
60
  end
51
61
 
52
62
  def exit!
@@ -14,6 +14,9 @@ module BotnetV2
14
14
  @ready_clients = Hash.new
15
15
  @work_bundles = Queue.new
16
16
  @result_bundles = Hash.new
17
+ @processed_tasks = 0
18
+ @started_tasks = 0
19
+ @worker_corrector = 0
17
20
  @exit = false
18
21
  @t1 = nil
19
22
  @t2 = nil
@@ -33,11 +36,15 @@ module BotnetV2
33
36
  def main_loop
34
37
  loop do
35
38
  connection = @ready_workers.pop
39
+ @worker_corrector = 1
36
40
  unless connection.closed?
37
41
  msg = Hash.new
38
42
  msg['onWork'] = @work_bundles.pop
43
+ @worker_corrector = 0
44
+ @started_tasks += 1
39
45
  connection.send msg
40
46
  end
47
+ @worker_corrector = 0
41
48
  end
42
49
  end
43
50
 
@@ -47,11 +54,27 @@ module BotnetV2
47
54
 
48
55
  def on_message (message, connection)
49
56
  @verified_clients[connection] = true if message['verify'] == @password
50
- @ready_workers << connection if message['worker_onReady'] != nil and @verified_clients[connection]
51
- @work_bundles << message['onWork'] if message['onWork'] != nil and @verified_clients[connection]
52
- @ready_clients[message['client_onDisconnect']] = nil if message['client_onDisconnect'] != nil and @verified_clients[connection]
57
+ return unless @verified_clients[connection]
58
+ @ready_workers << connection if message['worker_onReady'] != nil
59
+ @work_bundles << message['onWork'] if message['onWork'] != nil
60
+ @ready_clients[message['client_onDisconnect']] = nil if message['client_onDisconnect'] != nil
53
61
 
54
- if message['client_onReady'] != nil and @verified_clients[connection]
62
+ if message['status']
63
+ msg = Hash.new
64
+ report = Hash.new
65
+ report['ready_clients'] = @ready_clients.count
66
+ report['ready_workers'] = @ready_workers.length + @worker_corrector
67
+ report['verified_clients'] = @verified_clients.count
68
+ report['work_bundles'] = @work_bundles.length
69
+ report['result_bundles'] = count_pending_results @result_bundles
70
+ report['processed_tasks'] = @processed_tasks
71
+ report['active_tasks'] = @started_tasks - @processed_tasks
72
+ report['task_id'] = message['status']
73
+ msg['status'] = report
74
+ connection.send msg
75
+ end
76
+
77
+ if message['client_onReady'] != nil
55
78
  client_id = message['client_onReady']
56
79
  @ready_clients[client_id] = connection
57
80
  @result_bundles[client_id] = Queue.new if @result_bundles[client_id] == nil
@@ -61,7 +84,8 @@ module BotnetV2
61
84
  connection.send msg
62
85
  end
63
86
  end
64
- if message['onResult'] != nil and @verified_clients[connection]
87
+ if message['onResult'] != nil
88
+ @processed_tasks += 1
65
89
  client_id = message['onResult']['clientId']
66
90
  if @ready_clients[client_id] == nil
67
91
  @result_bundles[client_id] = Queue.new if @result_bundles[client_id] == nil
@@ -74,6 +98,14 @@ module BotnetV2
74
98
  end
75
99
  end
76
100
 
101
+ def count_pending_results(hashed_queues)
102
+ counter = 0
103
+ hashed_queues.each_key do |key|
104
+ counter += hashed_queues[key].length
105
+ end
106
+ counter
107
+ end
108
+
77
109
  def exit!
78
110
  @exit = true
79
111
  @main_loop.kill
@@ -1,3 +1,3 @@
1
1
  module BotnetV2
2
- VERSION = '1.0'
2
+ VERSION = '1.1'
3
3
  end
data/test/master_test.rb CHANGED
@@ -22,20 +22,54 @@ class MasterTest < Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  def test_create
25
+ # Create a master and a client to play with.
25
26
  master = BotnetV2::BotnetV2.create_master 'foobar'
26
- worker = BotnetV2::BotnetV2.create_worker 'foobar12', 'localhost'
27
- worker = BotnetV2::BotnetV2.create_worker 'foobar', 'localhost'
28
27
  client = BotnetV2::BotnetV2.create_client 'foobar', 1, 'localhost'
28
+ @verified_clients = 1
29
+ @ready_workers = 0
30
+ @processed_tasks = 0
31
+
32
+ # Test status of botnet...
33
+ client.net_status(Proc.new do |res| on_status(res) end)
34
+ sleep(0) until @done
35
+ @done = false
36
+
37
+ # Create a worker
38
+ worker = BotnetV2::BotnetV2.create_worker 'foobar', 'localhost'
39
+ @verified_clients = 2
40
+ @ready_workers = 1
41
+
42
+ # Now execute tasks and watch the status of the server change.
29
43
  client.execute('1+1', Proc.new do |res| on_result(res) end)
30
44
  sleep(0) until @done
45
+ @processed_tasks = 1
46
+ @done = false
47
+ client.net_status(Proc.new do |res| on_status(res) end)
48
+ sleep(0) until @done
49
+ @done = false
50
+ client.execute('1+1', Proc.new do |res| on_result(res) end)
51
+ sleep(0) until @done
52
+ @processed_tasks = 2
53
+ @done = false
54
+ client.net_status(Proc.new do |res| on_status(res) end)
55
+ sleep(0) until @done
31
56
  client.exit!
32
57
  worker.exit!
33
58
  master.exit!
34
- assert_equal(@result, 2, 'Wrong result')
59
+ end
60
+
61
+ def on_status(result)
62
+ assert_equal(result['ready_clients'], 1, "Invalid client count.")
63
+ assert_equal(result['verified_clients'], @verified_clients, "Invalid verified client count.")
64
+ assert_equal(result['ready_workers'], @ready_workers, "Invalid worker count.")
65
+ assert_equal(result['work_bundles'], 0, "Invalid worker count.")
66
+ assert_equal(result['processed_tasks'], @processed_tasks, "Invalid amount of tasks processed.")
67
+ assert_equal(result['active_tasks'], 0, "Invalid amount of tasks active.")
68
+ @done = true
35
69
  end
36
70
 
37
71
  def on_result(result)
38
- @result = result
72
+ assert_equal(result, 2, 'Wrong result')
39
73
  @done = true
40
74
  end
41
75
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: BotnetV2
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
- - Michael Fürst
7
+ - Penguinmenac3
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -62,7 +62,7 @@ files:
62
62
  - test/private.pem
63
63
  homepage: https://fuersts1.homeip.net/penguinmenac3/botnetv2
64
64
  licenses:
65
- - MIT
65
+ - GPL
66
66
  metadata: {}
67
67
  post_install_message:
68
68
  rdoc_options: []