indexing description: "Discovery service example" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" class DISCOVERY inherit L4E_PRIORITY_CONSTANTS THREAD_CONTROL ARGUMENTS create make feature {NONE} -- Initialization make is -- Create discovery example client local vampeer: P2P_PLATFORM failed: BOOLEAN do if not failed and argument_count = 1 then -- create stdout logger create_logger -- create vampeer platform vampeer := configure_platform if vampeer.module_status /= vampeer.init_failed then -- now start platform vampeer.start if vampeer.module_status = vampeer.start_ok then -- wait for connection from until npg.rendezvous_service.is_connected loop sleep (250000000) end -- publish our peer advertisement npg.discovery_service.publish_advertisement_remotely (npg.peer_advertisement, Void) -- query for peers query_for_peers sleep (60000000000) -- wait 1 minute end end elseif argument_count /= 1 then io.put_string ("Usage: " + argument (0) + " ConfigDirectory") io.new_line end -- stop platform if vampeer /= Void and vampeer.module_status = vampeer.start_ok then vampeer.stop end rescue failed := True retry end feature -- Access logger: L4E_LOGGER npg: P2P_PEERGROUP feature {NONE} -- Implementation create_logger is -- Create log hierarchy and set `logger' local log_hierarchy: L4E_HIERARCHY log_appender: L4E_APPENDER log_layout: L4E_DATE_TIME_LAYOUT do create log_hierarchy.make (info_p) logger := log_hierarchy.root create {L4E_STDOUT_APPENDER} log_appender.make ("stdoutapp") create log_layout log_appender.set_layout (log_layout) logger.add_appender (log_appender) ensure Logger_set: logger /= Void end configure_platform: P2P_PLATFORM is -- Configure platform and initialize net peer group local conf: P2P_CONFIGURATION do create Result.make (argument (1), logger) if not Result.is_configured then conf := Result.default_configuration conf.set_name ("discovery") conf.set_description ("Sends discovery query and waits for responses") Result.configure (conf) end if Result.is_configured then npg := Result.standard_net_peergroup end end discovery_response_handler (response: P2P_DISCOVERY_RESPONSE) is -- Handles discovery response for registered query require Response_valid: response /= Void and response.is_valid do if response.peer_advertisement /= Void then logger.info ("New discovered peer: %N" + response.peer_advertisement.out + "%N%N") end from response.responses.start until response.responses.after loop logger.info ("New discovered peer: %N" + response.responses.item_for_iteration.out + "%N%N") response.responses.forth end end query_for_peers is -- Send general peer discovery query local query: P2P_DISCOVERY_QUERY do create query.make ({P2P_DISCOVERY_SERVICE}.type_peer) query.set_threshold (10) npg.discovery_service.query_remote_advertisements (query, Void, agent discovery_response_handler) logger.info ("Discovery request sent.") end end