Пример #1
0
class Emmer(object):
    """This is the wrapping class for the Emmer framework. It initializes
    running services and also offers the client level interface.
    """
    def __init__(self):
        self.host = config.HOST
        self.port = config.PORT
        self.response_router = ResponseRouter()
        self.conversation_table = ConversationTable()
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.reactor = Reactor(self.sock, self.response_router,
                               self.conversation_table)
        self.performer = Performer(self.sock, self.conversation_table,
                                   config.RESEND_TIMEOUT,
                                   config.RETRIES_BEFORE_GIVEUP)

    def route_read(self, filename_pattern):
        """Adds a function with a filename pattern to the Emmer server. Upon a
        read request, Emmer will run the action corresponding to the first
        filename pattern to match the request's filename.

        Use this function as a decorator on a function to add that function
        as an action with which to handle a tftp conversation.

        Args:
            filename_pattern: a regex pattern to match filenames against.
        """
        def decorator(action):
            self.response_router.append_read_rule(filename_pattern, action)

        return decorator

    def route_write(self, filename_pattern):
        """Adds a function with a filename pattern to the Emmer server. Upon a
        write request, Emmer will run the action corresponding to the first
        filename pattern to match the request's filename.

        Use this function as a decorator on a function to add that function
        as an action with which to handle a tftp conversation.

        Args:
            filename_pattern: a regex pattern to match filenames against.
        """
        def decorator(action):
            self.response_router.append_write_rule(filename_pattern, action)

        return decorator

    def run(self):
        """Initiates the Emmer server. This includes:
        * Listening on the given UDP host and port.
        * Sending messages through the given port to reach out on timed out
          tftp conversations.
        """
        self.sock.bind((self.host, self.port))
        print "TFTP Server running at %s:%s" % (self.host, self.port)
        thread.start_new_thread(self.performer.run,
                                (config.PERFORMER_THREAD_INTERVAL,))
        self.reactor.run()
Пример #2
0
class Emmer(object):
    """This is the wrapping class for the Emmer framework. It initializes
    running services and also offers the client level interface.
    """
    def __init__(self):
        self.host = config.HOST
        self.port = config.PORT
        self.response_router = ResponseRouter()
        self.conversation_table = ConversationTable()
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.reactor = Reactor(self.sock, self.response_router,
                               self.conversation_table)
        self.performer = Performer(self.sock, self.conversation_table,
                                   config.RESEND_TIMEOUT,
                                   config.RETRIES_BEFORE_GIVEUP)

    def route_read(self, filename_pattern):
        """Adds a function with a filename pattern to the Emmer server. Upon a
        read request, Emmer will run the action corresponding to the first
        filename pattern to match the request's filename.

        Use this function as a decorator on a function to add that function
        as an action with which to handle a tftp conversation.

        Args:
            filename_pattern: a regex pattern to match filenames against.
        """
        def decorator(action):
            self.response_router.append_read_rule(filename_pattern, action)

        return decorator

    def route_write(self, filename_pattern):
        """Adds a function with a filename pattern to the Emmer server. Upon a
        write request, Emmer will run the action corresponding to the first
        filename pattern to match the request's filename.

        Use this function as a decorator on a function to add that function
        as an action with which to handle a tftp conversation.

        Args:
            filename_pattern: a regex pattern to match filenames against.
        """
        def decorator(action):
            self.response_router.append_write_rule(filename_pattern, action)

        return decorator

    def run(self):
        """Initiates the Emmer server. This includes:
        * Listening on the given UDP host and port.
        * Sending messages through the given port to reach out on timed out
          tftp conversations.
        """
        self.sock.bind((self.host, self.port))
        print "TFTP Server running at %s:%s" % (self.host, self.port)
        thread.start_new_thread(self.performer.run,
                                (config.PERFORMER_THREAD_INTERVAL, ))
        self.reactor.run()
Пример #3
0
def download(name):
    shared_mem = Queue.PriorityQueue()
    if platform == "win32":
    	directory = 'C:\Users' + user + '\Torrents\\'
    else:
    	directory = '/home/'+ user +'/Torrents/'
    Torrent = directory + name
    peerMngr = PeerManager(Torrent)
    bittorrentThread = Reactor(1, "Thread-1", peerMngr, shared_mem, debug=True)
    bittorrentThread.run()
Пример #4
0
def download(name):
    shared_mem = Queue.PriorityQueue()
    if platform == "win32":
        directory = 'C:\Users' + user + '\Torrents\\'
    else:
        directory = '/home/' + user + '/Torrents/'
    Torrent = directory + name
    peerMngr = PeerManager(Torrent)
    bittorrentThread = Reactor(1, "Thread-1", peerMngr, shared_mem, debug=True)
    bittorrentThread.run()
Пример #5
0
def test_io_watcher():

    reactor = Reactor()
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(('localhost',8001))
    def cb(a,b):
        # should be reworked, this is a bit of a hammer
        os.kill(os.getpid(), signal.SIGINT)
    io_event = events.ReadEvent(s, cb)
    reactor.install(io_event)
    reactor.run()
Пример #6
0
class Navigator:
    def __init__(self, config, data_store, telemetry, messagedispatcher):
        self.messagedispatcher = messagedispatcher
        self.reactor = Reactor(config, data_store, telemetry, messagedispatcher)
        self.current_target = Point(
            latitude = telemetry.get_location().latitude,
            longitude = telemetry.get_location().longitude,
            altitude = telemetry.get_location().altitude
        )
        self.c2_reactor = self.reactor.c2_reactor

    @asyncio.coroutine
    def startup(self):
        while True:
            action = self.reactor.run()
            if action is not None:
                if action.has_move():
                    self.current_target = action.move
            yield from asyncio.sleep(1)

    def get_current_target(self):
        return self.current_target
Пример #7
0
class Navigator:
    def __init__(self, config, data_store, telemetry, messagedispatcher, communicator, detection):
        self.uuid = config.get('DEFAULT', 'uuid')
        self.debug = 'True' == config.get('DEFAULT', 'debug')
        self.data_store = data_store
        self.messagedispatcher = messagedispatcher
        self.communicator = communicator
        self.reactor = Reactor(config, data_store, telemetry, messagedispatcher, communicator, detection)
        self.current_target = Point(
            latitude = telemetry.get_location().latitude,
            longitude = telemetry.get_location().longitude,
            altitude = telemetry.get_location().altitude
        )

    @asyncio.coroutine
    def startup(self):
        while True:
            action = self.reactor.run()
            grid = self.data_store.get_grid_state()
            if action is not None:
                if action.has_move():
                    self.current_target = action.move
                    if self.current_target.altitude < 10:
                        self.current_target.altitude = 100
                if action.has_claim_sector():
                    grid.set_state_for(action.claim_sector, datastore.SectorState.being_searched, self.uuid)
                if action.has_complete_sector():
                    grid.set_state_for(action.complete_sector, datastore.SectorState.searched, self.uuid)
                if (self.debug or self.current_target.altitude < 10) and action.has_move_info():
                    print(action.move_info)

            if grid is not None:
                yield from self.communicator.send_message(GridMesh(self.uuid, self.uuid, grid))

            yield from asyncio.sleep(1)

    def get_current_target(self):
        return self.current_target
Пример #8
0
def main():
    shared_mem = Queue.PriorityQueue()
    trackerFile = sys.argv[1]
    peerMngr = PeerManager(trackerFile)
    bittorrentThread = Reactor(1, "Thread-1", peerMngr, shared_mem, debug=True)
    bittorrentThread.run()
Пример #9
0
def main():
    shared_mem = Queue.PriorityQueue()
    trackerFile = sys.argv[1]
    peerMngr = PeerManager(trackerFile)
    bittorrentThread = Reactor(1, "Thread-1", peerMngr, shared_mem, debug=True)
    bittorrentThread.run()