root/lib/cyborghood/cyborg/botnet_dsl.rb @ 848944dc
e321ca6f | Marc Dequènes (Duck) | #--
|
|
# CyborgHood, a distributed system management software.
|
|||
# Copyright (c) 2009-2010 Marc Dequènes (Duck) <Duck@DuckCorp.org>
|
|||
#
|
|||
# This program is free software: you can redistribute it and/or modify
|
|||
# it under the terms of the GNU General Public License as published by
|
|||
# the Free Software Foundation, either version 3 of the License, or
|
|||
# (at your option) any later version.
|
|||
#
|
|||
# This program is distributed in the hope that it will be useful,
|
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|||
# GNU General Public License for more details.
|
|||
#
|
|||
# You should have received a copy of the GNU General Public License
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#++
|
|||
module CyborgHood
|
|||
module BotnetDSL
|
|||
848944dc | Marc Dequènes (Duck) | module BotnetTask
|
|
def ask(peer, key, cmd, *args)
|
|||
_add_subtask("botnet/peer/#{peer}/out") do |subtask|
|
|||
logger.debug "Task '#{@name}': Trying to contact peer '#{peer}'"
|
|||
@bot.contact_peer(peer) do |conv|
|
|||
if conv
|
|||
logger.debug "Task '#{@name}': Peer '#{peer}' contacted, starting conversation"
|
|||
# don't use the block call to leave the conversation thread open
|
|||
conv_thread = conv.thread(@notification_name)
|
|||
conv_thread.call(cmd, *args) do |reply|
|
|||
case reply[:status]
|
|||
when :ok
|
|||
subtask.results = {key => reply[:result]}
|
|||
when :decline
|
|||
# TODO: remove this case ???
|
|||
when :error
|
|||
subtask.errors << reply[:exception]
|
|||
5a8ebc1c | Marc Dequènes (Duck) | end
|
|
848944dc | Marc Dequènes (Duck) | subtask.finish
|
|
fd4ccbdd | Marc Dequènes (Duck) | end
|
|
848944dc | Marc Dequènes (Duck) | else
|
|
logger.debug "Task '#{@name}': Could not contact peer '#{peer}'"
|
|||
# TODO: retry (wait_timer + recursive call + counter)
|
|||
subtask.errors << CyberError.new(:unrecoverable, "botnet/client/dsl", "Task '#{@name}': could not contact peer '#{peer}'")
|
|||
subtask.finish
|
|||
fd4ccbdd | Marc Dequènes (Duck) | end
|
|
67e8f239 | Marc Dequènes (Duck) | end
|
|
end
|
|||
end
|
|||
e321ca6f | Marc Dequènes (Duck) | end
|
|
848944dc | Marc Dequènes (Duck) | ::CyborgHood::DSL::Task.class_eval do
|
|
include BotnetTask
|
|||
e321ca6f | Marc Dequènes (Duck) | end
|
|
end
|
|||
end
|