Project

General

Profile

« Previous | Next » 

Revision d57fd602

Added by Marc Dequènes about 14 years ago

  • ID d57fd602139e64243c0192e0db3c39bfddbf943f

[evol] add client support to BotNet

View differences:

lib/cyborghood/cyborg/botnet.rb
include CyborgServerRootInterfaceAddon
end
module BotNetClientUNIXSocket
def peer_socket(peer)
File.join(Config::RUN_DIR, peer.downcase + ".sock")
end
def contact_peer(peer, &block)
if @comm_list.has_key? peer
block.call @comm_list[peer]
else
EventMachine.connect_unix_domain(peer_socket(peer), Conversation, self, &block)
end
end
end
module BotNet
attr_reader :interface
def self.included(base)
case Config.instance.botnet.connection_type
when 'unix_socket'
return base.class_eval("include BotNetClientUNIXSocket")
else
raise CyberError.new(:unrecoverable, "config", "Unknown botnet connection type")
end
end
def setup
super
@comm_list = {}
lib/cyborghood/cyborg/botnet_server.rb
module BotNetServerUNIXSocket
def setup
super
@socket = File.join(Config::RUN_DIR, @config.bot_name.downcase + ".sock")
@socket = peer_socket(@config.bot_name)
at_exit { remove_socket_file }
end
lib/cyborghood/cyborg/conversation.rb
attr_reader :bot
def initialize(bot)
def initialize(bot, &block)
@bot = bot
@comm_logic_block = block
super
......
@bot.register_communication @peer_id, self
end
def set_comm_ready
@comm_logic_block.call self
end
def set_error_status(fatal = false)
# fatal status is conservative, it cannot be canceled
@reveive_fatal_error = @reveive_fatal_error || fatal
......
end
def send_line(msg)
return if error?
logger.debug "Sending data [#{identifier}]: #{msg}"
send_data "#{msg}\n"
end
......
unless msg_quit.nil?
send_quit_decline msg_quit
@comm_logic_block.call false
close_connection_after_writing
end
end
lib/cyborghood/cyborg/protocol.rb
if @negociation_sent
send_announce_ok(message)
@negociation_ok = true
@conversation.set_comm_ready
else
send_announce_helo(message)
@negociation_sent = true

Also available in: Unified diff