예제 #1
0
 def test_length(self):
     ''' Make sure that the output length is correct '''
     self.assertEqual(len(config._random_bytes(128)), 128)
예제 #2
0
 def test_content(self):
     ''' Make sure that the output content is correct '''
     result = config._random_bytes(128)
     for char in result:
         char = ord(char)
         self.assertTrue(char >= 32 and char <= 126)
예제 #3
0
# along with Neubot.  If not, see <http://www.gnu.org/licenses/>.
#

from neubot.bittorrent.negotiate import AUTH_PEERS
from neubot.bittorrent.peer import PeerNeubot
from neubot.bittorrent.config import _random_bytes

from neubot import utils

#
# The BitTorrent server must not change its PEER_ID
# each time a new client connects.  Instead it should
# keep using the same identifier over and over and
# over.
#
MY_ID = _random_bytes(20)

#
# We check whether a peer is authorized or not just at
# the beginning and from then on we rely on the watchdog
# mechanism that guarantees that at a point the stream
# will be closed anyway.
# We save just our download_speed which is indeed the
# peer's upload speed, the timestamp and the target bytes
# for the next test.
#
class ServerPeer(PeerNeubot):
    def configure(self, conf, measurer=None):
        conf["bittorrent.my_id"] = MY_ID
        PeerNeubot.configure(self, conf, measurer)