Revision c2b0e202
Added by Marc Dequènes almost 14 years ago
- ID c2b0e20294b329ca5e9bd42157532d301938b8f5
lib/cyborghood/cyborg/botnet.rb | ||
---|---|---|
|
||
module CyborgHood
|
||
module BotNet
|
||
attr_reader :interface
|
||
|
||
CORE_API_VERSION = "1.0~"
|
||
|
||
def self.included(base)
|
||
... | ... | |
end
|
||
|
||
def define_interface(version, &block)
|
||
@interface = DSL::ServerApiNode.new(self, &block)
|
||
@interface.add_behavior do
|
||
node "_cyborg_" do
|
||
on_request do |request|
|
||
request.reply.results = {
|
||
:name => bot.name,
|
||
:product_name => PRODUCT,
|
||
:product_version => VERSION,
|
||
:core_api_version => CORE_API_VERSION,
|
||
:cyborg_api_version => version
|
||
}
|
||
@interface_creation = Proc.new do
|
||
interface = DSL::ServerApiNode.new(self, &block)
|
||
# additional behavior to comply with the Cyborg API
|
||
interface.add_behavior do
|
||
node "_cyborg_" do
|
||
on_request do |request|
|
||
request.reply.results = {
|
||
:name => bot.name,
|
||
:product_name => PRODUCT,
|
||
:product_version => VERSION,
|
||
:core_api_version => CORE_API_VERSION,
|
||
:cyborg_api_version => version
|
||
}
|
||
end
|
||
end
|
||
end
|
||
end
|
||
interface
|
||
end # @interface_creation
|
||
end
|
||
|
||
def interface
|
||
# recreate dynamic interface each time, to ensure concurrent calls do not clash
|
||
@interface_creation.call
|
||
end
|
||
|
||
def contact_peer(peer, block, dont_open_new_connection = false)
|
Also available in: Unified diff
[fix] recreate the whole API interface tree, root included, to ensure no clash is possible during concurrent calls