from allmydata.download import Downloader
from allmydata.vdrive import VDrive
from allmydata.webish import WebishServer
+from allmydata.control import ControlServer
class Client(node.Node, Referenceable):
implements(RIClient)
def tub_ready(self):
self.my_pburl = self.tub.registerReference(self)
+ self.register_control()
self.maybe_connect_to_queen()
def set_queen_pburl(self, queen_pburl):
self.queen_connector = self.tub.connectTo(self.queen_pburl,
self._got_queen)
+ def register_control(self):
+ c = ControlServer()
+ c.setServiceParent(self)
+ control_url = self.tub.registerReference(c)
+ f = open("control.pburl", "w")
+ f.write(control_url + "\n")
+ f.close()
+ os.chmod("control.pburl", 0600)
+
def stopService(self):
if self.queen_connector:
self.queen_connector.stopConnecting()
--- /dev/null
+
+from zope.interface import implements
+from twisted.application import service
+from foolscap import Referenceable
+from allmydata.interfaces import RIControlClient
+
+
+class ControlServer(Referenceable, service.Service):
+
+ def remote_upload_from_file_to_uri(self, filename):
+ uploader = self.parent.getServiceNamed("uploader")
+ d = uploader.upload_filename(filename)
+ return d
+
+ def remote_download_from_uri_to_file(self, uri, filename):
+ downloader = self.parent.getServiceNamed("downloader")
+ d = downloader.download_to_filename(uri, filename)
+ d.addCallback(lambda res: filename)
+ return d
+
+ def remote_get_memory_usage(self):
+ # this is obviously linux-specific
+ stat_names = ("VmPeak",
+ "VmSize",
+ #"VmHWM",
+ "VmData")
+ for line in open("/proc/self/status", "r").readlines():
+ name, right = line.split(":",2)
+ if name in stat_names:
+ stats[name] = int(right.strip()) * 1024
+ return stats
from zope.interface import Interface
-from foolscap.schema import StringConstraint, ListOf, TupleOf, Any
+from foolscap.schema import StringConstraint, ListOf, TupleOf, Any, DictOf
from foolscap import RemoteInterface
Nodeid = StringConstraint(20) # binary format 20-byte SHA1 hash
class NotCapableError(Exception):
"""You have tried to write to a read-only node."""
+
+class RIControlClient(RemoteInterface):
+ def upload_from_file_to_uri(filename=str):
+ """Upload a file to the mesh. This accepts a filename (which must be
+ absolute) that points to a file on the node's local disk. The node
+ will read the contents of this file, upload it to the mesh, then
+ return the URI at which it was uploaded.
+ """
+ return URI
+
+ def download_from_uri_to_file(uri=URI, filename=str):
+ """Download a file from the mesh, placing it on the node's local disk
+ at the given filename (which must be absolute[?]). Returns the
+ absolute filename where the file was written."""
+ return str
+
+ # debug stuff
+
+ def get_memory_usage():
+ """Return a dict describes the amount of memory currently in use. The
+ keys are 'VmPeak', 'VmSize', and 'VmData'. The values are integers,
+ measuring memory consupmtion in bytes."""
+ return DictOf(str, int)