Exemple #1
0
    def on_fetch(self, event):
        address = common.format_address(datetime.datetime.utcnow())
        self.logger.info('User wants to fetch document "%s"', address)

        if not self.database.have_address(address):
            descriptions = {}
            descriptions['Quickly but with little deniability'] = 'centralized'
            descriptions['Slowely and with more deniability'] = 'community'
            if self.local_dir is not None:
                descriptions['With a local testing directory'] = 'local'
            if self.custom:
                descriptions['Using advanced tasks'] = 'custom'

            self.logger.info('Asking user how he wants to fetch the message')
            dlg = wx.SingleChoiceDialog(self, 'How do you want to fetch the news?\n\nThere is a tradeoff between deniability and speed:\nThe faster you download the news, the it will be easier\nfor a censor to identify your activity.', 'Task modules', sorted(descriptions.keys()))
            if dlg.ShowModal() != wx.ID_OK:
                dlg.Destroy()
                return
            task_list = descriptions[dlg.GetStringSelection()]
            dlg.Destroy()

            self.logger.info('User has elected to fetch using method "%s"' % task_list)

            self.database.set_active_task_list(task_list)
            self.update_task_list(task_list)

            self.fetch(address)
        else:
            self.logger.info('Address "%s" has already been fetched' % address)

        self.open(address)
Exemple #2
0
 def on_open(self, event):
     date = self.control.PyGetDate()
     if date is None:
         return
     self.address = common.format_address(date)
     if date not in self.dates:
         self.logger.info('User attempted to open "%s", which hasn\'t been downloaded yet', self.address)
         dlg = wx.MessageDialog(self,
                                'News for this date has not been downloaded.',
                                'Invalid date',
                                style=wx.OK|wx.ICON_ERROR)
         dlg.ShowModal()
         dlg.Destroy()
     else:
         self.logger.info('User wants to view news from "%s"', self.address)
         self.EndModal(wx.OK)
Exemple #3
0
def main():
    usage = 'usage: %s <task list> [options]'
    parser = OptionParser(usage=usage)
    parser.set_defaults(localdir=None)
    parser.add_option('-l', '--local-dir',
                      dest='localdir',
                      action='store',
                      type='string',
                      help='Local content host directory (testing)')
    (options, args) = parser.parse_args()

    if len(args) != 1:
        parser.error('Possible task lists: centralized, community or local')

    address = common.format_address(datetime.datetime.utcnow())
    snippets = get_snippets(args[0], options)

    data = download(address, snippets)
    print 'Retrieved article of length %d' % len(data)
Exemple #4
0
def main():
    usage = "usage: %s [options] <db_dir>"
    parser = OptionParser(usage=usage)
    parser.set_defaults(send_ratio=100, local_dir=None, estimate_db="estimate_db", payload_size=32000)
    parser.add_option(
        "-r",
        "--send-ratio",
        dest="send_ratio",
        action="store",
        type="float",
        help="Ratio between data to send and total data length",
    )
    parser.add_option(
        "-d",
        "--local-dir",
        dest="local_dir",
        action="store",
        type="string",
        help="Local content host directory (for testing)",
    )
    parser.add_option(
        "-e",
        "--estimate-db",
        dest="estimate_db",
        action="store",
        type="string",
        help="Location of capacity estimation database",
    )
    parser.add_option(
        "-m",
        "--memoize-db",
        dest="memoize",
        action="store",
        type="string",
        help="Location of memoization database (advanced)",
    )
    parser.add_option(
        "-f",
        "--file",
        dest="filename",
        action="store",
        type="string",
        help="Read news from a file; default is to fetch from BBC",
    )
    parser.add_option(
        "-s", "--size", dest="payload_size", action="store", type="int", help="Maximum size of payload to publish"
    )
    (options, args) = parser.parse_args()

    estimate_db = shelve.open(options.estimate_db, writeback=True)

    if len(args) != 1:
        parser.error("Need to specify donation database directory")

    while True:
        today = datetime.datetime.utcnow()
        address = common.format_address(today)

        print "Publishing document %s" % address

        if options.filename is not None:
            try:
                data = open(options.filename, "r").read()
            except:
                data = get_news(today, options.payload_size)
                try:
                    open(options.filename, "w").write(data)
                except:
                    pass
        else:
            data = get_news(today, options.payload_size)

        if get_database is not None:
            vis_database = get_database()
            vis_database.add_article_sender(data)

        db_dir = args[0]

        thread_info = []

        # Local directory
        if options.local_dir is not None:
            killswitch = threading.Event()
            thread = threading.Thread(
                target=send_news_local,
                args=(
                    address,
                    data,
                    db_dir,
                    options.local_dir,
                    options.send_ratio,
                    killswitch,
                    estimate_db,
                    options.memoize,
                ),
            )
            thread.daemon = True
            thread.start()
            thread_info.append((thread, killswitch))
        else:
            tags = get_tags()

            # Centralized
            killswitch = threading.Event()
            thread = threading.Thread(
                target=send_news_centralized,
                args=(address, data, db_dir, tags, options.send_ratio, killswitch, estimate_db),
            )
            thread.daemon = True
            thread.start()
            thread_info.append((thread, killswitch))

            # Community
            killswitch = threading.Event()
            thread = threading.Thread(
                target=send_news_community,
                args=(address, data, db_dir, tags, options.send_ratio, killswitch, estimate_db),
            )
            thread.daemon = True
            thread.start()
            thread_info.append((thread, killswitch))

        while today.day == datetime.datetime.utcnow().day:
            time.sleep(1)

        for (thread, killswitch) in thread_info:
            if thread.is_alive():
                killswitch.set()
                thread.join()
Exemple #5
0
def main():
    usage = 'usage: %s [options] <db_dir>'
    parser = OptionParser(usage=usage)
    parser.set_defaults(send_ratio=100,
                        local_dir=None,
                        estimate_db='estimate_db',
                        payload_size=32000)
    parser.add_option('-r',
                      '--send-ratio',
                      dest='send_ratio',
                      action='store',
                      type='float',
                      help='Ratio between data to send and total data length')
    parser.add_option('-d',
                      '--local-dir',
                      dest='local_dir',
                      action='store',
                      type='string',
                      help='Local content host directory (for testing)')
    parser.add_option('-e',
                      '--estimate-db',
                      dest='estimate_db',
                      action='store',
                      type='string',
                      help='Location of capacity estimation database')
    parser.add_option('-m',
                      '--memoize-db',
                      dest='memoize',
                      action='store',
                      type='string',
                      help='Location of memoization database (advanced)')
    parser.add_option(
        '-f',
        '--file',
        dest='filename',
        action='store',
        type='string',
        help='Read news from a file; default is to fetch from BBC')
    parser.add_option('-s',
                      '--size',
                      dest='payload_size',
                      action='store',
                      type='int',
                      help='Maximum size of payload to publish')
    (options, args) = parser.parse_args()

    estimate_db = shelve.open(options.estimate_db, writeback=True)

    if len(args) != 1:
        parser.error('Need to specify donation database directory')

    while True:
        today = datetime.datetime.utcnow()
        address = common.format_address(today)

        print 'Publishing document %s' % address

        if options.filename is not None:
            try:
                data = open(options.filename, 'r').read()
            except:
                data = get_news(today, options.payload_size)
                try:
                    open(options.filename, 'w').write(data)
                except:
                    pass
        else:
            data = get_news(today, options.payload_size)

        if get_database is not None:
            vis_database = get_database()
            vis_database.add_article_sender(data)

        db_dir = args[0]

        thread_info = []

        # Local directory
        if options.local_dir is not None:
            killswitch = threading.Event()
            thread = threading.Thread(target=send_news_local,
                                      args=(address, data, db_dir,
                                            options.local_dir,
                                            options.send_ratio, killswitch,
                                            estimate_db, options.memoize))
            thread.daemon = True
            thread.start()
            thread_info.append((thread, killswitch))
        else:
            tags = get_tags()

            # Centralized
            killswitch = threading.Event()
            thread = threading.Thread(target=send_news_centralized,
                                      args=(address, data, db_dir, tags,
                                            options.send_ratio, killswitch,
                                            estimate_db))
            thread.daemon = True
            thread.start()
            thread_info.append((thread, killswitch))

            # Community
            killswitch = threading.Event()
            thread = threading.Thread(target=send_news_community,
                                      args=(address, data, db_dir, tags,
                                            options.send_ratio, killswitch,
                                            estimate_db))
            thread.daemon = True
            thread.start()
            thread_info.append((thread, killswitch))

        while today.day == datetime.datetime.utcnow().day:
            time.sleep(1)

        for (thread, killswitch) in thread_info:
            if thread.is_alive():
                killswitch.set()
                thread.join()
Exemple #6
0
def main():
    usage = 'usage: %s [options] <db_dir>'
    parser = OptionParser(usage=usage)
    parser.set_defaults(send_ratio=100, local_dir=None, estimate_db='estimate_db')
    parser.add_option('-r', '--send-ratio', dest='send_ratio',
                      action='store', type='float',
                      help='Ratio between data to send and total data length')
    parser.add_option('-d', '--local-dir', dest='local_dir',
                      action='store', type='string',
                      help='Local content host directory (for testing)')
    parser.add_option('-e', '--estimate-db', dest='estimate_db',
                      action='store', type='string',
                      help='Location of capacity estimation database')
    (options, args) = parser.parse_args()

    estimate_db = shelve.open(options.estimate_db, writeback=True)

    if len(args) != 1:
        parser.error('Need to specify donation database directory')

    while True:
        today = datetime.datetime.utcnow()
        address = common.format_address(today)

        print 'Publishing document %s' % address

        data = get_news(today)
        db_dir = args[0]
        tags = get_tags()
        
        thread_info = []

        # Centralized
        killswitch = threading.Event()
        thread = threading.Thread(target=send_news_centralized,
                                  args=(address, data, db_dir, tags, options.send_ratio, killswitch, estimate_db))
        thread.daemon = True
        thread.start()
        thread_info.append((thread, killswitch))

        # Community
        killswitch = threading.Event()
        thread = threading.Thread(target=send_news_community,
                                  args=(address, data, db_dir, tags, options.send_ratio, killswitch, estimate_db))
        thread.daemon = True
        thread.start()
        thread_info.append((thread, killswitch))

        # Local directory
        if options.local_dir is not None:
            killswitch = threading.Event()
            thread = threading.Thread(target=send_news_community,
                                      args=(address, data, db_dir, options.local_dir, options.send_ratio, killswitch, estimate_db))
            thread.daemon = True
            thread.start()
            thread_info.append((thread, killswitch))

        while today.day == datetime.datetime.utcnow().day:
            time.sleep(1)

        for (thread, killswitch) in thread_info:
            if thread.is_alive():
                killswitch.set()
                thread.join()