Ejemplo n.º 1
0
def start(app: PaywalledProxy, host: str, port: int, elasticsearch: str):
    auth = os.environ.get('ES_CREDENTIALS')
    if auth is None:
        print(
            'Please provide elasticsearch credentials via ES_CREDENTIALS environment.'
        )
        sys.exit(1)
    elasticsearch_connection = Elasticsearch(elasticsearch,
                                             timeout=30,
                                             http_auth=auth)
    backend = ElasticsearchBackend(elasticsearch_connection)
    APIServer(app, backend)
    app.run(host=host, port=port, debug=True)
    app.join()
Ejemplo n.º 2
0
def make_paywalled_proxy(private_key: str,
                         state_filename: str,
                         contract_address=None,
                         flask_app=None,
                         web3=None) -> PaywalledProxy:
    """
    Args:
        private_key (str): receiver's private key
        state_filename (str): path to the state DB.
            If database doesn't exist, it'll be created and initialized.
        contract_address (str, optional): address of the channel manager contract.
        flask_app (optional): make proxy use this flask app
        web3 (Web3, optional): do not create a new web3 provider, but use this param instead
    Returns:
        PaywalledProxy: an initialized proxy.
        Do not forget to call `run()` to start serving requests.
    """
    if web3 is None:
        web3 = Web3(
            HTTPProvider(constants.WEB3_PROVIDER_DEFAULT,
                         request_kwargs={'timeout': 60}))
        contract_address = contract_address or NETWORK_CFG.CHANNEL_MANAGER_ADDRESS
    channel_manager = make_channel_manager(private_key, contract_address,
                                           state_filename, web3)
    return PaywalledProxy(channel_manager, flask_app, constants.HTML_DIR,
                          constants.JSLIB_DIR)
Ejemplo n.º 3
0
def make_paywalled_proxy(private_key: str,
                         state_filename: str,
                         contract_address=config.CHANNEL_MANAGER_ADDRESS,
                         flask_app=None, web3=None):
    if web3 is None:
        web3 = Web3(config.WEB3_PROVIDER)
    channel_manager = make_channel_manager(private_key, contract_address, state_filename, web3)
    proxy = PaywalledProxy(channel_manager, flask_app, config.HTML_DIR, config.JSLIB_DIR)
    return proxy
Ejemplo n.º 4
0
def make_paywalled_proxy(private_key: str,
                         state_filename: str,
                         flask_app=None,
                         web3=None):
    if web3 is None:
        web3 = Web3(config.WEB3_PROVIDER)
    channel_manager = make_channel_manager(private_key, state_filename, web3)
    proxy = PaywalledProxy(channel_manager, flask_app, config.HTML_DIR,
                           config.JSLIB_DIR)
    return proxy
Ejemplo n.º 5
0
def make_paywalled_proxy(
        private_key: str,
        state_filename: str,
        contract_address=config.CHANNEL_MANAGER_ADDRESS,
        flask_app=None,
        web3=None
) -> PaywalledProxy:
    if web3 is None:
        web3 = Web3(HTTPProvider(config.WEB3_PROVIDER_DEFAULT, request_kwargs={'timeout': 60}))
    channel_manager = make_channel_manager(private_key, contract_address, state_filename, web3)
    proxy = PaywalledProxy(channel_manager, flask_app, config.HTML_DIR, config.JSLIB_DIR)
    return proxy
Ejemplo n.º 6
0
 def __init__(self, proxy: PaywalledProxy, es: ElasticsearchBackend):
     self.proxy = proxy
     self.resource_cache = {}
     self.cache_lock = Lock()
     proxy.add_paywalled_resource(
         ExpensiveElasticsearch,
         '/_search',
         None,
         '/<string:_index>/_search',
         '/<string:_index>/<string:_type>/_search',
         '/_msearch',
         '/<string:_index>/_msearch',
         '/<string:_index>/<string:_type>/_msearch',
         '/_mapping',
         '/<string:_index>/_mapping',
         '/<string:_index>/<string:_type>/_mapping',
         resource_class_kwargs=dict(
             resource_cache=self.resource_cache,
             cache_lock=self.cache_lock,
             es=es,
         )
     )
Ejemplo n.º 7
0
def empty_proxy(channel_manager: ChannelManager, wait_for_blocks, use_tester: bool):
    app = PaywalledProxy(channel_manager)
    app.run()

    if use_tester:
        # Waiting only required on tester chains due to monkey-patched channel manager.
        wait_for_blocks(1)

    yield app
    app.stop()
Ejemplo n.º 8
0
def doggo_proxy(channel_manager, receiver_privkey, proxy_state_filename):
    app = PaywalledProxy(channel_manager)
    app.add_content(
        PaywalledContent("kitten.jpg", 1, lambda _: ("HI I AM A KITTEN", 200)))
    app.add_content(
        PaywalledContent("doggo.jpg", 2, lambda _: ("HI I AM A DOGGO", 200)))
    app.add_content(
        PaywalledContent("teapot.jpg", 3, lambda _: ("HI I AM A TEAPOT", 418)))
    #    app.add_content(PaywalledFile("test.txt", 10, "/tmp/test.txt"))
    app.run()
    yield app
    app.stop()
In his case we don't use a proxy, but directly a server
"""
from microraiden.proxy.paywalled_proxy import PaywalledProxy
from microraiden.config import CHANNEL_MANAGER_ADDRESS
import os
from microraiden.proxy.content import (PaywalledContent, PaywalledProxyUrl)

if __name__ == '__main__':
    private_key = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
    tempfile = os.path.join(os.path.expanduser('~'), '.raiden/echo_server.pkl')
    # set up a paywalled proxy
    # arguments are:
    #  - channel manager contract
    #  - private key to use for receiving funds
    #  - temporary file for storing state information (balance proofs)
    app = PaywalledProxy(CHANNEL_MANAGER_ADDRESS, private_key, tempfile)

    # Add resource defined by regex and with a fixed price of 1 token
    # We setup the resource to return whatever is supplied as a second argument
    #  in the URL.
    app.add_content(
        PaywalledContent("echofix\/[a-zA-Z0-9]+", 1, lambda request:
                         (request.split("/")[1], 200)))
    # Resource with a price determined by the second parameter
    app.add_content(
        PaywalledContent("echodyn\/[0-9]+",
                         lambda request: int(request.split("/")[1]),
                         lambda request: (int(request.split("/")[1]), 200)))
    app.add_content(
        PaywalledProxyUrl(
            "p\/[0-9]+", 1,
Ejemplo n.º 10
0
def doggo_proxy(channel_manager, receiver_privkey, proxy_state_filename,
                proxy_ssl, proxy_ssl_certs):
    app = PaywalledProxy(channel_manager)
    app.add_paywalled_resource(ExpensiveKitten, '/kitten.jpg', 1)
    app.add_paywalled_resource(ExpensiveDoggo, '/doggo.jpg', 2)
    app.add_paywalled_resource(ExpensiveTeapot, '/teapot.jpg', 3)
    #    app.add_content(PaywalledFile("test.txt", 10, "/tmp/test.txt"))
    ssl_context = proxy_ssl_certs if proxy_ssl else None
    app.run(ssl_context=ssl_context)
    yield app
    app.stop()
Ejemplo n.º 11
0
def doggo_proxy(
        channel_manager: ChannelManager,
        proxy_ssl: bool,
        proxy_ssl_certs
):
    app = PaywalledProxy(channel_manager)
    app.add_paywalled_resource(ExpensiveKitten, '/kitten.jpg', 1)
    app.add_paywalled_resource(ExpensiveDoggo, '/doggo.jpg', 2)
    app.add_paywalled_resource(ExpensiveTeapot, '/teapot.jpg', 3)
    ssl_context = proxy_ssl_certs if proxy_ssl else None
    app.run(ssl_context=ssl_context)
    yield app
    app.stop()