projects
/
quix0rs-apt-p2p.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
58eccda
)
HTTPServer responds correctly to requests for torrent strings.
author
Cameron Dale
<camrdale@gmail.com>
Fri, 29 Feb 2008 00:50:10 +0000
(16:50 -0800)
committer
Cameron Dale
<camrdale@gmail.com>
Fri, 29 Feb 2008 00:50:10 +0000
(16:50 -0800)
apt_dht/HTTPServer.py
patch
|
blob
|
history
diff --git
a/apt_dht/HTTPServer.py
b/apt_dht/HTTPServer.py
index 5c6904f764c9b016c357e7bca7d9ca2918f886f6..53755478d20f9e7f737003d824e06053b963060e 100644
(file)
--- a/
apt_dht/HTTPServer.py
+++ b/
apt_dht/HTTPServer.py
@@
-1,13
+1,14
@@
from urllib import unquote_plus
from urllib import unquote_plus
+from binascii import b2a_hex
from twisted.python import log
from twisted.internet import defer
from twisted.python import log
from twisted.internet import defer
-#from twisted.protocols import htb
from twisted.web2 import server, http, resource, channel, stream
from twisted.web2 import static, http_headers, responsecode
from policies import ThrottlingFactory
from twisted.web2 import server, http, resource, channel, stream
from twisted.web2 import static, http_headers, responsecode
from policies import ThrottlingFactory
+from apt_dht_Khashmir.bencode import bencode
class FileDownloader(static.File):
class FileDownloader(static.File):
@@
-113,16
+114,6
@@
class TopLevel(resource.Resource):
self.factory = channel.HTTPFactory(server.Site(self),
**{'maxPipeline': 10,
'betweenRequestsTimeOut': 60})
self.factory = channel.HTTPFactory(server.Site(self),
**{'maxPipeline': 10,
'betweenRequestsTimeOut': 60})
-# serverFilter = htb.HierarchicalBucketFilter()
-# serverBucket = htb.Bucket()
-#
-# # Cap total server traffic at 20 kB/s
-# serverBucket.maxburst = 20000
-# serverBucket.rate = 20000
-#
-# serverFilter.buckets[None] = serverBucket
-#
-# self.factory.protocol = htb.ShapedProtocolFactory(self.factory.protocol, serverFilter)
self.factory = ThrottlingFactory(self.factory, writeLimit = 30*1024)
return self.factory
self.factory = ThrottlingFactory(self.factory, writeLimit = 30*1024)
return self.factory
@@
-144,8
+135,12
@@
class TopLevel(resource.Resource):
hash = unquote_plus(segments[1])
files = self.db.lookupHash(hash)
if files:
hash = unquote_plus(segments[1])
files = self.db.lookupHash(hash)
if files:
- log.msg('Sharing %s with %s' % (files[0]['path'].path, request.remoteAddr))
- return FileUploader(files[0]['path'].path), ()
+ if 'path' in files[0]:
+ log.msg('Sharing %s with %s' % (files[0]['path'].path, request.remoteAddr))
+ return FileUploader(files[0]['path'].path), ()
+ else:
+ log.msg('Sending torrent string %s to %s' % (b2a_hex(hash), request.remoteAddr))
+ return static.Data(bencode({'t': files[0]['pieces']}), 'application/bencoded'), ()
else:
log.msg('Hash could not be found in database: %s' % hash)
else:
log.msg('Hash could not be found in database: %s' % hash)
@@
-165,13
+160,15
@@
if __name__ == '__builtin__':
# Running from twistd -ny HTTPServer.py
# Then test with:
# wget -S 'http://localhost:18080/~/whatever'
# Running from twistd -ny HTTPServer.py
# Then test with:
# wget -S 'http://localhost:18080/~/whatever'
- # wget -S 'http://localhost:18080/
.xsession-error
s'
+ # wget -S 'http://localhost:18080/
~/piece
s'
import os.path
from twisted.python.filepath import FilePath
class DB:
def lookupHash(self, hash):
import os.path
from twisted.python.filepath import FilePath
class DB:
def lookupHash(self, hash):
+ if hash == 'pieces':
+ return [{'pieces': 'abcdefghij0123456789\xca\xec\xb8\x0c\x00\xe7\x07\xf8~])\x8f\x9d\xe5_B\xff\x1a\xc4!'}]
return [{'path': FilePath(os.path.expanduser('~/school/optout'))}]
t = TopLevel(FilePath(os.path.expanduser('~')), DB(), None)
return [{'path': FilePath(os.path.expanduser('~/school/optout'))}]
t = TopLevel(FilePath(os.path.expanduser('~')), DB(), None)