Class: Secure::SimpleServer
- Inherits:
-
Object
- Object
- Secure::SimpleServer
- Defined in:
- lib/appswarm/secure_con.rb
Class Method Summary collapse
Instance Method Summary collapse
- #connect(host, port) ⇒ Object
- #connections ⇒ Object
- #eventConnected(host, port) ⇒ Object
- #getReturn(tx, conn) ⇒ Object
- #getTxId(conn) ⇒ Object
-
#initialize(port) ⇒ SimpleServer
constructor
A new instance of SimpleServer.
- #localHost ⇒ Object
- #localPort ⇒ Object
- #remote_func?(name) ⇒ Boolean
- #remote_sync_func?(name) ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(port) ⇒ SimpleServer
Returns a new instance of SimpleServer.
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/appswarm/secure_con.rb', line 271 def initialize(port) @@allowed||=[] @remote=[] @txMutex=Mutex.new @txId=0 @server=Server.new(port) @rtMutex=Mutex.new @returns={} @exceptions={} @connections={} @identified={} @txs={} @whiteboard=Whiteboard.new @server.hookDisconnected{|from| if @txs[from] @whitebaord.put(@txs[from],:disconnected) end } @server.hook{|from,msg,time| msg=msg[0] # pp "MSG:#{msg}" if msg.is_a?(Call) if msg.type==:call name=msg.name if @@allowed.member?(name) args=msg.args finished=false begin result=self.send(name,*args) finished=true rescue Object=>e if msg.tx from.send(Call.new(:exception,name,RemoteExceptionMS.new(e),msg.tx)) end end if msg.tx if finished from.send(Call.new(:return,name,result,msg.tx)) else end end else glog "invalid access with #{msg} from #{from} at #{time}" end elsif msg.type==:return @whiteboard.put(msg.tx,[:return,msg.args]) if false @rtMutex.synchronize { #puts "adding return #{msg.tx} #{msg.tx.class} on #{self}" @returns[msg.tx]=msg.args ##pp @returns } end elsif msg.type==:exception @whiteboard.put(msg.tx,[:exception,msg.args]) #@rtMutex.synchronize { # @exceptions[msg.tx]=msg.args #} elsif msg.type==:hi con=checkCon(from) con.remotePort=msg.args[:port] con.remoteHost=msg.args[:host] eventConnected(con.remoteHost,con.remotePort) end end } @server.hookConnected {|con| # nothing ATM - let it say "hi" first (see above) } end |
Class Method Details
.allow(*funcNames) ⇒ Object
384 385 386 387 |
# File 'lib/appswarm/secure_con.rb', line 384 def self.allow(*funcNames) @@allowed||=[] @@allowed+=funcNames end |
.remote(*funcNames) ⇒ Object
388 389 390 391 |
# File 'lib/appswarm/secure_con.rb', line 388 def self.remote(*funcNames) @@remote||=[] @@remote+=funcNames end |
.remote_sync(*funcNames) ⇒ Object
392 393 394 395 |
# File 'lib/appswarm/secure_con.rb', line 392 def self.remote_sync(*funcNames) @@remote_sync||=[] @@remote_sync+=funcNames end |
Instance Method Details
#connect(host, port) ⇒ Object
401 402 403 |
# File 'lib/appswarm/secure_con.rb', line 401 def connect(host,port) checkCon(@server.connect(host,port)) end |
#connections ⇒ Object
397 398 399 |
# File 'lib/appswarm/secure_con.rb', line 397 def connections @server.connections.map{|c|checkCon(c)} end |
#eventConnected(host, port) ⇒ Object
425 426 427 428 |
# File 'lib/appswarm/secure_con.rb', line 425 def eventConnected(host,port) glog "eventConnected #{host},#{port}" # pure virtual end |
#getReturn(tx, conn) ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/appswarm/secure_con.rb', line 345 def getReturn(tx,conn) result=@whiteboard.get(tx) case result[0] when :return return result[1] else raise RemoteException.new(result[1]) end loop do #puts "waiting for return...#{tx} #{tx.class} (on #{self})" @rtMutex.synchronize { if @returns.key?(tx) r=@returns[tx] @returns.delete(tx) return r end if @exceptions.key?(tx) r=@exceptions[tx] @exceptions.delete(tx) raise RemoteException.new(r) end } raise "Connection closed" unless conn.connection.valid sleep 0.1 end end |
#getTxId(conn) ⇒ Object
374 375 376 377 378 379 380 381 382 |
# File 'lib/appswarm/secure_con.rb', line 374 def getTxId(conn) cid=nil @txMutex.synchronize { @txId+=1 cid=@txId @txs[cid]=conn } cid end |
#localHost ⇒ Object
414 415 416 |
# File 'lib/appswarm/secure_con.rb', line 414 def localHost @server.host end |
#localPort ⇒ Object
417 418 419 |
# File 'lib/appswarm/secure_con.rb', line 417 def localPort @server.port end |
#remote_func?(name) ⇒ Boolean
405 406 407 408 |
# File 'lib/appswarm/secure_con.rb', line 405 def remote_func?(name) @@remote||=[] @@remote.member?(name) end |
#remote_sync_func?(name) ⇒ Boolean
409 410 411 412 |
# File 'lib/appswarm/secure_con.rb', line 409 def remote_sync_func?(name) @@remote_sync||=[] @@remote_sync.member?(name) end |
#stop ⇒ Object
421 422 423 |
# File 'lib/appswarm/secure_con.rb', line 421 def stop @server.stop end |