コード例 #1
0
ファイル: negotiate.py プロジェクト: ClaudioArtusio/neubot
    def do_negotiate(self, stream, request, nodelay=False):
        session = TRACKER.session_negotiate(request["authorization"])
        if not request["authorization"]:
            request["authorization"] = session.identifier

        #
        # XXX make sure we track ALSO the first connection of the
        # session (which is assigned an identifier in session_negotiate)
        # or, should this connection fail, we would not be able to
        # propagate quickly this information because unregister_connection
        # would not find an entry in self.connections{}.
        #
        if session.negotiations == 1:
            TRACKER.register_connection(stream, request["authorization"])
            nodelay = True

        if not session.active:
            if not nodelay:
                NOTIFIER.subscribe(RENEGOTIATE, self._do_renegotiate,
                          (stream, request), True)
                return

        m1 = compat.SpeedtestNegotiate_Response()
        m1.authorization = session.identifier
        m1.unchoked = session.active
        m1.queuePos = session.queuepos
        m1.publicAddress = stream.peername[0]
        s = marshal.marshal_object(m1, "text/xml")

        stringio = StringIO.StringIO(s)
        response = Message()
        response.compose(code="200", reason="Ok",
         body=stringio, mimetype="application/xml")
        stream.send_response(request, response)
コード例 #2
0
ファイル: negotiate.py プロジェクト: ClaudioArtusio/neubot
    def got_request_headers(self, stream, request):
        ret = True
        TRACKER.register_connection(stream, request["authorization"])

        if request.uri == "/speedtest/upload":
            request.body.write = lambda octets: None

        only_auth = self.conf.get("speedtest.negotiate.auth_only", False)
        if (only_auth and request.uri != "/speedtest/negotiate" and
          not TRACKER.session_active(request["authorization"])):
            LOG.warning("* Connection %s: Forbidden" % stream.logname)
            ret = False

        return ret
コード例 #3
0
ファイル: negotiate.py プロジェクト: ClaudioArtusio/neubot
 def _speedtest_check_timeout(self, *args, **kwargs):
     POLLER.sched(3, self._speedtest_check_timeout)
     if TRACKER.session_prune():
         NOTIFIER.publish(RENEGOTIATE)
コード例 #4
0
ファイル: negotiate.py プロジェクト: ClaudioArtusio/neubot
 def connection_lost(self, stream):
     TRACKER.unregister_connection(stream)
     NOTIFIER.publish(RENEGOTIATE)
コード例 #5
0
ファイル: negotiate.py プロジェクト: ClaudioArtusio/neubot
 def _speedtest_complete(self, request):
     TRACKER.session_delete(request["authorization"])
     NOTIFIER.publish(RENEGOTIATE)