def send_news_local(address, data, db_dir, local_dir, send_ratio, killswitch, estimate_db): """Publish news inside photos on a local content host, for testing.""" database = AppDatabase(db_dir, 'proxy_local') tasks = [DonateDirectoryTask(local_dir, address, database)] vector_provider = DonatedVectorProvider(database, killswitch, estimate_db) message_layer = MessageLayer(vector_provider, common.BLOCK_SIZE, common.MAX_UNIQUE_BLOCKS, tasks, common.TASKS_PER_MESSAGE, Timestamper(), mac=True) message_layer.send(address, data, send_ratio=send_ratio)
def send_news_centralized(address, data, db_dir, tags, send_ratio, killswitch, estimate_db): """Publish news inside stock photos on dedicated Flickr account.""" database = AppDatabase(db_dir, 'proxy_centralized') tasks = [DonateTagPairFlickrTask(('nature', 'vacation'), database)] vector_provider = DonatedVectorProvider(database, killswitch, estimate_db) message_layer = MessageLayer(vector_provider, common.BLOCK_SIZE, common.MAX_UNIQUE_BLOCKS, tasks, common.TASKS_PER_MESSAGE, Timestamper(), mac=True) message_layer.send(address, data, send_ratio=send_ratio)
def send_news_community(address, data, db_dir, tags, send_ratio, killswitch, estimate_db): """Publish news inside photos provided by community volunteers.""" database = AppDatabase(db_dir, 'proxy_community') tag_pairs = [(a, b) for a in tags for b in tags if a < b] tasks = map(lambda pair: DonateTagPairFlickrTask(pair, database), tag_pairs) vector_provider = DonatedVectorProvider(database, killswitch, estimate_db) message_layer = MessageLayer(vector_provider, common.BLOCK_SIZE, common.MAX_UNIQUE_BLOCKS, tasks, common.TASKS_PER_MESSAGE, Timestamper(), mac=True) message_layer.send(address, data, send_ratio=send_ratio)
def send_news_local(address, data, db_dir, local_dir, send_ratio, killswitch, estimate_db, memoize): """Publish news inside photos on a local content host, for testing.""" database = AppDatabase(db_dir, 'proxy_local') tasks = [DonateDirectoryTask(local_dir, address, database)] vector_provider = DonatedVectorProvider(database, killswitch, estimate_db) message_layer = MessageLayer(vector_provider, common.BLOCK_SIZE, common.MAX_UNIQUE_BLOCKS, tasks, common.TASKS_PER_MESSAGE, Timestamper(), mac=True, memoize_db=memoize) message_layer.send(address, data, send_ratio=send_ratio)
def main(): usage = 'usage: %s [options] <send|receive|delete> <id>' parser = OptionParser(usage=usage) parser.set_defaults() parser.add_option('-f', '--file', dest='filename', action='store', type='string', help='File to send') parser.add_option('-n', '--num-photos', dest='num_vectors', action='store', type='int', help='Number of photos to send') 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', '--directory', dest='directory', action='store', type='string', help='Directory to read photos from') parser.add_option('-t', '--tags-file', dest='tagsfile', action='store', type='string', help='File to read tags from') (options, args) = parser.parse_args() if len(args) != 2: parser.error('Need to specify action and message id') if options.tagsfile is None: parser.error('Need to specify tags file') block_size = 8 max_unique_blocks = 2**16 tasks_per_message = 3 flickr = auth_flickr() tags = [] for line in open(options.tagsfile, 'r'): tags.append(line.strip()) tag_pairs = [(a, b) for a in tags for b in tags if a < b] tasks = map(lambda pair: TagPairFlickrTask(flickr, pair), tag_pairs) if args[0] == 'send': if options.directory is None: parser.error( 'Must specify a directory with JPEGs in it, to embed and upload.' ) vector_provider = DirectoryVectorProvider(OutguessVector, options.directory, ['.jpeg', '.jpg']) if options.filename is None: print 'Enter message and press <Ctrl-D>' data = sys.stdin.read() else: data = open(options.filename, 'r').read() message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper) if options.num_vectors is not None: message_layer.send(args[1], data, num_vectors=options.num_vectors) elif options.send_ratio is not None: message_layer.send(args[1], data, send_ratio=options.send_ratio) else: message_layer.send(args[1], data) elif args[0] == 'receive': vector_provider = NullVectorProvider() message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper) data = message_layer.receive(args[1]) sys.stdout.write(data) elif args[0] == 'delete': results = flickr.photos_search(user_id='me') for photo in results[0]: #if photo.attrib['title'] == base64.b64encode(args[1]): flickr.photos_delete(photo_id=photo.attrib['id']) else: parser.error('Invalid action')
def main(): usage = 'usage: %s [options] <send|recieve> <id>' parser = OptionParser(usage=usage) parser.add_option('-u', '--username', dest='username', action='store', type='string', help='Twitter username') parser.add_option('-p', '--password', dest='password', action='store', type='string', help='Twitter password') parser.add_option('-f', '--file', dest='filename', action='store', type='string', help='File to send') parser.add_option('-n', '--num-tweets', dest='num_vectors', action='store', type='int', help='Number of tweets to send') 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', '--directory', dest='directory', action='store', type='string', help='Directory to read tweets from') (options, args) = parser.parse_args() if len(args) != 2: parser.error('Need to specify action and message id') block_size = 8 max_unique_blocks = 2**8 tasks_per_message = 3 if args[0] == 'send': if options.username is None or options.password is None: parser.error( 'Must specify Twitter username and password to send messages.') if options.directory is None: parser.error( 'Must specify a directory with tweets (*.tweet) in it, to embed and upload.' ) vector_provider = DirectoryVectorProvider(BlatantVector, options.directory, '.tweet') if options.filename is None: print 'Enter message and press <Ctrl-D>' data = sys.stdin.read() else: data = open(options.filename, 'r').read() driver = WebDriver() twitter_login(driver, options.username, options.password) tasks = [WebTwitterTask(driver, options.username, BlatantVector)] message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper) if options.num_vectors is not None: message_layer.send(args[1], data, num_vectors=options.num_vectors) elif options.send_ratio is not None: message_layer.send(args[1], data, send_ratio=options.send_ratio) else: message_layer.send(args[1], data) elif args[0] == 'receive': if options.username is None: parser.error('Must specify username to search') vector_provider = NullVectorProvider() driver = WebDriver() tasks = [WebTwitterTask(driver, options.username, BlatantVector)] message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper) data = message_layer.receive(args[1]) sys.stdout.write(data) elif args[0] == 'delete': parser.error( "Deletion not supported through Web interface yet. Use direct client." ) else: parser.error('Invalid action')
def main(): usage = 'usage: %s [options] <send|receive|delete> <id>' parser = OptionParser(usage=usage) parser.set_defaults(mapping_size=1, encoding_rate=0.1, encoding_deviation=0.0, task_overhead=0.0, task_deviation=0.0, database_size=1, time_overhead=0, time_deviation=0, upload=128, download=768, vectors_per_task=1, vector_length=200000, vector_deviation=10000) parser.add_option('-f', '--file', dest='filename', action='store', type='string', help='File to send') parser.add_option('-n', '--num-vectors', dest='num_vectors', action='store', type='int', help='Number of vectors to send') parser.add_option('-s', '--database-size', dest='database_size', action='store', type='int', help='Size of task database') parser.add_option('-m', '--mapping-size', dest='mapping_size', action='store', type='int', help='Size of task mapping') 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('-e', '--encoding-rate', dest='encoding_rate', action='store', type='float', help='Vector encoding rate') parser.add_option('-E', '--encoding-deviation', dest='encoding_deviation', action='store', type='float', help='Vector encoding deviation') parser.add_option('-l', '--vector-length', dest='vector_length', action='store', type='int', help='Average vector length in bytes') parser.add_option('-L', '--vector-deviation', dest='vector_deviation', action='store', type='int', help='Vector length deviation') parser.add_option('-t', '--task-overhead', dest='task_overhead', action='store', type='int', help='Task overhead in bytes') parser.add_option('-T', '--task-deviation', dest='task_deviation', action='store', type='int', help='Task overhead deviation, in bytes') parser.add_option('-v', '--vectors-per-task', dest='vectors_per_task', action='store', type='int', help='Number of vectors for each task') parser.add_option('-p', '--time-overhead', dest='time_overhead', action='store', type='float', help='Time overhead in seconds') parser.add_option('-P', '--time-deviation', dest='time_deviation', action='store', type='float', help='Time overhead deviation') parser.add_option('-u', '--upload-rate', dest='upload', action='store', type='int', help='Upload rate, in Kbps') parser.add_option('-d', '--download-rate', dest='download', action='store', type='int', help='Download rate, in Kbps') parser.add_option('-D', '--storage-directory', dest='storage_dir', action='store', type='string', help='Storage directory for published vectors') (options, args) = parser.parse_args() if len(args) != 2: parser.error('Need to specify action and message id') if options.storage_dir is None: parser.error('Must specify vector storage directory') block_size = 32 max_unique_blocks = 2**16 tasks = [] for i in range(options.database_size): overhead = random.gauss(options.task_overhead, options.task_deviation) task = SimulatedTask(overhead, options.time_overhead, options.time_deviation, options.download, options.upload, options.vectors_per_task, options.storage_dir) tasks.append(task) if args[0] == 'send': vector_provider = SimulatedVectorProvider(SimulatedVector, options.encoding_rate, options.encoding_deviation, options.vector_length, options.vector_deviation) if options.filename is None: print 'Enter message and press <Ctrl-D>' data = sys.stdin.read() else: data = open(options.filename, 'r').read() message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, options.mapping_size, timestamper) if options.num_vectors is not None: message_layer.send(args[1], data, num_vectors=options.num_vectors) elif options.send_ratio is not None: message_layer.send(args[1], data, send_ratio=options.send_ratio) else: message_layer.send(args[1], data) elif args[0] == 'receive': vector_provider = NullVectorProvider() message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, options.mapping_size, timestamper) data = message_layer.receive(args[1]) sys.stdout.write(data) elif args[0] == 'delete': for filename in os.listdir(options.storage_dir): if os.path.splitext(filename)[1] == '.vector': os.unlink(os.path.join(options.storage_dir, filename)) else: parser.error('Invalid action')
def main(): usage = 'usage: %s [options] <send|recieve> <id>' parser = OptionParser(usage=usage) parser.add_option('-u', '--username', dest='username', action='store', type='string', help='Twitter username') parser.add_option('-p', '--password', dest='password', action='store', type='string', help='Twitter password') parser.add_option('-f', '--file', dest='filename', action='store', type='string', help='File to send') parser.add_option('-n', '--num-tweets', dest='num_vectors', action='store', type='int', help='Number of tweets to send') 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', '--directory', dest='directory', action='store', type='string', help='Directory to read tweets from') (options, args) = parser.parse_args() if len(args) != 2: parser.error('Need to specify action and message id') block_size = 8 max_unique_blocks = 2**8 tasks_per_message = 3 snippets_path = os.path.abspath('snippets') if args[0] == 'send': if options.username is None or options.password is None: parser.error('Must specify Twitter username and password to send messages.') if options.directory is None: parser.error('Must specify a directory with tweets (*.tweet) in it, to embed and upload.') vector_provider = DirectoryVectorProvider(AllCapsVector, options.directory, '.tweet') if options.filename is None: print 'Enter message and press <Ctrl-D>' data = sys.stdin.read() else: data = open(options.filename, 'r').read() api = twitter.Api(username=options.username, password=options.password) tasks = [DirectTwitterTask(api, options.username, AllCapsVector)] message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper) if options.num_vectors is not None: message_layer.send(args[1], data, num_vectors=options.num_vectors) elif options.send_ratio is not None: message_layer.send(args[1], data, send_ratio=options.send_ratio) else: message_layer.send(args[1], data) elif args[0] == 'receive': if options.username is None: parser.error('Must specify username to search') vector_provider = NullVectorProvider() api = twitter.Api() tasks = [DirectTwitterTask(api, options.username, AllCapsVector)] message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper) data = message_layer.receive(args[1]) sys.stdout.write(data) elif args[0] == 'delete': if options.username is None or options.password is None: parser.error('Must specify Twitter username and password to delete messages.') api = twitter.Api(username=options.username, password=options.password) results = api.GetUserTimeline(options.username) for status in results: api.DestroyStatus(status.GetId()) time.sleep(1) else: parser.error('Invalid action')
def main(): usage = 'usage: %s [options] <send|receive|delete> <id>' parser = OptionParser(usage=usage) parser.set_defaults() parser.add_option('-f', '--file', dest='filename', action='store', type='string', help='File to send') parser.add_option('-n', '--num-photos', dest='num_vectors', action='store', type='int', help='Number of photos to send') 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', '--directory', dest='directory', action='store', type='string', help='Directory to read photos from') (options, args) = parser.parse_args() if len(args) != 2: parser.error('Need to specify action and message id') block_size = 8 max_unique_blocks = 2**16 tasks_per_message = 3 flickr = auth_flickr() tasks = [DirectFlickrTask(flickr)] if args[0] == 'send': if options.directory is None: parser.error('Must specify a directory with JPEGs in it, to embed and upload.') vector_provider = DirectoryVectorProvider(OutguessVector, options.directory, ['.jpeg', '.jpg']) if options.filename is None: print 'Enter message and press <Ctrl-D>' data = sys.stdin.read() else: data = open(options.filename, 'r').read() message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper, mac=True) if options.num_vectors is not None: message_layer.send(args[1], data, num_vectors=options.num_vectors) elif options.send_ratio is not None: message_layer.send(args[1], data, send_ratio=options.send_ratio) else: message_layer.send(args[1], data) elif args[0] == 'receive': vector_provider = NullVectorProvider() message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper, mac=True) data = message_layer.receive(args[1]) sys.stdout.write(data) elif args[0] == 'delete': results = flickr.photos_search(user_id='me') for photo in results[0]: #if photo.attrib['title'] == base64.b64encode(args[1]): flickr.photos_delete(photo_id=photo.attrib['id']) else: parser.error('Invalid action')
def main(): usage = "usage: %s [options] <send|receive|delete> <id>" parser = OptionParser(usage=usage) parser.set_defaults() parser.add_option("-f", "--file", dest="filename", action="store", type="string", help="File to send") parser.add_option( "-n", "--num-photos", dest="num_vectors", action="store", type="int", help="Number of photos to send" ) 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", "--directory", dest="directory", action="store", type="string", help="Directory to read photos from" ) parser.add_option( "-t", "--tags-file", dest="tagsfile", action="store", type="string", help="File to read tags from" ) (options, args) = parser.parse_args() if len(args) != 2: parser.error("Need to specify action and message id") if options.tagsfile is None: parser.error("Need to specify tags file") block_size = 8 max_unique_blocks = 2 ** 16 tasks_per_message = 3 flickr = auth_flickr() tags = [] for line in open(options.tagsfile, "r"): tags.append(line.strip()) tag_pairs = [(a, b) for a in tags for b in tags if a < b] tasks = map(lambda pair: TagPairFlickrTask(flickr, pair), tag_pairs) if args[0] == "send": if options.directory is None: parser.error("Must specify a directory with JPEGs in it, to embed and upload.") vector_provider = DirectoryVectorProvider(OutguessVector, options.directory, [".jpeg", ".jpg"]) if options.filename is None: print "Enter message and press <Ctrl-D>" data = sys.stdin.read() else: data = open(options.filename, "r").read() message_layer = MessageLayer( vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper ) if options.num_vectors is not None: message_layer.send(args[1], data, num_vectors=options.num_vectors) elif options.send_ratio is not None: message_layer.send(args[1], data, send_ratio=options.send_ratio) else: message_layer.send(args[1], data) elif args[0] == "receive": vector_provider = NullVectorProvider() message_layer = MessageLayer( vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper ) data = message_layer.receive(args[1]) sys.stdout.write(data) elif args[0] == "delete": results = flickr.photos_search(user_id="me") for photo in results[0]: # if photo.attrib['title'] == base64.b64encode(args[1]): flickr.photos_delete(photo_id=photo.attrib["id"]) else: parser.error("Invalid action")
def main(): usage = 'usage: %s [options] <send|recieve> <id>' parser = OptionParser(usage=usage) parser.add_option('-u', '--username', dest='username', action='store', type='string', help='Twitter username') parser.add_option('-p', '--password', dest='password', action='store', type='string', help='Twitter password') parser.add_option('-f', '--file', dest='filename', action='store', type='string', help='File to send') parser.add_option('-n', '--num-tweets', dest='num_vectors', action='store', type='int', help='Number of tweets to send') 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', '--directory', dest='directory', action='store', type='string', help='Directory to read tweets from') (options, args) = parser.parse_args() if len(args) != 2: parser.error('Need to specify action and message id') block_size = 8 max_unique_blocks = 2**8 tasks_per_message = 3 if args[0] == 'send': if options.username is None or options.password is None: parser.error('Must specify Twitter username and password to send messages.') if options.directory is None: parser.error('Must specify a directory with tweets (*.tweet) in it, to embed and upload.') vector_provider = DirectoryVectorProvider(BlatantVector, options.directory, '.tweet') if options.filename is None: print 'Enter message and press <Ctrl-D>' data = sys.stdin.read() else: data = open(options.filename, 'r').read() driver = WebDriver() twitter_login(driver, options.username, options.password) tasks = [WebTwitterTask(driver, options.username, BlatantVector)] message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper) if options.num_vectors is not None: message_layer.send(args[1], data, num_vectors=options.num_vectors) elif options.send_ratio is not None: message_layer.send(args[1], data, send_ratio=options.send_ratio) else: message_layer.send(args[1], data) elif args[0] == 'receive': if options.username is None: parser.error('Must specify username to search') vector_provider = NullVectorProvider() driver = WebDriver() tasks = [WebTwitterTask(driver, options.username, BlatantVector)] message_layer = MessageLayer(vector_provider, block_size, max_unique_blocks, tasks, tasks_per_message, timestamper) data = message_layer.receive(args[1]) sys.stdout.write(data) elif args[0] == 'delete': parser.error("Deletion not supported through Web interface yet. Use direct client.") else: parser.error('Invalid action')