示例#1
0
def echo_handler(stream, transport, protocol):
    peer = transport.get_extra_info('peername')
    print('New connection from {0}'.format(gruvi.saddr(peer)))
    while True:
        buf = stream.read1()
        if not buf:
            break
        stream.write(buf)
    print('Connection lost')
示例#2
0
 def connection_made(self, transport):
     super(EchoProtocol, self).connection_made(transport)
     peer = transport.get_extra_info('peername')
     print('New connection from {0}'.format(gruvi.saddr(peer)))
示例#3
0
# Gruvi example program: an echo server, using a Protocol

import gruvi


class EchoProtocol(gruvi.Protocol):
    def connection_made(self, transport):
        super(EchoProtocol, self).connection_made(transport)
        peer = transport.get_extra_info('peername')
        print('New connection from {0}'.format(gruvi.saddr(peer)))

    def data_received(self, data):
        self._transport.write(data)

    def eof_received(self):
        print('Connection lost')


server = gruvi.create_server(EchoProtocol, ('localhost', 0))
for addr in server.addresses:
    print('Listen on {0}'.format(gruvi.saddr(addr)))

try:
    gruvi.get_hub().switch()
except KeyboardInterrupt:
    print('Exiting on CTRL-C')
示例#4
0
# Gruvi example program: echo server, using StreamServer

import gruvi

def echo_handler(stream, transport, protocol):
    peer = transport.get_extra_info('peername')
    print('New connection from {0}'.format(gruvi.saddr(peer)))
    while True:
        buf = stream.read1()
        if not buf:
            break
        stream.write(buf)
    print('Connection lost')

server = gruvi.StreamServer(echo_handler)
server.listen(('localhost', 0))
for addr in server.addresses:
    print('Listen on {0}'.format(gruvi.saddr(addr)))

server.run()
示例#5
0
 def connection_made(self, transport):
     super(EchoProtocol, self).connection_made(transport)
     peer = transport.get_extra_info('peername')
     print('New connection from {0}'.format(gruvi.saddr(peer)))
示例#6
0
# Gruvi example program: echo server, using StreamServer

import gruvi


def echo_handler(stream, transport, protocol):
    peer = transport.get_extra_info("peername")
    print("New connection from {0}".format(gruvi.saddr(peer)))
    while True:
        buf = stream.read1()
        if not buf:
            break
        stream.write(buf)
    print("Connection lost")


server = gruvi.StreamServer(echo_handler)
server.listen(("localhost", 0))
for addr in server.addresses:
    print("Listen on {0}".format(gruvi.saddr(addr)))

try:
    gruvi.get_hub().switch()
except KeyboardInterrupt:
    print("Exiting on CTRL-C")
示例#7
0
    def run(self):
        """Initialize the backend and run its main loop."""
        self._log.debug('initializing backend components')

        self._log.debug('initializing password generator')
        pwgen = singleton(PasswordGenerator)

        self._log.debug('initializing document store')
        fname = os.path.join(self.options.data_dir, 'bluepass.db')
        store = singleton(Store, fname)

        self._log.debug('initializing model')
        model = singleton(Model, store)
        token = {'id': self.options.auth_token, 'expires': 0,
                 'allow': {'control_api': True}}
        model.create_token(token)

        self._log.debug('initializing locator')
        locator = singleton(Locator)
        for ls in platform.get_location_sources():
            self._log.debug('adding location source: {}', ls.name)
            locator.add_source(ls())

        self._log.debug('initializing sync API')
        syncapi = singleton(SyncApiServer)
        syncapi.listen(('0.0.0.0', 0))

        self._log.debug('initializing sync API publisher')
        publisher = singleton(SyncApiPublisher, syncapi)
        publisher.start()

        if locator.sources:
            self._log.debug('initializing background sync worker')
            syncer = singleton(Syncer)
            syncer.start()
        else:
            self._log.warning('no location sources available')
            self._log.warning('network synchronization is disabled')

        self._log.debug('initializing control API')
        ctrlapi = singleton(ControlApiServer)
        if self.options.trace:
            tracename = os.path.join(self.options.data_dir, 'backend.trace')
            tracefile = open(tracename, 'w')
            ctrlapi._set_tracefile(tracefile)
        addr = gruvi.paddr(self.options.listen)
        ctrlapi.listen(addr)

        fname = os.path.join(self.options.data_dir, 'backend.run')
        addr = ctrlapi.addresses[0]
        runinfo = { 'listen': gruvi.saddr(addr), 'pid': os.getpid() }
        util.write_atomic(fname, json.dumps(runinfo))

        #self._log.debug('initializing client API')
        #clientapi = singleton(ClientApiServer)
        #clientapi.listen()

        # This is where the backend runs (until stop_event is raised or CTRL-C
        # is pressed).
        self._stop_event.wait()

        self._log.debug('backend event loop terminated')

        self._log.debug('shutting down control API')
        ctrlapi.close()

        self._log.debug('shutting down document store')
        store.close()

        self._log.debug('stopped all backend components')

        return 0
示例#8
0
 def connection_made(self, transport):
     self._transport = transport
     peer = transport.get_extra_info('peername')
     print('New connection from {0}'.format(gruvi.saddr(peer)))