def addService(self, srvId, srvDesc, srvConnectionString): """ add a new service to the node. """ factory = EventFactory.getInstance(ControlEvent.TYPE) addSrv = factory.createADDSERVICE(srvId, srvDesc, srvConnectionString) self.incoming.put(addSrv) return self.ok
def set(self, name, value): """ Reception of a SET order. Modification of a characteristic of the node. E.g. the pseudo set('Pseudo', 'john')""" factory = EventFactory.getInstance(ControlEvent.TYPE) set = factory.createSET(name, value) self.incoming.put(set) return self.ok
def TIMER(self, event): manager = self.node.getPeersManager() nbSeeds = len(self.portList) nbPeers = manager.getNumberOfPeers() # we have connected to all other seeds if nbPeers == nbSeeds -1 : ar = manager.computeAwarenessRadius() self.node.setAwarenessRadius(ar) #self.node.setExpectedPeers(nbPeers) self.node.startPeriodicTasks() self.sendUpdates() self.node.setState(state.TooManyPeers()) else: self.logger.debug('Not connected to all seeds: %d/%d', nbPeers, nbSeeds -1) # relaunch timer self.startTimer() connectedPorts = [] for peer in manager.enumeratePeers(): connectedPorts.append(peer.getAddress().getPort()) #self.logger.debug('ports: %s' , str(connectedPorts)) for port in self.portList: if (port <> self.node.getAddress().getPort()) and \ ( port not in connectedPorts): f = EventFactory.getInstance(PeerEvent.TYPE) hello = f.createHELLO() hello.setRecipientAddress(Address(self.node.host, port)) self.node.dispatch(hello)
def disconnect(self): """ Disconnect node Return OK """ factory = EventFactory.getInstance(ControlEvent.TYPE) controlEvent = factory.createDISCONNECT self.incoming.put(controlEvent) return self.ok
def getNodeInfo(self): """ Return all the caracteristics of the node [id, positionX, positionY, AR, CA, pseudo, orientation ] """ factory = EventFactory.getInstance(ControlEvent.TYPE) controlEvent = factory.createGETNODEINFO() self.incoming.put(controlEvent) return self.ok
def delService(self, srvId): """ Remove a service srvId : id of the service to remove Return : OK """ factory = EventFactory.getInstance(ControlEvent.TYPE) rmSrv = factory.createDELSERVICE(srvId) self.incoming.put(rmSrv) return self.ok
def getPeerInfo(self, id): """ Return all the caracteristics of a peer [id, positionX, positionY, AR, CA, pseudo, orientation ] id : id of the peer """ factory = EventFactory.getInstance(ControlEvent.TYPE) controlEvent = factory.createGETPEERINFO(id) self.incoming.put(controlEvent) return self.ok
def move(self, x, y, z): """ Reception of a move order x,y,z : target coordinates. These parameters are passed as string to avoid int overflow problems """ assert z == 0 pos = Position(long(x), long(y), long(z)) factory = EventFactory.getInstance(ControlEvent.TYPE) move = factory.createMOVE(pos) self.incoming.put(move) return self.ok
def kill(self): """ Kill the node and stop connection betwwen navigator and node """ # send a KILL order to the node factory = EventFactory.getInstance(ControlEvent.TYPE) kill = factory.createKILL() self.incoming.put(kill) # stop this connector self.connector.stop() return self.ok