def addPeer (self, url, key, kind=Normal): """ adds a peer if it's not already there. the url should not be already parsed and the key should be in the proper format returns: naught """ self.debug (2, 'adding peer %s' % url, 2) self.acquire () purl= URL (url) proto= purl.proto () if proto=='umbie': if not self._navels.has_key (key): self._navels[key]= StubNavel (self._master, url, key, kind) else: # change the kind self._navels[key].setKind (kind) elif proto=='vice' and not self._vices.has_key (key): self._vices[key]= StubVice (self._master, url, key) elif proto=='virtue' and not self._virtues.has_key (key): self._virtues[key]= StubVirtue (self._master, url, key) else: # bark! self.debug (2, 'bark! >%s<' % proto) pass self.release ()
def delPeer (self, peer): url= URL (peer.url ()) key= peer.key () h= self.__proto[url.proto ()] self.acquire () if h.has_key (key): self.debug (2, '%s' % h, fast=False, level=5) self.debug (2, 'deleting %s: %s, %s' % (peer, url, key), fast=False, level=4) self.debug (1, 'deleting %s: %s, %s' % (peer, url, key)) del h[key] self.debug (2, '%s' % h, fast=False, level=3) self.release ()
def addServer (self, client): # this server answers to that client peer= None server= None # this ReqSock will be thrown away. socket= RequestSocket (client) socket.write (['hit here']) args= socket.read () self.debug (1, "args are: %s" % str(args)) what= next (args) if what: if what=='i am': try: url= args[0] self.debug (1, "%s" % url.__class__) if not isinstance (url, URL): url= URL (url) proto= url.proto () if proto=='umbie': key= int (args[1]) peer= self.getNavel (str(url), key) elif proto=='vice': peer= self.getVice (str(url)) elif proto=='virtue': peer= self.getVirtue (str(url)) else: # bark! pass except NoParse: socket.write (['bye']) socket.close () else: socket.write (['bye']) socket.close () if peer: socket.write (['ok']) # create a Server of the correct class # as defined in serverType # TODO: I could pass the ReqSock() instead of the socket() server= self._master._serverType (self._master, client) # this server is the one answering to that client peer.setServer (server) server.start () else: self.debug (1, 'no peer!') self.debug (1, 'server %s added' % peer)