示例#1
0
    def __init__(self, params):
        """ All informations about this node:
        host --> ip if the node, network_port, GUI_port, posX, posY, ar, ca,
        ori --> a point,
        exp --> expected number of neighbour, pseudo"""

        self.params=params

        # event queue, used for inter-thread communication
        self.events = NotificationQueue()
        self.connectors = []

        EventFactory.init(self)
        EventFactory.register(PeerEventFactory.TYPE, PeerEventFactory())
        EventFactory.register(ControlEventFactory.TYPE, ControlEventFactory())

        # network communication with peers is handled by this object
        self.peerConnector = UDPConnector(PeerEventParser(), self.events, params)
        self.connectors.append(self.peerConnector)

        if (not params.bot):
            self.controlConnector = XMLRPCConnector(ControlEventParser(), self.events, params)
            self.connectors.append(self.controlConnector)
        else:
            self.controlConnector = None

        id_ = self.createId()
        position = Position(params.pos_x, params.pos_y)
        address = Address(params.host, params.port)

        # call parent class constructor
        Entity.__init__(self, id_, position, params.orientation,
                        params.awareness_radius, params.calibre, params.pseudo,
                        address)

        # maximum expected number of neighbours.
        self.exp = params.expected_neighbours

        # our IP address or 'localhost' if not specified in config file
        self.host = params.host

        self.alive = True
        self.logger = logging.getLogger('root')
        self.logger.debug('node started')
        # manage all peers
        #peersParams = params.getPeersParams()
        self.peersManager = PeersManager(self, params)

        # set world size in Geometry class
        Geometry.SIZE = params.world_size

        # periodic tasks
        self.periodic = []

        self.state = None
        self.setState(state.NotConnected())
示例#2
0
    def __init__(self, id="", address=None, position=Position(0,0), orientation=0,
                 awarenessRadius=0, calibre=0, pseudo=""):
        """ Create a new Entity and keep information about it"""

        # call parent class constructor
        Entity.__init__(self, id, position, orientation, awarenessRadius, calibre,
                        pseudo, address)

        # last time when we saw this peer active
        self.activeTime = 0

        # local position is the position of this peer using a coordinate system
        # centered on the position of the node
        # this value is set-up by the peer manager
        #self.localPosition = position

        # set the ID of this peer
        #id = self.createId()
        #self.setId(id)

        # position and relative position
        #relative_position = Function.relativePosition(self.position,
        # globalvars.me.position)
        #self.local_position = [ relative_position[0] - globalvars.me.position[0],
        #relative_position[1] - globalvars.me.position[1] ]

        # two boolean variables indicating that
        # we received a message from this entity
        self.message_received = 1
        # we sent a message to this entity
        self.message_sent = 0

        # services provided by entity
        # {id_service: [desc_service, host, port], ...}
        self.services = {}

        # boolean confirmation of the accuracy of informations
        self.ok = 0