mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 04:57:54 +00:00
misc upload fixes and improvements
This commit is contained in:
parent
4be4caaf0a
commit
40f7fe3fe7
@ -6,6 +6,9 @@ from twisted.application import service
|
||||
from allmydata.util import idlib
|
||||
from allmydata import encode
|
||||
|
||||
from cStringIO import StringIO
|
||||
import sha
|
||||
|
||||
class NotEnoughPeersError(Exception):
|
||||
pass
|
||||
|
||||
@ -17,12 +20,6 @@ class HaveAllPeersError(Exception):
|
||||
class TooFullError(Exception):
|
||||
pass
|
||||
|
||||
def upload_a_file(peer, filename):
|
||||
u = Uploader(peer)
|
||||
u.set_filehandle(open(filename,"rb"))
|
||||
u.set_verifierid(hashthingy(filethingy))
|
||||
u.make_encoder()
|
||||
|
||||
class FileUploader:
|
||||
debug = False
|
||||
|
||||
@ -133,7 +130,7 @@ class Uploader(service.MultiService):
|
||||
"""
|
||||
name = "uploader"
|
||||
|
||||
def _compute_verifierid(self, filehandle):
|
||||
def _compute_verifierid(self, f):
|
||||
hasher = sha.new(netstring("allmydata_v1_verifierid"))
|
||||
f.seek(0)
|
||||
hasher.update(f.read())
|
||||
@ -141,11 +138,24 @@ class Uploader(service.MultiService):
|
||||
# note: this is only of the plaintext data, no encryption yet
|
||||
return hasher.digest()
|
||||
|
||||
def upload_file_by_name(self, filename):
|
||||
def upload_filename(self, filename):
|
||||
f = open(filename, "rb")
|
||||
def _done(res):
|
||||
f.close()
|
||||
return res
|
||||
d = self.upload_filehandle(f)
|
||||
d.addBoth(_done)
|
||||
return d
|
||||
|
||||
def upload_data(self, data):
|
||||
f = StringIO(data)
|
||||
return self.upload_filehandle(f)
|
||||
|
||||
def upload_filehandle(self, f):
|
||||
assert self.parent
|
||||
assert self.running
|
||||
f = open(filename, "rb")
|
||||
u = FileUploader(self.parent)
|
||||
u.set_filehandle(f)
|
||||
u.set_verifierid(self._compute_verifierid(f))
|
||||
u.make_encoder()
|
||||
d = u.start()
|
||||
|
Loading…
Reference in New Issue
Block a user