# Path: neubot/negotiate/server.py
# class NegotiateServerModule(object):
# 
#     ''' Each test should implement this interface '''
# 
#     # The minimal collect echoes the request body
#     def collect(self, stream, request_body):
#         ''' Invoked at the end of the test, to collect data '''
#         return request_body
# 
#     # Only speedtest reimplements this method
#     def collect_legacy(self, stream, request_body, request):
#         ''' Legacy interface to collect that also receives the
#             request object: speedtest needs to inspect the Authorization
#             header when the connecting client is pretty old '''
#         return self.collect(stream, request_body)
# 
#     # The minimal unchoke returns the stream unique identifier only
#     def unchoke(self, stream, request_body):
#         ''' Invoked when a stream is authorized to take the test '''
#         return { 'authorization': str(hash(stream)) }
# 
# Path: neubot/backend.py
# BACKEND = BackendProxy()
# 
# Path: neubot/privacy.py
# def count_valid(updates, prefix):
# def check(updates, check_all=False, prefix='privacy.'):
# def collect_allowed(message):
# def allowed_to_run():
# def complain():
# def complain_if_needed():
# def main(args):
# def print_policy():
# def test_settings(connection):
# def update_settings(connection, settings):
# def print_settings(connection, database_path):
# def __main(args):
# USAGE = '''usage: neubot privacy [-Pt] [-D setting=value] [-f database]'''
# POLICY = os.sep.join([utils_hier.WWWDIR, 'privacy.html'])


import logging
import hashlib
from neubot.negotiate.server import NegotiateServerModule
from neubot.backend import BACKEND
from neubot import privacy
            raise RuntimeError('Multiple unchoke')

    def collect(self, stream, request_body):
        ''' Invoked when we must save the result of a session '''
        sha1 = self._stream_to_sha1(stream)
        if sha1 not in self.peers:
            raise RuntimeError('Not authorized to collect')
        else:

            # Note: no more than one collect per session
            result = self.peers[sha1]
            del self.peers[sha1]

            #
            # Backward compatibility: the variable name changed from
            # can_share to can_publish after Neubot 0.4.5
            #
            if 'privacy_can_share' in request_body:
                request_body['privacy_can_publish'] = request_body[
                  'privacy_can_share']
                del request_body['privacy_can_share']

            #
            # Note that the following is not a bug: it's just that
            # the server saves results using the point of view of the
            # client, i.e. upload_speed _is_ client's upload speed.
            #
            request_body['timestamp'] = result['timestamp']
            request_body['upload_speed'] = result['upload_speed']


# Path: neubot/negotiate/server.py
# class NegotiateServerModule(object):
# 
#     ''' Each test should implement this interface '''
# 
#     # The minimal collect echoes the request body
#     def collect(self, stream, request_body):
#         ''' Invoked at the end of the test, to collect data '''
#         return request_body
# 
#     # Only speedtest reimplements this method
#     def collect_legacy(self, stream, request_body, request):
#         ''' Legacy interface to collect that also receives the
#             request object: speedtest needs to inspect the Authorization
#             header when the connecting client is pretty old '''
#         return self.collect(stream, request_body)
# 
#     # The minimal unchoke returns the stream unique identifier only
#     def unchoke(self, stream, request_body):
#         ''' Invoked when a stream is authorized to take the test '''
#         return { 'authorization': str(hash(stream)) }
# 
# Path: neubot/backend.py
# BACKEND = BackendProxy()
# 
# Path: neubot/privacy.py
# def count_valid(updates, prefix):
# def check(updates, check_all=False, prefix='privacy.'):
# def collect_allowed(message):
# def allowed_to_run():
# def complain():
# def complain_if_needed():
# def main(args):
# def print_policy():
# def test_settings(connection):
# def update_settings(connection, settings):
# def print_settings(connection, database_path):
# def __main(args):
# USAGE = '''usage: neubot privacy [-Pt] [-D setting=value] [-f database]'''
# POLICY = os.sep.join([utils_hier.WWWDIR, 'privacy.html'])


# Path: neubot/negotiate/server_bittorrent.py
import logging
import hashlib
from neubot.negotiate.server import NegotiateServerModule
from neubot.backend import BACKEND
from neubot import privacy

            raise RuntimeError('Multiple unchoke')

    def collect(self, stream, request_body):
        ''' Invoked when we must save the result of a session '''
        sha1 = self._stream_to_sha1(stream)
        if sha1 not in self.peers:
            raise RuntimeError('Not authorized to collect')
        else:

            # Note: no more than one collect per session
            result = self.peers[sha1]
            del self.peers[sha1]

            #
            # Backward compatibility: the variable name changed from
            # can_share to can_publish after Neubot 0.4.5
            #
            if 'privacy_can_share' in request_body:
                request_body['privacy_can_publish'] = request_body[
                  'privacy_can_share']
                del request_body['privacy_can_share']

            #
            # Note that the following is not a bug: it's just that
            # the server saves results using the point of view of the
            # client, i.e. upload_speed _is_ client's upload speed.
            #
            request_body['timestamp'] = result['timestamp']
            request_body['upload_speed'] = result['upload_speed']


            if privacy.collect_allowed(request_body):