def main(argv): (opts, args) = get_option_parser().parse_args(argv) if len(args) != 2: print get_option_parser().get_usage() return 1 filepath = os.path.abspath(args[1]) filename = args[1][args[1].rfind('/') + 1:] instance = pynorm.Instance() session = instance.createSession(opts.address, opts.port) if opts.iface: session.setMulticastInterface(opts.iface) session.setTxRate(256e10) session.startSender(randint(0, 1000), 1024**2, 1400, 64, 16) print 'Sending file %s' % filename session.fileEnqueue(filepath, filename) try: for event in instance: if event == 'NORM_TX_FLUSH_COMPLETED': print 'Flush completed, exiting.' return 0 else: print event except KeyboardInterrupt: pass print 'Exiting.' return 0
def main(argv): (opts, args) = get_option_parser().parse_args(argv) if len(args) != 2: print get_option_parser().get_usage() return 1 path = os.path.abspath(args[1]) instance = pynorm.Instance() instance.setCacheDirectory(path) session = instance.createSession(opts.address, opts.port) if opts.iface: session.setMulticastInterface(opts.iface) session.startReceiver(1024*1024) try: for event in instance: if event == 'NORM_RX_OBJECT_INFO': event.object.filename = os.path.join(path, event.object.info) print 'Downloading file %s' % event.object.filename elif event == 'NORM_RX_OBJECT_UPDATED': print 'File %s - %i bytes left to download' % ( event.object.filename, event.object.bytesPending) elif event == 'NORM_RX_OBJECT_COMPLETED': print 'File %s completed' % event.object.filename return 0 elif event == 'NORM_RX_OBJECT_ABORTED': print 'File %s aborted' % event.object.filename return 1 else: print event except KeyboardInterrupt: pass print 'Exiting.' return 0
def __init__(self): self.normInstance = pynorm.Instance() self.normSession = None # Sender state members self.normTxLock = Lock() # for thread-safe access to NORM tx state variables self.normTxReady = Lock() self.norm_tx_vacancy = True self.norm_tx_queue_count = 0 self.norm_tx_queue_max = 2048 self.norm_tx_watermark_pending = False self.norm_acking = False self.tx_msg_cache = {} # Receiver state members self.normRxLock = Lock() self.normRxReady = Lock() self.normRxReady.acquire() # no rx messages yet self.output_msg_queue = deque() random.seed(None)
def main(argv): (opts, args) = get_option_parser().parse_args(argv) if len(args) != 2: print get_option_parser().get_usage() return 1 path = os.path.abspath(args[1]) instance = pynorm.Instance() instance.setCacheDirectory(path) try: instance.openDebugPipe(opts.pipe) except pynorm.NormError: print 'Could not connect to pipe, disabling...' pynorm.setDebugLevel(opts.debug) manager = Manager(instance) manager.register(pynorm.NORM_RX_OBJECT_INFO, newObject, path) # manager.register(pynorm.NORM_RX_OBJECT_UPDATED, updatedObject) manager.register(pynorm.NORM_RX_OBJECT_COMPLETED, complete) manager.register(pynorm.NORM_RX_OBJECT_ABORTED, abort) manager.start() session = instance.createSession(opts.address, opts.port) if opts.iface: session.setMulticastInterface(opts.iface) session.startReceiver(1024 * 1024) print 'Starting listener on %s:%i' % (opts.address, opts.port) try: while True: manager.join(2) except KeyboardInterrupt: pass print 'Exiting...' instance.stop() manager.join() return 0
def main(argv): (opts, args) = get_option_parser().parse_args(argv) if len(args) != 2: print get_option_parser().get_usage() return 1 instance = pynorm.Instance() session = instance.createSession(opts.address, opts.port) if opts.iface: session.setMulticastInterface(opts.iface) session.startReceiver(1024 * 1024) session.startSender(randint(0, 1000), 1024**2, 1400, 64, 16) stream = session.streamOpen(1024 * 1024) gui = Gui(stream, args[1]) manager = Manager(instance) manager.register(pynorm.NORM_RX_OBJECT_UPDATED, lambda e: gui.showText(e.object.streamRead(1024)[1])) # manager.register(pynorm.NORM_RX_OBJECT_INFO, # lambda e: gui.showText('%s joined the chat' % e.object.info)) manager.start() try: curses.wrapper(gui) except KeyboardInterrupt: pass print 'Exiting...' stream.streamClose(True) instance.stop() manager.join() return 0
def main(argv): (opts, args) = get_option_parser().parse_args(argv) if len(args) != 1: print 'Error: Invalid arguments' print get_option_parser().format_help() return 1 if opts.send is None and opts.receive is None: print 'No operation specified!' print 'Must provide a --send or --receive flag!' print get_option_parser().format_help() return 1 instance = pynorm.Instance() session = instance.createSession(opts.address, opts.port) if opts.iface: session.setMulticastInterface(opts.iface) session.setTxRate(256e10) session.startReceiver(1024 * 1024) session.startSender(randint(0, 1000), 1024**2, 1400, 64, 16) if opts.receive is not None: path = os.path.abspath(opts.receive) instance.setCacheDirectory(path) print 'Setting cache directory to %s' % path if opts.send is not None: filepath = os.path.abspath(opts.send) filename = opts.send[opts.send.rfind('/') + 1:] print 'Sending file %s' % filename session.fileEnqueue(filepath, filename) try: for event in instance: if event.type == c.NORM_TX_FLUSH_COMPLETED: if event.object.type == c.NORM_OBJECT_FILE: print 'Flush completed for file %s' % event.object.filename elif event.type == c.NORM_RX_OBJECT_INFO: if event.object.type == c.NORM_OBJECT_FILE: event.object.filename = os.path.join( path, event.object.info) print 'Downloading file %s' % event.object.filename elif event.object.type == c.NORM_OBJECT_DATA: # I put the sender node ID in the info field # If it doesn't match ours, we dont care about it if int(event.object.info) != session.nodeId: event.object.cancel() elif event.type == c.NORM_RX_OBJECT_UPDATED: if event.object.type == c.NORM_OBJECT_FILE: print 'File %s - %i bytes left to download' % ( event.object.filename, event.object.bytesPending) # Let the sender know how much we have done data = pickle.dumps( (event.object.filename, event.object.bytesPending), -1) session.dataEnqueue(data, str(event.object.sender.id)) elif event == 'NORM_RX_OBJECT_COMPLETED': if event.object.type == c.NORM_OBJECT_FILE: print 'File %s completed' % event.object.filename elif event.object.type == c.NORM_OBJECT_DATA: try: # This fails sometimes, not sure why yet, so ignore errors filename, pending = pickle.loads( event.object.accessData()) except KeyError: continue print 'Node %i - File: %s - Pending: %i' % ( event.object.sender.id, filename, pending) elif event == 'NORM_RX_OBJECT_ABORTED': if event.object.type == c.NORM_OBJECT_FILE: print 'File %s aborted' % event.object.filename except KeyboardInterrupt: pass print 'Exiting.' return 0