Пример #1
0
def makeBroadcasterService(endpoint, local_ivo, test_interval, whitelist):
    """Create a VOEvent receiver service.

    The receiver service accepts VOEvent messages submitted to the broker by
    authors.

    Parameters
    ----------
    endpoint : implements `twisted.internet.interfaces.IStreamServerEndpoint`
        The endpoint to which the service will listen.
    local_ivo : `str`
        IVOA identifier for the subscriber.
    test_interval: `int`
        The interval in seconds between test events to be broadcast. If ``0``,
        no test events will be sent.
    whitelist : `list` of `ipaddress.IPv4Network` or `ipaddress.IPv6Network`
        Only addresses which fall in a network included in the whitelist are
        permitted to subscribe.
    """
    factory = VOEventBroadcasterFactory(local_ivo, test_interval)
    if log.LEVEL >= log.Levels.INFO:
        factory.noisy = False

    whitelisting_factory = WhitelistingFactory(factory, whitelist,
                                               "subscription")
    if log.LEVEL >= log.Levels.INFO:
        whitelisting_factory.noisy = False

    service = StreamServerEndpointService(endpoint, whitelisting_factory)

    # Shut down, rather than simply logging an error, if we can't bind.
    service._raiseSynchronously = True

    return service
Пример #2
0
def makeBroadcasterService(endpoint, local_ivo, test_interval, whitelist):
    """Create a VOEvent receiver service.

    The receiver service accepts VOEvent messages submitted to the broker by
    authors.

    Parameters
    ----------
    endpoint : implements `twisted.internet.interfaces.IStreamServerEndpoint`
        The endpoint to which the service will listen.
    local_ivo : `str`
        IVOA identifier for the subscriber.
    test_interval: `int`
        The interval in seconds between test events to be broadcast. If ``0``,
        no test events will be sent.
    whitelist : `list` of `ipaddress.IPv4Network` or `ipaddress.IPv6Network`
        Only addresses which fall in a network included in the whitelist are
        permitted to subscribe.
    """
    factory = VOEventBroadcasterFactory(local_ivo, test_interval)
    if log.LEVEL >= log.Levels.INFO:
        factory.noisy = False

    whitelisting_factory = WhitelistingFactory(factory, whitelist,
                                               "subscription")
    if log.LEVEL >= log.Levels.INFO:
        whitelisting_factory.noisy = False

    service = StreamServerEndpointService(endpoint, whitelisting_factory)

    # Shut down, rather than simply logging an error, if we can't bind.
    service._raiseSynchronously = True

    return service
Пример #3
0
def makeService(config):
    event_db = Event_DB(config['eventdb'])
    LoopingCall(event_db.prune, MAX_AGE).start(PRUNE_INTERVAL)

    broker_service = MultiService()
    if config['broadcast']:
        broadcaster_factory = VOEventBroadcasterFactory(
            config["local-ivo"], config['broadcast-test-interval']
        )
        if log.LEVEL >= log.Levels.INFO: broadcaster_factory.noisy = False
        broadcaster_service = TCPServer(
            config['broadcast-port'],
            broadcaster_factory
        )
        broadcaster_service.setName("Broadcaster")
        broadcaster_service.setServiceParent(broker_service)

        # If we're running a broadcast, we will rebroadcast any events we
        # receive to it.
        config['handlers'].append(EventRelay(broadcaster_factory))

    if config['receive']:
        receiver_factory = VOEventReceiverFactory(
            local_ivo=config['local-ivo'],
            validators=[
                CheckPreviouslySeen(event_db),
                CheckSchema(
                    os.path.join(comet.__path__[0], "schema/VOEvent-v2.0.xsd")
                ),
                CheckIVORN()
            ],
            handlers=config['handlers']
        )
        if log.LEVEL >= log.Levels.INFO: receiver_factory.noisy = False
        whitelisting_factory = WhitelistingFactory(receiver_factory, config['whitelist'])
        if log.LEVEL >= log.Levels.INFO: whitelisting_factory.noisy = False
        receiver_service = TCPServer(config['receive-port'], whitelisting_factory)
        receiver_service.setName("Receiver")
        receiver_service.setServiceParent(broker_service)

    for host, port in config["remotes"]:
        subscriber_factory = VOEventSubscriberFactory(
            local_ivo=config["local-ivo"],
            validators=[CheckPreviouslySeen(event_db)],
            handlers=config['handlers'],
            filters=config['filters']
        )
        if log.LEVEL >= log.Levels.INFO: subscriber_factory.noisy = False
        remote_service = TCPClient(host, port, subscriber_factory)
        remote_service.setName("Remote %s:%d" % (host, port))
        remote_service.setServiceParent(broker_service)

    if not broker_service.services:
        reactor.callWhenRunning(log.warning, "No services requested; stopping.")
        reactor.callWhenRunning(reactor.stop)
    return broker_service
Пример #4
0
def makeReceiverService(endpoint, local_ivo, validators, handlers, whitelist):
    """Create a VOEvent receiver service.

    The receiver service accepts VOEvent messages submitted to the broker by
    authors.

    Parameters
    ----------
    endpoint : implements `twisted.internet.interfaces.IStreamServerEndpoint`
        The endpoint to which the service will listen.
    local_ivo : `str`
        IVOA identifier for the subscriber.
    validators : `list` of implementers of `~comet.icomet.IValidator`.
        Validators which will be applied to incoming events. Events which fail
        validation will be rejected.
    handlers : `list` of implementers of `~comet.icomet.IHandler`.
        Handlers to which events which pass validation will be passed.
    whitelist : `list` of `ipaddress.IPv4Network` or `ipaddress.IPv6Network`
        Submissions are only accepted from addresses which fall in a network
        included in the whitelist.

    Warnings
    --------
    Although a non-TCP endpoint can be specified (a Unix domain socket, for
    example), the whitelist won't be applied to it correctly (indeed, it will
    probably break horribly).
    """
    factory = VOEventReceiverFactory(local_ivo=local_ivo,
                                     validators=validators,
                                     handlers=handlers)
    if log.LEVEL >= log.Levels.INFO:
        factory.noisy = False

    whitelisting_factory = WhitelistingFactory(factory, whitelist,
                                               "submission")
    if log.LEVEL >= log.Levels.INFO:
        whitelisting_factory.noisy = False

    service = StreamServerEndpointService(endpoint, whitelisting_factory)

    # Shut down, rather than simply logging an error, if we can't bind.
    service._raiseSynchronously = True

    return service
Пример #5
0
def makeReceiverService(endpoint, local_ivo, validators, handlers, whitelist):
    """Create a VOEvent receiver service.

    The receiver service accepts VOEvent messages submitted to the broker by
    authors.

    Parameters
    ----------
    endpoint : implements `twisted.internet.interfaces.IStreamServerEndpoint`
        The endpoint to which the service will listen.
    local_ivo : `str`
        IVOA identifier for the subscriber.
    validators : `list` of implementers of `~comet.icomet.IValidator`.
        Validators which will be applied to incoming events. Events which fail
        validation will be rejected.
    handlers : `list` of implementers of `~comet.icomet.IHandler`.
        Handlers to which events which pass validation will be passed.
    whitelist : `list` of `ipaddress.IPv4Network` or `ipaddress.IPv6Network`
        Submissions are only accepted from addresses which fall in a network
        included in the whitelist.

    Warnings
    --------
    Although a non-TCP endpoint can be specified (a Unix domain socket, for
    example), the whitelist won't be applied to it correctly (indeed, it will
    probably break horribly).
    """
    factory = VOEventReceiverFactory(local_ivo=local_ivo,
                                     validators=validators,
                                     handlers=handlers)
    if log.LEVEL >= log.Levels.INFO:
        factory.noisy = False

    whitelisting_factory = WhitelistingFactory(factory, whitelist, "submission")
    if log.LEVEL >= log.Levels.INFO:
        whitelisting_factory.noisy = False

    service = StreamServerEndpointService(endpoint, whitelisting_factory)

    # Shut down, rather than simply logging an error, if we can't bind.
    service._raiseSynchronously = True

    return service
Пример #6
0
def makeService(config):
    event_db = Event_DB(config['eventdb'])
    LoopingCall(event_db.prune, MAX_AGE).start(PRUNE_INTERVAL)

    broker_service = MultiService()
    if config['broadcast']:
        broadcaster_factory = VOEventBroadcasterFactory(
            config["local-ivo"], config['broadcast-test-interval']
        )
        if log.LEVEL >= log.Levels.INFO: broadcaster_factory.noisy = False
        broadcaster_whitelisting_factory = WhitelistingFactory(
            broadcaster_factory, config['subscriber-whitelist'], "subscription"
        )
        if log.LEVEL >= log.Levels.INFO: broadcaster_whitelisting_factory.noisy = False
        broadcaster_service = TCPServer(
            config['broadcast-port'],
            broadcaster_whitelisting_factory
        )
        broadcaster_service.setName("Broadcaster")
        broadcaster_service.setServiceParent(broker_service)

        # If we're running a broadcast, we will rebroadcast any events we
        # receive to it.
        config['handlers'].append(EventRelay(broadcaster_factory))

    if config['receive']:
        receiver_factory = VOEventReceiverFactory(
            local_ivo=config['local-ivo'],
            validators=[
                CheckPreviouslySeen(event_db),
                CheckSchema(
                    os.path.join(comet.__path__[0], "schema/VOEvent-v2.0.xsd")
                ),
                CheckIVOID()
            ],
            handlers=config['handlers']
        )
        if log.LEVEL >= log.Levels.INFO: receiver_factory.noisy = False
        author_whitelisting_factory = WhitelistingFactory(
            receiver_factory, config['author-whitelist'], "submission"
        )
        if log.LEVEL >= log.Levels.INFO: author_whitelisting_factory.noisy = False
        receiver_service = TCPServer(config['receive-port'], author_whitelisting_factory)
        receiver_service.setName("Receiver")
        receiver_service.setServiceParent(broker_service)

    for host, port in config["remotes"]:
        subscriber_factory = VOEventSubscriberFactory(
            local_ivo=config["local-ivo"],
            validators=[CheckPreviouslySeen(event_db)],
            handlers=config['handlers'],
            filters=config['filters']
        )
        if log.LEVEL >= log.Levels.INFO: subscriber_factory.noisy = False
        remote_service = TCPClient(host, port, subscriber_factory)
        remote_service.setName("Remote %s:%d" % (host, port))
        remote_service.setServiceParent(broker_service)

    if not broker_service.services:
        reactor.callWhenRunning(log.warn, "No services requested; stopping.")
        reactor.callWhenRunning(reactor.stop)
    return broker_service