Thread: SF.net SVN: fclient: [258] trunk/sandbox/fcp2/client.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <ju...@us...> - 2008-02-26 10:06:52
|
Revision: 258 http://fclient.svn.sourceforge.net/fclient/?rev=258&view=rev Author: jurner Date: 2008-02-26 02:06:56 -0800 (Tue, 26 Feb 2008) Log Message: ----------- renamed FcpClient to Client Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-02-26 10:01:29 UTC (rev 257) +++ trunk/sandbox/fcp2/client.py 2008-02-26 10:06:56 UTC (rev 258) @@ -215,7 +215,7 @@ #************************************************************************************************* # #************************************************************************************************* -class FcpClient(object): +class Client(object): """ @ivar events: events the client supports """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-26 14:42:28
|
Revision: 266 http://fclient.svn.sourceforge.net/fclient/?rev=266&view=rev Author: jurner Date: 2008-02-26 06:42:33 -0800 (Tue, 26 Feb 2008) Log Message: ----------- added WithDataTypes flag to getConfig() Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-02-26 10:46:05 UTC (rev 265) +++ trunk/sandbox/fcp2/client.py 2008-02-26 14:42:33 UTC (rev 266) @@ -1,4 +1,4 @@ -"""Freenet client protocol 2.0 implementation +"""Fcp2 client implementation Compatibility: >= Freenet 0.7 Build #1107 @@ -1309,6 +1309,7 @@ withSortOrder=True, withShortDescription=True, withLongDescription=True, + withDataTypes=True, ): """ @event: ConfigData(event, msg) @@ -1322,6 +1323,7 @@ WithForceWriteFlag=withForceWriteFlag, WithShortDescription=withShortDescription, WithLongDescription=withLongDescription, + WithDataTypes=withDataTypes, ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-26 15:53:56
|
Revision: 274 http://fclient.svn.sourceforge.net/fclient/?rev=274&view=rev Author: jurner Date: 2008-02-26 07:53:48 -0800 (Tue, 26 Feb 2008) Log Message: ----------- beautifications Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-02-26 15:30:00 UTC (rev 273) +++ trunk/sandbox/fcp2/client.py 2008-02-26 15:53:48 UTC (rev 274) @@ -177,13 +177,13 @@ # TODO: check if this is a bug in Fcp # NOTE: seems to be fixed in [build 1112], fixes removed #------------------------------------------------------------------------------------------------------------------------------------------------- +import os, sys + import atexit import copy import logging -import os import socket import subprocess -import sys import time @@ -196,13 +196,12 @@ def __del__(self): sys.path.pop(0) hack = _RelImportHack(2) - from fcp2 import consts -from fcp2.config import Config -from fcp2.events import Events -from fcp2.message import Message -import fcp2.params as FcParams -from fcp2.uri import Uri +from fcp2 import config +from fcp2 import events +from fcp2 import message +from fcp2 import fcparams +from fcp2 import uri from fcp2.fcp_lib import namespace from fcp2.fcp_lib import tools @@ -239,10 +238,10 @@ ExpectedNodeBuild = 1107 consts = consts - Config = Config - Message = Message - FcParams = FcParams - Uri = Uri + config = config + message = message + fcparams = fcparams + Uri = uri def __init__(self, @@ -256,23 +255,21 @@ """ self._connectionName = self.setConnectionName(connectionName) self._ddaTests = [] # currently running DDA tests (request0, ... requestN) - self._requests = {} # currently running requests (requestIdentifier --> request) - - self._logEvent = logging.getLogger(consts.LoggerNames.ClientEvents) - self._logMessage = logging.getLogger(consts.LoggerNames.ClientMessages) - self._logRuntime = logging.getLogger(consts.LoggerNames.ClientRuntime) - + self.events = events.Events() + self._loggers = { + 'Event': logging.getLogger(consts.LoggerNames.ClientEvents), + 'Message': logging.getLogger(consts.LoggerNames.ClientMessages), + 'Runtime': logging.getLogger(consts.LoggerNames.ClientRuntime), + } self._nodeHelloMessage = None + self._requests = {} # currently running requests (requestIdentifier --> request) self._socket = None - - self.events = Events() + for event in self.events: event += self._captureEvent - self.setDebugVerbosity(consts.DebugVerbosity.Warning if debugVerbosity is None else debugVerbosity) atexit.register(self.close) - - + ############################################################### ## ## private methods @@ -282,7 +279,7 @@ """Closes the client @param msg: message to pass to the ClientDisconnected event or None to not inform listeners """ - self._logRuntime.info(consts.LogMessages.ClientClose) + self._loggers['Runtime'].info(consts.LogMessages.ClientClose) # clean left over DDA test tmp files for initialRequest in self._ddaTests: @@ -352,7 +349,7 @@ @return: (str) identifer of therequest @note: the identifier returned is unique to the client but may not be unique to the node """ - identifier = self.FcParams.newUuid(uuids=self._requests) if identifier is None else identifier + identifier = fcparams.newUuid(uuids=self._requests) if identifier is None else identifier if requestType & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): @@ -393,7 +390,7 @@ }) # equip msg with some persistent pparams if msg.get('ClientToken', None) is None: - msg['ClientToken'] = self.FcParams.messageToParams(msg) + msg['ClientToken'] = fcparams.messageToParams(msg) elif requestType & consts.RequestType.MaskGenerateKeypair: msg.params.update({ @@ -433,7 +430,7 @@ def _captureEvent(self, event, request): if event != self.events.Idle: - self._logEvent.debug(consts.LogMessages.EventTriggered + event.name) + self._loggers['Event'].debug(consts.LogMessages.EventTriggered + event.name) ############################################################### ## @@ -444,7 +441,7 @@ """Closes the client @note: make shure to call close() when done with the client """ - msg = self.Message( + msg = message.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.Close, Param=None, @@ -483,7 +480,7 @@ @event: ClientConnected(event, message) is triggered as soon as the client is connected """ - self._logRuntime.info(consts.LogMessages.Connecting) + self._loggers['Runtime'].info(consts.LogMessages.Connecting) # try to Connect socket if self._socket is not None: @@ -503,7 +500,7 @@ except socket.error, d: yield None else: - self._logRuntime.info(consts.LogMessages.Connected) + self._loggers['Runtime'].info(consts.LogMessages.Connected) # send ClientHello and wait for NodeHello #NOTE: thought I could leave ClientHelloing up to the caller @@ -528,7 +525,7 @@ if self.versionCheckNodeHello(msg): self.events.ClientConnected(msg) else: - disconnectMsg = self.Message( + disconnectMsg = message.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.VersionMissmatch, Param=msg, @@ -538,17 +535,17 @@ raise StopIteration else: - self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint()) + self._loggers['Message'].debug(consts.LogMessages.MessageReceived + msg.pprint()) break break # continue polling - self._logRuntime.info(consts.LogMessages.ConnectionRetry) + self._loggers['Runtime'].info(consts.LogMessages.ConnectionRetry) timeElapsed += timeout time.sleep(timeout) - self._logRuntime.info(consts.LogMessages.ConnectingFailed) - disconnectMsg = self.Message( + self._loggers['Runtime'].info(consts.LogMessages.ConnectingFailed) + disconnectMsg = message.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.ConnectingFailed, Param=None, @@ -569,7 +566,7 @@ @param connectionName: (str) connection name or None to use an arbitrary connection name @return: (str) connection name """ - self._connectionName = self.FcParams.newUuid() if connectionName is None else connectionName + self._connectionName = fcparams.newUuid() if connectionName is None else connectionName return self._connectionName @@ -577,11 +574,10 @@ """Sets the verbosity level of the client @note: see L{consts.DebugVerbosity} """ - self._logEvent.setLevel(debugVerbosity) - self._logMessage.setLevel(debugVerbosity) - self._logRuntime.setLevel(debugVerbosity) - + for logger in self._loggers.values(): + logger.setLevel(debugVerbosity) + def startFreenet(self, cmdline): """Starts freenet @param cmdline: commandline to start freenet (like '/freenet/run.sh start' or 'c:\freenet\start.bat') @@ -635,7 +631,7 @@ return False # resend request with new identifier - newIdentifier = self.FcParams.newUuid(uuids=self._requests) + newIdentifier = fcparams.newUuid(uuids=self._requests) self._requests[newIdentifier] = initialRequest del self._requests[requestIdentifier] initialRequest['Identifier'] = newIdentifier @@ -648,7 +644,7 @@ elif msg.name == consts.Message.ProtocolError: code = msg['Code'] if code == consts.ProtocolError.ShuttingDown: - disconnectMsg = self.Message( + disconnectMsg = message.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.Shutdown, Param=None, @@ -667,7 +663,7 @@ # handle DDA errors elif code == consts.ProtocolError.DDADenied: - ddaRequestMsg = self.Message(consts.Message.TestDDARequest) + ddaRequestMsg = message.Message(consts.Message.TestDDARequest) if initialRequest.name == consts.Message.ClientGet: ddaRequestMsg['WantWriteDirectory'] = True directory = os.path.dirname(initialRequest['Filename']) @@ -897,7 +893,7 @@ # unknown request... try to restore it if initialRequest is None: - fcParams = self.FcParams.paramsFromRequest(msg) + fcParams = fcparams.paramsFromRequest(msg) # not one of our requests... so cancel it if fcParams is None or CancelPersistentRequests: @@ -911,12 +907,12 @@ initialRequest = copy.deepcopy(msg) self._registerRequest( initialRequest, - fcParams[self.FcParams.IRequestType], + fcParams[fcparams.IRequestType], identifier=requestIdentifier, - initTime=fcParams[self.FcParams.IInitTime], + initTime=fcParams[fcparams.IInitTime], userData=None, - persistentUserData=fcParams[self.FcParams.IPersistentUserData], - filenameCollision=fcParams[self.FcParams.IFilenameCollision], + persistentUserData=fcParams[fcparams.IPersistentUserData], + filenameCollision=fcParams[fcparams.IFilenameCollision], ) initialRequest.name = consts.Message.ClientGet @@ -940,7 +936,7 @@ modified = {} # check if PersistentUserData has changed - params = self.FcParams.paramsFromRequest(initialRequest) + params = fcparams.paramsFromRequest(initialRequest) if params is not None: clientToken = msg.get('ClientToken', None) if clientToken is not None: @@ -950,7 +946,7 @@ # otherwise we would have to set flags to indicate wich member # of ClientToken changed. See --> modifyRequest() modified[consts.RequestModified.PersistentUserData] = None - for i, fcParam in enumerate(self.FcParams.FcParams): + for i, fcParam in enumerate(fcparams.FcParams): initialRequest[fcParam] = params[i] # check if PriorityClass has changed @@ -991,7 +987,7 @@ # unknown request... try to restore it if initialRequest is None: - fcParams = self.FcParams.paramsFromRequest(msg) + fcParams = fcparams.paramsFromRequest(msg) # not one of our requests... so cancel it if fcParams is None or CancelPersistentRequests: @@ -1003,15 +999,15 @@ return True initialRequest = copy.deepcopy(msg) - requestType = fcParams[self.FcParams.IRequestType] + requestType = fcParams[fcparams.IRequestType] self._registerRequest( initialRequest, requestType, identifier=requestIdentifier, - initTime=fcParams[self.FcParams.IInitTime], + initTime=fcParams[fcparams.IInitTime], userData=None, - persistentUserData=fcParams[self.FcParams.IPersistentUserData], - filenameCollision=fcParams[self.FcParams.IFilenameCollision], + persistentUserData=fcParams[fcparams.IPersistentUserData], + filenameCollision=fcParams[fcparams.IFilenameCollision], ) # determine initial message name @@ -1146,7 +1142,7 @@ ## #################################################### elif msg.name == consts.Message.CloseConnectionDuplicateClientName: - disconnectMsg = self.Message( + disconnectMsg = message.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.DuplicateClientName, Param=None, @@ -1160,8 +1156,8 @@ return False #TODO:no idea if the node may pass uris with prefixes like 'freenet:'... strip it anyways - insertURI = self.Uri(msg['InsertURI']).uri - requestURI = self.Uri(msg['RequestURI']).uri + insertURI = uri.Uri(msg['InsertURI']).uri + requestURI = uri.Uri(msg['RequestURI']).uri if initialRequest['FcRequestType'] == consts.RequestType.GenerateUSKKeypair: insertURI = insertURI.replace(consts.KeyType.SSK, consts.KeyType.USK, 1) @@ -1190,11 +1186,11 @@ @note: use this method to run the client step by step. If you want to run the client unconditionally use L{run} """ - msg = self.Message.fromSocket(self._socket) + msg = message.Message.fromSocket(self._socket) if msg.name == consts.Message.ClientSocketDied: - self._logRuntime.critical(consts.LogMessages.SocketDied) + self._loggers['Runtime'].critical(consts.LogMessages.SocketDied) if dispatch: - disconnectMsg = self.Message( + disconnectMsg = message.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.SocketDied, Param=msg, @@ -1206,7 +1202,7 @@ if dispatch: self.events.Idle(msg) else: - self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint()) + self._loggers['Message'].debug(consts.LogMessages.MessageReceived + msg.pprint()) if dispatch: self.handleMessage(msg) return msg @@ -1224,7 +1220,7 @@ try: msg = self.next() except KeyboardInterrupt: - self._logRuntime.info(consts.LogMessages.KeyboardInterrupt) + self._loggers['Runtime'].info(consts.LogMessages.KeyboardInterrupt) return if msg.name == consts.Message.ClientSocketDied: return @@ -1242,13 +1238,13 @@ break if not haveRunningRequests: - self._logRuntime.info(consts.LogMessages.AllRequestsCompleted) + self._loggers['Runtime'].info(consts.LogMessages.AllRequestsCompleted) break try: msg = self.next() except KeyboardInterrupt: - self._logRuntime.info(consts.LogMessages.KeyboardInterrupt) + self._loggers['Runtime'].info(consts.LogMessages.KeyboardInterrupt) break if msg.name == consts.Message.ClientSocketDied: @@ -1268,7 +1264,7 @@ @note: you can use this method to send a message to the node, bypassing all track keeping methods of the client """ - return self.sendMessageEx(self.Message(name, data=data, **params)) + return self.sendMessageEx(message.Message(name, data=data, **params)) def sendMessageEx(self, msg): @@ -1282,15 +1278,15 @@ @note: you can use this method to send a message to the node, bypassing all track keeping methods of the client """ - self._logMessage.debug(consts.LogMessages.MessageSend + msg.pprint()) + self._loggers['Message'].debug(consts.LogMessages.MessageSend + msg.pprint()) try: msg.send(self._socket) except socket.error, d: - self._logRuntime.critical(consts.LogMessages.SocketDied) - disconnectMsg = self.Message( + self._loggers['Runtime'].critical(consts.LogMessages.SocketDied) + disconnectMsg = message.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.SocketDied, - Param=self.Message(consts.Message.ClientSocketDied, Exception=socket.error, Details=d) + Param=message.Message(consts.Message.ClientSocketDied, Exception=socket.error, Details=d) ) self._close(disconnectMsg) raise socket.error(d) @@ -1331,7 +1327,7 @@ """Modifies node configuration values @param params: (dict) containing parameters to modify """ - msg = self.Message(consts.Message.ModifyConfig) + msg = message.Message(consts.Message.ModifyConfig) msg.params = params self.sendMessageEx(msg) @@ -1342,7 +1338,7 @@ ## ######################################################## def clientGet(self, - uri, + key, requestType, userData, persistentUserData, @@ -1350,7 +1346,7 @@ **messageParams ): """Requests a key from the node - @param uri: (str) uri of the file to request (may contain prefixes like 'freenet:' or 'http://') + @param key: (str) key or Uri of the file to request (may contain prefixes like 'freenet:' or 'http://') @param requestType: (L{consts.RequestType}) sub type of the message @param userData: any non persistent data to associate to the request or None @param persistentUserData: any string to associate to the request as persistent data or None @@ -1360,8 +1356,8 @@ @return: (str) identifier of the request """ - uri = self.Uri(uri).uri - msg = self.Message(consts.Message.ClientGet, URI=uri) + key = uri.Uri(key).uri + msg = message.Message(consts.Message.ClientGet, URI=key) for paramName, value in messageParams.items(): if value is not None: msg[paramName] = value @@ -1379,7 +1375,7 @@ def getData(self, - uri, + key, allowedMimeTypes=None, binaryBlob=False, @@ -1395,7 +1391,7 @@ ): """Requests datae from the node - @param uri: uri of the data to request (may contain prefixes like 'freenet:' or 'http://') + @param key: (str) key or Uri of the data to request (may contain prefixes like 'freenet:' or 'http://') @param allowedMimeTypes: (str) list of allowed mime types @param binaryBlob: (bool) if True, the file is retrieved as binary blob file @@ -1410,10 +1406,10 @@ @return: (str) request identifier - @event: L{Events.RequestCompleted} triggered as soon as the request is complete - @event: L{Events.RequestFailed} triggered if the request failes - @event: L{Events.RequestStarted} triggered as soon as the request is started - @event: L{Events.RequestModified} trigggered if the request identifier changes + @event: L{events.RequestCompleted} triggered as soon as the request is complete + @event: L{events.RequestFailed} triggered if the request failes + @event: L{events.RequestStarted} triggered as soon as the request is started + @event: L{events.RequestModified} trigggered if the request identifier changes or the request is modified otherwise (see L{modifyRequest}) @note: the identifier of the request may change at any time. You should be prepaired to handle @@ -1422,7 +1418,7 @@ as soon as it completes or failes """ return self.clientGet( - uri, + key, consts.RequestType.GetData, userData, persistentUserData, @@ -1440,13 +1436,12 @@ Persistence=persistence, PriorityClass=priorityClass, ReturnType=consts.ReturnType.Direct, - URI=self.Uri(uri).uri, Verbosity=consts.Verbosity.ReportProgress, ) def getFile(self, - uri, + key, filename, allowedMimeTypes=None, @@ -1464,7 +1459,7 @@ ): """Requests a file from the node - @param uri: uri of the file to request (may contain prefixes like 'freenet:' or 'http://') + @param key: (str) key or Uri of the file to request (may contain prefixes like 'freenet:' or 'http://') @param filename: (full path) filename to store the file to @param allowedMimeTypes: (str) list of allowed mime types @@ -1491,7 +1486,7 @@ as soon as it completes or failes """ return self.clientGet( - uri, + key, consts.RequestType.GetFile, userData, persistentUserData, @@ -1510,13 +1505,12 @@ Persistence=persistence, PriorityClass=priorityClass, ReturnType=consts.ReturnType.Disk, - URI=self.Uri(uri).uri, Verbosity=consts.Verbosity.ReportProgress, ) def getKeyInfo(self, - uri, + key, dsOnly=False, ignoreDS=False, @@ -1529,7 +1523,7 @@ ): """Requests info about a key - @param uri: uri of the file to request (may contain prefixes like 'freenet:' or 'http://') + @param key: (str) key or Uri of the file to request (may contain prefixes like 'freenet:' or 'http://') @param dsOnly: if True, retrieves the file from the local data store only @param ignoreDS: If True, ignores the local data store @@ -1552,7 +1546,7 @@ """ # how to retrieve meta info about a key? ...idea is to provoke a GetFailed (TooBig) return self.clientGet( - uri, + key, consts.RequestType.GetKeyInfo, userData, persistentUserData, @@ -1568,25 +1562,24 @@ Persistence=persistence, PriorityClass=priorityClass, ReturnType=consts.ReturnType.Nothing, - URI=self.Uri(uri).uri, Verbosity=consts.Verbosity.ReportProgress, ) #TODO: persists until connection is closed... can this request be removed? - def subscribeUSK(self, uri, dontPoll=True): + def subscribeUSK(self, key, dontPoll=True): """Asks the node to notify the client when an USK is updated - @param uri: uri of the USK to subscribe to + @param key: (str) key or Uri of the USK to subscribe to @param dontPoll: if True, does whatever ??? @return: (str) identifer of the request @note: this request can not be removed or modified and the {consts.RequestStatus.Completed} flag is always set """ - msg = self.Message( + msg = message.Message( consts.Message.SubscribeUSK, - URI=uri, + URI=uri.Uri(key).uri, DontPoll=dontPoll, ) self._registerRequest(msg, consts.RequestType.SubscribeUSK) @@ -1602,7 +1595,7 @@ ######################################################## def clientPut(self, requestType, - uri, + key, data=None, persistentUserData='', userData=None, @@ -1611,7 +1604,7 @@ ): """Uploads to the node @param requestType: (L{consts.RequestType}). Can be PutData, PutDir or PutMultiple - @param uri: + @param key: (str) key or Uri @param data: (str) for L{consts.RequestType.PutData} data to upload or None @param persistentUserData: (str) persistent data to be assosiated to the request @param userData: (any) any data to be associated to the request at runtime @@ -1642,7 +1635,7 @@ else: raise ValueError('Unsupported request type') - msg = self.Message(msgName, URI=uri) + msg = message.Message(msgName, URI=key) contentType = msgParams.get('ContentType', None) if contentType is not None: del msgParams['ContentType'] @@ -1724,7 +1717,7 @@ @param userData: (any) any data to be associated to the request at runtime @return: (str) request identifier """ - msg = self.Message( + msg = message.Message( consts.Message.ClientPut, URI=consts.KeyType.KSK + name, Persistence=persistence, @@ -2045,21 +2038,21 @@ if persistentUserData is not None: initialRequest['FcPersistentUserData'] = persistentUserData - initialRequest['ClientToken'] = self.FcParams.messageToParams(initialRequest) + initialRequest['ClientToken'] = fcparams.messageToParams(initialRequest) modified[consts.RequestModified.PersistentUserData] = None initialRequest['FcModified'] = modified self.events.RequestModified(initialRequest) return - msg = self.Message( + msg = message.Message( consts.Message.ModifyPersistentRequest, Identifier=initialRequest['Identifier'], Global=False, ) if persistentUserData is not None: initialRequest['FcPersistentUserData'] = persistentUserData - msg['ClientToken'] = self.FcParams.messageToParams(initialRequest) + msg['ClientToken'] = fcparams.messageToParams(initialRequest) if priorityClass is not None: msg['PriorityClass'] = priorityClass @@ -2077,7 +2070,7 @@ # remove Persistence.Connection emidiately # ..make up a PersistentRequestRemoved message for this case if initialRequest['Persistence'] == consts.Persistence.Connection: - msg = self.Message(consts.Message.PersistentRequestRemoved, Identifier=requestIdentifier, Global=False) + msg = message.Message(consts.Message.PersistentRequestRemoved, Identifier=requestIdentifier, Global=False) self._finalizeRequest(msg, initialRequest, self.events.RequestRemoved) else: self.sendMessage( @@ -2248,7 +2241,7 @@ @param detailed: (bool) If True, detailed information is returned @return: (str) request identifier """ - msg = self.Message( + msg = message.Message( consts.Message.GetPluginInfo, PluginName=pluginName, Detailed=detailed, @@ -2265,7 +2258,7 @@ @param data: (str) data to pass along with the messaage or None @return: (str) request identifier """ - msg = self.Message( + msg = message.Message( consts.Message.FCPPluginMessage, PluginName=pluginName, **params @@ -2288,7 +2281,7 @@ @param keypairType: type of keypair to generate (either L{consts.KeyType.SSK} or L{consts.KeyType.SSK}) @return: identifier of the request - @event: L{Events.KeypairGenerated} triggered as soon as the request is complete + @event: L{events.KeypairGenerated} triggered as soon as the request is complete @requestparam: B{FcModified:} (dict) @requestparam: B{FcPrivateKey:} None. Will contain the private key as soon as the key is generated @@ -2301,7 +2294,7 @@ raise ValueError('keypairType must be %s or %s' % (consts.KeyType.SSK, consts.KeyType.USK)) requestType = consts.RequestType.GenerateSSKKeypair if keypairType == consts.KeyType.SSK else consts.RequestType.GenerateUSKKeypair - msg = self.Message(consts.Message.GenerateSSK) + msg = message.Message(consts.Message.GenerateSSK) self._registerRequest(msg, requestType) self.sendMessageEx(msg) return msg['Identifier'] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-26 16:02:58
|
Revision: 275 http://fclient.svn.sourceforge.net/fclient/?rev=275&view=rev Author: jurner Date: 2008-02-26 08:03:02 -0800 (Tue, 26 Feb 2008) Log Message: ----------- beautifications Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-02-26 15:53:48 UTC (rev 274) +++ trunk/sandbox/fcp2/client.py 2008-02-26 16:03:02 UTC (rev 275) @@ -218,15 +218,11 @@ """ @ivar events: events the client supports """ - - DefaultFcpHost = os.environ.get('FCP_HOST', '127.0.0.1').strip() - try: - DefaultFcpPort = int(os.environ.get('FCP_PORT', '').strip()) - except ValueError: - DefaultFcpPort = 9481 - - - + ExpectedFcpVersion = 2.0 + ExpectedNodeBuild = 1107 + DefaultFcpHost = os.environ.get('FCP_HOST', '127.0.0.1') + DefaultFcpPort = int(os.environ.get('FCP_PORT', '9481')) + #TODO: check if required # suggested by Mathew Toseland to use about 32k for mimeType requests # basic sizes of keys are: 1k for SSks and 32k for CHKs @@ -234,9 +230,7 @@ MaxSizeKeyInfo = 32768 MinimumRunTime = 1 # minimum time (seconds) the client will run when run() is called (FIX: 0001931) SocketTimeout = 0.1 - ExpectedFcpVersion = 2.0 - ExpectedNodeBuild = 1107 - + consts = consts config = config message = message @@ -275,6 +269,11 @@ ## private methods ## ############################################################### + def _captureEvent(self, event, request): + if event != self.events.Idle: + self._loggers['Event'].debug(consts.LogMessages.EventTriggered + event.name) + + def _close(self, msg): """Closes the client @param msg: message to pass to the ClientDisconnected event or None to not inform listeners @@ -412,9 +411,7 @@ 'FcPluginReply': None, }) - - - + else: msg.params.update({ 'FcRequestType': requestType, # identifies sub message types @@ -427,11 +424,6 @@ msg['Identifier'] = identifier self._requests[identifier] = msg - - def _captureEvent(self, event, request): - if event != self.events.Idle: - self._loggers['Event'].debug(consts.LogMessages.EventTriggered + event.name) - ############################################################### ## ## connection related methods This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-26 17:22:22
|
Revision: 278 http://fclient.svn.sourceforge.net/fclient/?rev=278&view=rev Author: jurner Date: 2008-02-26 08:22:06 -0800 (Tue, 26 Feb 2008) Log Message: ----------- fixed some crossreferences for epydoc Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-02-26 16:21:17 UTC (rev 277) +++ trunk/sandbox/fcp2/client.py 2008-02-26 16:22:06 UTC (rev 278) @@ -453,7 +453,7 @@ @param duration: (int) how many seconds try to connect before giving up @param timeout: (int) how much time to wait before another attempt to connect - @return: (L{fcp2_0_message.Message}) NodeHello or None if no connection could be established + @return: (L{message.Message}) NodeHello or None if no connection could be established """ nodeHello = None for nodeHello in self.iterConnect(host=host, port=port, duration=duration, timeout=timeout): @@ -468,7 +468,7 @@ @param duration: (int) how many seconds try to connect before giving up @param timeout: (int) how much time to wait before another attempt to connect - @return: (L{fcp2_0_message.Message}) NodeHello if successful, None otherwise for the next iteration + @return: (L{message.Message}) NodeHello if successful, None otherwise for the next iteration @event: ClientConnected(event, message) is triggered as soon as the client is connected """ @@ -1398,10 +1398,9 @@ @return: (str) request identifier - @event: L{events.RequestCompleted} triggered as soon as the request is complete - @event: L{events.RequestFailed} triggered if the request failes - @event: L{events.RequestStarted} triggered as soon as the request is started - @event: L{events.RequestModified} trigggered if the request identifier changes + @event: L{events.Events.RequestCompleted} triggered as soon as the request is complete + @event: L{events.Events.RequestFailed} triggered if the request failes + @event: L{events.Events.RequestModified} trigggered if the request identifier changes or the request is modified otherwise (see L{modifyRequest}) @note: the identifier of the request may change at any time. You should be prepaired to handle @@ -1990,7 +1989,7 @@ def getRequest(self, requestIdentifier): """Returns a (initial) message, given its identifier @param requestIdentifier: identifier of the message - @return: L{Message} + @return: L{message.Message} """ return self._requests[requestIdentifier] @@ -2079,7 +2078,7 @@ def resendRequest(self, request): """Resends a request - @param request: (L{fcp2_0_message.Message}) + @param request: (L{message.Message}) @return: (str) request identifier @note: you can use this method to resend get / put requests.All attempts to resend other requests @@ -2273,7 +2272,7 @@ @param keypairType: type of keypair to generate (either L{consts.KeyType.SSK} or L{consts.KeyType.SSK}) @return: identifier of the request - @event: L{events.KeypairGenerated} triggered as soon as the request is complete + @event: L{events.Events.KeypairGenerated} triggered as soon as the request is complete @requestparam: B{FcModified:} (dict) @requestparam: B{FcPrivateKey:} None. Will contain the private key as soon as the key is generated This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-27 12:06:09
|
Revision: 287 http://fclient.svn.sourceforge.net/fclient/?rev=287&view=rev Author: jurner Date: 2008-02-27 04:05:55 -0800 (Wed, 27 Feb 2008) Log Message: ----------- combed over docs Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-02-27 00:13:21 UTC (rev 286) +++ trunk/sandbox/fcp2/client.py 2008-02-27 12:05:55 UTC (rev 287) @@ -201,6 +201,7 @@ from fcp2 import events from fcp2 import message from fcp2 import fcparams +from fcp2 import types from fcp2 import uri from fcp2.fcp_lib import namespace @@ -217,16 +218,18 @@ class Client(object): """ @ivar events: events the client supports + + + @todo: cvar MaxSizeKeyInfo. Check if required. + suggested by Mathew Toseland to use about 32k for mimeType requests + basic sizes of keys are: 1k for SSks and 32k for CHKs without MaxSize + DataFound will have DataLength set to 0 (?!) + """ ExpectedFcpVersion = 2.0 ExpectedNodeBuild = 1107 DefaultFcpHost = os.environ.get('FCP_HOST', '127.0.0.1') DefaultFcpPort = int(os.environ.get('FCP_PORT', '9481')) - - #TODO: check if required - # suggested by Mathew Toseland to use about 32k for mimeType requests - # basic sizes of keys are: 1k for SSks and 32k for CHKs - # without MaxSize DataFound will have DataLength set to 0 (?!) MaxSizeKeyInfo = 32768 MinimumRunTime = 1 # minimum time (seconds) the client will run when run() is called (FIX: 0001931) SocketTimeout = 0.1 @@ -235,6 +238,7 @@ config = config message = message fcparams = fcparams + types = types Uri = uri @@ -277,6 +281,8 @@ def _close(self, msg): """Closes the client @param msg: message to pass to the ClientDisconnected event or None to not inform listeners + + @todo: complain if the client is already closed? """ self._loggers['Runtime'].info(consts.LogMessages.ClientClose) @@ -289,7 +295,7 @@ self._requests = {} if self._socket is None: - #TODO: complain or not? + # complain or not? pass else: self._socket.close() @@ -574,8 +580,9 @@ """Starts freenet @param cmdline: commandline to start freenet (like '/freenet/run.sh start' or 'c:\freenet\start.bat') @return: (str) whatever freenet returns + + @todo: on windows it may be necessary to hide the command window """ - #TODO: on windows it may be necessary to hide the command window p = subprocess.Popen( args=cmdline, shell=True, @@ -706,7 +713,6 @@ self._finalizeRequest(msg, initialRequest, self.events.PluginInfoFailed) return True - # TODO: just a guess that FCPPluginMessage can trigger an AccessDenied error elif initialRequest.name == consts.Message.FCPPluginMessage: initialRequest['FcErrorMessage'] = msg initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error @@ -796,7 +802,6 @@ testFailed = not msg.params.get('ReadDirectoryAllowed', False) if testFailed: - #TODO: check if errorMsg gives reasonable feedback initialRequest['FcRequestStatus'] = consts.RequestStatus.Error initialRequest['FcErrorMessage'] = initialRequest['FcTestDDA']['ErrorMsg'] self._finalizeRequest(msg, initialRequest, self.events.RequestFailed) @@ -937,6 +942,10 @@ # ...as long as no other param is changed at runtime we are ok # otherwise we would have to set flags to indicate wich member # of ClientToken changed. See --> modifyRequest() + # + # hmm ..thinking again, this would only work if we could make shure + # PersistentUserData can only be modified through modifyRequest(). + # So no way. modified[consts.RequestModified.PersistentUserData] = None for i, fcParam in enumerate(fcparams.FcParams): initialRequest[fcParam] = params[i] @@ -1557,8 +1566,6 @@ ) - - #TODO: persists until connection is closed... can this request be removed? def subscribeUSK(self, key, dontPoll=True): """Asks the node to notify the client when an USK is updated @param key: (str) key or Uri of the USK to subscribe to @@ -1567,6 +1574,8 @@ @note: this request can not be removed or modified and the {consts.RequestStatus.Completed} flag is always set + + @todo: looks like USK subscribes will persist untill connection is closed. Can they be removed somehow? """ msg = message.Message( consts.Message.SubscribeUSK, @@ -2013,6 +2022,8 @@ @note: you can not change the priority of requests with Persistence=L{consts.Persistence.Connection}. All attempts to do so are ignored. Too bad, but doing so is not implemented in the client protocol. + @todo: currently we ignore any attempts to change priority class for requests with persistence == connection + Fcp does not provide means to do so. """ initialRequest = self._requests[requestIdentifier] if not initialRequest['FcRequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): @@ -2022,8 +2033,6 @@ # no way to change priority here ..this is simply not implemented in the protocol if initialRequest['Persistence'] == consts.Persistence.Connection: modified = {} - - #TODO: currently we ignore any attempts to change priority class #if priorityClass is not None: # raise ValueError('Can not modify priority of requests with Persistence=connection') @@ -2072,10 +2081,7 @@ else: del self._requests[requestIdentifier] - #TODO: check how Fcp responds when the identifier is unknown or something else goes - # werong. Maybe a ProtocolError.NoSuchIdentifier ??? Naa ...never seen this - - + def resendRequest(self, request): """Resends a request @param request: (L{message.Message}) @@ -2086,6 +2092,8 @@ @note: actually a new request is created and registered. Todo so, the request passed is copied. If it is a persistent request, it will be removed. The new request will have FcInitTime reset and FcUserData amd FcPersistentUserData taken over from the old request + + @todo: reset init time or not? Currently it is not reset. """ requestType = request.get('FcRequestType', consts.RequestType.Null) if not requestType & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): @@ -2101,7 +2109,7 @@ newRequest, requestType, filenameCollision=newRequest['FcFilenameCollision'] & consts.FilenameCollision.MaskHandle, - #initTime=time.time(), # TODO: reset init time or not? + #initTime=time.time(), persistentUserData=newRequest['FcPersistentUserData'], userData=oldUserData, ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-27 14:13:35
|
Revision: 295 http://fclient.svn.sourceforge.net/fclient/?rev=295&view=rev Author: jurner Date: 2008-02-27 06:13:38 -0800 (Wed, 27 Feb 2008) Log Message: ----------- added debug level quiet ++ some more docs Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-02-27 14:13:28 UTC (rev 294) +++ trunk/sandbox/fcp2/client.py 2008-02-27 14:13:38 UTC (rev 295) @@ -212,11 +212,21 @@ #<-- rel import hack logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) +logging.addLevelName(consts.DebugVerbosity.Quiet, '') #************************************************************************************************* # #************************************************************************************************* class Client(object): """ + @cvar ExpectedFcpVersion: (float) minimum expected Freenet client protocol version + @cvar ExpectedNodeBuild: (int) minimum expected node build + @cvar DefaultFcpHost: (str) default Fcp host + @cvar DefaultFcpPort: (int) default Fcp port + @cvar MaxSizeKeyInfo: (bytes) maximum request size for key info requests + @cvar inimumRunTime: (seconds) minimum runtime when the L{run} method is called. + Required to make shure persistent requests can be taken up from the node. + @cvar SocketTimeout: (seconds) default socket timeout + @ivar events: events the client supports @@ -231,7 +241,7 @@ DefaultFcpHost = os.environ.get('FCP_HOST', '127.0.0.1') DefaultFcpPort = int(os.environ.get('FCP_PORT', '9481')) MaxSizeKeyInfo = 32768 - MinimumRunTime = 1 # minimum time (seconds) the client will run when run() is called (FIX: 0001931) + MinimumRunTime = 1s # FIX: 0001931 SocketTimeout = 0.1 consts = consts This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-27 14:15:05
|
Revision: 297 http://fclient.svn.sourceforge.net/fclient/?rev=297&view=rev Author: jurner Date: 2008-02-27 06:14:59 -0800 (Wed, 27 Feb 2008) Log Message: ----------- ups... Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-02-27 14:14:01 UTC (rev 296) +++ trunk/sandbox/fcp2/client.py 2008-02-27 14:14:59 UTC (rev 297) @@ -241,7 +241,7 @@ DefaultFcpHost = os.environ.get('FCP_HOST', '127.0.0.1') DefaultFcpPort = int(os.environ.get('FCP_PORT', '9481')) MaxSizeKeyInfo = 32768 - MinimumRunTime = 1s # FIX: 0001931 + MinimumRunTime = 1 # FIX: 0001931 SocketTimeout = 0.1 consts = consts This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-27 16:55:34
|
Revision: 298 http://fclient.svn.sourceforge.net/fclient/?rev=298&view=rev Author: jurner Date: 2008-02-27 08:55:41 -0800 (Wed, 27 Feb 2008) Log Message: ----------- Some fixes for uploadMultiple and more docs Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-02-27 14:14:59 UTC (rev 297) +++ trunk/sandbox/fcp2/client.py 2008-02-27 16:55:41 UTC (rev 298) @@ -1486,10 +1486,12 @@ @return: (str) request identifier - @event: RequestCompleted(event, message) triggered when the request is complete - @event: RequestFailed(event, message) triggered when the request failes - @event: RequestStarted(event, message) triggered when as the request is started - @event: RequestModified(event, message) trigggered if the request identifier changes, + @event: (L{events.Event.RequestCompleted}) triggered when the request is complete + @event: (L{events.Event.RequestFailed}) triggered when the request failes + @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable + @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed + @event: (L{events.Event.RequestCompressed}) triggered as soon as compressing of the request is completed + filename changes or the request is modified otherwise (see L{modifyRequest}) @note: if persistence is L{consts.Persistence.Connection} the request is removed from the client @@ -1623,8 +1625,7 @@ @note: the Fcp message parameter 'Metadata.ContentType' may be passed as 'ContentType' to this method - @note: to upload multiple items at once (see: PutComplexDir) pass a dict for each item - containig the following members: + @note: to upload multiple items at once pass a dict for each item containig the following members: - FcRequestType: L{consts.RequestType.PutData}, L{consts.RequestType.PutFile} or L{consts.RequestType.PutRedirect} - Data: if requestType is L{consts.RequestType.PutData}, data to upload @@ -1660,39 +1661,71 @@ msg.data = data if items is not None: - mapping = { - consts.RequestType.PutData: consts.UploadFrom.Direct, - consts.RequestType.PutFile: consts.UploadFrom.Disk, - consts.RequestType.PutRedirect: consts.UploadFrom.Redirect, - } if requestType != consts.RequestType.PutMultiple: raise ValueError('Items can only be passed along with PutMultiple uploads') + uploadTypeMapping = { + consts.RequestType.PutData: consts.UploadFrom.Direct, + consts.RequestType.PutFile: consts.UploadFrom.Disk, + consts.RequestType.PutRedirect: consts.UploadFrom.Redirect, + } + # requestType --> [(allowedParam: boolParamIsRequired), ...] + paramMapping = { + consts.RequestType.PutData: [ + ('Name', True), + ('Data', True), + ('ContentType', False), + ], + consts.RequestType.PutFile: [ + ('Name', True), + ('Filename', True), + ('Metadata.ContentType', False), + ], + consts.RequestType.PutRedirect: [ + ('Name', True), + ('TargetURI', True), + ], + } + data = '' for n, item in enumerate(items): + requestType = item.get('FcRequestType', None) if requestType is None: raise ValueError('No request type specified for item: %s' % n) - uploadFrom = mapping.get(requestType, None) + uploadFrom = uploadTypeMapping.get(requestType, None) if uploadFrom is None: - raise valueError('Unsupported request type for item %s: %s' % (n, requestType)) + raise ValueError('Unsupported request type for item %s: %s' % (n, requestType)) contentType = item.get('ContentType', None) - if conetntType is not None: + if contentType is not None: del msgParams['ContentType'] item['Metadata.ContentType'] = contentType + allowedParams = dict(paramMapping[requestType]) msg.params['Files.%s.UploadFrom' % n] = uploadFrom for param, value in item.items(): if param.startswith('Fc'): continue - elif param == 'Data': - data += data - msg.params['Files.%s.DataLength' % n] = len(data) + + if param in allowedParams: + del allowedParams[param] + else: + raise ValueError('Unsupported param for item %s: %s' % (n, param)) + + if param == 'Data': + data += value + msg.params['Files.%s.DataLength' % n] = len(value) continue msg.params['Files.%s.%s' % (n, param)] = value + # errorcheck params + if allowedParams: + for paramName, isRequired in allowedParams.items(): + if isRequired: + raise ValueError('Param "%s" is required for item %s' % (paramName, n)) + msg['DefaultName'] = items[0].get('Name', '') if data: msg.data = data @@ -1750,7 +1783,6 @@ contentType=None, dontCompress=None, - filename=None, maxRetries=None, persistence=consts.Persistence.Connection, priorityClass=consts.Priority.Medium, @@ -1759,9 +1791,31 @@ userData=None, persistentUserData='', ): + """Uploads data + @param data: (bytes) data to upload + + @param contentType: (str) content type. If not specified, the node will guess the content type + @param dontCompress: (bool) if True, the node won't try to compress the data + @param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide + @param priorityClass: (L{consts.Priority}) priority of the request + @paramtargetFilename: (str) filename to append to the key (may not contain slashes) + + @param userData: any non persistent data to associate to the request + @param persistentUserData: any string to associate to the request as persistent data + + @event: (L{events.Event.RequestCompleted}) triggered when the request is complete + @event: (L{events.Event.RequestFailed}) triggered when the request failes + @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable + @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed + @event: (L{events.Event.RequestCompressed}) triggered as soon as compressing of the request is completed + + @note: if the upload is successful the node will create a L{consts.KeyType.CHK} key under wich + the data can be retreieved. The key can be accessed as 'URI' member of the request as soon + as the L{events.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event + is triggered. + + @todo: EarlyEncode and GetCHKOnly message params not implemented """ - @param data: () - """ return self.clientPut( consts.RequestType.PutData, consts.KeyType.CHK, @@ -1791,8 +1845,8 @@ directory, allowUnreadableFiles=False, contentType=None, + dontCompress=None, defaultName=None, - dontCompress=None, maxRetries=None, persistence=consts.Persistence.Connection, priorityClass=consts.Priority.Medium, @@ -1802,9 +1856,36 @@ persistentUserData='', ): + """Uploads the contents of a directory + + @param directory: (str) directory to upload + + @param contentType: (str) content type. If not specified, the node will guess the content type + @param defaultName: (str) the default item to display when the key is requested + @param dontCompress: (bool) if True, the node won't try to compress the data + @param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide + @param priorityClass: (L{consts.Priority}) priority of the request + @paramtargetFilename: (str) filename to append to the key (may not contain slashes) + + @param userData: any non persistent data to associate to the request + @param persistentUserData: any string to associate to the request as persistent data + + @event: (L{events.Event.RequestCompleted}) triggered when the request is complete + @event: (L{events.Event.RequestFailed}) triggered when the request failes + @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable + @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed + @event: (L{events.Event.RequestCompressed}) triggered as soon as compressing of the request is completed + + @note: if the upload is successful the node will create a L{consts.KeyType.CHK} key under wich + the data can be retreieved. The key can be accessed as 'URI' member of the request as soon + as the L{events.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event + is triggered. + + @note: when uploaded items of the directory can be accessed under Key/MyItemName/MyItemSubname + + @todo: EarlyEncode and GetCHKOnly message params not implemented + @todo: 2MiB allowed? Have to test this """ - @param targetFilename: (str) filename to append to the CHK key or None (may not contain slashes) - """ return self.clientPut( consts.RequestType.PutDir, consts.KeyType.CHK, @@ -1845,10 +1926,31 @@ persistentUserData='', ): + """Uploads a file + @param filename: (bytes) data to upload + + @param contentType: (str) content type. If not specified, the node will guess the content type + @param dontCompress: (bool) if True, the node won't try to compress the data + @param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide + @param priorityClass: (L{consts.Priority}) priority of the request + @paramtargetFilename: (str) filename to append to the key (may not contain slashes) + + @param userData: any non persistent data to associate to the request + @param persistentUserData: any string to associate to the request as persistent data + + @event: (L{events.Event.RequestCompleted}) triggered when the request is complete + @event: (L{events.Event.RequestFailed}) triggered when the request failes + @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable + @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed + @event: (L{events.Event.RequestCompressed}) triggered as soon as compressing of the request is completed + + @note: if the upload is successful the node will create a L{consts.KeyType.CHK} key under wich + the data can be retreieved. The key can be accessed as 'URI' member of the request as soon + as the L{events.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event + is triggered. + + @todo: EarlyEncode and GetCHKOnly message params not implemented """ - @param targetFilename: (str) filename to append to the CHK key or None (may not contain slashes) - """ - return self.clientPut( consts.RequestType.PutFile, consts.KeyType.CHK, @@ -1890,14 +1992,44 @@ persistentUserData='', ): - """Uploads multiple items at once + """Uploads multiple items at once to be retrievable under one key - @param items: + @param items: (list) list of items to upload - @param targetFilename: (str) filename to append to the CHK key or None (may not contain slashes) + @param contentType: (str) content type. If not specified, the node will guess the content type + @param dontCompress: (bool) if True, the node won't try to compress the data + @param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide + @param priorityClass: (L{consts.Priority}) priority of the request + @paramtargetFilename: (str) filename to append to the key (may not contain slashes) + @param userData: any non persistent data to associate to the request + @param persistentUserData: any string to associate to the request as persistent data + @event: (L{events.Event.RequestCompleted}) triggered when the request is complete + @event: (L{events.Event.RequestFailed}) triggered when the request failes + @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable + @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed + @event: (L{events.Event.RequestCompressed}) triggered as soon as compressing of the request is completed + @note: if the upload is successful the node will create a L{consts.KeyType.CHK} key under wich + the data can be retreieved. The key can be accessed as 'URI' member of the request as soon + as the L{events.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event + is triggered. + + @note: to upload multiple items at once pass a dict for each item containig the following members: + + - FcRequestType: L{consts.RequestType.PutData}, L{consts.RequestType.PutFile} or L{consts.RequestType.PutRedirect} + - Data: if requestType is L{consts.RequestType.PutData}, data to upload + - Filename: if requestType is L{consts.RequestType.PutFile}, filepath of the file to upload + - TargetURI: if requestType is L{consts.RequestType.PutRedirect}, uri to redirect to + - Name: name under wich the item will be accesible via freenet + - Metadata.ContentType: (optional) may be passed as 'ContentType' + + All items will be accessible under one single key as 'Uri/Name'. The default item (the item when + only 'Uri' is requested from freenet) is always the first item in the list. + + + @todo: EarlyEncode and GetCHKOnly message params not implemented """ return self.clientPut( consts.RequestType.PutMultiple, @@ -1909,7 +2041,6 @@ items=items, # fcp params - Filename=directory, AllowUnreadableFiles=allowUnreadableFiles, ContentType=contentType, DefaultName=defaultName, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-29 13:02:27
|
Revision: 300 http://fclient.svn.sourceforge.net/fclient/?rev=300&view=rev Author: jurner Date: 2008-02-29 05:02:31 -0800 (Fri, 29 Feb 2008) Log Message: ----------- fixes for resendRequest() Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-02-27 16:56:03 UTC (rev 299) +++ trunk/sandbox/fcp2/client.py 2008-02-29 13:02:31 UTC (rev 300) @@ -2061,8 +2061,42 @@ ## SSK ClientPut related methods ## ######################################################## - def sskPutData(self): - pass + def sskPutData(self, + data, + privateKey, + + contentType=None, + dontCompress=None, + maxRetries=None, + persistence=consts.Persistence.Connection, + priorityClass=consts.Priority.Medium, + targetFilename=None, + + userData=None, + persistentUserData='', + ): + return self.clientPut( + consts.RequestType.PutData, + privateKey, + + data=data, + persistentUserData=persistentUserData, + userData=userData, + + # fcp params + ContentType=contentType, + DataLength=len(data), + #EarlyEncode='false', + #GetCHKOnly='false', + Global=False, + Identifier=None, + MaxRetries=maxRetries, + DontCompress=dontCompress, + Persistence=persistence, + PriorityClass=priorityClass, + UploadFrom=consts.UploadFrom.Direct, + Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression, + ) def sskPutDir(self): pass @@ -2234,6 +2268,9 @@ request, it will be removed. The new request will have FcInitTime reset and FcUserData amd FcPersistentUserData taken over from the old request + @note: for SSK and USK puts, the private key is taken from request['FcPrivateKey']. Adjust private (and public + key) if necessary + @todo: reset init time or not? Currently it is not reset. """ requestType = request.get('FcRequestType', consts.RequestType.Null) @@ -2245,7 +2282,22 @@ oldUserData, request['FcUserData'] = request['FcUserData'], None newRequest = copy.deepcopy(request) - # remove and cancel request + # reset key if necessary + if requestType & consts.RequestType.MaskPut: + requestUri = uri.Uri(request['URI']) + if requestUri.keyType == consts.KeyType.CHK: + newRequest['URI'] = consts.KeyType.CHK + elif requestUri.keyType == consts.KeyType.SSK: + newRequest['URI'] = request['FcPrivateKey'] + filename = requestUri.fileName() + if filename: + newRequest['URI'] += '/' + filename + elif requestUri.keyType == consts.KeyType.USK: + newRequest['URI'] = request['FcPrivateKey'] + filename = requestUri.fileName() + if filename: + newRequest['URI'] += '/' + filename + self._registerRequest( newRequest, requestType, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-03-04 17:39:07
|
Revision: 308 http://fclient.svn.sourceforge.net/fclient/?rev=308&view=rev Author: jurner Date: 2008-03-04 09:39:14 -0800 (Tue, 04 Mar 2008) Log Message: ----------- use new key module ++ many a things I can't remember now Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-03-04 17:38:18 UTC (rev 307) +++ trunk/sandbox/fcp2/client.py 2008-03-04 17:39:14 UTC (rev 308) @@ -202,7 +202,7 @@ from fcp2 import message from fcp2 import fcparams from fcp2 import types -from fcp2 import uri +from fcp2 import key from fcp2.fcp_lib import namespace from fcp2.fcp_lib import tools @@ -249,7 +249,7 @@ message = message fcparams = fcparams types = types - Uri = uri + key = key def __init__(self, @@ -1167,8 +1167,8 @@ return False #TODO:no idea if the node may pass uris with prefixes like 'freenet:'... strip it anyways - insertURI = uri.Uri(msg['InsertURI']).uri - requestURI = uri.Uri(msg['RequestURI']).uri + insertURI = key.stripKey(msg['InsertURI']) + requestURI = key.stripKey(msg['RequestURI']) if initialRequest['FcRequestType'] == consts.RequestType.GenerateUSKKeypair: insertURI = insertURI.replace(consts.KeyType.SSK, consts.KeyType.USK, 1) @@ -1367,7 +1367,6 @@ @return: (str) identifier of the request """ - key = uri.Uri(key).uri msg = message.Message(consts.Message.ClientGet, URI=key) for paramName, value in messageParams.items(): if value is not None: @@ -1591,7 +1590,7 @@ """ msg = message.Message( consts.Message.SubscribeUSK, - URI=uri.Uri(key).uri, + URI=key, DontPoll=dontPoll, ) self._registerRequest(msg, consts.RequestType.SubscribeUSK) @@ -1646,6 +1645,7 @@ else: raise ValueError('Unsupported request type') + #TODO: autoconvert keys to python classes??? msg = message.Message(msgName, URI=key) contentType = msgParams.get('ContentType', None) if contentType is not None: @@ -1741,6 +1741,47 @@ return msg['Identifier'] + def putData(self, + key, + data, + + contentType=None, + dontCompress=None, + maxRetries=None, + persistence=consts.Persistence.Connection, + priorityClass=consts.Priority.Medium, + targetFilename=None, + + userData=None, + persistentUserData='', + + ): + return self.clientPut( + consts.RequestType.PutData, + key, + + data=data, + persistentUserData=persistentUserData, + userData=userData, + + # fcp params + ContentType=contentType, + DataLength=len(data), + #EarlyEncode='false', + #GetCHKOnly='false', + Global=False, + Identifier=None, + MaxRetries=maxRetries, + DontCompress=dontCompress, + Persistence=persistence, + PriorityClass=priorityClass, + TargetFilename=targetFilename, + UploadFrom=consts.UploadFrom.Direct, + Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression, + ) + + + def putRedirect(self, name, targetURI, @@ -1844,6 +1885,7 @@ def chkPutDir(self, directory, allowUnreadableFiles=False, + contentType=None, dontCompress=None, defaultName=None, @@ -1859,32 +1901,14 @@ """Uploads the contents of a directory @param directory: (str) directory to upload - - @param contentType: (str) content type. If not specified, the node will guess the content type - @param defaultName: (str) the default item to display when the key is requested - @param dontCompress: (bool) if True, the node won't try to compress the data - @param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide - @param priorityClass: (L{consts.Priority}) priority of the request - @paramtargetFilename: (str) filename to append to the key (may not contain slashes) - - @param userData: any non persistent data to associate to the request - @param persistentUserData: any string to associate to the request as persistent data - - @event: (L{events.Event.RequestCompleted}) triggered when the request is complete - @event: (L{events.Event.RequestFailed}) triggered when the request failes - @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable - @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed - @event: (L{events.Event.RequestCompressed}) triggered as soon as compressing of the request is completed - - @note: if the upload is successful the node will create a L{consts.KeyType.CHK} key under wich - the data can be retreieved. The key can be accessed as 'URI' member of the request as soon - as the L{events.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event - is triggered. - - @note: when uploaded items of the directory can be accessed under Key/MyItemName/MyItemSubname + @param allowUnreadableFiles: if True, unreadable files in the directory are ignored, if False the request fails + if it encounters an unreadavle file. + @note: for other params see L{chkPutData} + @note: once uploaded, items of the directory can be accessed under Key/MyItemName/MyItemSubname + @todo: EarlyEncode and GetCHKOnly message params not implemented - @todo: 2MiB allowed? Have to test this + @todo: 2MiB compressed zize allowed? """ return self.clientPut( consts.RequestType.PutDir, @@ -1929,26 +1953,8 @@ """Uploads a file @param filename: (bytes) data to upload - @param contentType: (str) content type. If not specified, the node will guess the content type - @param dontCompress: (bool) if True, the node won't try to compress the data - @param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide - @param priorityClass: (L{consts.Priority}) priority of the request - @paramtargetFilename: (str) filename to append to the key (may not contain slashes) + @note: for other params see L{chkPutData} - @param userData: any non persistent data to associate to the request - @param persistentUserData: any string to associate to the request as persistent data - - @event: (L{events.Event.RequestCompleted}) triggered when the request is complete - @event: (L{events.Event.RequestFailed}) triggered when the request failes - @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable - @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed - @event: (L{events.Event.RequestCompressed}) triggered as soon as compressing of the request is completed - - @note: if the upload is successful the node will create a L{consts.KeyType.CHK} key under wich - the data can be retreieved. The key can be accessed as 'URI' member of the request as soon - as the L{events.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event - is triggered. - @todo: EarlyEncode and GetCHKOnly message params not implemented """ return self.clientPut( @@ -1996,26 +2002,7 @@ @param items: (list) list of items to upload - @param contentType: (str) content type. If not specified, the node will guess the content type - @param dontCompress: (bool) if True, the node won't try to compress the data - @param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide - @param priorityClass: (L{consts.Priority}) priority of the request - @paramtargetFilename: (str) filename to append to the key (may not contain slashes) - - @param userData: any non persistent data to associate to the request - @param persistentUserData: any string to associate to the request as persistent data - - @event: (L{events.Event.RequestCompleted}) triggered when the request is complete - @event: (L{events.Event.RequestFailed}) triggered when the request failes - @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable - @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed - @event: (L{events.Event.RequestCompressed}) triggered as soon as compressing of the request is completed - - @note: if the upload is successful the node will create a L{consts.KeyType.CHK} key under wich - the data can be retreieved. The key can be accessed as 'URI' member of the request as soon - as the L{events.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event - is triggered. - + @note: for other params see L{chkPutData} @note: to upload multiple items at once pass a dict for each item containig the following members: - FcRequestType: L{consts.RequestType.PutData}, L{consts.RequestType.PutFile} or L{consts.RequestType.PutRedirect} @@ -2064,7 +2051,7 @@ def sskPutData(self, data, privateKey, - + contentType=None, dontCompress=None, maxRetries=None, @@ -2075,6 +2062,18 @@ userData=None, persistentUserData='', ): + """Uploads data that can be updated by the owner + + @param data: (bytes) data to upload + @params privateKey: see: private key as generated by L{generateKeypair} + '/' + name + + @note: for other params see L{chkPutData} + @note: use this method to upload updatable data. First you need to create a public / private + keypair. The private key is used for uploading, the public key for retrieving the data. + You should add a name to the keypairs like: "privateKey/MyData" and "publicKey/MyData". + This may aswell be used to implement a basic edition scheme: "privateKey/MyEdition-0", + "privateKey/MyEdition-1" + """ return self.clientPut( consts.RequestType.PutData, privateKey, @@ -2086,6 +2085,7 @@ # fcp params ContentType=contentType, DataLength=len(data), + #EarlyEncode='false', #GetCHKOnly='false', Global=False, @@ -2114,8 +2114,8 @@ ## ######################################################## def uskPutData(self, - insertURI, data, + privateKey, contentType=None, dontCompress=None, @@ -2134,7 +2134,7 @@ return self.clientPut( consts.RequestType.PutData, - insertURI, + privateKey, #insertURI + 'foo/0/', userData=userData, persistentUserData=persistentUserData, @@ -2284,19 +2284,20 @@ # reset key if necessary if requestType & consts.RequestType.MaskPut: - requestUri = uri.Uri(request['URI']) - if requestUri.keyType == consts.KeyType.CHK: + requestKey = key.KeyBase.fcpToPython(request['URI']) + if requestKey is None: + raise ValueError('Ups, URI of the request seems not to be valid') + + if requestKey.KeyType == consts.KeyType.CHK: newRequest['URI'] = consts.KeyType.CHK - elif requestUri.keyType == consts.KeyType.SSK: + elif requestKey.KeyType == consts.KeyType.SSK: newRequest['URI'] = request['FcPrivateKey'] - filename = requestUri.fileName() - if filename: - newRequest['URI'] += '/' + filename - elif requestUri.keyType == consts.KeyType.USK: + if requestKey.filename: + newRequest['URI'] += '/' + requestKey.filename + elif requestKey.KeyType == consts.KeyType.USK: newRequest['URI'] = request['FcPrivateKey'] - filename = requestUri.fileName() - if filename: - newRequest['URI'] += '/' + filename + if requestKey.filename: + newRequest['URI'] += '/' + requestKey.filename self._registerRequest( newRequest, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-03-06 11:58:27
|
Revision: 311 http://fclient.svn.sourceforge.net/fclient/?rev=311&view=rev Author: jurner Date: 2008-03-06 03:58:32 -0800 (Thu, 06 Mar 2008) Log Message: ----------- use iohandler now Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-03-06 11:57:34 UTC (rev 310) +++ trunk/sandbox/fcp2/client.py 2008-03-06 11:58:32 UTC (rev 311) @@ -182,7 +182,6 @@ import atexit import copy import logging -import socket import subprocess import time @@ -199,8 +198,9 @@ from fcp2 import consts from fcp2 import config from fcp2 import events -from fcp2 import message from fcp2 import fcparams +from fcp2 import message +from fcp2 import iohandler from fcp2 import types from fcp2 import key @@ -225,8 +225,7 @@ @cvar MaxSizeKeyInfo: (bytes) maximum request size for key info requests @cvar inimumRunTime: (seconds) minimum runtime when the L{run} method is called. Required to make shure persistent requests can be taken up from the node. - @cvar SocketTimeout: (seconds) default socket timeout - + @ivar events: events the client supports @@ -242,8 +241,7 @@ DefaultFcpPort = int(os.environ.get('FCP_PORT', '9481')) MaxSizeKeyInfo = 32768 MinimumRunTime = 1 # FIX: 0001931 - SocketTimeout = 0.1 - + consts = consts config = config message = message @@ -271,7 +269,7 @@ } self._nodeHelloMessage = None self._requests = {} # currently running requests (requestIdentifier --> request) - self._socket = None + self.ioHandler = iohandler.IOHandler() for event in self.events: event += self._captureEvent @@ -294,7 +292,7 @@ @todo: complain if the client is already closed? """ - self._loggers['Runtime'].info(consts.LogMessages.ClientClose) + self._loggers['Runtime'].info(consts.LogMessages.Closing) # clean left over DDA test tmp files for initialRequest in self._ddaTests: @@ -304,14 +302,9 @@ self._ddaTests = [] self._requests = {} - if self._socket is None: - # complain or not? - pass - else: - self._socket.close() - self._socket = None - if msg is not None: - self.events.ClientDisconnected(msg) + self.ioHandler.close() + if msg is not None: + self.events.ClientDisconnected(msg) def _finalizeRequest(self, msg, request, event): @@ -488,43 +481,31 @@ @event: ClientConnected(event, message) is triggered as soon as the client is connected """ - self._loggers['Runtime'].info(consts.LogMessages.Connecting) - # try to Connect socket - if self._socket is not None: - self._close(None) - - # poll untill freenet responds - timeElapsed = 0 - while timeElapsed < duration: - - # try to Connect socket - if self._socket is not None: - self._close(None) - self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self._socket.settimeout(self.SocketTimeout) - try: - self._socket.connect((host, port)) - except socket.error, d: - yield None - else: - self._loggers['Runtime'].info(consts.LogMessages.Connected) - - # send ClientHello and wait for NodeHello - #NOTE: thought I could leave ClientHelloing up to the caller - # but instad of responding with ClientHelloMustBeFirst - # as expected when not doing so, the node disconnects. - # So take it over here. - self.sendMessage( + #TODO: we have to yield a few round here to make NodeHello injection work in unittests + # no idea exactly how many... + disconnectReason = None + disconnectParam = None + t0 = time.time() + for result in self.ioHandler.iterConnect(duration=duration, timeout=timeout, host=host, port=port): + yield None + timeElapsed = time.time() - t0 + + # try to get handshake + if result: + errorMsg = self.sendMessage( consts.Message.ClientHello, Name=self._connectionName, ExpectedVersion=self.ExpectedFcpVersion, ) + yield None + if errorMsg is None: + timeElapsed = 0 while timeElapsed <= duration: + yield None msg = self.next(dispatch=False) - if msg.name == consts.Message.ClientSocketTimeout: - timeElapsed += self.SocketTimeout + timeElapsed += max(self.ioHandler.io.Timeout, 0.1) yield None elif msg.name == consts.Message.NodeHello: @@ -532,35 +513,29 @@ # check if version is ok if self.versionCheckNodeHello(msg): self.events.ClientConnected(msg) + yield self._nodeHelloMessage + raise StopIteration else: - disconnectMsg = message.Message( - consts.Message.ClientDisconnected, - DisconnectReason=consts.DisconnectReason.VersionMissmatch, - Param=msg, - ) - self._close(disconnectMsg) - yield self._nodeHelloMessage - raise StopIteration + disconnectReason = consts.DisconnectReason.VersionMissmatch + disconnectParam = msg + break else: - self._loggers['Message'].debug(consts.LogMessages.MessageReceived + msg.pprint()) + disconnectReason = consts.DisconnectReason.UnkownNodeHello + disconnectParam = msg break - break - - # continue polling - self._loggers['Runtime'].info(consts.LogMessages.ConnectionRetry) - timeElapsed += timeout - time.sleep(timeout) - self._loggers['Runtime'].info(consts.LogMessages.ConnectingFailed) + + if disconnectReason is None: + disconnectReason=consts.DisconnectReason.ConnectingFailed disconnectMsg = message.Message( consts.Message.ClientDisconnected, - DisconnectReason=consts.DisconnectReason.ConnectingFailed, - Param=None, + DisconnectReason=disconnectReason, + Param=disconnectParam, ) self._close(disconnectMsg) - raise StopIteration - + raise StopIteration + def getConnectionName(self): """Returns the connection name used by the client @@ -584,6 +559,7 @@ """ for logger in self._loggers.values(): logger.setLevel(debugVerbosity) + self.ioHandler.setDebugVerbosity(debugVerbosity) def startFreenet(self, cmdline): @@ -624,7 +600,7 @@ @param msg: (Message) to handle @return: True if the message was handled, False otherwise """ - + CancelPersistentRequests = 0 # for testing... if True, cancels all PersistentRequests # check if we have an initial request corrosponding to msg @@ -1197,28 +1173,26 @@ @note: use this method to run the client step by step. If you want to run the client unconditionally use L{run} """ - msg = message.Message.fromSocket(self._socket) - if msg.name == consts.Message.ClientSocketDied: - self._loggers['Runtime'].critical(consts.LogMessages.SocketDied) + try: + msg = self.ioHandler.readMessage() + except iohandler.IOTimeout, details: + msg = message.Message(consts.Message.ClientSocketTimeout) if dispatch: - disconnectMsg = message.Message( + self.events.Idle(msg) + except iohandler.IOBroken, details: + msg = message.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.SocketDied, - Param=msg, + Param=details, ) - self._close(disconnectMsg) - #raise socket.error(msg['Param']['Details']) - - elif msg.name == consts.Message.ClientSocketTimeout: - if dispatch: - self.events.Idle(msg) + self._close(msg) + raise iohandler.IOBroken(details) else: - self._loggers['Message'].debug(consts.LogMessages.MessageReceived + msg.pprint()) if dispatch: self.handleMessage(msg) return msg + - def run(self): """Runs the client unconditionally untill all requests have completed @note: a KeyboardInterrupt will stop the client @@ -1268,10 +1242,8 @@ @param data: data to atatch to the message @param params: {para-name: param-calue, ...} of parameters to pass along with the message (see freenet protocol) - @raise SocketError: if the socket connection to the node dies unexpectedly - If an error handler is passed to the client it is called emidiately before the error - is raised. + @note: you can use this method to send a message to the node, bypassing all track keeping methods of the client """ @@ -1280,29 +1252,27 @@ def sendMessageEx(self, msg): """Sends a message to freenet - @param msg: (Message) message to send - @return: Message - @raise SocketError: if the socket connection to the node dies unexpectedly. - If an error handler is passed to the client it is called emidiately before the error - is raised. - + @param msg: (L{message.Message}) message to send + @return: (L{message.Message}) disconnect if something went wrong + + @note: If an error occurs the client is closed @note: you can use this method to send a message to the node, bypassing all track keeping methods of the client """ - self._loggers['Message'].debug(consts.LogMessages.MessageSend + msg.pprint()) + errorMsg = None try: - msg.send(self._socket) - except socket.error, d: - self._loggers['Runtime'].critical(consts.LogMessages.SocketDied) - disconnectMsg = message.Message( + self.ioHandler.sendMessageEx(msg) + except iohandler.IOBroken, details: + errorMsg = message.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.SocketDied, - Param=message.Message(consts.Message.ClientSocketDied, Exception=socket.error, Details=d) + Param=details ) - self._close(disconnectMsg) - raise socket.error(d) - return msg + self._close(errorMsg) + raise iohandler.IOBroken(details) + return errorMsg + ######################################################### ## ## config related methods This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-03-06 17:43:58
|
Revision: 322 http://fclient.svn.sourceforge.net/fclient/?rev=322&view=rev Author: jurner Date: 2008-03-06 09:44:00 -0800 (Thu, 06 Mar 2008) Log Message: ----------- runtime loggeris nolonger needed Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-03-06 12:12:21 UTC (rev 321) +++ trunk/sandbox/fcp2/client.py 2008-03-06 17:44:00 UTC (rev 322) @@ -264,7 +264,6 @@ self.events = events.Events() self._loggers = { 'Event': logging.getLogger(consts.LoggerNames.ClientEvents), - 'Message': logging.getLogger(consts.LoggerNames.ClientMessages), 'Runtime': logging.getLogger(consts.LoggerNames.ClientRuntime), } self._nodeHelloMessage = None @@ -524,8 +523,7 @@ disconnectReason = consts.DisconnectReason.UnkownNodeHello disconnectParam = msg break - - + if disconnectReason is None: disconnectReason=consts.DisconnectReason.ConnectingFailed disconnectMsg = message.Message( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-03-07 09:53:14
|
Revision: 329 http://fclient.svn.sourceforge.net/fclient/?rev=329&view=rev Author: jUrner Date: 2008-03-07 01:53:17 -0800 (Fri, 07 Mar 2008) Log Message: ----------- private message params come now without Fc prefix Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-03-06 18:25:54 UTC (rev 328) +++ trunk/sandbox/fcp2/client.py 2008-03-07 09:53:17 UTC (rev 329) @@ -295,8 +295,8 @@ # clean left over DDA test tmp files for initialRequest in self._ddaTests: - if initialRequest['FcTestDDA'].get('TmpFile', None) is not None: - tools.saveRemoveFile(initialRequest['FcTestDDA']['TmpFile']) + if initialRequest['TestDDA'].get('TmpFile', None) is not None: + tools.saveRemoveFile(initialRequest['TestDDA']['TmpFile']) self._ddaTests = [] self._requests = {} @@ -324,9 +324,9 @@ #NOTE: non Get / Put related requests do not have a Persistence param removeRequest = request.params.get('Persistence', consts.Persistence.Connection) == consts.Persistence.Connection if removeRequest: - request['FcRequestStatus'] |= consts.RequestStatus.RemovedFromQueue + request['RequestStatus'] |= consts.RequestStatus.RemovedFromQueue - request['FcRequestStatus'] |= consts.RequestStatus.Completed + request['RequestStatus'] |= consts.RequestStatus.Completed if event is not None: event(request) @@ -358,41 +358,44 @@ """ identifier = fcparams.newUuid(uuids=self._requests) if identifier is None else identifier + #TODO: keep an eye on additional params, they may collide with Fcp parameters + Private = message.Message.privateParamName + if requestType & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): msg.params.update({ # persistent params that will go into identifier - 'FcRequestType': requestType, # identifies sub message types - 'FcInitTime': time.time() if initTime is None else initTime, # when was the request started? - 'FcFilenameCollision': filenameCollision, # handle fielanem collisions? - 'FcPersistentUserData': persistentUserData, # any user defined persistent data + Private('RequestType'): requestType, # identifies sub message types + Private('InitTime'): time.time() if initTime is None else initTime, # when was the request started? + Private('FilenameCollision'): filenameCollision, # handle fielanem collisions? + Private('PersistentUserData'): persistentUserData, # any user defined persistent data # non persistent params - 'FcRequestStatus': consts.RequestStatus.Null, - 'FcErrorMessage': None, # error message in case an error occured - 'FcUserData': userData, # any user defined runtime data here + Private('RequestStatus'): consts.RequestStatus.Null, + Private('ErrorMessage'): None, # error message in case an error occured + Private('UserData'): userData, # any user defined runtime data here # params for SSKKeypair - 'FcPrivateKey': None, - 'FcPublicKey': None, + Private('PrivateKey'): None, + Private('PublicKey'): None, # params from DataFound - 'FcMetadataContentType': '', # contecnt type - 'FcDataLength': '', # content size + Private('MetadataContentType'): '', # contecnt type + Private('MetadataSize'): 0, # content size # params from PersistentRequestModified - 'FcModified': {}, + Private('Modified'): {}, # params for DDA test - 'FcTestDDA': {}, + Private('TestDDA'): {}, # params for SimpleProgress - 'FcProgressTotal': '0', - 'FcProgressRequired': '0', - 'FcProgressFailed': '0', - 'FcProgressFatalyFailed': '0', - 'FcProgressSucceeeded': '0', + Private('ProgressTotal'): 0, + Private('ProgressRequired'): 0, + Private('ProgressFailed'): 0, + Private('ProgressFatalyFailed'): 0, + Private('ProgressSucceeeded'): 0, }) # equip msg with some persistent pparams @@ -401,34 +404,33 @@ elif requestType & consts.RequestType.MaskGenerateKeypair: msg.params.update({ - 'FcRequestType': requestType, # identifies sub message types - 'FcRequestStatus': consts.RequestStatus.Null, - 'FcInitTime': initTime, # when was the request started? - 'FcModified': {}, + Private('RequestType'): requestType, # identifies sub message types + Private('RequestStatus'): consts.RequestStatus.Null, + Private('InitTime'): initTime, # when was the request started? + Private('Modified'): {}, - 'FcPrivateKey': None, - 'FcPublicKey': None, + Private('PrivateKey'): None, + Private('PublicKey'): None, }) elif requestType & consts.RequestType.PluginMessage: msg.params.update({ - 'FcRequestType': requestType, # identifies sub message types - 'FcRequestStatus': consts.RequestStatus.Null, - 'FcInitTime': initTime, # when was the request started? - 'FcModified': {}, + Private('RequestType'): requestType, # identifies sub message types + Private('RequestStatus'): consts.RequestStatus.Null, + Private('InitTime'): initTime, # when was the request started? + Private('Modified'): {}, - 'FcPluginReply': None, + Private('PluginReply'): None, }) else: msg.params.update({ - 'FcRequestType': requestType, # identifies sub message types - 'FcRequestStatus': consts.RequestStatus.Null, - 'FcInitTime': initTime, # when was the request started? - 'FcModified': {}, + Private('RequestType'): requestType, # identifies sub message types + Private('RequestStatus'): consts.RequestStatus.Null, + Private('InitTime'): initTime, # when was the request started? + Private('Modified'): {}, }) - msg['FcRequestStatus'] |= consts.RequestStatus.Null msg['Identifier'] = identifier self._requests[identifier] = msg @@ -618,7 +620,7 @@ self._requests[newIdentifier] = initialRequest del self._requests[requestIdentifier] initialRequest['Identifier'] = newIdentifier - initialRequest['FcModified'] = {consts.RequestModified.Identifier: requestIdentifier} + initialRequest['Modified'] = {consts.RequestModified.Identifier: requestIdentifier} self.events.RequestModified(initialRequest) self.sendMessageEx(initialRequest) return True @@ -656,7 +658,7 @@ ddaRequestMsg['Directory'] = directory # add params required for testing - initialRequest['FcTestDDA'] = { + initialRequest['TestDDA'] = { 'Directory': directory, 'Replied': False, 'TmpFile': None, @@ -670,44 +672,44 @@ # handle filename collisions elif code == consts.ProtocolError.DiskTargetExists: - handleCollision = initialRequest.get('FcFilenameCollision', consts.FilenameCollision.HandleNever) + handleCollision = initialRequest.get('FilenameCollision', consts.FilenameCollision.HandleNever) collisionHandled = bool(handleCollision & consts.FilenameCollision.CollisionHandled) # rename filename if handleCollision & consts.FilenameCollision.HandleRename: filename = initialRequest['Filename'] - initialRequest['FcFilenameCollision'] |= consts.FilenameCollision.CollisionHandled + initialRequest['FilenameCollision'] |= consts.FilenameCollision.CollisionHandled newFilename = namespace.unique_filename(filename, extensions=1, ispostfixed=collisionHandled) initialRequest['Filename'] = newFilename - initialRequest['FcModified'] = {consts.RequestModified.Filename: filename} + initialRequest['Modified'] = {consts.RequestModified.Filename: filename} self.sendMessageEx(initialRequest) self.events.RequestModified(initialRequest) return True # don't handle else: - initialRequest['FcFilenameCollision'] &= ~consts.FilenameCollision.CollisionHandled + initialRequest['FilenameCollision'] &= ~consts.FilenameCollision.CollisionHandled # handle plugin related request failures elif code == consts.ProtocolError.NoSuchPlugin or code == consts.ProtocolError.AccessDenied: if initialRequest.name == consts.Message.GetPluginInfo: - initialRequest['FcErrorMessage'] = msg - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error + initialRequest['ErrorMessage'] = msg + initialRequest['RequestStatus'] |= consts.RequestStatus.Error self._finalizeRequest(msg, initialRequest, self.events.PluginInfoFailed) return True elif initialRequest.name == consts.Message.FCPPluginMessage: - initialRequest['FcErrorMessage'] = msg - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error + initialRequest['ErrorMessage'] = msg + initialRequest['RequestStatus'] |= consts.RequestStatus.Error self._finalizeRequest(msg, initialRequest, self.events.PluginMessageFailed) return True # only requests should get through to here # NOTE: Fcp already removed the request - initialRequest['FcErrorMessage'] = msg - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error + initialRequest['ErrorMessage'] = msg + initialRequest['RequestStatus'] |= consts.RequestStatus.Error self._finalizeRequest(msg, initialRequest, self.events.RequestFailed) return True @@ -726,9 +728,9 @@ # find message that triggered the call for initialRequest in self._ddaTests: - if initialRequest['FcTestDDA']['Directory'] == directory: - if not initialRequest['FcTestDDA']['Replied']: - initialRequest['FcTestDDA']['Replied'] = True + if initialRequest['TestDDA']['Directory'] == directory: + if not initialRequest['TestDDA']['Replied']: + initialRequest['TestDDA']['Replied'] = True break else: # fell through @@ -749,7 +751,7 @@ if not written: tools.saveRemoveFile(fpathWrite) else: - initialRequest['FcTestDDA']['TmpFile'] = fpathWrite + initialRequest['TestDDA']['TmpFile'] = fpathWrite self.sendMessage( consts.Message.TestDDAResponse, @@ -765,8 +767,8 @@ # find message that triggered the call for initialRequest in self._ddaTests: - if initialRequest['FcTestDDA']['Directory'] == directory: - if initialRequest['FcTestDDA']['Replied']: + if initialRequest['TestDDA']['Directory'] == directory: + if initialRequest['TestDDA']['Replied']: break else: # fell through @@ -774,9 +776,9 @@ # remove test and clean tmp data self._ddaTests.remove(initialRequest) - if initialRequest['FcTestDDA']['TmpFile'] is not None: - tools.saveRemoveFile(initialRequest['FcTestDDA']['TmpFile']) - wantWrite = initialRequest.params['FcTestDDA']['WantWrite'] + if initialRequest['TestDDA']['TmpFile'] is not None: + tools.saveRemoveFile(initialRequest['TestDDA']['TmpFile']) + wantWrite = initialRequest.params['TestDDA']['WantWrite'] # check if test was sucessful testFailed = False @@ -786,8 +788,8 @@ testFailed = not msg.params.get('ReadDirectoryAllowed', False) if testFailed: - initialRequest['FcRequestStatus'] = consts.RequestStatus.Error - initialRequest['FcErrorMessage'] = initialRequest['FcTestDDA']['ErrorMsg'] + initialRequest['RequestStatus'] = consts.RequestStatus.Error + initialRequest['ErrorMessage'] = initialRequest['TestDDA']['ErrorMsg'] self._finalizeRequest(msg, initialRequest, self.events.RequestFailed) return True @@ -817,7 +819,7 @@ if initialRequest is None: return False - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success + initialRequest['RequestStatus'] |= consts.RequestStatus.Success initialRequest.data = msg.data self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted) return True @@ -826,16 +828,16 @@ if initialRequest is None: return False - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success - initialRequest['FcMetadataContentType'] = msg.get('Metadata.ContentType', '') - initialRequest['FcDataLength'] = msg.get('DataLength', '') + initialRequest['RequestStatus'] |= consts.RequestStatus.Success + initialRequest['MetadataContentType'] = msg.get('Metadata.ContentType', '') + initialRequest['MetadataSize'] = msg.get('DataLength', '') # except from GetData all requests are complete here. Next GetData will run through AllData... # For GetData with persistence != connection the node sends no All Data message # whatever that is good for ..fix this here to get all GetData request to complete on # All Data. - if initialRequest['FcRequestType'] == consts.RequestType.GetData: + if initialRequest['RequestType'] == consts.RequestType.GetData: if initialRequest['Persistence'] != consts.Persistence.Connection: self.sendMessage( consts.Message.GetRequestStatus, @@ -858,14 +860,14 @@ return False # check if it is one of our requests for key information - if code == consts.FetchError.TooBig and initialRequest['FcRequestType'] == consts.RequestType.GetKeyInfo: - initialRequest['FcMetadataContentType'] = msg.get('ExpectedMetadata.ContentType', '') - initialRequest['FcDataLength'] = msg.get('ExpectedDataLength', -1) - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success + if code == consts.FetchError.TooBig and initialRequest['RequestType'] == consts.RequestType.GetKeyInfo: + initialRequest['MetadataContentType'] = msg.get('ExpectedMetadata.ContentType', '') + initialRequest['DataLength'] = msg.get('ExpectedDataLength', -1) + initialRequest['RequestStatus'] |= consts.RequestStatus.Success self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted) else: - initialRequest['FcErrorMessage'] = msg - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error + initialRequest['ErrorMessage'] = msg + initialRequest['RequestStatus'] |= consts.RequestStatus.Error self._finalizeRequest(msg, initialRequest, self.events.RequestFailed) return True @@ -878,6 +880,8 @@ # not one of our requests... so cancel it if fcParams is None or CancelPersistentRequests: + if fcParams is None: + self._loggers['Runtime'].critical(consts.LogMessages.RequestInvalidClientToken) self.sendMessage( consts.Message.RemovePersistentRequest, Identifier=requestIdentifier, @@ -902,7 +906,7 @@ #FIX: [0001965: Persistence vs PersistenceType] if 'PersistenceType' in initialRequest.params: initialRequest['Persistence'] = initialRequest.params.pop('PersistenceType') - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Restored + initialRequest['RequestStatus'] |= consts.RequestStatus.Restored self.events.RequestRestored(initialRequest) return True @@ -940,7 +944,7 @@ modified[consts.RequestModified.PriorityClass] = None initialRequest['PriorityClass'] = priorityClass - initialRequest['FcModified'] = modified + initialRequest['Modified'] = modified self.events.RequestModified(initialRequest) return True @@ -949,7 +953,7 @@ if initialRequest is None: return False - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed + initialRequest['RequestStatus'] |= consts.RequestStatus.Removed self._finalizeRequest(msg, initialRequest, self.events.RequestRemoved) return True @@ -958,11 +962,11 @@ if initialRequest is None: return False - initialRequest['FcProgressTotal'] = msg['Total'] - initialRequest['FcProgressRequired'] = msg['Required'] - initialRequest['FcProgressFailed'] = msg['Failed'] - initialRequest['FcProgressFatalyFailed'] = msg['FatallyFailed'] - initialRequest['FcProgressSucceeeded'] = msg['Succeeded'] + initialRequest['ProgressTotal'] = msg['Total'] + initialRequest['ProgressRequired'] = msg['Required'] + initialRequest['ProgressFailed'] = msg['Failed'] + initialRequest['ProgressFatalyFailed'] = msg['FatallyFailed'] + initialRequest['ProgressSucceeeded'] = msg['Succeeded'] self.events.RequestProgress(initialRequest) return True @@ -976,6 +980,8 @@ # not one of our requests... so cancel it if fcParams is None or CancelPersistentRequests: + if fcParams is None: + self._loggers['Runtime'].critical(consts.LogMessages.RequestInvalidClientToken) self.sendMessage( consts.Message.RemovePersistentRequest, Identifier=requestIdentifier, @@ -1005,7 +1011,7 @@ #FIX: remove Started param from PersistentGet / Put del initialRequest.params['Started'] - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Restored + initialRequest['RequestStatus'] |= consts.RequestStatus.Restored self.events.RequestRestored(initialRequest) return True @@ -1021,8 +1027,8 @@ if code == consts.InsertError.Canceled: return False - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error - initialRequest['FcErrorMessage'] = msg + initialRequest['RequestStatus'] |= consts.RequestStatus.Error + initialRequest['ErrorMessage'] = msg self._finalizeRequest(msg, initialRequest, self.events.RequestFailed) return True @@ -1042,7 +1048,7 @@ # TODO: StartupTime and CompletionTime are passed, but # as long as no corrosponding params are passed in DataFound # we ignore them - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success + initialRequest['RequestStatus'] |= consts.RequestStatus.Success initialRequest['URI'] = msg['URI'] self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted) return True @@ -1057,14 +1063,14 @@ elif msg.name == consts.Message.FinishedCompression: if initialRequest is None: return False - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Compressed + initialRequest['RequestStatus'] |= consts.RequestStatus.Compressed self.events.RequestCompressionFinished(initialRequest) return True elif msg.name == consts.Message.StartedCompression: if initialRequest is None: return False - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Compressing + initialRequest['RequestStatus'] |= consts.RequestStatus.Compressing self.events.RequestCompressionStarted(initialRequest) return True @@ -1109,15 +1115,15 @@ if initialRequest is None: return False - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success + initialRequest['RequestStatus'] |= consts.RequestStatus.Success self._finalizeRequest(msg, initialRequest, self.events.PluginInfo) return True elif msg.name == consts.Message.FCPPluginReply: if initialRequest is None: return False - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success - initialRequest['FcPluginReply'] = msg + initialRequest['RequestStatus'] |= consts.RequestStatus.Success + initialRequest['PluginReply'] = msg self._finalizeRequest(msg, initialRequest, self.events.PluginMessage) return True @@ -1144,13 +1150,13 @@ insertURI = key.stripKey(msg['InsertURI']) requestURI = key.stripKey(msg['RequestURI']) - if initialRequest['FcRequestType'] == consts.RequestType.GenerateUSKKeypair: + if initialRequest['RequestType'] == consts.RequestType.GenerateUSKKeypair: insertURI = insertURI.replace(consts.KeyType.SSK, consts.KeyType.USK, 1) requestURI = requestURI.replace(consts.KeyType.SSK, consts.KeyType.USK, 1) - initialRequest['FcPrivateKey'] = insertURI - initialRequest['FcPublicKey'] = requestURI - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success + initialRequest['PrivateKey'] = insertURI + initialRequest['PublicKey'] = requestURI + initialRequest['RequestStatus'] |= consts.RequestStatus.Success self._finalizeRequest(msg, initialRequest, self.events.KeypairGenerated) return True @@ -1216,7 +1222,7 @@ # check if we have running requests. Assert False haveRunningRequests = False for request in self._requests.values(): - if not request['FcRequestStatus'] & consts.RequestStatus.Completed: + if not request['RequestStatus'] & consts.RequestStatus.Completed: haveRunningRequests = True break @@ -1562,7 +1568,7 @@ DontPoll=dontPoll, ) self._registerRequest(msg, consts.RequestType.SubscribeUSK) - msg['FcRequestStatus'] |= consts.RequestStatus.Completed + msg['RequestStatus'] |= consts.RequestStatus.Completed self.sendMessageEx(msg) return msg['Identifier'] @@ -1594,7 +1600,7 @@ to this method @note: to upload multiple items at once pass a dict for each item containig the following members: - - FcRequestType: L{consts.RequestType.PutData}, L{consts.RequestType.PutFile} or L{consts.RequestType.PutRedirect} + - RequestType: L{consts.RequestType.PutData}, L{consts.RequestType.PutFile} or L{consts.RequestType.PutRedirect} - Data: if requestType is L{consts.RequestType.PutData}, data to upload - Filename: if requestType is L{consts.RequestType.PutFile}, filepath of the file to upload - TargetURI: if requestType is L{consts.RequestType.PutRedirect}, uri to redirect to @@ -1658,8 +1664,7 @@ data = '' for n, item in enumerate(items): - - requestType = item.get('FcRequestType', None) + requestType = item.get('RequestType', None) if requestType is None: raise ValueError('No request type specified for item: %s' % n) uploadFrom = uploadTypeMapping.get(requestType, None) @@ -1674,7 +1679,7 @@ allowedParams = dict(paramMapping[requestType]) msg.params['Files.%s.UploadFrom' % n] = uploadFrom for param, value in item.items(): - if param.startswith('Fc'): + if param == 'RequestType': continue if param in allowedParams: @@ -2169,7 +2174,7 @@ Fcp does not provide means to do so. """ initialRequest = self._requests[requestIdentifier] - if not initialRequest['FcRequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): + if not initialRequest['RequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): raise ValueError('Can not modify request: %s' % initialRequest.name) #FIX: [0002083] @@ -2180,11 +2185,11 @@ # raise ValueError('Can not modify priority of requests with Persistence=connection') if persistentUserData is not None: - initialRequest['FcPersistentUserData'] = persistentUserData + initialRequest['PersistentUserData'] = persistentUserData initialRequest['ClientToken'] = fcparams.messageToParams(initialRequest) modified[consts.RequestModified.PersistentUserData] = None - initialRequest['FcModified'] = modified + initialRequest['Modified'] = modified self.events.RequestModified(initialRequest) return @@ -2194,7 +2199,7 @@ Global=False, ) if persistentUserData is not None: - initialRequest['FcPersistentUserData'] = persistentUserData + initialRequest['PersistentUserData'] = persistentUserData msg['ClientToken'] = fcparams.messageToParams(initialRequest) if priorityClass is not None: msg['PriorityClass'] = priorityClass @@ -2207,8 +2212,8 @@ @param requestIdentifier: (str) identifier of the request to remove """ initialRequest = self._requests[requestIdentifier] - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed | consts.RequestStatus.Completed - if initialRequest['FcRequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): + initialRequest['RequestStatus'] |= consts.RequestStatus.Removed | consts.RequestStatus.Completed + if initialRequest['RequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): # remove Persistence.Connection emidiately # ..make up a PersistentRequestRemoved message for this case @@ -2236,18 +2241,18 @@ request, it will be removed. The new request will have FcInitTime reset and FcUserData amd FcPersistentUserData taken over from the old request - @note: for SSK and USK puts, the private key is taken from request['FcPrivateKey']. Adjust private (and public + @note: for SSK and USK puts, the private key is taken from request['PrivateKey']. Adjust private (and public key) if necessary @todo: reset init time or not? Currently it is not reset. """ - requestType = request.get('FcRequestType', consts.RequestType.Null) + requestType = request.get('RequestType', consts.RequestType.Null) if not requestType & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): raise ValueError('Can not resend request: %s' % requestMessage.name) # we don't know what UserData may be, so back it up before copying oldIdentifier = request['Identifier'] - oldUserData, request['FcUserData'] = request['FcUserData'], None + oldUserData, request['UserData'] = request['UserData'], None newRequest = copy.deepcopy(request) # reset key if necessary @@ -2259,25 +2264,25 @@ if requestKey.KeyType == consts.KeyType.CHK: newRequest['URI'] = consts.KeyType.CHK elif requestKey.KeyType == consts.KeyType.SSK: - newRequest['URI'] = request['FcPrivateKey'] + newRequest['URI'] = request['PrivateKey'] if requestKey.filename: newRequest['URI'] += '/' + requestKey.filename elif requestKey.KeyType == consts.KeyType.USK: - newRequest['URI'] = request['FcPrivateKey'] + newRequest['URI'] = request['PrivateKey'] if requestKey.filename: newRequest['URI'] += '/' + requestKey.filename self._registerRequest( newRequest, requestType, - filenameCollision=newRequest['FcFilenameCollision'] & consts.FilenameCollision.MaskHandle, + filenameCollision=newRequest['FilenameCollision'] & consts.FilenameCollision.MaskHandle, #initTime=time.time(), - persistentUserData=newRequest['FcPersistentUserData'], + persistentUserData=newRequest['PersistentUserData'], userData=oldUserData, ) if oldIdentifier in self._requests: - request['FcUserData'] = oldUserData + request['UserData'] = oldUserData self.removeRequest(request['Identifier']) self.sendMessageEx(newRequest) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-03-08 11:10:19
|
Revision: 337 http://fclient.svn.sourceforge.net/fclient/?rev=337&view=rev Author: jUrner Date: 2008-03-08 03:10:20 -0800 (Sat, 08 Mar 2008) Log Message: ----------- adapt to new message handling and a few fixes PluginMessage is not kept track of anymore Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-03-08 11:05:30 UTC (rev 336) +++ trunk/sandbox/fcp2/client.py 2008-03-08 11:10:20 UTC (rev 337) @@ -319,7 +319,7 @@ that the request has been completed and remove it fom our queue if necessary. Non Get / Put requests will be removed in any case. """ - removeRequest = msg.name in (consts.Message.ProtocolError, consts.Message.PersistentRequestRemoved) + removeRequest = msg == message.ProtocolError or msg == message.PersistentRequestRemoved if not removeRequest: #NOTE: non Get / Put related requests do not have a Persistence param removeRequest = request.params.get('Persistence', consts.Persistence.Connection) == consts.Persistence.Connection @@ -358,80 +358,42 @@ """ identifier = fcparams.newUuid(uuids=self._requests) if identifier is None else identifier + # equip requests with some additional params + #TODO: keep an eye on additional params, they may collide with Fcp parameters - Private = message.Message.privateParamName + Private = message.PrivateParam - if requestType & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): - - msg.params.update({ - - # persistent params that will go into identifier - Private('RequestType'): requestType, # identifies sub message types - Private('InitTime'): time.time() if initTime is None else initTime, # when was the request started? - Private('FilenameCollision'): filenameCollision, # handle fielanem collisions? - Private('PersistentUserData'): persistentUserData, # any user defined persistent data - - # non persistent params - Private('RequestStatus'): consts.RequestStatus.Null, - Private('ErrorMessage'): None, # error message in case an error occured - Private('UserData'): userData, # any user defined runtime data here - - # params for SSKKeypair - Private('PrivateKey'): None, - Private('PublicKey'): None, - - # params from DataFound - Private('MetadataContentType'): '', # contecnt type - Private('MetadataSize'): 0, # content size - - # params from PersistentRequestModified - Private('Modified'): {}, - - # params for DDA test - Private('TestDDA'): {}, - - # params for SimpleProgress - Private('ProgressTotal'): 0, - Private('ProgressRequired'): 0, - Private('ProgressFailed'): 0, - Private('ProgressFatalyFailed'): 0, - Private('ProgressSucceeeded'): 0, - - }) - # equip msg with some persistent pparams - if msg.get('ClientToken', None) is None: - msg['ClientToken'] = fcparams.messageToParams(msg) - + """ + @requestparam: B{ErrorMessage:} (L{messageMessage}) if an error occured + @requestparam: B{Modified:} (dict) + @requestparam: B{Modified:} (dict) + @requestparam: B{PrivateKey:} None. Will contain the private key as soon as the key is generated + @requestparam: B{PublicKey:} None. Will contain the public key as soon as the key is generated + @requestparam: B{RequestStatus:} one or more of the L{consts.RequestStatus} flags + @requestparam: B{RequestType:} one or more of the L{consts.RequestType} flags + @requestparam: B{Identifier:} identifier of the request + """ + msg['Identifier'] = fcparams.newUuid(uuids=self._requests) if identifier is None else identifier + msg['RequestType'] = requestType + msg['InitTime'] = time.time() if initTime is None else initTime + if requestType & consts.RequestType.MaskGet: + msg['FilenameCollision'] = filenameCollision + msg['UserData'] = userData + msg['PersistentUserData'] = persistentUserData + msg['ClientToken'] = fcparams.messageToParams(msg) + elif requestType & consts.RequestType.MaskPut: + msg['UserData'] = userData + msg['PersistentUserData'] = persistentUserData + msg['ClientToken'] = fcparams.messageToParams(msg) elif requestType & consts.RequestType.MaskGenerateKeypair: - msg.params.update({ - Private('RequestType'): requestType, # identifies sub message types - Private('RequestStatus'): consts.RequestStatus.Null, - Private('InitTime'): initTime, # when was the request started? - Private('Modified'): {}, - - Private('PrivateKey'): None, - Private('PublicKey'): None, - }) - - elif requestType & consts.RequestType.PluginMessage: - msg.params.update({ - Private('RequestType'): requestType, # identifies sub message types - Private('RequestStatus'): consts.RequestStatus.Null, - Private('InitTime'): initTime, # when was the request started? - Private('Modified'): {}, - - Private('PluginReply'): None, - }) - + pass + elif requestType & consts.RequestType.SubscribeUSK: + msg['UserData'] = userData + elif requestType & consts.RequestType.PluginInfo: + pass else: - msg.params.update({ - Private('RequestType'): requestType, # identifies sub message types - Private('RequestStatus'): consts.RequestStatus.Null, - Private('InitTime'): initTime, # when was the request started? - Private('Modified'): {}, - }) - - msg['Identifier'] = identifier + raise ValueError('Can not register request: ' + msg.name) + self._requests[identifier] = msg ############################################################### @@ -443,8 +405,7 @@ """Closes the client @note: make shure to call close() when done with the client """ - msg = message.Message( - consts.Message.ClientDisconnected, + msg = message.ClientDisconnected( DisconnectReason=consts.DisconnectReason.Close, Param=None, ) @@ -453,7 +414,7 @@ def closeFreenet(self): """Shuts down the freenet node""" - self.sendMessage(consts.Message.Shutdown) + self.sendMessage(message.Shutdown()) def connect(self, host=DefaultFcpHost, port=DefaultFcpPort, duration=20, timeout=0.5): @@ -495,9 +456,10 @@ # try to get handshake if result: errorMsg = self.sendMessage( - consts.Message.ClientHello, - Name=self._connectionName, - ExpectedVersion=self.ExpectedFcpVersion, + message.ClientHello( + Name=self._connectionName, + ExpectedVersion=self.ExpectedFcpVersion, + ) ) yield None if errorMsg is None: @@ -505,11 +467,11 @@ while timeElapsed <= duration: yield None msg = self.next(dispatch=False) - if msg.name == consts.Message.ClientSocketTimeout: + if msg == message.ClientSocketTimeout: timeElapsed += max(self.ioHandler.io.Timeout, 0.1) yield None - elif msg.name == consts.Message.NodeHello: + elif msg == message.NodeHello: self._nodeHelloMessage = msg # check if version is ok if self.versionCheckNodeHello(msg): @@ -522,14 +484,13 @@ break else: - disconnectReason = consts.DisconnectReason.UnkownNodeHello + disconnectReason = consts.DisconnectReason.UnknownNodeHello disconnectParam = msg break if disconnectReason is None: disconnectReason=consts.DisconnectReason.ConnectingFailed - disconnectMsg = message.Message( - consts.Message.ClientDisconnected, + disconnectMsg = message.ClientDisconnected( DisconnectReason=disconnectReason, Param=disconnectParam, ) @@ -611,8 +572,9 @@ ## errors ## #################################################### - if msg.name == consts.Message.IdentifierCollision: + if msg == message.IdentifierCollision: if initialRequest is None: + self.events.IdentifierCollision(msg) return False # resend request with new identifier @@ -622,15 +584,14 @@ initialRequest['Identifier'] = newIdentifier initialRequest['Modified'] = {consts.RequestModified.Identifier: requestIdentifier} self.events.RequestModified(initialRequest) - self.sendMessageEx(initialRequest) + self.sendMessage(initialRequest) return True - elif msg.name == consts.Message.ProtocolError: + elif msg == message.ProtocolError: code = msg['Code'] if code == consts.ProtocolError.ShuttingDown: - disconnectMsg = message.Message( - consts.Message.ClientDisconnected, + disconnectMsg = message.ClientDisconnected( DisconnectReason=consts.DisconnectReason.Shutdown, Param=None, ) @@ -643,13 +604,13 @@ return True if initialRequest is None: + self.events.ProtocolError(msg) return False - - + # handle DDA errors elif code == consts.ProtocolError.DDADenied: - ddaRequestMsg = message.Message(consts.Message.TestDDARequest) - if initialRequest.name == consts.Message.ClientGet: + ddaRequestMsg = message.TestDDARequest() + if initialRequest == message.ClientGet: ddaRequestMsg['WantWriteDirectory'] = True directory = os.path.dirname(initialRequest['Filename']) else: @@ -666,7 +627,7 @@ 'ErrorMsg': msg, } self._ddaTests.append(initialRequest) - self.sendMessageEx(ddaRequestMsg) + self.sendMessage(ddaRequestMsg) return True @@ -682,7 +643,7 @@ newFilename = namespace.unique_filename(filename, extensions=1, ispostfixed=collisionHandled) initialRequest['Filename'] = newFilename initialRequest['Modified'] = {consts.RequestModified.Filename: filename} - self.sendMessageEx(initialRequest) + self.sendMessage(initialRequest) self.events.RequestModified(initialRequest) return True @@ -693,18 +654,12 @@ # handle plugin related request failures elif code == consts.ProtocolError.NoSuchPlugin or code == consts.ProtocolError.AccessDenied: - if initialRequest.name == consts.Message.GetPluginInfo: + if initialRequest == message.GetPluginInfo: initialRequest['ErrorMessage'] = msg initialRequest['RequestStatus'] |= consts.RequestStatus.Error self._finalizeRequest(msg, initialRequest, self.events.PluginInfoFailed) return True - elif initialRequest.name == consts.Message.FCPPluginMessage: - initialRequest['ErrorMessage'] = msg - initialRequest['RequestStatus'] |= consts.RequestStatus.Error - self._finalizeRequest(msg, initialRequest, self.events.PluginMessageFailed) - return True - # only requests should get through to here # NOTE: Fcp already removed the request @@ -723,7 +678,7 @@ ## TestDDA drill. ## #################################################### - elif msg.name == consts.Message.TestDDAReply: + elif msg == message.TestDDAReply: directory = msg['Directory'] # find message that triggered the call @@ -754,14 +709,15 @@ initialRequest['TestDDA']['TmpFile'] = fpathWrite self.sendMessage( - consts.Message.TestDDAResponse, - Directory=msg['Directory'], - ReadContent=readContent, + message.TestDDAResponse( + Directory=msg['Directory'], + ReadContent=readContent, + ) ) return True - elif msg.name == consts.Message.TestDDAComplete: + elif msg == message.TestDDAComplete: # clean up tmp file directory = msg['Directory'] @@ -794,7 +750,7 @@ return True # else: resend message - self.sendMessageEx(initialRequest) + self.sendMessage(initialRequest) return True #################################################### @@ -802,11 +758,11 @@ ## config related ## #################################################### - elif msg.name == consts.Message.ConfigData: + elif msg == message.ConfigData: self.events.ConfigData(msg) return True - elif msg.name == consts.Message.NodeData: + elif msg == message.NodeData: self.events.NodeData(msg) return True @@ -815,7 +771,7 @@ ## get / put related ## #################################################### - elif msg.name == consts.Message.AllData: + elif msg == message.AllData: if initialRequest is None: return False @@ -824,7 +780,7 @@ self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted) return True - elif msg.name == consts.Message.DataFound: + elif msg == message.DataFound: if initialRequest is None: return False @@ -840,10 +796,11 @@ if initialRequest['RequestType'] == consts.RequestType.GetData: if initialRequest['Persistence'] != consts.Persistence.Connection: self.sendMessage( - consts.Message.GetRequestStatus, - Identifier=initialRequest['Identifier'], - Global=False, - OnlyData=True + message.GetRequestStatus( + Identifier=initialRequest['Identifier'], + Global=False, + OnlyData=True + ) ) else: self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted) @@ -851,7 +808,7 @@ return True - elif msg.name == consts.Message.GetFailed: + elif msg == message.GetFailed: if initialRequest is None: return False @@ -872,7 +829,7 @@ return True - elif msg.name == consts.Message.PersistentGet: + elif msg == message.PersistentGet: # unknown request... try to restore it if initialRequest is None: @@ -883,13 +840,14 @@ if fcParams is None: self._loggers['Runtime'].critical(consts.LogMessages.RequestInvalidClientToken) self.sendMessage( - consts.Message.RemovePersistentRequest, - Identifier=requestIdentifier, - Global=msg['Global'], + message.RemovePersistentRequest( + Identifier=requestIdentifier, + Global=msg['Global'], + ) ) return True - initialRequest = copy.deepcopy(msg) + initialRequest = message.ClientGet() self._registerRequest( initialRequest, fcParams[fcparams.IRequestType], @@ -899,8 +857,8 @@ persistentUserData=fcParams[fcparams.IPersistentUserData], filenameCollision=fcParams[fcparams.IFilenameCollision], ) - - initialRequest.name = consts.Message.ClientGet + + initialRequest.params.update(msg.params) #FIX: remove Started param from PersistentGet / Put del initialRequest.params['Started'] #FIX: [0001965: Persistence vs PersistenceType] @@ -914,7 +872,7 @@ return False - elif msg.name == consts.Message.PersistentRequestModified: + elif msg == message.PersistentRequestModified: if initialRequest is None: return False @@ -949,7 +907,7 @@ return True - elif msg.name == consts.Message.PersistentRequestRemoved: + elif msg == message.PersistentRequestRemoved: if initialRequest is None: return False @@ -958,7 +916,7 @@ return True - elif msg.name == consts.Message.SimpleProgress: + elif msg == message.SimpleProgress: if initialRequest is None: return False @@ -972,7 +930,7 @@ ## put related - elif msg.name == consts.Message.PersistentPut: + elif msg == message.PersistentPut or msg == message.PersistentPutDir: # unknown request... try to restore it if initialRequest is None: @@ -983,14 +941,21 @@ if fcParams is None: self._loggers['Runtime'].critical(consts.LogMessages.RequestInvalidClientToken) self.sendMessage( - consts.Message.RemovePersistentRequest, - Identifier=requestIdentifier, - Global=msg['Global'], + message.RemovePersistentRequest( + Identifier=requestIdentifier, + Global=msg['Global'], + ) ) return True - initialRequest = copy.deepcopy(msg) requestType = fcParams[fcparams.IRequestType] + if requestType in (consts.RequestType.PutData, consts.RequestType.PutFile): + initialRequest = message.ClientPut() + elif requestType == consts.RequestType.PutDir: + initialRequest = message.ClientPutDiskDir() + elif request == consts.RequestType.PutMultiple: + initialRequest = message.ClientPutComplexDir() + self._registerRequest( initialRequest, requestType, @@ -1000,15 +965,7 @@ persistentUserData=fcParams[fcparams.IPersistentUserData], filenameCollision=fcParams[fcparams.IFilenameCollision], ) - - # determine initial message name - if requestType in (consts.RequestType.PutData, consts.RequestType.PutFile): - initialRequest.name = consts.Message.ClientPut - elif requestType == consts.RequestType.PutDir: - initialRequest.name = consts.Message.ClientPutDiskDir - elif requestType == consts.RequestType.PutMultiple: - initialRequest.name = consts.Message.ClientPutComplexDir - + #FIX: remove Started param from PersistentGet / Put del initialRequest.params['Started'] initialRequest['RequestStatus'] |= consts.RequestStatus.Restored @@ -1019,7 +976,7 @@ return False - elif msg.name == consts.Message.PutFailed: + elif msg == message.PutFailed: if initialRequest is None: return False @@ -1033,7 +990,7 @@ return True - elif msg.name == consts.Message.PutFetchable: + elif msg == message.PutFetchable: if initialRequest is None: # something went wrong return False @@ -1042,7 +999,7 @@ return True - elif msg.name == consts.Message.PutSuccessful: + elif msg == message.PutSuccessful: if initialRequest is None: return False # TODO: StartupTime and CompletionTime are passed, but @@ -1054,20 +1011,20 @@ return True - elif msg.name == consts.Message.URIGenerated: + elif msg == message.URIGenerated: if initialRequest is None: return False initialRequest['URI'] = msg['URI'] return True - elif msg.name == consts.Message.FinishedCompression: + elif msg == message.FinishedCompression: if initialRequest is None: return False initialRequest['RequestStatus'] |= consts.RequestStatus.Compressed self.events.RequestCompressionFinished(initialRequest) return True - elif msg.name == consts.Message.StartedCompression: + elif msg == message.StartedCompression: if initialRequest is None: return False initialRequest['RequestStatus'] |= consts.RequestStatus.Compressing @@ -1079,31 +1036,31 @@ ## Peer related messages ## #################################################### - elif msg.name == consts.Message.EndListPeers: + elif msg == message.EndListPeers: self.events.EndListPeers(msg) return True - elif msg.name == consts.Message.EndListPeerNotes: + elif msg == message.EndListPeerNotes: self.events.EndListPeerNotes(msg.params) return True - elif msg.name == consts.Message.Peer: + elif msg == message.Peer: self.events.Peer(msg) return True - elif msg.name == consts.Message.PeerNote: + elif msg == message.PeerNote: self.events.PeerNote(msg) return True - elif msg.name == consts.Message.PeerRemoved: + elif msg == message.PeerRemoved: self.events.PeerRemoved(msg) return True - elif msg.name == consts.Message.UnknownNodeIdentifier: + elif msg == message.UnknownNodeIdentifier: self.events.PeerUnknown(msg) return True - elif msg.name == consts.Message.UnknownPeerNoteType: + elif msg == message.UnknownPeerNoteType: self.events.PeerNoteTypeUnknown(msg) return True #################################################### @@ -1111,7 +1068,7 @@ ## plugins ## #################################################### - elif msg.name == consts.Message.PluginInfo: + elif msg == message.PluginInfo: if initialRequest is None: return False @@ -1119,12 +1076,8 @@ self._finalizeRequest(msg, initialRequest, self.events.PluginInfo) return True - elif msg.name == consts.Message.FCPPluginReply: - if initialRequest is None: - return False - initialRequest['RequestStatus'] |= consts.RequestStatus.Success - initialRequest['PluginReply'] = msg - self._finalizeRequest(msg, initialRequest, self.events.PluginMessage) + elif msg == message.FCPPluginReply: + self.events.PluginMessage(msg) return True #################################################### @@ -1132,9 +1085,8 @@ ## others ## #################################################### - elif msg.name == consts.Message.CloseConnectionDuplicateClientName: - disconnectMsg = message.Message( - consts.Message.ClientDisconnected, + elif msg == message.CloseConnectionDuplicateClientName: + disconnectMsg = message.ClientDisconnected( DisconnectReason=consts.DisconnectReason.DuplicateClientName, Param=None, ) @@ -1142,7 +1094,7 @@ return True - elif msg.name == consts.Message.SSKKeypair: + elif msg == message.SSKKeypair: if initialRequest is None: return False @@ -1160,7 +1112,7 @@ self._finalizeRequest(msg, initialRequest, self.events.KeypairGenerated) return True - elif msg.name == consts.Message.SubscribedUSKUpdate: + elif msg == message.SubscribedUSKUpdate: if initialRequest is None: return False self.events.USKUpdated(msg) @@ -1180,12 +1132,11 @@ try: msg = self.ioHandler.readMessage() except iohandler.IOTimeout, details: - msg = message.Message(consts.Message.ClientSocketTimeout) + msg = message.ClientSocketTimeout() if dispatch: self.events.Idle(msg) except iohandler.IOBroken, details: - msg = message.Message( - consts.Message.ClientDisconnected, + msg = message.ClientDisconnected( DisconnectReason=consts.DisconnectReason.SocketDied, Param=details, ) @@ -1211,7 +1162,7 @@ except KeyboardInterrupt: self._loggers['Runtime'].info(consts.LogMessages.KeyboardInterrupt) return - if msg.name == consts.Message.ClientSocketDied: + if msg == message.ClientSocketDied: return #n = 0 @@ -1236,26 +1187,12 @@ self._loggers['Runtime'].info(consts.LogMessages.KeyboardInterrupt) break - if msg.name == consts.Message.ClientSocketDied: + if msg == message.ClientSocketDied: break - def sendMessage(self, name, data=None, **params): + def sendMessage(self, msg): """Sends a message to freenet - @param name: name of the message to send - @param data: data to atatch to the message - @param params: {para-name: param-calue, ...} of parameters to pass along - with the message (see freenet protocol) - - - @note: you can use this method to send a message to the node, bypassing all - track keeping methods of the client - """ - return self.sendMessageEx(message.Message(name, data=data, **params)) - - - def sendMessageEx(self, msg): - """Sends a message to freenet @param msg: (L{message.Message}) message to send @return: (L{message.Message}) disconnect if something went wrong @@ -1267,8 +1204,7 @@ try: self.ioHandler.sendMessageEx(msg) except iohandler.IOBroken, details: - errorMsg = message.Message( - consts.Message.ClientDisconnected, + errorMsg = message.ClientDisconnected( DisconnectReason=consts.DisconnectReason.SocketDied, Param=details ) @@ -1296,15 +1232,16 @@ @event: ConfigData(event, msg) """ self.sendMessage( - consts.Message.GetConfig, - WithSortOrder=withSortOrder, - WithCurrent=withCurrent, - WithDefaults=withDefaults, - WithExpertFlag=withExpertFlag, - WithForceWriteFlag=withForceWriteFlag, - WithShortDescription=withShortDescription, - WithLongDescription=withLongDescription, - WithDataTypes=withDataTypes, + message.GetConfig( + WithSortOrder=withSortOrder, + WithCurrent=withCurrent, + WithDefaults=withDefaults, + WithExpertFlag=withExpertFlag, + WithForceWriteFlag=withForceWriteFlag, + WithShortDescription=withShortDescription, + WithLongDescription=withLongDescription, + WithDataTypes=withDataTypes, + ) ) @@ -1312,9 +1249,9 @@ """Modifies node configuration values @param params: (dict) containing parameters to modify """ - msg = message.Message(consts.Message.ModifyConfig) + msg = message.ModifyConfig() msg.params = params - self.sendMessageEx(msg) + self.sendMessage(msg) ######################################################## @@ -1341,7 +1278,7 @@ @return: (str) identifier of the request """ - msg = message.Message(consts.Message.ClientGet, URI=key) + msg = message.ClientGet(URI=key) for paramName, value in messageParams.items(): if value is not None: msg[paramName] = value @@ -1353,7 +1290,7 @@ persistentUserData=persistentUserData, userData=userData, ) - self.sendMessageEx(msg) + self.sendMessage(msg) return msg['Identifier'] @@ -1562,14 +1499,13 @@ @todo: looks like USK subscribes will persist untill connection is closed. Can they be removed somehow? """ - msg = message.Message( - consts.Message.SubscribeUSK, + msg = message.SubscribeUSK( URI=key, DontPoll=dontPoll, ) self._registerRequest(msg, consts.RequestType.SubscribeUSK) msg['RequestStatus'] |= consts.RequestStatus.Completed - self.sendMessageEx(msg) + self.sendMessage(msg) return msg['Identifier'] @@ -1611,16 +1547,16 @@ only 'Uri' is requested from freenet) is always the first item in the list. """ if requestType in (consts.RequestType.PutData, consts.RequestType.PutFile): - msgName = consts.Message.ClientPut + msgName = message.ClientPut.name elif requestType == consts.RequestType.PutDir: - msgName = consts.Message.ClientPutDiskDir + msgName = message.ClientPutDiskDir.name elif requestType == consts.RequestType.PutMultiple: - msgName = consts.Message.ClientPutComplexDir + msgName = message.ClientPutComplexDir.name else: raise ValueError('Unsupported request type') #TODO: autoconvert keys to python classes??? - msg = message.Message(msgName, URI=key) + msg = message.MessagesAll[msgName](URI=key) contentType = msgParams.get('ContentType', None) if contentType is not None: del msgParams['ContentType'] @@ -1710,7 +1646,7 @@ persistentUserData=persistentUserData, userData=userData, ) - self.sendMessageEx(msg) + self.sendMessage(msg) return msg['Identifier'] @@ -1774,8 +1710,7 @@ @param userData: (any) any data to be associated to the request at runtime @return: (str) request identifier """ - msg = message.Message( - consts.Message.ClientPut, + msg = message.ClientPut( URI=consts.KeyType.KSK + name, Persistence=persistence, PriorityClass=priorityClass, @@ -1788,7 +1723,7 @@ persistentUserData=persistentUserData, userData=userData, ) - self.sendMessageEx(msg) + self.sendMessage(msg) return msg['Identifier'] #CHK @@ -1978,7 +1913,7 @@ @note: for other params see L{chkPutData} @note: to upload multiple items at once pass a dict for each item containig the following members: - - FcRequestType: L{consts.RequestType.PutData}, L{consts.RequestType.PutFile} or L{consts.RequestType.PutRedirect} + - RequestType: L{consts.RequestType.PutData}, L{consts.RequestType.PutFile} or L{consts.RequestType.PutRedirect} - Data: if requestType is L{consts.RequestType.PutData}, data to upload - Filename: if requestType is L{consts.RequestType.PutFile}, filepath of the file to upload - TargetURI: if requestType is L{consts.RequestType.PutRedirect}, uri to redirect to @@ -2193,8 +2128,7 @@ self.events.RequestModified(initialRequest) return - msg = message.Message( - consts.Message.ModifyPersistentRequest, + msg = message.ModifyPersistentRequest( Identifier=initialRequest['Identifier'], Global=False, ) @@ -2204,7 +2138,7 @@ if priorityClass is not None: msg['PriorityClass'] = priorityClass - self.sendMessageEx(msg) + self.sendMessage(msg) def removeRequest(self, requestIdentifier): @@ -2218,13 +2152,14 @@ # remove Persistence.Connection emidiately # ..make up a PersistentRequestRemoved message for this case if initialRequest['Persistence'] == consts.Persistence.Connection: - msg = message.Message(consts.Message.PersistentRequestRemoved, Identifier=requestIdentifier, Global=False) + msg = message.PersistentRequestRemoved(Identifier=requestIdentifier, Global=False) self._finalizeRequest(msg, initialRequest, self.events.RequestRemoved) else: self.sendMessage( - consts.Message.RemovePersistentRequest, - Global=False, - Identifier=requestIdentifier, + message.RemovePersistentRequest( + Global=False, + Identifier=requestIdentifier, + ) ) else: del self._requests[requestIdentifier] @@ -2248,7 +2183,7 @@ """ requestType = request.get('RequestType', consts.RequestType.Null) if not requestType & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): - raise ValueError('Can not resend request: %s' % requestMessage.name) + raise ValueError('Can not resend request: %s' % request.name) # we don't know what UserData may be, so back it up before copying oldIdentifier = request['Identifier'] @@ -2285,7 +2220,7 @@ request['UserData'] = oldUserData self.removeRequest(request['Identifier']) - self.sendMessageEx(newRequest) + self.sendMessage(newRequest) return newRequest['Identifier'] ######################################################## @@ -2304,10 +2239,11 @@ @param giveOpennetRef: if True, the opennet reference is retuned instead of the darknet """ self.sendMessage( - consts.Message.GetNode, - WithPrivate=withPrivate, - WithVolatile=withVolatile, - GiveOpennetRef=giveOpennetRef, + message.GetNode( + WithPrivate=withPrivate, + WithVolatile=withVolatile, + GiveOpennetRef=giveOpennetRef, + ) ) @@ -2316,8 +2252,9 @@ @param identity: identity of the peer to request information for """ self.sendMessage( - consts.Message.ListPeer, - NodeIdentifier=identity, + message.ListPeer( + NodeIdentifier=identity, + ) ) @@ -2329,8 +2266,9 @@ @note: listPeerNotes() is only available for darknet nodes """ self.sendMessage( - consts.Message.ListPeerNotes, - NodeIdentifier=identity + message.ListPeerNotes( + NodeIdentifier=identity + ) ) @@ -2343,9 +2281,10 @@ @event: EndListPeers(event, params). """ self.sendMessage( - consts.Message.ListPeers, - WithMetadata=withMetaData, - WithVolatile=withVolantile, + message.ListPeers( + WithMetadata=withMetaData, + WithVolatile=withVolantile, + ) ) @@ -2358,9 +2297,10 @@ @note: you can only modify darknet peers """ - msg = Message( - consts.Message.ModifyPeer, - NodeIdentifier=identity, + msg = MessageEx( + message.ModifyPeer( + NodeIdentifier=identity, + ) ) if allowLocalAddresses is not None: msg['AllowLocalAddresses'] = allowLocalAddresses @@ -2368,7 +2308,7 @@ msg['IsDisabled'] = isDisabled if isListenOnly is not None: msg['IsListenOnly'] = isListenOnly - self.sendMessageEx(msg) + self.sendMessage(msg) def modifyPeerNote(self, identity, note): @@ -2379,11 +2319,12 @@ @note: you can only modify notes of darknet peers """ self.sendMessage( - consts.Message.ModifyPeerNote, - NodeIdentifier=identity, - #NOTE: currently fcp supports only this one type - PeerNoteType=consts.PeerNoteType.Private, - NoteText=note + message.ModifyPeerNote( + NodeIdentifier=identity, + #NOTE: currently fcp supports only this one type + PeerNoteType=consts.PeerNoteType.Private, + NoteText=note + ) ) @@ -2392,8 +2333,9 @@ @param identity: identity of the peer node to remove """ self.sendMessage( - consts.Message.RemovePeer, - NodeIdentifier=identity, + message.RemovePeer( + NodeIdentifier=identity, + ) ) ########################################################## @@ -2407,34 +2349,41 @@ @param detailed: (bool) If True, detailed information is returned @return: (str) request identifier """ - msg = message.Message( - consts.Message.GetPluginInfo, + msg = message.GetPluginInfo( PluginName=pluginName, Detailed=detailed, ) self._registerRequest(msg, consts.RequestType.PluginInfo) - self.sendMessageEx(msg) + self.sendMessage(msg) return msg['Identifier'] - def sendPluginMessage(self, pluginName, params, data=None): + def sendPluginMessage(self, pluginName, identifier, params, data=None): """Sends a message to a plugin @param pluginName: name of the plugin to send the message to + @param identifier: (str) identifier to identify plugin responses or protocol errors @param params: (dict) additional params to pass to the plugin (each parameter has to be prefixed with 'Param.') @param data: (str) data to pass along with the messaage or None - @return: (str) request identifier + @return: (L{message.FCPPluginMessage}) + + @note: the client does not keep track of messages send to a plugin, because the plugin + may or may not return. If the plugin sends a reply, a L{events.PluginMessage} is triggered. + If something goes wrong, L{events.ProtocolError} or an is L{events.IdentifierCollision} + is triggered. Use the identifier passed to identify responses. + + @todo: this is method not tested. Assumption: identifer does not have to be unique to + the node. Most likely it has to be unique to the plugin. """ - msg = message.Message( - consts.Message.FCPPluginMessage, + msg = message.FCPPluginMessage( PluginName=pluginName, + Identifier=identifier, **params ) if data is not None: msg['DataLength'] = len(data) msg.data = data - self._registerRequest(msg, consts.RequestType.PluginMessage) - self.sendMessageEx(msg) - return msg['Identifier'] + self.sendMessage(msg) + return msg ########################################################## ## @@ -2448,21 +2397,14 @@ @return: identifier of the request @event: L{events.Events.KeypairGenerated} triggered as soon as the request is complete - - @requestparam: B{FcModified:} (dict) - @requestparam: B{FcPrivateKey:} None. Will contain the private key as soon as the key is generated - @requestparam: B{FcPublivcKey:} None. Will contain the public key as soon as the key is generated - @requestparam: B{FcRequestStatus:} one or more of the L{consts.RequestStatus} flags - @requestparam: B{FcRequestType:} one or more of the L{consts.RequestType} flags - @requestparam: B{Identifier:} identifier of the request """ if keypairType not in (consts.KeyType.SSK, consts.KeyType.USK): raise ValueError('keypairType must be %s or %s' % (consts.KeyType.SSK, consts.KeyType.USK)) requestType = consts.RequestType.GenerateSSKKeypair if keypairType == consts.KeyType.SSK else consts.RequestType.GenerateUSKKeypair - msg = message.Message(consts.Message.GenerateSSK) + msg = message.GenerateSSK() self._registerRequest(msg, requestType) - self.sendMessageEx(msg) + self.sendMessage(msg) return msg['Identifier'] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-03-09 12:54:37
|
Revision: 349 http://fclient.svn.sourceforge.net/fclient/?rev=349&view=rev Author: jUrner Date: 2008-03-09 05:54:35 -0700 (Sun, 09 Mar 2008) Log Message: ----------- many comb overs Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-03-09 12:53:45 UTC (rev 348) +++ trunk/sandbox/fcp2/client.py 2008-03-09 12:54:35 UTC (rev 349) @@ -177,6 +177,14 @@ # TODO: check if this is a bug in Fcp # NOTE: seems to be fixed in [build 1112], fixes removed #------------------------------------------------------------------------------------------------------------------------------------------------- +# PutComplexDir +# +# x. currently not handled on PersistentPut. have to test this +# +# +#------------------------------------------------------------------------------------------------------------------------------------------------ + + import os, sys import atexit @@ -205,7 +213,8 @@ from fcp2 import key from fcp2.fcp_lib import namespace -from fcp2.fcp_lib import tools +from fcp2.fcp_lib import tools +from fcp2.fcp_lib import uuid del hack @@ -301,7 +310,8 @@ self._ddaTests = [] self._requests = {} - self.ioHandler.close() + if self.ioHandler.isOpen(): + self.ioHandler.close() if msg is not None: self.events.ClientDisconnected(msg) @@ -334,6 +344,19 @@ del self._requests[request['Identifier']] + + def _newUuid(self, uuids=None): + """Creates a new unique identifier + @param uuids: if desired any iterable containing uuids to enshure the identifier is unique in the iterable + @return: (str) uuid + + """ + uuid_ = uuid.uuid_time() + if uuids is not None: + while uuid_ in uuids: + uuid_ = uuid_time() + return uuid_ + def _registerRequest(self, msg, requestType, @@ -356,7 +379,7 @@ @return: (str) identifer of therequest @note: the identifier returned is unique to the client but may not be unique to the node """ - identifier = fcparams.newUuid(uuids=self._requests) if identifier is None else identifier + identifier = self.newUuid(uuids=self._requests) if identifier is None else identifier # equip requests with some additional params @@ -373,18 +396,22 @@ @requestparam: B{RequestType:} one or more of the L{consts.RequestType} flags @requestparam: B{Identifier:} identifier of the request """ - msg['Identifier'] = fcparams.newUuid(uuids=self._requests) if identifier is None else identifier + msg['Identifier'] = self._newUuid(uuids=self._requests) if identifier is None else identifier msg['RequestType'] = requestType msg['InitTime'] = time.time() if initTime is None else initTime if requestType & consts.RequestType.MaskGet: msg['FilenameCollision'] = filenameCollision msg['UserData'] = userData msg['PersistentUserData'] = persistentUserData - msg['ClientToken'] = fcparams.messageToParams(msg) + msg['ClientToken'] = '' + msg.updatePersistentParams() + elif requestType & consts.RequestType.MaskPut: msg['UserData'] = userData msg['PersistentUserData'] = persistentUserData - msg['ClientToken'] = fcparams.messageToParams(msg) + msg['ClientToken'] = '' + msg.updatePersistentParams() + elif requestType & consts.RequestType.MaskGenerateKeypair: pass elif requestType & consts.RequestType.SubscribeUSK: @@ -401,18 +428,18 @@ ## connection related methods ## ############################################################### + #TESTED def close(self): """Closes the client @note: make shure to call close() when done with the client """ msg = message.ClientDisconnected( DisconnectReason=consts.DisconnectReason.Close, - Param=None, ) self._close(msg) - - - def closeFreenet(self): + + #TESTED + def closeNode(self): """Shuts down the freenet node""" self.sendMessage(message.Shutdown()) @@ -431,7 +458,15 @@ pass return nodeHello + #TESTED + def isOpen(self): + """Checks if the clients connection is open + @return: (bool) True if so, False otherwise + """ + return self.ioHandler.isOpen() + + #TESTED def iterConnect(self, host=DefaultFcpHost, port=DefaultFcpPort, duration=20, timeout=0.5): """Iterator to stablish a connection to a freenet node @param host: (str) host of th node @@ -446,53 +481,50 @@ #TODO: we have to yield a few round here to make NodeHello injection work in unittests # no idea exactly how many... - disconnectReason = None - disconnectParam = None + if self.ioHandler.isOpen(): + disconnectMsg = message.ClientDisconnected( + DisconnectReason=consts.DisconnectReason.Reconnect, + ) + self._close(disconnectMsg) + + disconnectReason = consts.DisconnectReason.IOConnectFailed t0 = time.time() for result in self.ioHandler.iterConnect(duration=duration, timeout=timeout, host=host, port=port): yield None - timeElapsed = time.time() - t0 - + # try to get handshake + timeElapsed = time.time() - t0 if result: - errorMsg = self.sendMessage( + self.sendMessage( message.ClientHello( Name=self._connectionName, ExpectedVersion=self.ExpectedFcpVersion, ) ) - yield None - if errorMsg is None: - timeElapsed = 0 - while timeElapsed <= duration: + + while timeElapsed <= duration: + yield None + msg = self.next(dispatch=False) + if msg == message.ClientSocketTimeout: + disconnectReason = consts.DisconnectReason.NoNodeHello + timeElapsed += max(self.ioHandler.io.Timeout, 0.1) yield None - msg = self.next(dispatch=False) - if msg == message.ClientSocketTimeout: - timeElapsed += max(self.ioHandler.io.Timeout, 0.1) - yield None - - elif msg == message.NodeHello: - self._nodeHelloMessage = msg - # check if version is ok - if self.versionCheckNodeHello(msg): - self.events.ClientConnected(msg) - yield self._nodeHelloMessage - raise StopIteration - else: - disconnectReason = consts.DisconnectReason.VersionMissmatch - disconnectParam = msg - break - + elif msg == message.NodeHello: + self._nodeHelloMessage = msg + # check if version is ok + if self.versionCheckNodeHello(msg): + self.events.ClientConnected(msg) + yield self._nodeHelloMessage + raise StopIteration else: - disconnectReason = consts.DisconnectReason.UnknownNodeHello - disconnectParam = msg - break + disconnectReason = consts.DisconnectReason.VersionMissmatch + break + else: + disconnectReason = consts.DisconnectReason.UnknownNodeHello + break - if disconnectReason is None: - disconnectReason=consts.DisconnectReason.ConnectingFailed disconnectMsg = message.ClientDisconnected( DisconnectReason=disconnectReason, - Param=disconnectParam, ) self._close(disconnectMsg) raise StopIteration @@ -510,7 +542,7 @@ @param connectionName: (str) connection name or None to use an arbitrary connection name @return: (str) connection name """ - self._connectionName = fcparams.newUuid() if connectionName is None else connectionName + self._connectionName = self._newUuid() if connectionName is None else connectionName return self._connectionName @@ -523,8 +555,8 @@ self.ioHandler.setDebugVerbosity(debugVerbosity) - def startFreenet(self, cmdline): - """Starts freenet + def startNode(self, cmdline): + """Starts the freenet node @param cmdline: commandline to start freenet (like '/freenet/run.sh start' or 'c:\freenet\start.bat') @return: (str) whatever freenet returns @@ -543,10 +575,10 @@ def versionCheckNodeHello(self, nodeHelloMessage): """Performa a version check of the client against the specified NodeHello message @return: (bool) True if version is ok, False otherwise - @note: if this check returns False the client will emidiately disconnect in L{connect()} - and triggers a ClientDisconnected event. Overwrite to adjust + @note: this implementation checks for FCPVersion == L{ExpectedFcpVersion} + and a Build >= L{ExpectedNodeBuild} """ - if nodeHelloMessage['FCPVersion'] >= self.ExpectedFcpVersion: + if nodeHelloMessage['FCPVersion'] == self.ExpectedFcpVersion: if nodeHelloMessage['Build'] >= self.ExpectedNodeBuild: return True return False @@ -578,7 +610,7 @@ return False # resend request with new identifier - newIdentifier = fcparams.newUuid(uuids=self._requests) + newIdentifier = self._newUuid(uuids=self._requests) self._requests[newIdentifier] = initialRequest del self._requests[requestIdentifier] initialRequest['Identifier'] = newIdentifier @@ -592,8 +624,7 @@ code = msg['Code'] if code == consts.ProtocolError.ShuttingDown: disconnectMsg = message.ClientDisconnected( - DisconnectReason=consts.DisconnectReason.Shutdown, - Param=None, + DisconnectReason=consts.DisconnectReason.NodeClosing, ) self._close(disconnectMsg) return True @@ -829,16 +860,24 @@ return True - elif msg == message.PersistentGet: + elif msg == message.PersistentGet or msg == message.PersistentPut or msg == message.PersistentPutDir: # unknown request... try to restore it if initialRequest is None: - fcParams = fcparams.paramsFromRequest(msg) - - # not one of our requests... so cancel it - if fcParams is None or CancelPersistentRequests: - if fcParams is None: - self._loggers['Runtime'].critical(consts.LogMessages.RequestInvalidClientToken) + + #FIXME: PutComplexDir??? + if msg == message.PersistentGet: + initialRequest = message.ClientGet() + elif msg == message.PersistentPut: + initialRequest = message.ClientPut() + elif msg == message.PersistentPutDir: + initialRequest = message.ClientPutDiskDir() + + initialRequest.params.update(msg.params) + result = initialRequest.restorePersistentParams() + if not result or CancelPersistentRequests: + if not result: + self._loggers['Runtime'].critical(consts.LogMessages.InvalidPersistentParams) self.sendMessage( message.RemovePersistentRequest( Identifier=requestIdentifier, @@ -847,18 +886,8 @@ ) return True - initialRequest = message.ClientGet() - self._registerRequest( - initialRequest, - fcParams[fcparams.IRequestType], - identifier=requestIdentifier, - initTime=fcParams[fcparams.IInitTime], - userData=None, - persistentUserData=fcParams[fcparams.IPersistentUserData], - filenameCollision=fcParams[fcparams.IFilenameCollision], - ) - - initialRequest.params.update(msg.params) + self._requests[initialRequest['Identifier']] = initialRequest + #FIX: remove Started param from PersistentGet / Put del initialRequest.params['Started'] #FIX: [0001965: Persistence vs PersistenceType] @@ -868,7 +897,7 @@ self.events.RequestRestored(initialRequest) return True - # known request ..we don't handle that + # known request ..don't handle it return False @@ -879,23 +908,22 @@ modified = {} # check if PersistentUserData has changed - params = fcparams.paramsFromRequest(initialRequest) - if params is not None: - clientToken = msg.get('ClientToken', None) - if clientToken is not None: + clientToken = msg.get('ClientToken', None) + if clientToken is not None: + modified[consts.RequestModified.PersistentUserData] = None + + #TODO: its more or less a guess that PersistentUserData has changed + # ...as long as no other param is changed at runtime we are ok + # otherwise we would have to set flags to indicate wich member + # of ClientToken changed. See --> modifyRequest() + # + # hmm ..thinking again, this would only work if we could make shure + # PersistentUserData can only be modified through modifyRequest(). + # So no way. + + #TODO: ??? try ...except + initialRequest.restorePersistentParams() - #TODO: its more or less a guess that PersistentUserData has changed - # ...as long as no other param is changed at runtime we are ok - # otherwise we would have to set flags to indicate wich member - # of ClientToken changed. See --> modifyRequest() - # - # hmm ..thinking again, this would only work if we could make shure - # PersistentUserData can only be modified through modifyRequest(). - # So no way. - modified[consts.RequestModified.PersistentUserData] = None - for i, fcParam in enumerate(fcparams.FcParams): - initialRequest[fcParam] = params[i] - # check if PriorityClass has changed priorityClass = msg.get('PriorityClass', None) if priorityClass is not None: @@ -930,52 +958,6 @@ ## put related - elif msg == message.PersistentPut or msg == message.PersistentPutDir: - - # unknown request... try to restore it - if initialRequest is None: - fcParams = fcparams.paramsFromRequest(msg) - - # not one of our requests... so cancel it - if fcParams is None or CancelPersistentRequests: - if fcParams is None: - self._loggers['Runtime'].critical(consts.LogMessages.RequestInvalidClientToken) - self.sendMessage( - message.RemovePersistentRequest( - Identifier=requestIdentifier, - Global=msg['Global'], - ) - ) - return True - - requestType = fcParams[fcparams.IRequestType] - if requestType in (consts.RequestType.PutData, consts.RequestType.PutFile): - initialRequest = message.ClientPut() - elif requestType == consts.RequestType.PutDir: - initialRequest = message.ClientPutDiskDir() - elif request == consts.RequestType.PutMultiple: - initialRequest = message.ClientPutComplexDir() - - self._registerRequest( - initialRequest, - requestType, - identifier=requestIdentifier, - initTime=fcParams[fcparams.IInitTime], - userData=None, - persistentUserData=fcParams[fcparams.IPersistentUserData], - filenameCollision=fcParams[fcparams.IFilenameCollision], - ) - - #FIX: remove Started param from PersistentGet / Put - del initialRequest.params['Started'] - initialRequest['RequestStatus'] |= consts.RequestStatus.Restored - self.events.RequestRestored(initialRequest) - return True - - # known request ..we don't handle that - return False - - elif msg == message.PutFailed: if initialRequest is None: return False @@ -1088,7 +1070,6 @@ elif msg == message.CloseConnectionDuplicateClientName: disconnectMsg = message.ClientDisconnected( DisconnectReason=consts.DisconnectReason.DuplicateClientName, - Param=None, ) self._close(disconnectMsg) return True @@ -1137,8 +1118,7 @@ self.events.Idle(msg) except iohandler.IOBroken, details: msg = message.ClientDisconnected( - DisconnectReason=consts.DisconnectReason.SocketDied, - Param=details, + DisconnectReason=consts.DisconnectReason.ConnectionDied, ) self._close(msg) raise iohandler.IOBroken(details) @@ -1200,19 +1180,20 @@ @note: you can use this method to send a message to the node, bypassing all track keeping methods of the client """ - errorMsg = None + + # Reminder to self: + # + # if socket dies on sendall ther is no way to determine if and how much data was send + # ...so assume data was send, cos there is no way to proove it was not send try: self.ioHandler.sendMessageEx(msg) except iohandler.IOBroken, details: errorMsg = message.ClientDisconnected( - DisconnectReason=consts.DisconnectReason.SocketDied, - Param=details + DisconnectReason=consts.DisconnectReason.ConnectionDied, ) self._close(errorMsg) raise iohandler.IOBroken(details) - return errorMsg - - + ######################################################### ## ## config related methods @@ -2121,7 +2102,7 @@ if persistentUserData is not None: initialRequest['PersistentUserData'] = persistentUserData - initialRequest['ClientToken'] = fcparams.messageToParams(initialRequest) + initialRequest['ClientToken'] = initialRequest.updatePersistentParams() modified[consts.RequestModified.PersistentUserData] = None initialRequest['Modified'] = modified @@ -2134,7 +2115,7 @@ ) if persistentUserData is not None: initialRequest['PersistentUserData'] = persistentUserData - msg['ClientToken'] = fcparams.messageToParams(initialRequest) + msg['ClientToken'] = initialRequest.updatePersistentParams() if priorityClass is not None: msg['PriorityClass'] = priorityClass @@ -2207,10 +2188,12 @@ if requestKey.filename: newRequest['URI'] += '/' + requestKey.filename + + filenameCollision = newRequest.get('FilenameCollision', None) self._registerRequest( newRequest, requestType, - filenameCollision=newRequest['FilenameCollision'] & consts.FilenameCollision.MaskHandle, + filenameCollision= None if filenameCollision is None else filenameCollision & consts.FilenameCollision.MaskHandle, #initTime=time.time(), persistentUserData=newRequest['PersistentUserData'], userData=oldUserData, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-03-10 13:03:41
|
Revision: 355 http://fclient.svn.sourceforge.net/fclient/?rev=355&view=rev Author: jUrner Date: 2008-03-10 06:03:44 -0700 (Mon, 10 Mar 2008) Log Message: ----------- some fixes for mesages Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-03-10 13:03:35 UTC (rev 354) +++ trunk/sandbox/fcp2/client.py 2008-03-10 13:03:44 UTC (rev 355) @@ -379,7 +379,7 @@ @return: (str) identifer of therequest @note: the identifier returned is unique to the client but may not be unique to the node """ - identifier = self.newUuid(uuids=self._requests) if identifier is None else identifier + identifier = self._newUuid(uuids=self._requests) if identifier is None else identifier # equip requests with some additional params @@ -865,27 +865,19 @@ # unknown request... try to restore it if initialRequest is None: - #FIXME: PutComplexDir??? - if msg == message.PersistentGet: + #NOTE: there is no distinction between ClientPutDiskDir and ClientPutComplexDir + # so a bit of additional work here + requestType = msg['RequestType'] + if requestType & consts.RequestType.MaskGet: initialRequest = message.ClientGet() - elif msg == message.PersistentPut: + elif requestType == consts.RequestType.PutMultiple: + initialRequest = message.ClientPutComplexDir() + elif requestType == consts.RequestType.PutDir: + initialRequest = message.ClientPutdiskDir() + else: initialRequest = message.ClientPut() - elif msg == message.PersistentPutDir: - initialRequest = message.ClientPutDiskDir() - - initialRequest.params.update(msg.params) - result = initialRequest.restorePersistentParams() - if not result or CancelPersistentRequests: - if not result: - self._loggers['Runtime'].critical(consts.LogMessages.InvalidPersistentParams) - self.sendMessage( - message.RemovePersistentRequest( - Identifier=requestIdentifier, - Global=msg['Global'], - ) - ) - return True + initialRequest.params.update(msg.params) self._requests[initialRequest['Identifier']] = initialRequest #FIX: remove Started param from PersistentGet / Put @@ -1581,6 +1573,7 @@ data = '' for n, item in enumerate(items): + n += 10 requestType = item.get('RequestType', None) if requestType is None: raise ValueError('No request type specified for item: %s' % n) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-03-11 01:01:28
|
Revision: 357 http://fclient.svn.sourceforge.net/fclient/?rev=357&view=rev Author: jUrner Date: 2008-03-10 18:01:33 -0700 (Mon, 10 Mar 2008) Log Message: ----------- a few fixes Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-03-10 13:03:53 UTC (rev 356) +++ trunk/sandbox/fcp2/client.py 2008-03-11 01:01:33 UTC (rev 357) @@ -206,7 +206,6 @@ from fcp2 import consts from fcp2 import config from fcp2 import events -from fcp2 import fcparams from fcp2 import message from fcp2 import iohandler from fcp2 import types @@ -254,7 +253,6 @@ consts = consts config = config message = message - fcparams = fcparams types = types key = key @@ -529,14 +527,14 @@ self._close(disconnectMsg) raise StopIteration - + #TESTED def getConnectionName(self): """Returns the connection name used by the client @return: (str) connection name """ return self._connectionName - - + + #TESTED def setConnectionName(self, connectionName=None): """Sets the connection name to be used by the client @param connectionName: (str) connection name or None to use an arbitrary connection name @@ -544,17 +542,26 @@ """ self._connectionName = self._newUuid() if connectionName is None else connectionName return self._connectionName + + #TESTED + def getDebugVerbosity(self): + """Returns the current verbosity level of the client + @return: L{consts.DebugVerbosity} + """ + for logger in self._loggers.values(): + return logger.getEffectiveLevel() - + #TESTED def setDebugVerbosity(self, debugVerbosity): """Sets the verbosity level of the client - @note: see L{consts.DebugVerbosity} + @param debugVerbosity: L{consts.DebugVerbosity} """ for logger in self._loggers.values(): logger.setLevel(debugVerbosity) self.ioHandler.setDebugVerbosity(debugVerbosity) + #TESTED def startNode(self, cmdline): """Starts the freenet node @param cmdline: commandline to start freenet (like '/freenet/run.sh start' or 'c:\freenet\start.bat') @@ -571,7 +578,7 @@ stdout, stderr = p.communicate() return stdout - + #TESTED def versionCheckNodeHello(self, nodeHelloMessage): """Performa a version check of the client against the specified NodeHello message @return: (bool) True if version is ok, False otherwise @@ -588,13 +595,14 @@ ## runtime related methods ## ######################################################### + #TESTED def handleMessage(self, msg): """Handles a message from the freenet node @param msg: (Message) to handle @return: True if the message was handled, False otherwise """ - CancelPersistentRequests = 0 # for testing... if True, cancels all PersistentRequests + CancelPersistentRequests = 1 # for testing... if True, cancels all PersistentRequests # check if we have an initial request corrosponding to msg requestIdentifier = msg.get('Identifier', None) @@ -865,6 +873,15 @@ # unknown request... try to restore it if initialRequest is None: + if CancelPersistentRequests: + self.sendMessage( + message.RemovePersistentRequest( + Identifier=msg['Identifier'], + Global=msg['Global'], + ) + ) + return True + #NOTE: there is no distinction between ClientPutDiskDir and ClientPutComplexDir # so a bit of additional work here requestType = msg['RequestType'] @@ -1095,7 +1112,7 @@ # default return False - + #TESTED def next(self, dispatch=True): """Pumps the next message waiting @param dispatch: if True the message is dispatched to L{handleMessage} @@ -1104,22 +1121,22 @@ """ try: msg = self.ioHandler.readMessage() - except iohandler.IOTimeout, details: + except self.ioHandler.IOTimeout, details: msg = message.ClientSocketTimeout() if dispatch: self.events.Idle(msg) - except iohandler.IOBroken, details: + except self.ioHandler.IOBroken, details: msg = message.ClientDisconnected( DisconnectReason=consts.DisconnectReason.ConnectionDied, ) self._close(msg) - raise iohandler.IOBroken(details) + raise self.ioHandler.IOBroken(details) else: if dispatch: self.handleMessage(msg) return msg - + #TESTED def run(self): """Runs the client unconditionally untill all requests have completed @note: a KeyboardInterrupt will stop the client @@ -1162,7 +1179,7 @@ if msg == message.ClientSocketDied: break - + #TESTED def sendMessage(self, msg): """Sends a message to freenet @param msg: (L{message.Message}) message to send @@ -1178,19 +1195,20 @@ # if socket dies on sendall ther is no way to determine if and how much data was send # ...so assume data was send, cos there is no way to proove it was not send try: - self.ioHandler.sendMessageEx(msg) - except iohandler.IOBroken, details: + self.ioHandler.sendMessage(msg) + except self.ioHandler.IOBroken, details: errorMsg = message.ClientDisconnected( DisconnectReason=consts.DisconnectReason.ConnectionDied, ) self._close(errorMsg) - raise iohandler.IOBroken(details) + raise self.ioHandler.IOBroken(details) ######################################################### ## ## config related methods ## ######################################################### + #TESTED def getConfig(self, withCurrent=True, withDefaults=True, @@ -1218,6 +1236,7 @@ ) + #TESTED def modifyConfig(self, params): """Modifies node configuration values @param params: (dict) containing parameters to modify @@ -1225,8 +1244,7 @@ msg = message.ModifyConfig() msg.params = params self.sendMessage(msg) - - + ######################################################## ## ## ClientGet related methods @@ -1573,7 +1591,6 @@ data = '' for n, item in enumerate(items): - n += 10 requestType = item.get('RequestType', None) if requestType is None: raise ValueError('No request type specified for item: %s' % n) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-03-11 11:19:10
|
Revision: 364 http://fclient.svn.sourceforge.net/fclient/?rev=364&view=rev Author: jUrner Date: 2008-03-11 04:19:16 -0700 (Tue, 11 Mar 2008) Log Message: ----------- key objects are is now accepted on get Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-03-11 01:04:40 UTC (rev 363) +++ trunk/sandbox/fcp2/client.py 2008-03-11 11:19:16 UTC (rev 364) @@ -602,7 +602,7 @@ @return: True if the message was handled, False otherwise """ - CancelPersistentRequests = 1 # for testing... if True, cancels all PersistentRequests + CancelPersistentRequests = 0 # for testing... if True, cancels all PersistentRequests # check if we have an initial request corrosponding to msg requestIdentifier = msg.get('Identifier', None) @@ -898,7 +898,8 @@ self._requests[initialRequest['Identifier']] = initialRequest #FIX: remove Started param from PersistentGet / Put - del initialRequest.params['Started'] + if 'Started' in initialRequest.params: + del initialRequest.params['Started'] #FIX: [0001965: Persistence vs PersistenceType] if 'PersistenceType' in initialRequest.params: initialRequest['Persistence'] = initialRequest.params.pop('PersistenceType') @@ -1105,7 +1106,9 @@ elif msg == message.SubscribedUSKUpdate: if initialRequest is None: return False - self.events.USKUpdated(msg) + + initialRequest['Edition'] =msg['Edition'] + self.events.USKUpdated(initialRequest) return True @@ -1269,6 +1272,9 @@ @return: (str) identifier of the request """ + if hasattr(key, 'toString'): + key = key.toString() + msg = message.ClientGet(URI=key) for paramName, value in messageParams.items(): if value is not None: @@ -1285,7 +1291,7 @@ return msg['Identifier'] - + #TESTED def getData(self, key, @@ -1351,6 +1357,7 @@ ) + #TESTED def getFile(self, key, filename, @@ -1422,6 +1429,7 @@ ) + #TESTED def getKeyInfo(self, key, @@ -1479,6 +1487,7 @@ ) + #TESTED def subscribeUSK(self, key, dontPoll=True): """Asks the node to notify the client when an USK is updated @param key: (str) key or Uri of the USK to subscribe to @@ -1490,6 +1499,8 @@ @todo: looks like USK subscribes will persist untill connection is closed. Can they be removed somehow? """ + if hasattr(key, 'toString'): + key = key.toString() msg = message.SubscribeUSK( URI=key, DontPoll=dontPoll, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-04-08 10:05:12
|
Revision: 370 http://fclient.svn.sourceforge.net/fclient/?rev=370&view=rev Author: jUrner Date: 2008-04-08 03:05:01 -0700 (Tue, 08 Apr 2008) Log Message: ----------- adapt to rename event Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-04-08 10:04:42 UTC (rev 369) +++ trunk/sandbox/fcp2/client.py 2008-04-08 10:05:01 UTC (rev 370) @@ -887,6 +887,11 @@ requestType = msg['RequestType'] if requestType & consts.RequestType.MaskGet: initialRequest = message.ClientGet() + + #FIXME: does not work as expected + # ClientPutdiskDir is just a subtype of ClientPutComplexDir + # and will be passed as Files.N.* container + elif requestType == consts.RequestType.PutMultiple: initialRequest = message.ClientPutComplexDir() elif requestType == consts.RequestType.PutDir: @@ -1013,7 +1018,7 @@ if initialRequest is None: return False initialRequest['RequestStatus'] |= consts.RequestStatus.Compressed - self.events.RequestCompressionFinished(initialRequest) + self.events.RequestCompressionCompleted(initialRequest) return True elif msg == message.StartedCompression: @@ -1892,6 +1897,7 @@ ) + def chkPutMultiple(self, items, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-04-09 07:31:32
|
Revision: 379 http://fclient.svn.sourceforge.net/fclient/?rev=379&view=rev Author: jUrner Date: 2008-04-09 00:31:36 -0700 (Wed, 09 Apr 2008) Log Message: ----------- moved errors and loggers to consts for easier access Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-04-09 07:30:07 UTC (rev 378) +++ trunk/sandbox/fcp2/client.py 2008-04-09 07:31:36 UTC (rev 379) @@ -269,10 +269,6 @@ self._connectionName = self.setConnectionName(connectionName) self._ddaTests = [] # currently running DDA tests (request0, ... requestN) self.events = events.Events() - self._loggers = { - 'Event': logging.getLogger(consts.LoggerNames.ClientEvents), - 'Runtime': logging.getLogger(consts.LoggerNames.ClientRuntime), - } self._nodeHelloMessage = None self._requests = {} # currently running requests (requestIdentifier --> request) self.ioHandler = iohandler.IOHandler() @@ -289,16 +285,16 @@ ############################################################### def _captureEvent(self, event, request): if event != self.events.Idle: - self._loggers['Event'].debug(consts.LogMessages.EventTriggered + event.name) - - + consts.Logger.Event.info(consts.LogMessages.EventTriggered + event.name) + + def _close(self, msg): """Closes the client @param msg: message to pass to the ClientDisconnected event or None to not inform listeners @todo: complain if the client is already closed? """ - self._loggers['Runtime'].info(consts.LogMessages.Closing) + consts.Logger.Client.info(consts.LogMessages.Closing) # clean left over DDA test tmp files for initialRequest in self._ddaTests: @@ -548,19 +544,17 @@ """Returns the current verbosity level of the client @return: L{consts.DebugVerbosity} """ - for logger in self._loggers.values(): - return logger.getEffectiveLevel() + return consts.Logger.Client.getEffectiveLevel() + #TESTED def setDebugVerbosity(self, debugVerbosity): """Sets the verbosity level of the client @param debugVerbosity: L{consts.DebugVerbosity} """ - for logger in self._loggers.values(): - logger.setLevel(debugVerbosity) - self.ioHandler.setDebugVerbosity(debugVerbosity) + consts.Logger.Client.setLevel(debugVerbosity) + - #TESTED def startNode(self, cmdline): """Starts the freenet node @@ -1129,16 +1123,16 @@ """ try: msg = self.ioHandler.readMessage() - except self.ioHandler.IOTimeout, details: + except consts.IOTimeoutError, details: msg = message.ClientSocketTimeout() if dispatch: self.events.Idle(msg) - except self.ioHandler.IOBroken, details: + except consts.IOBrokenError, details: msg = message.ClientDisconnected( DisconnectReason=consts.DisconnectReason.ConnectionDied, ) self._close(msg) - raise self.ioHandler.IOBroken(details) + raise consts.IOBrokenError(details) else: if dispatch: self.handleMessage(msg) @@ -1157,7 +1151,7 @@ try: msg = self.next() except KeyboardInterrupt: - self._loggers['Runtime'].info(consts.LogMessages.KeyboardInterrupt) + consts.Logger.Client.info(consts.LogMessages.KeyboardInterrupt) return if msg == message.ClientSocketDied: return @@ -1175,13 +1169,13 @@ break if not haveRunningRequests: - self._loggers['Runtime'].info(consts.LogMessages.AllRequestsCompleted) + consts.Logger.Client.info(consts.LogMessages.AllRequestsCompleted) break try: msg = self.next() except KeyboardInterrupt: - self._loggers['Runtime'].info(consts.LogMessages.KeyboardInterrupt) + sconsts.Logger.Client.info(consts.LogMessages.KeyboardInterrupt) break if msg == message.ClientSocketDied: @@ -1204,12 +1198,12 @@ # ...so assume data was send, cos there is no way to proove it was not send try: self.ioHandler.sendMessage(msg) - except self.ioHandler.IOBroken, details: + except consts.IOBrokenError, details: errorMsg = message.ClientDisconnected( DisconnectReason=consts.DisconnectReason.ConnectionDied, ) self._close(errorMsg) - raise self.ioHandler.IOBroken(details) + raise consts.IOBrokenError(details) ######################################################### ## This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-04-09 07:44:54
|
Revision: 385 http://fclient.svn.sourceforge.net/fclient/?rev=385&view=rev Author: jUrner Date: 2008-04-09 00:44:59 -0700 (Wed, 09 Apr 2008) Log Message: ----------- moved more logging stuff to consts Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-04-09 07:44:40 UTC (rev 384) +++ trunk/sandbox/fcp2/client.py 2008-04-09 07:44:59 UTC (rev 385) @@ -218,9 +218,6 @@ del hack #<-- rel import hack - -logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) -logging.addLevelName(consts.DebugVerbosity.Quiet, '') #************************************************************************************************* # #************************************************************************************************* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-04-09 08:03:55
|
Revision: 388 http://fclient.svn.sourceforge.net/fclient/?rev=388&view=rev Author: jUrner Date: 2008-04-09 01:03:56 -0700 (Wed, 09 Apr 2008) Log Message: ----------- docs Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-04-09 07:45:33 UTC (rev 387) +++ trunk/sandbox/fcp2/client.py 2008-04-09 08:03:56 UTC (rev 388) @@ -881,7 +881,7 @@ #FIXME: does not work as expected # ClientPutdiskDir is just a subtype of ClientPutComplexDir - # and will be passed as Files.N.* container + # items will be passed as Files.N.* container elif requestType == consts.RequestType.PutMultiple: initialRequest = message.ClientPutComplexDir() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-04-09 21:54:46
|
Revision: 394 http://fclient.svn.sourceforge.net/fclient/?rev=394&view=rev Author: jUrner Date: 2008-04-09 14:45:27 -0700 (Wed, 09 Apr 2008) Log Message: ----------- fixed docs Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-04-09 21:26:57 UTC (rev 393) +++ trunk/sandbox/fcp2/client.py 2008-04-09 21:45:27 UTC (rev 394) @@ -1390,11 +1390,9 @@ @return: (str) request identifier - @event: (L{events.Event.RequestCompleted}) triggered when the request is complete - @event: (L{events.Event.RequestFailed}) triggered when the request failes - @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable - @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed - @event: (L{events.Event.RequestCompressed}) triggered as soon as compressing of the request is completed + @event: (L{events.Events.RequestCompleted}) triggered when the request is complete + @event: (L{events.Events.RequestFailed}) triggered when the request failes + @event: (L{events.Events.RequestFetchable}) triggered as soon as the request is fetchable filename changes or the request is modified otherwise (see L{modifyRequest}) @@ -1745,20 +1743,20 @@ @param dontCompress: (bool) if True, the node won't try to compress the data @param maxRetries: (int) maximum number of retries or -1 to retry forver or None to leave it to the node to decide @param priorityClass: (L{consts.Priority}) priority of the request - @paramtargetFilename: (str) filename to append to the key (may not contain slashes) + @param targetFilename: (str) filename to append to the key (may not contain slashes) @param userData: any non persistent data to associate to the request @param persistentUserData: any string to associate to the request as persistent data - @event: (L{events.Event.RequestCompleted}) triggered when the request is complete - @event: (L{events.Event.RequestFailed}) triggered when the request failes - @event: (L{events.Event.RequestFetchable}) triggered as soon as the request is fetchable - @event: (L{events.Event.RequestCompressing}) triggered when the request is about to be compressed - @event: (L{events.Event.RequestCompressed}) triggered as soon as compressing of the request is completed + @event: (L{events.Events.RequestCompleted}) triggered when the request is complete + @event: (L{events.Events.RequestFailed}) triggered when the request failes + @event: (L{events.Events.RequestFetchable}) triggered as soon as the request is fetchable + @event: (L{events.Events.RequestCompressionStarted}) triggered when the request is about to be compressed + @event: (L{events.Events.RequestCompressionComopleted}) triggered as soon as compressing of the request is completed @note: if the upload is successful the node will create a L{consts.KeyType.CHK} key under wich the data can be retreieved. The key can be accessed as 'URI' member of the request as soon - as the L{events.Event.RequestFetchable} or the L{events.Event.RequestCompleted} event + as the L{events.Events.RequestFetchable} or the L{events.Events.RequestCompleted} event is triggered. @todo: EarlyEncode and GetCHKOnly message params not implemented @@ -1972,7 +1970,7 @@ """Uploads data that can be updated by the owner @param data: (bytes) data to upload - @params privateKey: see: private key as generated by L{generateKeypair} + '/' + name + @param privateKey: see: private key as generated by L{generateKeypair} + '/' + name @note: for other params see L{chkPutData} @note: use this method to upload updatable data. First you need to create a public / private @@ -2369,7 +2367,7 @@ @note: the client does not keep track of messages send to a plugin, because the plugin may or may not return. If the plugin sends a reply, a L{events.PluginMessage} is triggered. - If something goes wrong, L{events.ProtocolError} or an is L{events.IdentifierCollision} + If something goes wrong, L{events.Events.ProtocolError} or an is L{events.Events.IdentifierCollision} is triggered. Use the identifier passed to identify responses. @todo: this is method not tested. Assumption: identifer does not have to be unique to This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-05-05 07:57:18
|
Revision: 399 http://fclient.svn.sourceforge.net/fclient/?rev=399&view=rev Author: jUrner Date: 2008-05-05 00:57:16 -0700 (Mon, 05 May 2008) Log Message: ----------- Fcp now allows to remove non-persistent requests. adapt Modified Paths: -------------- trunk/sandbox/fcp2/client.py Modified: trunk/sandbox/fcp2/client.py =================================================================== --- trunk/sandbox/fcp2/client.py 2008-04-09 21:46:27 UTC (rev 398) +++ trunk/sandbox/fcp2/client.py 2008-05-05 07:57:16 UTC (rev 399) @@ -138,8 +138,15 @@ # #FIX: workaround for the "related" part #------------------------------------------------------------------------------------------------------------------------------------------------ - + # [0002200 - handle persistent and non-peristent request uniformly] +# +# removbe request is now handled uniformly in Fcp. modify request not yet. +# +#------------------------------------------------------------------------------------------------------------------------------------------------- + + + # Todos #------------------------------------------------------------------------------------------------------------------------------------------------ # clean up @@ -307,6 +314,7 @@ self.events.ClientDisconnected(msg) + #TODO: check if this method is still needed def _finalizeRequest(self, msg, request, event): """Finalzes a request @param msg: message that is the reason for finalizing @@ -320,7 +328,7 @@ that the request has been completed and remove it fom our queue if necessary. Non Get / Put requests will be removed in any case. """ - removeRequest = msg == message.ProtocolError or msg == message.PersistentRequestRemoved + removeRequest = msg == message.ProtocolError or msg == message.PersistentRequestRemoved # TODO: PersistentRequestRemoved??? if not removeRequest: #NOTE: non Get / Put related requests do not have a Persistence param removeRequest = request.params.get('Persistence', consts.Persistence.Connection) == consts.Persistence.Connection @@ -844,7 +852,10 @@ code = msg['Code'] if code == consts.FetchError.Canceled: - return False + initialRequest['RequestStatus'] |= onsts.RequestStatus.Removed | consts.RequestStatus.Completed | consts.RequestStatus.RemovedFromQueue + del self._requests[requestIdentifier] + self.events.RequestRemoved(initialRequest) + return True # check if it is one of our requests for key information if code == consts.FetchError.TooBig and initialRequest['RequestType'] == consts.RequestType.GetKeyInfo: @@ -941,13 +952,15 @@ return True - elif msg == message.PersistentRequestRemoved: - if initialRequest is None: - return False + # don't handle PersistentRequestRemoved. instead we handle it in Get/PutFailed + # + #elif msg == message.PersistentRequestRemoved: + # if initialRequest is None: + # return False - initialRequest['RequestStatus'] |= consts.RequestStatus.Removed - self._finalizeRequest(msg, initialRequest, self.events.RequestRemoved) - return True + # initialRequest['RequestStatus'] |= consts.RequestStatus.Removed + # self._finalizeRequest(msg, initialRequest, self.events.RequestRemoved) + # return True elif msg == message.SimpleProgress: @@ -970,7 +983,10 @@ code = msg['Code'] if code == consts.InsertError.Canceled: - return False + initialRequest['RequestStatus'] |= onsts.RequestStatus.Removed | consts.RequestStatus.Completed | consts.RequestStatus.RemovedFromQueue + del self._requests[requestIdentifier] + self.events.RequestRemoved(initialRequest) + return True initialRequest['RequestStatus'] |= consts.RequestStatus.Error initialRequest['ErrorMessage'] = msg @@ -2145,22 +2161,15 @@ initialRequest = self._requests[requestIdentifier] initialRequest['RequestStatus'] |= consts.RequestStatus.Removed | consts.RequestStatus.Completed if initialRequest['RequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): - - # remove Persistence.Connection emidiately - # ..make up a PersistentRequestRemoved message for this case - if initialRequest['Persistence'] == consts.Persistence.Connection: - msg = message.PersistentRequestRemoved(Identifier=requestIdentifier, Global=False) - self._finalizeRequest(msg, initialRequest, self.events.RequestRemoved) - else: - self.sendMessage( - message.RemovePersistentRequest( + self.sendMessage( + message.RemoveRequest( Global=False, Identifier=requestIdentifier, ) - ) + ) else: del self._requests[requestIdentifier] - + def resendRequest(self, request): """Resends a request This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |