bittorrent/stream.py: forward send_complete to peer.py

Forward send_complete() event to peer.  This is needed by next
patch.  Which will modify peer.py to immediately write more PIECEs
on the socket as soon as send_complete() event is delivered.  In
turn, this is key to put the control of test duration in the hands
of the peer that uploads.
bittorrent/peer.py: allow to control duration at the uploader

Add peer a new self.version attribute.  When this attribute is 1,
the behavior is the traditional one.  Conversely, when the attribute
is 2, test duration is controlled by the uploader.  Since the default
value is 1, this commit introduces no functional change.

When version is 2, the uploader sends a new piece whenever the
send queue is empty.  This allows to control duration, since
it can stop sending as soon as the elapsed upload time is greater
than the target elapsed time.  This form of control is more
robust, because there is no latency caused by queueing in the
equation.
bittorrent/peer.py: add simple main()

Add simple main().  This main() allows to test code in this
file directly.  So we can test version 2 of the code, without
the need of changing other parts of the tree.
bittorrent/peer.py: add code to behave strictly as a bittorrent peer

This commit adds version 3 of the test.  This version differs very
little from version 2, in terms of lines of code.  But the behavior
is radically different.  Indeed, it behaves like a typical bittorrent
peer, and each request is followed by a response.

Despite being a test that sends a piece for each request, version
3 is radically different from version 1 too.  In particular, it
does not attempt to play tricks to fill the pipeline.  As a
consequence, I guess TCP would be buffer limited in most cases.

I don't need this piece of code soon.  Still, I decided to commit
it, because it may be (and, indeed, already is) handy.  There is
value in being able to compare a test that saturates the bottleneck
(version 2) and a test with a strict behavior (version 3).
bittorrent/peer.py: repair version 3 of bittorrent test

I accidentally changed one == 2 into one >= 2.  So, version 3 of
the test was not working properly any more.  This commit replaces
the wrong >= with ==.  And version 3 of the test works again.
bittorrent/peer.py: change the scope of the comment

Looking again at the code I noticed that the comment had a
wrong scope, and that made it misleading.
bittorrent/client.py: negotiate version-2 test

Negotiate version-2 test by default.  There is value in controlling
the transmission test at the sender, namely that test duration is more
predictable.
bittorrent server: Cope with version-1 and version-2 tests

Teach bittorrent negotiator and server how to deal with both
version-1 and version-2.  Be liberal in what we accept, do
not assume the client will send us the number of target bytes.
Even if it does.
bittorrent/peer.py: log test version

Log test version at level debug, to help find out quickly cases
where there is a version mismatch between the peers.
add bytegen_speedtest.py: random bytes generator for speedtest
speedtest/client.py: control test duration at the sender

Add new state variable 'version'.  When version is 2, test
duration is controlled by the sender.  This allows for more
predictable duration, since we avoid all the problems with
network queueing delay that chime in when control is shared
between client and server.

Given the advantages, this diff also initializes to 2 the
version.
speedtest/server.py: control test duration at the sender

When there is no range header, the server will auto-switch to
version 2 of the test.  With version 2, duration is controlled
by the sender.  This allows for more predictable duration,
since we avoid all the problems with network queueing delay
that chime in, instead, when control is shared between client
and server.
log: Added a wrapper for stdlib logging
Globally replace LOG with logging where feasible.
Globally remove % operator when logging.
Revert "Globally remove % operator when logging."

This reverts commit 250acc10c90bc216e112d948a8e6e94ae49e3062,
because Marco has later sent me a better patch.
Globally remove % operator when logging.
log: fixed two pylint warnings.

 1. C:320,0:LogWrapper: Missing docstring
 2. W:326,8:LogWrapper.emit: Access to a protected member _log of
    a client class
log.py: avoid LogWrapper.emit() pylint warning

In LogWrapper.emit() pylint complains that we are using * or **
magic.  Avoid that by:

1. creating a Logger.log_tuple() function that receives a tuple
   and not *args;

2. teaching LogWrapper.emit() to use Logger.log_tuple() rather
   that Loggger.log().
log.py: strip newlines from args.

The previous behavior inside log() was to strip every message line
before merging the arguments (args). Now we strip the message after
merging args in order to also catch newlines and spaces inside args.