コード例 #1
0
    def _getConnectionPool(self):
        pool = HTTPConnectionPool(reactor, self._persistent)

        if self._persistent:
            pool.maxPersistentPerHost = self._maxPersistentPerHost
            pool.cachedConnectionTimeout = self._cachedConnectionTimeout
            pool.retryAutomatically = self._retryAutomatically

        return pool
コード例 #2
0
ファイル: client.py プロジェクト: vesellov/bitdust.devel
    def _getConnectionPool(self):
        pool = HTTPConnectionPool(reactor, self._persistent)

        if self._persistent:
            pool.maxPersistentPerHost = self._maxPersistentPerHost
            pool.cachedConnectionTimeout = self._cachedConnectionTimeout
            pool.retryAutomatically = self._retryAutomatically

        return pool
コード例 #3
0
 def __init__(self, hs):
     self.hs = hs
     self.signing_key = hs.config.signing_key[0]
     self.server_name = hs.hostname
     reactor = hs.get_reactor()
     pool = HTTPConnectionPool(reactor)
     pool.retryAutomatically = False
     pool.maxPersistentPerHost = 5
     pool.cachedConnectionTimeout = 2 * 60
     self.agent = Agent.usingEndpointFactory(
         reactor, MatrixFederationEndpointFactory(hs), pool=pool)
     self.clock = hs.get_clock()
     self._store = hs.get_datastore()
     self.version_string = hs.version_string.encode('ascii')
     self._next_id = 1
     self.default_timeout = 60
コード例 #4
0
    def __init__(self, hs):
        self.hs = hs
        self.signing_key = hs.config.signing_key[0]
        self.server_name = hs.hostname
        reactor = hs.get_reactor()
        pool = HTTPConnectionPool(reactor)
        pool.retryAutomatically = False
        pool.maxPersistentPerHost = 5
        pool.cachedConnectionTimeout = 2 * 60
        self.agent = Agent.usingEndpointFactory(
            reactor, MatrixFederationEndpointFactory(hs), pool=pool
        )
        self.clock = hs.get_clock()
        self._store = hs.get_datastore()
        self.version_string_bytes = hs.version_string.encode('ascii')
        self.default_timeout = 60

        def schedule(x):
            reactor.callLater(_EPSILON, x)

        self._cooperator = Cooperator(scheduler=schedule)
コード例 #5
0
ファイル: dp5twistedclient.py プロジェクト: haraldh/dp5
def dp5twistedclientFactory(state):
    global commonhttppool
    ## Build an async client
    cli = AsyncDP5Client(state)
    
    # Use a common pool of HTTPs connections
    if commonhttppool is None:
        httppool = HTTPConnectionPool(reactor, persistent=True)
        httppool.maxPersistentPerHost = 5
        httppool.retryAutomatically = False
    else:
        httppool = commonhttppool

    cli.pool = httppool
    cli.agent = Agent(reactor, pool=httppool)
    cli.inflight = 0

    ## Define the networking for registration
    def send_registration(cli, epoch, combined, msg, cb, xfail):
        if combined:
            ser = cli.state["combined"]["regServer"]
            surl = str("https://"+ser+"/register?epoch=%s" % (epoch-1))
        else:
            ser = cli.state["standard"]["regServer"]
            surl = str("https://" + ser + "/register?epoch=%s" % (epoch-1))

        cli.inflight += 1
        try:
            body = FileBodyProducer(StringIO(msg))

            d = cli.agent.request(
                'POST',
                surl,
                Headers({'User-Agent': ['DP5 Twisted Client']}),
                body)

            def err(*args):
                # print "REG ERROR", args
                # print args
                cli.inflight -= 1
                xfail(args[0])

            def cbRequest(response):
                finished = Deferred()
                finished.addCallback(cb)
                finished.addErrback(err)
                response.deliverBody(BufferedReception(finished))
                cli.inflight -= 1
                return finished

            d.addCallback(cbRequest)
            d.addErrback(err)
        except Exception as e:
            print e
            cli.inflight -= 1
            err(e)

    cli.register_handlers += [send_registration]

    ## Define the networking for lookups
    def send_lookup(cli, epoch, combined, seq, msg, cb, xfail):
        if msg == "":
            #print "No need to relay lookup"
            return cb("")

        if combined:
            ser = cli.state["combined"]["lookupServers"][seq]
            surl = str("https://"+ser+"/lookup?epoch=%s" % epoch)
        else:
            ser = cli.state["standard"]["lookupServers"][seq]
            surl = str("https://" + ser + "/lookup?epoch=%s" % epoch)

        cli.inflight += 1
        try:
            body = FileBodyProducer(StringIO(msg))

            d = cli.agent.request(
                'POST',
                surl,
                Headers({'User-Agent': ['DP5 Twisted Client']}),
                body)

            def err(*args):
                cli.inflight -= 1
                xfail(args[0])

            def cbRequest(response):
                finished = Deferred()
                finished.addCallback(cb)
                finished.addErrback(err)
                response.deliverBody(BufferedReception(finished))
                cli.inflight -= 1
                return finished
            
            d.addCallback(cbRequest)
            d.addErrback(err)
        except Exception as e:
            print e
            cli.inflight -= 1
            err(e)

    cli.lookup_handlers += [send_lookup]

    def loopupdate():
        cli.update()

    cli.l = task.LoopingCall(loopupdate)
    period = float(cli.state["epoch_lengthCB"] / 20.0)
    # cli.l.start(period) # call every second
    delay = 0.1 # random.random() * 10.0
    reactor.callLater(delay, cli.l.start, period)
    return cli
コード例 #6
0
ファイル: dp5twistedclient.py プロジェクト: haraldh/dp5
import random

import limits
limits.set_limits()

from users import User
import cPickle

SSLPOOL = True

## Common pool of HTTPs connection to
## ensure that SSL is not the bottle neck.
if SSLPOOL:
    commonhttppool = HTTPConnectionPool(reactor, persistent=True)
    commonhttppool.maxPersistentPerHost = 50
    commonhttppool.retryAutomatically = False
else:
    commonhttppool = None


class BufferedReception(Protocol):
    def __init__(self, finished):
        self.finished = finished
        self.bytes = None

    def dataReceived(self, bytes):        
        if self.bytes == None:
            self.bytes = StringIO()
        self.bytes.write(bytes)

    def connectionLost(self, reason):
コード例 #7
0
def dp5twistedclientFactory(state):
    global commonhttppool
    ## Build an async client
    cli = AsyncDP5Client(state)

    # Use a common pool of HTTPs connections
    if commonhttppool is None:
        httppool = HTTPConnectionPool(reactor, persistent=True)
        httppool.maxPersistentPerHost = 5
        httppool.retryAutomatically = False
    else:
        httppool = commonhttppool

    cli.pool = httppool
    cli.agent = Agent(reactor, pool=httppool)
    cli.inflight = 0

    ## Define the networking for registration
    def send_registration(cli, epoch, combined, msg, cb, xfail):
        if combined:
            ser = cli.state["combined"]["regServer"]
            surl = str("https://" + ser + "/register?epoch=%s" % (epoch - 1))
        else:
            ser = cli.state["standard"]["regServer"]
            surl = str("https://" + ser + "/register?epoch=%s" % (epoch - 1))

        cli.inflight += 1
        try:
            body = FileBodyProducer(StringIO(msg))

            d = cli.agent.request(
                'POST', surl, Headers({'User-Agent': ['DP5 Twisted Client']}),
                body)

            def err(*args):
                # print "REG ERROR", args
                # print args
                cli.inflight -= 1
                xfail(args[0])

            def cbRequest(response):
                finished = Deferred()
                finished.addCallback(cb)
                finished.addErrback(err)
                response.deliverBody(BufferedReception(finished))
                cli.inflight -= 1
                return finished

            d.addCallback(cbRequest)
            d.addErrback(err)
        except Exception as e:
            print e
            cli.inflight -= 1
            err(e)

    cli.register_handlers += [send_registration]

    ## Define the networking for lookups
    def send_lookup(cli, epoch, combined, seq, msg, cb, xfail):
        if msg == "":
            #print "No need to relay lookup"
            return cb("")

        if combined:
            ser = cli.state["combined"]["lookupServers"][seq]
            surl = str("https://" + ser + "/lookup?epoch=%s" % epoch)
        else:
            ser = cli.state["standard"]["lookupServers"][seq]
            surl = str("https://" + ser + "/lookup?epoch=%s" % epoch)

        cli.inflight += 1
        try:
            body = FileBodyProducer(StringIO(msg))

            d = cli.agent.request(
                'POST', surl, Headers({'User-Agent': ['DP5 Twisted Client']}),
                body)

            def err(*args):
                cli.inflight -= 1
                xfail(args[0])

            def cbRequest(response):
                finished = Deferred()
                finished.addCallback(cb)
                finished.addErrback(err)
                response.deliverBody(BufferedReception(finished))
                cli.inflight -= 1
                return finished

            d.addCallback(cbRequest)
            d.addErrback(err)
        except Exception as e:
            print e
            cli.inflight -= 1
            err(e)

    cli.lookup_handlers += [send_lookup]

    def loopupdate():
        cli.update()

    cli.l = task.LoopingCall(loopupdate)
    period = float(cli.state["epoch_lengthCB"] / 20.0)
    # cli.l.start(period) # call every second
    delay = 0.1  # random.random() * 10.0
    reactor.callLater(delay, cli.l.start, period)
    return cli
コード例 #8
0
import random

import limits
limits.set_limits()

from users import User
import cPickle

SSLPOOL = True

## Common pool of HTTPs connection to
## ensure that SSL is not the bottle neck.
if SSLPOOL:
    commonhttppool = HTTPConnectionPool(reactor, persistent=True)
    commonhttppool.maxPersistentPerHost = 50
    commonhttppool.retryAutomatically = False
else:
    commonhttppool = None


class BufferedReception(Protocol):
    def __init__(self, finished):
        self.finished = finished
        self.bytes = None

    def dataReceived(self, bytes):
        if self.bytes == None:
            self.bytes = StringIO()
        self.bytes.write(bytes)

    def connectionLost(self, reason):