1
0

inserter.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # The contents of this file are subject to the BitTorrent Open Source License
  2. # Version 1.1 (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. ### generate a bunch of nodes that use a single contact point
  11. usage = "usage: inserter.py <contact host> <contact port>"
  12. from utkhashmir import UTKhashmir
  13. from BitTorrent.RawServer_twisted import RawServer
  14. from BitTorrent.defaultargs import common_options, rare_options
  15. from khashmir.khash import newID
  16. from random import randrange
  17. from BitTorrent.stackthreading import Event
  18. import sys, os
  19. from khashmir.krpc import KRPC
  20. KRPC.noisy = 1
  21. done = 0
  22. def d(n):
  23. global done
  24. done = done+1
  25. if __name__=="__main__":
  26. host, port = sys.argv[1:]
  27. x = UTKhashmir("", 22038, "/tmp/cgcgcgc")
  28. x.addContact(host, int(port))
  29. x.rawserver.listen_once()
  30. x.findCloseNodes(d)
  31. while not done:
  32. x.rawserver.listen_once()
  33. l = []
  34. for i in range(10):
  35. k = newID()
  36. v = randrange(10000,20000)
  37. l.append((k, v))
  38. x.announcePeer(k, v, d)
  39. done = 1
  40. while done < 10:
  41. x.rawserver.listen_once(1)
  42. for k,v in l:
  43. print ">>>", `k`, v