PeerID.py 820 B

123456789101112131415161718192021
  1. # The contents of this file are subject to the BitTorrent Open Source License
  2. # Version 1.0 (the License). You may not copy or use this file, in either
  3. # source code or executable form, except in compliance with the License. You
  4. # may obtain a copy of the License at http://www.bittorrent.com/license/.
  5. #
  6. # Software distributed under the License is distributed on an AS IS basis,
  7. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  8. # for the specific language governing rights and limitations under the
  9. # License.
  10. # Written by Greg Hazel
  11. # based on code by Matt Chisholm
  12. import os
  13. from BitTorrent import version
  14. def make_id():
  15. myid = 'M' + version.split()[0].replace('.', '-')
  16. padded = myid[:8] + '-' * (8 - len(myid))
  17. myid = padded + os.urandom(6).encode('hex')
  18. return myid