require File.expand_path('../abstract_node.rb',__FILE__) require 'secure_con.rb' class WrongProtocol@protocol, :connections=>connections.length } end def connect(rnodeId) return if nodeList.member?(rnodeId) raise "Can't connect to myself" if rnodeId==nodeId begin pp "NODE-ID #{rnodeId}" pp "NODE-ID #{rnodeId.protocol}" raise WrongProtocol if rnodeId.protocol!=:secure puts "#{nodeId} CONNCTING #{rnodeId} " c=super(rnodeId.address,rnodeId.port) puts "#{nodeId} CONNECTED #{rnodeId} " Thread.new { @nodeList << c.identifyMe(nodeId) @app.log "connected #{nodeId}" } c rescue ConnectionClosed=>e nil end end def getConnection(rNodeId) connections.select{|c|c.remoteHost==rNodeId.address and c.remotePort==rNodeId.port}[0] end def sendAll(*s) connections.p_map{|c| begin c.remoteCallSync(*s) rescue ConnectionClosed=>e :nothing end }.select{|x|x!=:nothing} end # FIXME: may be deprecated def setHook(&hook) @hook=hook end remote :remoteCall, :close remote_sync :remoteCallSync, :identifyMe allow :remoteCall, :identifyMe, :remoteCallSync def remoteCall(name,*s) pp "RemoteCall #{name}" @hook.call(name,*s) end def remoteCallSync(name,*s) pp "RemoteCall #{name}" @hook.call(name,*s) end def eventConnected(host,port) super all=connections.select{|i|i.remoteHost==host and i.remotePort==port} if all.length>1 pp "FOUND:",all.length all[1..-1].each{|c| pp "NOT YET CLOSE #{c}" #c.disconnect # close last in list } end end #end def identifyMe(pid) connection=getConnection(pid) @nodeList<