fclient-commit Mailing List for fclient (Page 31)
Status: Pre-Alpha
Brought to you by:
jurner
You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(23) |
Nov
(54) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(17) |
Feb
(209) |
Mar
(63) |
Apr
(31) |
May
(7) |
Jun
(39) |
Jul
(390) |
Aug
(122) |
Sep
(6) |
Oct
|
Nov
|
Dec
|
From: <ju...@us...> - 2008-02-12 15:59:45
|
Revision: 212 http://fclient.svn.sourceforge.net/fclient/?rev=212&view=rev Author: jurner Date: 2008-02-12 07:59:48 -0800 (Tue, 12 Feb 2008) Log Message: ----------- Wrong param name in SimpleProgress. It's "FinalzedTotal" not "Fianlized" Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_types.py Modified: trunk/sandbox/fcp/fcp2_0_types.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_types.py 2008-02-12 15:57:09 UTC (rev 211) +++ trunk/sandbox/fcp/fcp2_0_types.py 2008-02-12 15:59:48 UTC (rev 212) @@ -698,7 +698,7 @@ 'Failed': FcpTypeInt, 'FatalyFailed': FcpTypeInt, 'Succeeded': FcpTypeInt, - 'Finalized': FcpTypeBool, + 'FinalizedTotal': FcpTypeBool, }, 'SubscribedUSKUpdate': { 'Edition': FcpTypeInt, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-12 15:57:04
|
Revision: 211 http://fclient.svn.sourceforge.net/fclient/?rev=211&view=rev Author: jurner Date: 2008-02-12 07:57:09 -0800 (Tue, 12 Feb 2008) Log Message: ----------- pprint now print python types not Fcp types Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-12 15:56:20 UTC (rev 210) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-12 15:57:09 UTC (rev 211) @@ -165,10 +165,10 @@ continue # convert python to fcp value if necessary - if paramTypes is not None: - paramType = paramTypes.get(param, None) - if paramType is not None: - value = paramType.pythonToFcp(value) + #if paramTypes is not None: + # paramType = paramTypes.get(param, None) + # if paramType is not None: + # value = paramType.pythonToFcp(value) out.append('>> %s=%s' % (param, value)) out.append('>>EndMessage') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-12 15:56:25
|
Revision: 210 http://fclient.svn.sourceforge.net/fclient/?rev=210&view=rev Author: jurner Date: 2008-02-12 07:56:20 -0800 (Tue, 12 Feb 2008) Log Message: ----------- added some more logger consts Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_consts.py Modified: trunk/sandbox/fcp/fcp2_0_consts.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-12 15:55:42 UTC (rev 209) +++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-12 15:56:20 UTC (rev 210) @@ -168,9 +168,10 @@ """Consts indicating the verbosity level for debugging""" Debug = logging.DEBUG Info = logging.INFO - Warning = logging.WARNING + Warning = logging.WARNING + Error = logging.ERROR + Critical = logging.CRITICAL - class DisconnectReason(BaseBitFlags): """Reasons for client disconnect @cvar Close: the clent has been closed This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-12 15:55:39
|
Revision: 209 http://fclient.svn.sourceforge.net/fclient/?rev=209&view=rev Author: jurner Date: 2008-02-12 07:55:42 -0800 (Tue, 12 Feb 2008) Log Message: ----------- combed over logging Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_client.py Modified: trunk/sandbox/fcp/fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_client.py 2008-02-12 09:50:22 UTC (rev 208) +++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-12 15:55:42 UTC (rev 209) @@ -142,11 +142,6 @@ # Todos #------------------------------------------------------------------------------------------------------------------------------------------------ -# logging -# -# logging is not very accurate. What to log at wich level? What details? -# -#------------------------------------------------------------------------------------------------------------------------------------------------ # clean up # # x. move saveWriteFile and friends to a separate module @@ -469,7 +464,8 @@ def _logEvent(self, event, request): - self._log.info(consts.LogMessages.EventTriggered + event.name) + if event != self.events.Idle: + self._log.debug(consts.LogMessages.EventTriggered + event.name) ############################################################### ## @@ -1252,7 +1248,7 @@ """ msg = self.Message.fromSocket(self._socket) if msg.name == consts.Message.ClientSocketDied: - self._log.info(consts.LogMessages.SocketDied) + self._log.critical(consts.LogMessages.SocketDied) if dispatch: disconnectMsg = self.Message( consts.Message.ClientDisconnected, @@ -1333,7 +1329,7 @@ try: msg.send(self._socket) except socket.error, d: - self._log.info(consts.LogMessages.SocketDied) + self._log.critical(consts.LogMessages.SocketDied) disconnectMsg = self.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.SocketDied, @@ -2197,14 +2193,24 @@ # #***************************************************************************** if __name__ == '__main__': + + Dir = os.path.dirname(os.path.abspath(__file__)) + c = FcpClient( connectionName='test', debugVerbosity=consts.DebugVerbosity.Debug ) + log = c.getLogger() + fpath = os.path.join(Dir, 'test.log') + handler = logging.FileHandler(fpath, 'w') + logging.getLogger('').addHandler(handler) + nodeHello = c.connect() if nodeHello is not None: + + #for i in xrange(10): # c.next() @@ -2320,8 +2326,6 @@ identifier = c.chkPutFile( fpath, ) - - c.run() #for i in xrange(500): # c.next() @@ -2359,7 +2363,7 @@ def testUskPutData(): def cb(event, request): - insertURI = request['InsertURI'] + insertURI = request['FcPrivateKey'] insertURI = 'USK@AKva7OolWsdAICB8ZE1hDgFqBJigJpYN2edJd6deiApU,dOitAHZSrt27Tl4wK7F-VHVShJVvzR7eNWKsXBolq8k,AQECAAE/' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-12 09:50:19
|
Revision: 208 http://fclient.svn.sourceforge.net/fclient/?rev=208&view=rev Author: jurner Date: 2008-02-12 01:50:22 -0800 (Tue, 12 Feb 2008) Log Message: ----------- listeners get now informed on regular client closes Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_client.py Modified: trunk/sandbox/fcp/fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_client.py 2008-02-12 09:47:25 UTC (rev 207) +++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-12 09:50:22 UTC (rev 208) @@ -8,8 +8,7 @@ @note: The client implementation never uses or watches the global queue. No implementation should ever do so. Global is evil. -@note: the client is not thread save, nor will it ever be. If you need that, create another client -and connect it to the node. +@note: the client is not thread save. Sample code. Connect to the freenet node:: @@ -316,6 +315,30 @@ ## private methods ## ############################################################### + def _close(self, msg): + """Closes the client + @param msg: message to pass to the ClientDisconnected event or None to not inform listeners + """ + self._log.info(consts.LogMessages.ClientClose) + + # clean left over DDA test tmp files + for initialRequest in self._ddaTests: + if initialRequest['FcTestDDA'].get('TmpFile', None) is not None: + saveRemoveFile(initialRequest['FcTestDDA']['TmpFile']) + + self._ddaTests = [] + self._requests = {} + + if self._socket is None: + #TODO: complain or not? + pass + else: + self._socket.close() + self._socket = None + if msg is not None: + self.events.ClientDisconnected(msg) + + def _finalizeRequest(self, msg, request, event): """Finalzes a request @param msg: message that is the reason for finalizing @@ -457,19 +480,13 @@ """Closes the client @note: make shure to call close() when done with the client """ - self._log.info(consts.LogMessages.ClientClose) - if self._socket is not None: - self._socket.close() - self._socket = None + msg = self.Message( + consts.Message.ClientDisconnected, + DisconnectReason=consts.DisconnectReason.Close, + Param=None, + ) + self._close(msg) - # clean left over DDA test tmp files - for initialRequest in self._ddaTests: - if initialRequest['FcTestDDA'].get('TmpFile', None) is not None: - saveRemoveFile(initialRequest['FcTestDDA']['TmpFile']) - - self._ddaTests = [] - self._requests = {} - def closeFreenet(self): """Shuts down the freenet node""" @@ -506,7 +523,7 @@ # try to Connect socket if self._socket is not None: - self.close() + self._close(None) # poll untill freenet responds timeElapsed = 0 @@ -548,13 +565,12 @@ if self.versionCheckNodeHello(msg): self.events.ClientConnected(msg) else: - self.close() - msg = self.Message( + disconnectMsg = self.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.VersionMissmatch, Param=msg, ) - self.events.ClientDisconnected(msg) + self._close(disconnectMsg) yield self._nodeHelloMessage raise StopIteration @@ -568,14 +584,13 @@ timeElapsed += timeout time.sleep(timeout) - msg = self.Message( + self._log.info(consts.LogMessages.ConnectingFailed) + disconnectMsg = self.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.ConnectingFailed, Param=None, ) - self.events.ClientDisconnected(msg) - self._log.info(consts.LogMessages.ConnectingFailed) - self.close() + self._close(disconnectMsg) raise StopIteration @@ -585,6 +600,10 @@ """ return self._connectionName + def getLogger(self): + """Returns the L{logging.Logger} used by the client""" + return self._log + 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 @@ -671,13 +690,12 @@ elif msg.name == consts.Message.ProtocolError: code = msg['Code'] if code == consts.ProtocolError.ShuttingDown: - self.close() - msg = self.Message( + disconnectMsg = self.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.Shutdown, Param=None, ) - self.events.ClientDisconnected(msg) + self._close(disconnectMsg) return True @@ -1188,13 +1206,12 @@ ## #################################################### elif msg.name == consts.Message.CloseConnectionDuplicateClientName: - self.close() - msg = self.Message( + disconnectMsg = self.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.DuplicateClientName, Param=None, ) - self.events.ClientDisconnected(msg) + self._close(disconnectMsg) return True @@ -1237,12 +1254,12 @@ if msg.name == consts.Message.ClientSocketDied: self._log.info(consts.LogMessages.SocketDied) if dispatch: - msg = self.Message( + disconnectMsg = self.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.SocketDied, Param=msg, ) - self.events.ClientDisconnected(msg) + self._close(disconnectMsg) #raise socket.error(msg['Param']['Details']) elif msg.name == consts.Message.ClientSocketTimeout: @@ -1317,13 +1334,12 @@ msg.send(self._socket) except socket.error, d: self._log.info(consts.LogMessages.SocketDied) - self.close() - msg = self.Message( + disconnectMsg = self.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.SocketDied, Param=self.Message(consts.Message.ClientSocketDied, Exception=socket.error, Details=d) ) - self.events.ClientDisconnected(msg) + self._close(disconnectMsg) raise socket.error(d) return msg @@ -1661,12 +1677,14 @@ return msg['Identifier'] def clientPut(self, + requestType, uri, - requestType, - userData, - persistentUserData, - data, - **messageParams): + data=None, + persistentUserData='', + userData=None, + + **messageParams + ): msg = self.Message(consts.Message.ClientPut, URI=uri) for paramName, value in messageParams.items(): @@ -1706,12 +1724,13 @@ @param data: () """ return self.clientPut( + consts.RequestType.Put, consts.KeyType.CHK, - consts.RequestType.Put, - userData, - persistentUserData, - data, + data=data, + persistentUserData=persistentUserData, + userData=userData, + # fcp params ContentType=contentType, DataLength=len(data), @@ -1733,9 +1752,9 @@ def chkPutFile(self, + filename, contentType=None, dontCompress=None, - filename=None, maxRetries=None, persistence=consts.Persistence.Connection, priorityClass=consts.Priority.Medium, @@ -1746,16 +1765,18 @@ ): """ - @param filename: (str) filename to append to the CHK key or None (may not contain slashes) + @param TargetFilename: (str) filename to append to the CHK key or None (may not contain slashes) """ return self.clientPut( + consts.RequestType.Put, consts.KeyType.CHK, - consts.RequestType.Put, - userData, - persistentUserData, - None, + + data=None, + persistentUserData=persistentUserData, + userData=userData, + # fcp params Filename=filename, ContentType=contentType, @@ -2279,8 +2300,10 @@ 'test123', #persistence=c.Persistence.Reboot, ) - for i in xrange(500): - c.next() + + c.run() + #for i in xrange(500): + # c.next() #c.removeRequest(myIdentifier) #for i in xrange(5): # c.next() @@ -2299,8 +2322,9 @@ ) - for i in xrange(500): - c.next() + c.run() + #for i in xrange(500): + # c.next() #c.removeRequest(identifier) #for i in xrange(5): # c.next() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-12 09:47:28
|
Revision: 207 http://fclient.svn.sourceforge.net/fclient/?rev=207&view=rev Author: jurner Date: 2008-02-12 01:47:25 -0800 (Tue, 12 Feb 2008) Log Message: ----------- added new const to DisconnectReason to indicate regular client close Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_consts.py Modified: trunk/sandbox/fcp/fcp2_0_consts.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-11 10:57:05 UTC (rev 206) +++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-12 09:47:25 UTC (rev 207) @@ -173,12 +173,14 @@ class DisconnectReason(BaseBitFlags): """Reasons for client disconnect + @cvar Close: the clent has been closed @cvar ConnectingFailed: connection could not be established @cvar DuplicateClientName: another client opend a connection with the same connection name @cvar Shutdown: regular shutdown of the connection @cvar SocketDied: connection to the node died unexpectingly @cvar VersionMissmatch: node or Fcp version did not match """ + Close = 0x0 ConnectingFailed = 0x1 DuplicateClientName = 0x2 Shutdown = 0x4 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-11 10:57:07
|
Revision: 206 http://fclient.svn.sourceforge.net/fclient/?rev=206&view=rev Author: jurner Date: 2008-02-11 02:57:05 -0800 (Mon, 11 Feb 2008) Log Message: ----------- up, how this gotten into? Removed Paths: ------------- trunk/sandbox/fcp/oo1.py Deleted: trunk/sandbox/fcp/oo1.py =================================================================== --- trunk/sandbox/fcp/oo1.py 2008-02-11 10:56:46 UTC (rev 205) +++ trunk/sandbox/fcp/oo1.py 2008-02-11 10:57:05 UTC (rev 206) @@ -1 +0,0 @@ - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-11 10:56:46
|
Revision: 205 http://fclient.svn.sourceforge.net/fclient/?rev=205&view=rev Author: jurner Date: 2008-02-11 02:56:46 -0800 (Mon, 11 Feb 2008) Log Message: ----------- up, how this gotten into? Modified Paths: -------------- trunk/sandbox/fcp/oo1.py Modified: trunk/sandbox/fcp/oo1.py =================================================================== --- trunk/sandbox/fcp/oo1.py 2008-02-11 10:55:27 UTC (rev 204) +++ trunk/sandbox/fcp/oo1.py 2008-02-11 10:56:46 UTC (rev 205) @@ -1,216 +1 @@ -# -*- coding: utf-8 -*- - - -s = '''console.allowedHosts -console.bindTo -console.directEnabled -console.enabled -console.port -console.ssl -fcp.allowedHosts -fcp.allowedHostsFullAccess -fcp.assumeDownloadDDAIsAllowed -fcp.assumeUploadDDAIsAllowed -fcp.bindTo -fcp.enabled -fcp.persistentDownloadsEnabled -fcp.persistentDownloadsFile -fcp.persistentDownloadsInterval -fcp.port -fcp.ssl -fproxy.CSSOverride -fproxy.advancedModeEnabled -fproxy.allowedHosts -fproxy.allowedHostsFullAccess -fproxy.bindTo -fproxy.css -fproxy.doRobots -fproxy.enabled -fproxy.javascriptEnabled -fproxy.port -fproxy.showPanicButton -fproxy.ssl -logger.dirname -logger.enabled -logger.interval -logger.maxCachedBytes -logger.maxCachedLines -logger.maxZippedLogsSize -logger.priority -logger.priorityDetail -node.alwaysAllowLocalAddresses -node.assumeNATed -node.bindTo -node.clientThrottleFile -node.databaseMaxMemory -node.disableHangCheckers -node.disableProbabilisticHTLs -node.downloadAllowedDirs -node.downloadsDir -node.extraPeerDataDir -node.includeLocalAddressesInNoderefs -node.inputBandwidthLimit -node.ipAddressOverride -node.l10n -node.lazyResume -node.listenPort -node.load.aggressiveGC -node.load.freeHeapBytesThreshold -node.load.freeHeapPercentThreshold -node.load.memoryChecker -node.load.nodeThrottleFile -node.load.threadLimit -node.maxBackgroundUSKFetchers -node.maxHTL -node.name -node.nodeDir -node.oneConnectionPerIP -node.opennet.acceptSeedConnections -node.opennet.alwaysAllowLocalAddresses -node.opennet.assumeNATed -node.opennet.bindTo -node.opennet.enabled -node.opennet.listenPort -node.opennet.maxOpennetPeers -node.opennet.oneConnectionPerIP -node.opennet.testingDropPacketsEvery -node.outputBandwidthLimit -node.passOpennetPeersThroughDarknet -node.persistentTempDir -node.scheduler.CHKinserter_priority_policy -node.scheduler.CHKrequester_priority_policy -node.scheduler.SSKinserter_priority_policy -node.scheduler.SSKrequester_priority_policy -node.storeDir -node.storeForceBigShrinks -node.storeSize -node.tempDir -node.tempIPAddressHint -node.testingDropPacketsEvery -node.testnet.enabled -node.updater.URI -node.updater.autoupdate -node.updater.enabled -node.updater.extURI -node.updater.revocationURI -node.uploadAllowedDirs -pluginmanager.loadplugin -pluginmanager2.loadedPlugins -ssl.sslEnable -ssl.sslKeyPass -ssl.sslKeyStore -ssl.sslKeyStorePass -ssl.sslVersion -toadletsymlinker.symlinks''' - -print '{' -for i in s.split('\n'): - print " '%s': ValueTypeUnknown," % i - -print '}' - -ValueTypeUnknown = 0 - -p = { - 'console.allowedHosts': ValueTypeUnknown, - 'console.bindTo': ValueTypeUnknown, - 'console.directEnabled': ValueTypeUnknown, - 'console.enabled': ValueTypeUnknown, - 'console.port': ValueTypeUnknown, - 'console.ssl': ValueTypeUnknown, - 'fcp.allowedHosts': ValueTypeUnknown, - 'fcp.allowedHostsFullAccess': ValueTypeUnknown, - 'fcp.assumeDownloadDDAIsAllowed': ValueTypeUnknown, - 'fcp.assumeUploadDDAIsAllowed': ValueTypeUnknown, - 'fcp.bindTo': ValueTypeUnknown, - 'fcp.enabled': ValueTypeUnknown, - 'fcp.persistentDownloadsEnabled': ValueTypeUnknown, - 'fcp.persistentDownloadsFile': ValueTypeUnknown, - 'fcp.persistentDownloadsInterval': ValueTypeUnknown, - 'fcp.port': ValueTypeUnknown, - 'fcp.ssl': ValueTypeUnknown, - 'fproxy.CSSOverride': ValueTypeUnknown, - 'fproxy.advancedModeEnabled': ValueTypeUnknown, - 'fproxy.allowedHosts': ValueTypeUnknown, - 'fproxy.allowedHostsFullAccess': ValueTypeUnknown, - 'fproxy.bindTo': ValueTypeUnknown, - 'fproxy.css': ValueTypeUnknown, - 'fproxy.doRobots': ValueTypeUnknown, - 'fproxy.enabled': ValueTypeUnknown, - 'fproxy.javascriptEnabled': ValueTypeUnknown, - 'fproxy.port': ValueTypeUnknown, - 'fproxy.showPanicButton': ValueTypeUnknown, - 'fproxy.ssl': ValueTypeUnknown, - 'logger.dirname': ValueTypeUnknown, - 'logger.enabled': ValueTypeUnknown, - 'logger.interval': ValueTypeUnknown, - 'logger.maxCachedBytes': ValueTypeUnknown, - 'logger.maxCachedLines': ValueTypeUnknown, - 'logger.maxZippedLogsSize': ValueTypeUnknown, - 'logger.priority': ValueTypeUnknown, - 'logger.priorityDetail': ValueTypeUnknown, - 'node.alwaysAllowLocalAddresses': ValueTypeUnknown, - 'node.assumeNATed': ValueTypeUnknown, - 'node.bindTo': ValueTypeUnknown, - 'node.clientThrottleFile': ValueTypeUnknown, - 'node.databaseMaxMemory': ValueTypeUnknown, - 'node.disableHangCheckers': ValueTypeUnknown, - 'node.disableProbabilisticHTLs': ValueTypeUnknown, - 'node.downloadAllowedDirs': ValueTypeUnknown, - 'node.downloadsDir': ValueTypeUnknown, - 'node.extraPeerDataDir': ValueTypeUnknown, - 'node.includeLocalAddressesInNoderefs': ValueTypeUnknown, - 'node.inputBandwidthLimit': ValueTypeUnknown, - 'node.ipAddressOverride': ValueTypeUnknown, - 'node.l10n': ValueTypeUnknown, - 'node.lazyResume': ValueTypeUnknown, - 'node.listenPort': ValueTypeUnknown, - 'node.load.aggressiveGC': ValueTypeUnknown, - 'node.load.freeHeapBytesThreshold': ValueTypeUnknown, - 'node.load.freeHeapPercentThreshold': ValueTypeUnknown, - 'node.load.memoryChecker': ValueTypeUnknown, - 'node.load.nodeThrottleFile': ValueTypeUnknown, - 'node.load.threadLimit': ValueTypeUnknown, - 'node.maxBackgroundUSKFetchers': ValueTypeUnknown, - 'node.maxHTL': ValueTypeUnknown, - 'node.name': ValueTypeUnknown, - 'node.nodeDir': ValueTypeUnknown, - 'node.oneConnectionPerIP': ValueTypeUnknown, - 'node.opennet.acceptSeedConnections': ValueTypeUnknown, - 'node.opennet.alwaysAllowLocalAddresses': ValueTypeUnknown, - 'node.opennet.assumeNATed': ValueTypeUnknown, - 'node.opennet.bindTo': ValueTypeUnknown, - 'node.opennet.enabled': ValueTypeUnknown, - 'node.opennet.listenPort': ValueTypeUnknown, - 'node.opennet.maxOpennetPeers': ValueTypeUnknown, - 'node.opennet.oneConnectionPerIP': ValueTypeUnknown, - 'node.opennet.testingDropPacketsEvery': ValueTypeUnknown, - 'node.outputBandwidthLimit': ValueTypeUnknown, - 'node.passOpennetPeersThroughDarknet': ValueTypeUnknown, - 'node.persistentTempDir': ValueTypeUnknown, - 'node.scheduler.CHKinserter_priority_policy': ValueTypeUnknown, - 'node.scheduler.CHKrequester_priority_policy': ValueTypeUnknown, - 'node.scheduler.SSKinserter_priority_policy': ValueTypeUnknown, - 'node.scheduler.SSKrequester_priority_policy': ValueTypeUnknown, - 'node.storeDir': ValueTypeUnknown, - 'node.storeForceBigShrinks': ValueTypeUnknown, - 'node.storeSize': ValueTypeUnknown, - 'node.tempDir': ValueTypeUnknown, - 'node.tempIPAddressHint': ValueTypeUnknown, - 'node.testingDropPacketsEvery': ValueTypeUnknown, - 'node.testnet.enabled': ValueTypeUnknown, - 'node.updater.URI': ValueTypeUnknown, - 'node.updater.autoupdate': ValueTypeUnknown, - 'node.updater.enabled': ValueTypeUnknown, - 'node.updater.extURI': ValueTypeUnknown, - 'node.updater.revocationURI': ValueTypeUnknown, - 'node.uploadAllowedDirs': ValueTypeUnknown, - 'pluginmanager.loadplugin': ValueTypeUnknown, - 'pluginmanager2.loadedPlugins': ValueTypeUnknown, - 'ssl.sslEnable': ValueTypeUnknown, - 'ssl.sslKeyPass': ValueTypeUnknown, - 'ssl.sslKeyStore': ValueTypeUnknown, - 'ssl.sslKeyStorePass': ValueTypeUnknown, - 'ssl.sslVersion': ValueTypeUnknown, - 'toadletsymlinker.symlinks': ValueTypeUnknown, -} \ No newline at end of file + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-11 10:55:22
|
Revision: 204 http://fclient.svn.sourceforge.net/fclient/?rev=204&view=rev Author: jurner Date: 2008-02-11 02:55:27 -0800 (Mon, 11 Feb 2008) Log Message: ----------- reworked tests. In theory it is now possible to test against the running node Modified Paths: -------------- trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py Modified: trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-11 10:54:36 UTC (rev 203) +++ trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-11 10:55:27 UTC (rev 204) @@ -26,40 +26,114 @@ del parentdir #<-- rel import hack - from dummy_socket import DummySocket +#*********************************************************************************** +# +#*********************************************************************************** +DIR = os.path.dirname(os.path.abspath(__file__)) +TestAgainstNode = 0 # don't know how to test against node. Do not touch this! +#*********************************************************************************** +# +#*********************************************************************************** +class MyFcpClient(FcpClient): + """Customized client recording all messages it sends + """ + def __init__(self, *args, **kwargs): + FcpClient.__init__(self, *args, **kwargs) + self.test_messagesSend = [] + + def sendMessageEx(self, msg): + FcpClient.sendMessageEx(self, msg) + # deepcopy here, we need exact state + msg = copy.deepcopy(msg) + self.test_messagesSend.append(msg) + +#*********************************************************************************** +# +#*********************************************************************************** +class DummySocketModule(object): + """Dummy socket module we inject into the client module for testing + + """ + AF_INET = socket.AF_INET + SOCK_STREAM = socket.SOCK_STREAM + error = socket.error + socket = DummySocket() + + def __init__(self): + self.lastSocket = None + + def __getattribute__(self, name): + obj = object.__getattribute__(self, name) + if name == 'socket': + self.lastSocket = obj + return obj + +#*********************************************************************************** +# +#*********************************************************************************** +class MySocketFactory(object): + """Real and alive socket. Can be used to test against the running node. Not used currently + + Usage: -DIR = os.path.dirname(os.path.abspath(__file__)) + DummySocketModule.socket = MySocketFactory() + + """ + def __init__(self, *args, **kwargs): + self.socket = None + self.closed = False + + def __call__(self, *args, **kwargs): + self.socket = socket.socket(*args, **kwargs) + return self + + def sendResponseMessage(self, *args, **kwargs): + pass + + def connect(self, *args, **kwargs): + return self.socket.connect(*args, **kwargs) + + def sendall(self, bytes): + return self.socket.sendall(bytes) + + def settimeout(self, n): + return self.socket.settimeout(n) + + def recv(self, n): + return self.socket.recv(n) + + def close(self): + self.closed = True + result = self.socket.close() + self.socket = None + return result + #*********************************************************************************** # #*********************************************************************************** class BaseTestClient(unittest.TestCase): - """Base class that does not connect to FcpClient prior to each test""" + """Base class for all tests""" + if TestAgainstNode: + DummySocketModule.socket = MySocketFactory() + fcpClient = MyFcpClient( + #debugVerbosity=FcpClient.consts.DebugVerbosity.Debug + ) + + # inject our customized socket module + socketModule = DummySocketModule() + fcp2_0_client.socket = socketModule + + def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) - # replace socket module with our dummy socket module - self.oldSocketModule = None - self.socket = DummySocket() - class DummySocketModule(object): - AF_INET = socket.AF_INET - SOCK_STREAM = socket.SOCK_STREAM - error = socket.error - socket = self.socket - self.socketModule = DummySocketModule - - self.fcpClient = None # client to test self.events = [] # events received from the client - self.messages = [] # messages the client sent self.tmpfiles = [] # temp files used for testing (will be removed on tearDown) - def _captureMessagesFromClient(self, bytes): - s = DummySocket() - s.setResponse(bytes) - self.messages.append(self.fcpClient.Message.fromSocket(s)) - + def _captureEventsFromClient(self, event, msg): # have to copy message here, to get exact state msg = copy.deepcopy(msg) @@ -67,27 +141,34 @@ def connectClient(self): """Connects to the client""" - enum = self.fcpClient.iterConnect(duration=0.2, timeout=0.1) - msg = enum.next() - self.failIf(msg is not None) - #NOTE: have to send directly via socket here (our sendResponseMessage - # calls client.next() autkmatically) - self.socket.sendResponseMessage( - 'NodeHello', - FCPVersion='2.0', - Node='Fred', - Version=str(self.fcpClient.ExpectedFcpVersion), - Revision='999999999999', - Build='999999', - ExRevision='9999999999', - Testnet='false', - CompressionCodecs='1', - ConnectionIdentifier='any', - NodeLanguage='en', + for n, nodeHello in enumerate(self.fcpClient.iterConnect(duration=20, timeout=0.1)): + if n == 0: + self.assertHasNextMessage( + consts.Message.ClientHello + ) + self.sendResponseMessage( + 'NodeHello', + FCPVersion='2.0', + Node='Fred', + Version=str(self.fcpClient.ExpectedFcpVersion), + Revision='999999999999', + Build='9999999999', + ExRevision='9999999999', + Testnet='false', + CompressionCodecs='1', + ConnectionIdentifier='any', + NodeLanguage='en', + + callNext=False, + ) + + # check events the client triggered + self.assertHasNextEvent( + self.fcpClient.events.ClientConnected, + consts.Message.NodeHello, ) - msg = enum.next() - self.messages.pop(0) - self.events.pop(0) + + self.assertHasNextEvent(None) def assertHasNextEvent(self, expectedEvent=None, @@ -159,10 +240,10 @@ @return: message if a message was received or None """ if messageName is None: - self.failIf(self.messages) + self.failIf(self.fcpClient.test_messagesSend) else: - self.failUnless(self.messages) - msg = self.messages.pop(0) + self.failUnless(self.fcpClient.test_messagesSend) + msg = self.fcpClient.test_messagesSend.pop(0) self.assertEqual(msg.name, messageName) if param1 is not None: param1, value1 = param1 @@ -189,29 +270,20 @@ self.assertEqual(data, msg.data) return msg - def sendResponseMessage(self, messageName, data=None, **params): + def sendResponseMessage(self, messageName, data=None, callNext=True, **params): """Posts a message to the client""" - self.socket.sendResponseMessage(messageName, data=data, **params) - self.fcpClient.next() + self.socketModule.lastSocket.sendResponseMessage(messageName, data=data, **params) + if not TestAgainstNode: + if callNext: + self.fcpClient.next() def setUp(self): - self.oldSocketModule = fcp2_0_client.socket - fcp2_0_client.socket = self.socketModule - - self.fcpClient = FcpClient() - # conect all events self.events = [] # events received from the client for event in self.fcpClient.events: event += self._captureEventsFromClient - - # capture all messages the client sent - self.messages = [] # messages the client send - self.socket.setBytesReceiver(self._captureMessagesFromClient) def tearDown(self): - fcp2_0_client.socket = self.oldSocketModule - # disconnect all events for event in self.fcpClient.events: event -= self._captureEventsFromClient @@ -221,17 +293,6 @@ #*********************************************************************************** # #*********************************************************************************** -class BaseTestConnectedClient(BaseTestClient): - """Base class that automatically connects to FcpClient prior to each test""" - - def setUp(self): - BaseTestClient.setUp(self) - self.connectClient() - - -#*********************************************************************************** -# -#*********************************************************************************** #TODO: class Test.... set/getDebugVerbosity / connectionName and friends... (BaseTestConnectedClient): #*********************************************************************************** @@ -240,7 +301,7 @@ class TestConnect(BaseTestClient): - def testClose(self): + def XXXtestClose(self): self.failIf(self.socket.closed) self.connectClient() self.fcpClient.close() @@ -248,11 +309,16 @@ - def testConnect(self): - nodeHello = self.fcpClient.connect(duration=0.2, timeout=0.1) + def XXXtestConnect(self): + nodeHello = self.fcpClient.connect(duration=10, timeout=0.1) + self.failIf(nodeHello is None) + return + + + nodeHello = self.fcpClient.connect(duration=0, timeout=0) self.failIf(nodeHello is not None) - self.socket.sendResponseMessage( + self.socketModule.lastSocket.sendResponseMessage( 'NodeHello', FCPVersion='2.0', Node='Fred', @@ -265,68 +331,57 @@ ConnectionIdentifier='any', NodeLanguage='en', ) - nodeHello = self.fcpClient.connect(duration=0.2, timeout=0.1) + nodeHello = self.fcpClient.connect(duration=10, timeout=0.1) self.failIf(nodeHello is None) - def testIterConnect_Failure(self): + def test_0_IterIterConnect_RFailure(self): - # simulate a failed connection attempt - enum = self.fcpClient.connect(duration=0.2, timeout=0.1) - t0 = time.time() - while time.time() - t0 < 1: - try: - nodeHello = enum.next() - except: break - else: - raise RuntimeError('Fell trough') + # we cannot test against node here + if not TestAgainstNode: - - # check messages the client send - self.assertHasNextMessage(consts.Message.ClientHello) - - # check events the client triggered - self.assertHasNextEvent( - self.fcpClient.events.ClientDisconnected, - consts.Message.ClientDisconnected, - ('DisconnectReason', consts.DisconnectReason.ConnectingFailed), - ) - - self.assertHasNextEvent(None) - - # did the client clean up our socket? - self.failUnless(self.socket.closed) + for n, nodeHello in enumerate(self.fcpClient.iterConnect(duration=1, timeout=0.1)): + if n == 0: + self.assertHasNextMessage( + consts.Message.ClientHello + ) - - def testIterConnect_Success(self): + # check events the client triggered + self.assertHasNextEvent( + self.fcpClient.events.ClientDisconnected, + consts.Message.ClientDisconnected, + ('DisconnectReason', consts.DisconnectReason.ConnectingFailed), + ) + + self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + self.failUnless(self.socketModule.lastSocket.closed) + + #self.fcpClient.connect(duration=20, timeout=0.1) + - # simulate a successful connection attempt - enum = self.fcpClient.iterConnect(duration=0.2, timeout=0.1) - msg = enum.next() - self.failIf(msg is not None) - - # check messages the client send message - self.assertHasNextMessage( - consts.Message.ClientHello - ) - - #NOTE: have to send directly via socket here (our sendResponseMessage - # calls client.next() autkmatically) - self.socket.sendResponseMessage( - 'NodeHello', - FCPVersion='2.0', - Node='Fred', - Version=str(self.fcpClient.ExpectedFcpVersion), - Revision='999999999999', - Build='9999999999', - ExRevision='9999999999', - Testnet='false', - CompressionCodecs='1', - ConnectionIdentifier='any', - NodeLanguage='en', - ) - msg = enum.next() + def test_1_IterConnect_Success(self): + for n, nodeHello in enumerate(self.fcpClient.iterConnect(duration=20, timeout=0.1)): + if n == 0: + self.assertHasNextMessage( + consts.Message.ClientHello + ) + self.sendResponseMessage( + 'NodeHello', + FCPVersion='2.0', + Node='Fred', + Version=str(self.fcpClient.ExpectedFcpVersion), + Revision='999999999999', + Build='9999999999', + ExRevision='9999999999', + Testnet='false', + CompressionCodecs='1', + ConnectionIdentifier='any', + NodeLanguage='en', + callNext=False, + ) + # check events the client triggered self.assertHasNextEvent( self.fcpClient.events.ClientConnected, @@ -334,13 +389,14 @@ ) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) #*********************************************************************************** # #*********************************************************************************** -class TestDisconnectReason(BaseTestConnectedClient): +class TestDisconnectReason(BaseTestClient): - def testDuplicateClientName(self): + def test_1000_DuplicateClientName(self): self.sendResponseMessage('CloseConnectionDuplicateClientName') msg = self.assertHasNextEvent( @@ -351,12 +407,16 @@ self.failUnless('Param' in msg.params) self.assertEqual(msg['Param'], None) + self.failUnless(self.socketModule.lastSocket.closed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + self.connectClient() - def testSocketDied_Receive(self): + def test_1001_SocketDied_Receive(self): - self.socket.close() + self.socketModule.lastSocket.close() self.fcpClient.next() # check if ClientDisconnected events has been triggered @@ -369,12 +429,16 @@ self.failUnless('Param' in msg.params) self.assertEqual(msg['Param'].name, consts.Message.ClientSocketDied) + self.failUnless(self.socketModule.lastSocket.closed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + self.connectClient() - def testSocketDied_Send(self): + def test_1002_SocketDied_Send(self): - self.socket.close() + self.socketModule.lastSocket.close() # send a test message self.assertRaises(socket.error, self.fcpClient.sendMessage, 'test' ) @@ -389,10 +453,13 @@ self.failUnless('Param' in msg.params) self.assertEqual(msg['Param'].name, consts.Message.ClientSocketDied) + self.failUnless(self.socketModule.lastSocket.closed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + self.connectClient() - def testShutdown(self): + def test_1003_Shutdown(self): self.fcpClient.closeFreenet() @@ -412,10 +479,14 @@ self.failUnless('Param' in msg.params) self.assertEqual(msg['Param'], None) + self.failUnless(self.socketModule.lastSocket.closed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + self.connectClient() + - def testVersionMismatch(self): + def test_1004_VersionMismatch(self): # cheat a bit and reconnect client enum = self.fcpClient.iterConnect(duration=0.2, timeout=0.1) @@ -427,7 +498,7 @@ #NOTE: have to send directly via socket here (our sendResponseMessage # calls client.next() autkmatically) - self.socket.sendResponseMessage( + self.socketModule.lastSocket.sendResponseMessage( 'NodeHello', FCPVersion='0.0', Node='Fred', @@ -439,6 +510,8 @@ CompressionCodecs='1', ConnectionIdentifier='any', NodeLanguage='en', + + callNext=False ) msg = enum.next() @@ -452,31 +525,42 @@ self.failUnless('Param' in msg.params) self.assertEqual(msg['Param'].name, consts.Message.NodeHello) + self.failUnless(self.socketModule.lastSocket.closed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + self.connectClient() #*********************************************************************************** # #*********************************************************************************** -class TestClientGet(BaseTestConnectedClient): +class TestClientGet(BaseTestClient): - def testClientGetRegistered(self): + def test_2000_ClientGetRegistered(self): # request a arbitrary file myIdentifier = self.fcpClient.getData( 'arbitrary-uri', ) - self.assertHasNextMessage( - consts.Message.ClientGet, - ) + myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + + self.assertHasNextMessage(consts.Message.ClientGet) self.assertHasNextEvent(None) - self.failUnless(self.fcpClient.getRequests() ) + self.failUnless(myIdentifier in requestsAll) myRequest = self.fcpClient.getRequest(myIdentifier) self.assertEqual(myIdentifier, myRequest['Identifier']) self.assertEqual(myRequest['FcRequestStatus'], consts.RequestStatus.Null) + self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + del requestsAll[myIdentifier] + self.failIf(requestsAll) + + - def testGetData_Success(self): + def test_2001_GetData_Success(self): # request a arbitrary file myIdentifier = self.fcpClient.getData( @@ -485,6 +569,8 @@ myRequest = self.fcpClient.getRequest(myIdentifier) requestsAll = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.ClientGet) + # respond to the file request self.sendResponseMessage( 'PersistentGet', @@ -567,18 +653,25 @@ ) self.failUnless(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + del requestsAll[myIdentifier] + self.failIf(requestsAll) - def testGetData_Failure(self): + + def test_2002_GetData_Failure(self): # request a arbitrary file myIdentifier = self.fcpClient.getData( 'arbitrary-uri', ) myRequest = self.fcpClient.getRequest(myIdentifier) - requestsAll = self.fcpClient.getRequests() + requestsAll = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.ClientGet) + # respond to the file request self.sendResponseMessage( 'PersistentGet', @@ -605,6 +698,7 @@ ) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) #return @@ -633,9 +727,13 @@ self.failUnless(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + del requestsAll[myIdentifier] + self.failIf(requestsAll) - def testGetFile_Success(self): + def test_2003_GetFile_Success(self): # request a arbitrary file myIdentifier = self.fcpClient.getFile( @@ -676,9 +774,12 @@ self.failIf(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + self.failIf(requestsAll) - def testGetFile_Failure(self): + def test_2004_GetFile_Failure(self): # request a arbitrary file myIdentifier = self.fcpClient.getFile( @@ -715,9 +816,12 @@ self.failIf(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + self.failIf(requestsAll) + - def testGetKeyInfo_Success(self): + def test_2005_GetKeyInfo_Success(self): # request a arbitrary uri myIdentifier = self.fcpClient.getKeyInfo( @@ -757,9 +861,12 @@ self.failIf(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + self.failIf(requestsAll) - def testGetKeyInfo_TooBig(self): + + def test_2006_GetKeyInfo_TooBig(self): # test specdial case where ProtocolError.TooBig is handled as success # request a arbitrary uri @@ -795,16 +902,21 @@ ) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + self.failIf(requestsAll) + - def testGetKeyInfo_Failure(self): + def test_2007_GetKeyInfo_Failure(self): # request a arbitrary file myIdentifier = self.fcpClient.getKeyInfo( 'arbitrary-uri', ) myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.ClientGet) # respond to the file request @@ -831,6 +943,9 @@ ) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + self.failIf(requestsAll) #*********************************************************************************** # @@ -840,9 +955,9 @@ #*********************************************************************************** # #*********************************************************************************** -class TestRequests(BaseTestConnectedClient): +class TestRequests(BaseTestClient): - def testModifyRequest_Persistent(self): + def test_3000_ModifyRequest_Persistent(self): # request a arbitrary file myIdentifier = self.fcpClient.getFile( @@ -853,6 +968,8 @@ persistence=consts.Persistence.Reboot, ) myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.ClientGet) # respond to the file request @@ -861,7 +978,9 @@ Started='false', **myRequest.params ) - + #self.assertNextMessage(consts.Message.ClientGet) + + # test modify persistent user data self.fcpClient.modifyRequest(myIdentifier, persistentUserData='bar', priorityClass=consts.Priority.High) msg = self.assertHasNextMessage(consts.Message.ModifyPersistentRequest) @@ -879,9 +998,13 @@ self.assertEqual(consts.Priority.High, myRequest['PriorityClass']) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + del requestsAll[myIdentifier] + self.failIf(requestsAll) - def testModifyRequest_NonPersistent(self): + def test_3001_ModifyRequest_NonPersistent(self): # request a arbitrary file myIdentifier = self.fcpClient.getFile( @@ -891,6 +1014,8 @@ priorityClass=consts.Priority.Medium, ) myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.ClientGet) # respond to the file request @@ -912,6 +1037,7 @@ # 'PersistentRequestModified', # **msg.params # ) + self.assertHasNextEvent(self.fcpClient.events.RequestModified) self.failUnless(consts.RequestModified.PersistentUserData in myRequest['FcModified']) @@ -920,9 +1046,13 @@ #self.assertEqual(consts.Priority.High, myRequest['PriorityClass']) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + del requestsAll[myIdentifier] + self.failIf(requestsAll) - def testRemoveRequest_NonPersistent(self): + def test_3002_RemoveRequest_NonPersistent(self): # request a file myIdentifier = self.fcpClient.getFile( @@ -930,7 +1060,9 @@ 'arbitrary.txt' ) myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.ClientGet) # respond to the file request self.sendResponseMessage( 'PersistentGet', @@ -962,9 +1094,12 @@ ) self.failIf(self.fcpClient.getRequests()) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + self.failIf(requestsAll) - def testRemoveRequest_persistent(self): + def test_3003_RemoveRequest_persistent(self): # request a file myIdentifier = self.fcpClient.getFile( @@ -973,7 +1108,10 @@ persistence=consts.Persistence.Reboot, ) myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.ClientGet) + # respond to the file request self.sendResponseMessage( 'PersistentGet', @@ -1015,10 +1153,13 @@ self.failIf(self.fcpClient.getRequests()) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + self.failIf(requestsAll) - def testResendRequest_NonPersistent(self): + def test_3004_ResendRequest_NonPersistent(self): myIdentifier = self.fcpClient.getData('any-key') myRequest = self.fcpClient.getRequest(myIdentifier) @@ -1041,8 +1182,14 @@ self.assertHasNextMessage(consts.Message.ClientGet) + self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + del requestsAll[newIdentifier] + self.failIf(requestsAll) + - def testResendRequest_Persistent(self): + def test_3005_ResendRequest_Persistent(self): myIdentifier = self.fcpClient.getData('any-key', persistence=consts.Persistence.Reboot) myRequest = self.fcpClient.getRequest(myIdentifier) @@ -1077,14 +1224,17 @@ self.failUnless(newIdentifier in requestsAll) self.failIf(myIdentifier in requestsAll) + del requestsAll[newIdentifier] + self.failIf(requestsAll) + #*********************************************************************************** # #*********************************************************************************** #TODO: testRestoreClientPut and friends -class TestRestoreRequests(BaseTestConnectedClient): +class TestRestoreRequests(BaseTestClient): - def testRestorePersistentGet_InvalidIdentifier(self): + def test_4000_RestorePersistentGet_InvalidIdentifier(self): # throw an invalid PersistentRequest at the client myIdentifier = 'true-invalid-request-identifier' @@ -1110,9 +1260,10 @@ # the client should not trigger any events self.assertHasNextEvent(None) + self.assertHasNextMessage(None) - def testRestorePersistentGet_ValidIdentifier(self): + def test_4001_RestorePersistentGet_ValidIdentifier(self): # we need a valid identifier to restore a request, so hack a bit myIdentifier = self.fcpClient.getFile( @@ -1122,6 +1273,8 @@ myRequest = self.fcpClient.getRequest(myIdentifier) requestsAll = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.ClientGet) + self.fcpClient.removeRequest(myIdentifier) self.sendResponseMessage( 'PersistentRequestRemoved', @@ -1152,6 +1305,10 @@ self.failUnless(myIdentifier in requestsAll) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + del requestsAll[myIdentifier] + self.failIf(requestsAll) #*********************************************************************************** # @@ -1160,15 +1317,17 @@ #TODO: testDDAWriteDenied #TODO: testDDAWriteDenied_WriteDisallowed -class TestDDA(BaseTestConnectedClient): +class TestDDA(BaseTestClient): - def testDDAWriteDenied(self): + def test_5000_DDAWriteDenied(self): # request a file myIdentifier = self.fcpClient.getFile( 'arbitrary-uri', os.path.join(DIR, 'DDATest.txt') ) + myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() # client schould send a ClientGet self.assertHasNextMessage(consts.Message.ClientGet) @@ -1243,6 +1402,12 @@ requests = self.fcpClient.getRequests() self.assertEqual(len(requests), 1) + + self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + del requestsAll[myIdentifier] + self.failIf(requestsAll) #def testDDAReadDenied(self): @@ -1252,15 +1417,17 @@ #*********************************************************************************** # #*********************************************************************************** -class TestCollisions(BaseTestConnectedClient): +class TestCollisions(BaseTestClient): - def testIdentifierCollision(self): + def test_6000_IdentifierCollision(self): # request a file myIdentifier = self.fcpClient.getFile( 'arbitrary-uri', os.path.join(DIR, 'test.txt') ) + myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() # client schould send a ClientGet self.assertHasNextMessage(consts.Message.ClientGet) @@ -1275,10 +1442,6 @@ # client schould send a new ClientGet self.assertHasNextMessage(consts.Message.ClientGet) - # check client state - requests = self.fcpClient.getRequests() - self.assertEqual(len(requests), 1) - # check if RequestModified event has been triggered msg = self.assertHasNextEvent( self.fcpClient.events.RequestModified, @@ -1286,13 +1449,19 @@ ) self.failUnless(consts.RequestModified.Identifier in msg['FcModified']) - self.assertEqual(msg['FcModified'][consts.RequestModified.Identifier], myIdentifier) - self.assertNotEqual(msg['Identifier'], myIdentifier) + oldIdentifier = msg['FcModified'][consts.RequestModified.Identifier] + newIdentifier = msg['Identifier'] + self.assertEqual(oldIdentifier, myIdentifier) + self.assertNotEqual(newIdentifier, myIdentifier) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + del requestsAll[newIdentifier] + self.failIf(requestsAll) - def testFilenameCollision_HandleRename(self): + def test_6001_FilenameCollision_HandleRename(self): # request a file fpath = os.path.join(DIR, 'test.txt') @@ -1304,14 +1473,12 @@ fpath, filenameCollision=consts.FilenameCollision.HandleRename, ) + myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() # client schould send a ClientGet self.assertHasNextMessage(consts.Message.ClientGet) - # check if our request was registered - requests = self.fcpClient.getRequests() - self.failUnless(len(requests) == 1) - # now respond with a ProtocolError self.sendResponseMessage( 'ProtocolError', @@ -1322,7 +1489,8 @@ Global='false', ) - # client schould send a new ClientGet with a differing filename + # client schould send a new ClientGet with a different filename + self.assertHasNextMessage(consts.Message.ClientGet) msg = self.assertHasNextEvent( self.fcpClient.events.RequestModified, consts.Message.ClientGet @@ -1341,9 +1509,13 @@ self.failUnless(filenameCollision & consts.FilenameCollision.CollisionHandled) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + del requestsAll[myIdentifier] + self.failIf(requestsAll) + - def testFilenameCollision_HandleNever(self): + def test_6002_FilenameCollision_HandleNever(self): # request a file fpath = os.path.join(DIR, 'test.txt') @@ -1356,6 +1528,7 @@ filenameCollision=consts.FilenameCollision.HandleNever, ) myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() # client schould send a ClientGet self.assertHasNextMessage(consts.Message.ClientGet) @@ -1381,7 +1554,10 @@ self.failIf(self.fcpClient.getRequests()) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + self.failIf(requestsAll) + #*********************************************************************************** # #*********************************************************************************** @@ -1390,10 +1566,10 @@ #*********************************************************************************** # #*********************************************************************************** -class TestPlugins(BaseTestConnectedClient): +class TestPlugins(BaseTestClient): - def testGetPluginInfo_Success(self): + def testGet_8000_PluginInfo_Success(self): myIdentifier = self.fcpClient.getPluginInfo('hi there') myRequest = self.fcpClient.getRequest(myIdentifier) @@ -1422,12 +1598,17 @@ ), ) + self.failIf(myIdentifier in requestsAll) + self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + self.assertHasNextEvent(None) - self.failIf(myIdentifier in requestsAll) - self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + self.assertHasNextMessage(None) + + self.failIf(requestsAll) + - def testGetPluginInfo_Failure(self): + def test_8001_GetPluginInfo_Failure(self): myIdentifier = self.fcpClient.getPluginInfo('hi there') myRequest = self.fcpClient.getRequest(myIdentifier) requestsAll = self.fcpClient.getRequests() @@ -1455,12 +1636,16 @@ ), ) + self.failIf(myIdentifier in requestsAll) + self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + self.assertHasNextEvent(None) - self.failIf(myIdentifier in requestsAll) - self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + self.assertHasNextMessage(None) + + self.failIf(requestsAll) - def testSendPluginMessage_Success(self): + def test_8002_SendPluginMessage_Success(self): myIdentifier = self.fcpClient.sendPluginMessage('hi there', {'foo': "bar"}) myRequest = self.fcpClient.getRequest(myIdentifier) @@ -1493,12 +1678,16 @@ reply = msg['FcPluginReply'] self.failUnless(reply.params.get('baz', None) == '12345') - self.assertHasNextEvent(None) self.failIf(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + + self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + + self.failIf(requestsAll) - def testGetSendPluginMessage_Failure(self): + def test_8003_GetSendPluginMessage_Failure(self): myIdentifier = self.fcpClient.sendPluginMessage('hi there', {'foo': "bar"}) myRequest = self.fcpClient.getRequest(myIdentifier) requestsAll = self.fcpClient.getRequests() @@ -1527,9 +1716,12 @@ ), ) - self.assertHasNextEvent(None) self.failIf(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + + self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + self.failIf(requestsAll) #*********************************************************************************** @@ -1538,13 +1730,14 @@ #*********************************************************************************** # #*********************************************************************************** -class TestGenerateKeypair(BaseTestConnectedClient): +class TestGenerateKeypair(BaseTestClient): - def testGeberateSSKKeypair(self): + def test_10000_GeberateSSKKeypair(self): myIdentifier = self.fcpClient.generateKeypair(consts.KeyType.SSK) myRequest = self.fcpClient.getRequest(myIdentifier) requestsAll = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.GenerateSSK) self.sendResponseMessage( 'SSKKeypair', Identifier=myIdentifier, @@ -1562,16 +1755,20 @@ consts.RequestStatus.RemovedFromQueue ), ) - self.assertHasNextEvent(None) self.failIf(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + self.failIf(requestsAll) - def testGeberateUSKKeypair(self): + + def test_10001_GeberateUSKKeypair(self): myIdentifier = self.fcpClient.generateKeypair(consts.KeyType.USK) myRequest = self.fcpClient.getRequest(myIdentifier) requestsAll = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.GenerateSSK) self.sendResponseMessage( 'SSKKeypair', Identifier=myIdentifier, @@ -1589,18 +1786,21 @@ consts.RequestStatus.RemovedFromQueue ), ) - self.assertHasNextEvent(None) self.failIf(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + + self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + self.failIf(requestsAll) #*********************************************************************************** # #*********************************************************************************** -class TestSubscribeUSK(BaseTestConnectedClient): +class TestSubscribeUSK(BaseTestClient): - def testSubscribe(self): + def test_11000_Subscribe(self): myIdentifier = self.fcpClient.subscribeUSK('arbitrary') myRequest = self.fcpClient.getRequest(myIdentifier) @@ -1609,6 +1809,7 @@ self.failUnless(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + self.assertHasNextMessage(consts.Message.SubscribeUSK) self.sendResponseMessage( 'SubscribedUSKUpdate', Identifier=myIdentifier, @@ -1624,15 +1825,19 @@ ('URI', 'arbitryry/99/'), ) self.assertHasNextEvent(None) + self.assertHasNextMessage(None) + del requestsAll[myIdentifier] + self.failIf(requestsAll) + #********************************************************************************* # #********************************************************************************* def suite(): - - tests = ( + + testCases = ( TestConnect, TestDisconnectReason, TestClientGet, @@ -1647,8 +1852,8 @@ ) suite = unittest.TestSuite() - for test in tests: - suite.addTest(unittest.makeSuite(test)) + for testCase in testCases: + suite.addTest(unittest.makeSuite(testCase)) return suite def test(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-11 10:54:29
|
Revision: 203 http://fclient.svn.sourceforge.net/fclient/?rev=203&view=rev Author: jurner Date: 2008-02-11 02:54:36 -0800 (Mon, 11 Feb 2008) Log Message: ----------- ... Modified Paths: -------------- trunk/sandbox/fcp/test_fcp/dummy_socket.py Modified: trunk/sandbox/fcp/test_fcp/dummy_socket.py =================================================================== --- trunk/sandbox/fcp/test_fcp/dummy_socket.py 2008-02-11 10:53:36 UTC (rev 202) +++ trunk/sandbox/fcp/test_fcp/dummy_socket.py 2008-02-11 10:54:36 UTC (rev 203) @@ -17,8 +17,6 @@ self.bytes = '' self.responseBytes = '' - - def setBytes(self, bytes): self.bytes = bytes @@ -39,8 +37,7 @@ assert params['DataLength'] == len(data) self.responseBytes += data - - + def setBytesReceiver(self, cb): self.bytesReceiver = cb @@ -87,4 +84,6 @@ self.timeout = n - \ No newline at end of file + + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-11 10:53:34
|
Revision: 202 http://fclient.svn.sourceforge.net/fclient/?rev=202&view=rev Author: jurner Date: 2008-02-11 02:53:36 -0800 (Mon, 11 Feb 2008) Log Message: ----------- fixed message names Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_consts.py Modified: trunk/sandbox/fcp/fcp2_0_consts.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-11 10:52:59 UTC (rev 201) +++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-11 10:53:36 UTC (rev 202) @@ -228,6 +228,9 @@ KeyboardInterrupt = 'keyboard interrupt' # kick out SocketDied = 'socket died' AllRequestsCompleted = 'All requests completed' + + EventTriggered = 'Event Triggered: ' + class Message: @@ -300,9 +303,9 @@ URIGenerated = 'URIGenerated' # client s (internal use only) - ClientSocketTimeout = 1 - ClientSocketDied = 2 - ClientDisconnected = 3 + ClientSocketTimeout = 'FcSocketTimeout' + ClientSocketDied = 'FcSocketDied' + ClientDisconnected = 'FcClientDisconnected' class RequestStatus(BaseBitFlags): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-11 10:52:58
|
Revision: 201 http://fclient.svn.sourceforge.net/fclient/?rev=201&view=rev Author: jurner Date: 2008-02-11 02:52:59 -0800 (Mon, 11 Feb 2008) Log Message: ----------- added basic event logging + a client gets closed on duplicate connection name Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_client.py Modified: trunk/sandbox/fcp/fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_client.py 2008-02-11 10:51:58 UTC (rev 200) +++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-11 10:52:59 UTC (rev 201) @@ -140,6 +140,26 @@ #FIX: workaround for the "related" part #------------------------------------------------------------------------------------------------------------------------------------------------ + +# Todos +#------------------------------------------------------------------------------------------------------------------------------------------------ +# logging +# +# logging is not very accurate. What to log at wich level? What details? +# +#------------------------------------------------------------------------------------------------------------------------------------------------ +# clean up +# +# x. move saveWriteFile and friends to a separate module +# +#------------------------------------------------------------------------------------------------------------------------------------------------ +# Fcp types vs. Python types +# +# x. Fcp seems to use kibibytes. Autoconvert to kilobytes? +# +#------------------------------------------------------------------------------------------------------------------------------------------------ + + import atexit import copy import cPickle @@ -252,7 +272,7 @@ # 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 = '32000' + MaxSizeKeyInfo = 32768 #TODO: 32k SocketTimeout = 0.1 ExpectedFcpVersion = 2.0 ExpectedNodeBuild = 1107 @@ -284,6 +304,8 @@ self._socket = None self.events = Events() + for event in self.events: + event += self._logEvent self.setDebugVerbosity(consts.DebugVerbosity.Warning if debugVerbosity is None else debugVerbosity) atexit.register(self.close) @@ -422,6 +444,10 @@ msg['Identifier'] = identifier self._requests[identifier] = msg + + def _logEvent(self, event, request): + self._log.info(consts.LogMessages.EventTriggered + event.name) + ############################################################### ## ## connection related methods @@ -443,6 +469,7 @@ self._ddaTests = [] self._requests = {} + def closeFreenet(self): """Shuts down the freenet node""" @@ -483,7 +510,7 @@ # poll untill freenet responds timeElapsed = 0 - while timeElapsed <= duration: + while timeElapsed < duration: # try to Connect socket if self._socket is not None: @@ -1161,6 +1188,7 @@ ## #################################################### elif msg.name == consts.Message.CloseConnectionDuplicateClientName: + self.close() msg = self.Message( consts.Message.ClientDisconnected, DisconnectReason=consts.DisconnectReason.DuplicateClientName, @@ -1220,7 +1248,6 @@ elif msg.name == consts.Message.ClientSocketTimeout: if dispatch: self.events.Idle(msg) - else: if dispatch: self.handleMessage(msg) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-11 10:51:54
|
Revision: 200 http://fclient.svn.sourceforge.net/fclient/?rev=200&view=rev Author: jurner Date: 2008-02-11 02:51:58 -0800 (Mon, 11 Feb 2008) Log Message: ----------- Sketch for frost boards was broken. Now the spam flood viewer is working again. Modified Paths: -------------- trunk/sandbox/fcp/boards/frost.py Modified: trunk/sandbox/fcp/boards/frost.py =================================================================== --- trunk/sandbox/fcp/boards/frost.py 2008-02-09 18:03:51 UTC (rev 199) +++ trunk/sandbox/fcp/boards/frost.py 2008-02-11 10:51:58 UTC (rev 200) @@ -48,16 +48,18 @@ def __init__(self): - self.fcpClient = FcpClient(debugVerbosity=FcpClient.DebugVerbosity.Debug) - for nodeHello in self.fcpClient.connect(): - pass + self.fcpClient = FcpClient(debugVerbosity=FcpClient.consts.DebugVerbosity.Debug) + nodeHello = self.fcpClient.connect() + if nodeHello is None: + return False + self.fcpClient.events.RequestCompleted += self.handleRequestCompleted def handleRequestCompleted(self, event, request): - self.fcpClient.removeRequest(request['Identifier']) - print request['FcData'] + #self.fcpClient.removeRequest(request['Identifier']) + print request.data @@ -66,7 +68,7 @@ slot = -1 while True: slot += 1 - if slot > 30: break + if slot > 10: break ksk = 'KSK@frost|message|%s|%s-%s-%s.xml' % (section, startDate.toString(), boardName, slot) print ksk @@ -76,12 +78,12 @@ maxSize='33000' ) - for i in xrange(300): + for i in xrange(50): self.fcpClient.next() -if __name__ == '__amain__': +if __name__ == '__main__': board = FrostBoard() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-09 18:03:57
|
Revision: 199 http://fclient.svn.sourceforge.net/fclient/?rev=199&view=rev Author: jurner Date: 2008-02-09 10:03:51 -0800 (Sat, 09 Feb 2008) Log Message: ----------- fix: PriorityClass can not be changed for requests with Persistence=connection. This is not possible Fcp Modified Paths: -------------- trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py Modified: trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-09 18:03:38 UTC (rev 198) +++ trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-09 18:03:51 UTC (rev 199) @@ -842,8 +842,7 @@ #*********************************************************************************** class TestRequests(BaseTestConnectedClient): - - def testModifyRequest(self): + def testModifyRequest_Persistent(self): # request a arbitrary file myIdentifier = self.fcpClient.getFile( @@ -851,6 +850,7 @@ 'arbitryry.txt', persistentUserData='foo', priorityClass=consts.Priority.Medium, + persistence=consts.Persistence.Reboot, ) myRequest = self.fcpClient.getRequest(myIdentifier) self.assertHasNextMessage(consts.Message.ClientGet) @@ -881,6 +881,47 @@ self.assertHasNextEvent(None) + def testModifyRequest_NonPersistent(self): + + # request a arbitrary file + myIdentifier = self.fcpClient.getFile( + 'arbitrary-uri', + 'arbitryry.txt', + persistentUserData='foo', + priorityClass=consts.Priority.Medium, + ) + myRequest = self.fcpClient.getRequest(myIdentifier) + self.assertHasNextMessage(consts.Message.ClientGet) + + # respond to the file request + self.sendResponseMessage( + 'PersistentGet', + Started='false', + **myRequest.params + ) + + # test modify persistent user data + self.fcpClient.modifyRequest(myIdentifier, persistentUserData='bar', priorityClass=consts.Priority.High) + + # no way to modify priority in Fcp. The client ignores all attempts to do so currently + # no message is send,instead the event is triggered emidiately + + #msg = self.assertHasNextMessage(consts.Message.ModifyPersistentRequest) + # respond to the file request + #self.sendResponseMessage( + # 'PersistentRequestModified', + # **msg.params + # ) + self.assertHasNextEvent(self.fcpClient.events.RequestModified) + + self.failUnless(consts.RequestModified.PersistentUserData in myRequest['FcModified']) + #self.failUnless(consts.RequestModified.PriorityClass in myRequest['FcModified']) + self.assertEqual('bar', myRequest['FcPersistentUserData']) + #self.assertEqual(consts.Priority.High, myRequest['PriorityClass']) + + self.assertHasNextEvent(None) + + def testRemoveRequest_NonPersistent(self): # request a file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-09 18:03:38
|
Revision: 198 http://fclient.svn.sourceforge.net/fclient/?rev=198&view=rev Author: jurner Date: 2008-02-09 10:03:38 -0800 (Sat, 09 Feb 2008) Log Message: ----------- fix: PriorityClass can not be changed for requests with Persistence=connection. This is not possible Fcp Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_client.py Modified: trunk/sandbox/fcp/fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_client.py 2008-02-09 09:36:15 UTC (rev 197) +++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-09 18:03:38 UTC (rev 198) @@ -132,7 +132,14 @@ #FIX: we handle collisions in the client as savely as possible. But no guarantee either when a colliding file # (...) finds his way into the download directory while downloading another. #------------------------------------------------------------------------------------------------------------------------------------------------ - +# [0002083: RemovePersistentRequest ignores unknown requests] +# +# minor one, but related to it a major one: you can not change the Priority of requests with +# Persistence=conncetion +# +#FIX: workaround for the "related" part +#------------------------------------------------------------------------------------------------------------------------------------------------ + import atexit import copy import cPickle @@ -1855,11 +1862,33 @@ @note: you can use this method to modify get / put related requests All attempts to modify other requests will fail @note: a RequestModified event is triggered as soon as the request has actually been modified + @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 simply not implemented in the client protocol. + """ initialRequest = self._requests[requestIdentifier] if not initialRequest['FcRequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): raise ValueError('Can not modify request: %s' % initialRequest.name) + #FIX: [0002083] + # 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') + + if persistentUserData is not None: + initialRequest['FcPersistentUserData'] = persistentUserData + initialRequest['ClientToken'] = self.FcParams.messageToParams(initialRequest) + modified[consts.RequestModified.PersistentUserData] = None + + initialRequest['FcModified'] = modified + self.events.RequestModified(initialRequest) + return + + msg = self.Message( consts.Message.ModifyPersistentRequest, Identifier=initialRequest['Identifier'], @@ -2158,18 +2187,31 @@ #testGetData() def testGetFile(): + + def cb(event, request): + c.sendMessage( + #c.consts.Message.RemovePersistentRequest, + c.consts.Message.ModifyPersistentRequest, + Identifier=request['Identifier'], + PriorityClass=0, + Global=False, + ) + pass + filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.jpg') print filename identifier = c.getFile( 'CHK@q4~2soHTd9SOINIoXmg~dn7LNUAOYzN1tHNHT3j4c9E,gcVRtoglEhgqN-DJolXPqJ4yX1f~1gBGh89HNWlFMWQ,AAIC--8/snow_002%20%2810%29.jpg', filename, filenameCollision=consts.FilenameCollision.HandleRename, - #persistence=consts.Persistence.Forever, + #persistence=consts.Persistence.Reboot, ) - c.run() - #for i in xrange(50): - # c.next() + c.events.RequestProgress += cb + + #c.run() + for i in xrange(50): + c.next() #c.removeRequest(identifier) #for i in xrange(5): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-09 09:36:13
|
Revision: 197 http://fclient.svn.sourceforge.net/fclient/?rev=197&view=rev Author: jurner Date: 2008-02-09 01:36:15 -0800 (Sat, 09 Feb 2008) Log Message: ----------- some fixes and a debug helper for bitflags Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_consts.py Modified: trunk/sandbox/fcp/fcp2_0_consts.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-09 09:35:22 UTC (rev 196) +++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-09 09:36:15 UTC (rev 197) @@ -6,6 +6,31 @@ #************************************************************************ # #************************************************************************ +class BaseBitFlags(object): + """Base class for classes containing bitflags (bitflags only that is)""" + + @classmethod + def humanReadable(clss, flags): + """Returns a list containing human readable names of bitflags as + defined in the class + @param flags: bit flags to translate into human readables + @return: (list) + + @note: use this for debugging for example + """ + out = [] + for name in dir(clss): + if name[0].isupper(): + const = getattr(clss, name) + if isinstance(const, (int, long)): + if flags & const: + out.append(name) + return out + +#************************************************************************ +# +#************************************************************************ + FcpTrue = 'true' FcpFalse = 'false' @@ -146,7 +171,7 @@ Warning = logging.WARNING -class DisconnectReason: +class DisconnectReason(BaseBitFlags): """Reasons for client disconnect @cvar ConnectingFailed: connection could not be established @cvar DuplicateClientName: another client opend a connection with the same connection name @@ -154,14 +179,14 @@ @cvar SocketDied: connection to the node died unexpectingly @cvar VersionMissmatch: node or Fcp version did not match """ - ConnectingFailed = 1 - DuplicateClientName = 2 - Shutdown = 3 - SocketDied = 4 - VersionMissmatch = 5 #TODO: implement??? + ConnectingFailed = 0x1 + DuplicateClientName = 0x2 + Shutdown = 0x4 + SocketDied = 0x8 + VersionMissmatch = 0x10 #TODO: implement??? -class FilenameCollision: +class FilenameCollision(BaseBitFlags): """Filename collision flags @cvar HandleNever: don't handle filename collisions @cvar HandleRename: rename file on collisions @@ -215,7 +240,7 @@ ClientPut = 'ClientPut' ClientPutDiskDir = 'ClientPutDiskDir' ClientPutComplexDir = 'ClientPutComplexDir' - FCPPlugin = 'FCPPlugin' + FCPPluginMessage = 'FCPPluginMessage' GenerateSSK = 'GenerateSSK' GetConfig = 'GetConfig' # (since 1027) GetNode = 'GetNode' @@ -279,19 +304,8 @@ ClientSocketDied = 2 ClientDisconnected = 3 - ClientKeyRequestMessages = ( - ClientGet, - ClientPut, - ClientPutDiskDir, - ClientPutComplexDir, - ) - ClientPluginMessages = ( - GetPluginInfo, - FCPPlugin, - ) - -class RequestStatus: +class RequestStatus(BaseBitFlags): """Request status flags @cvar Null: no status @cvar Restored: the request was restored when the client was started @@ -318,9 +332,9 @@ Completed =0x10000000 RemovedFromQueue = 0x2000000 - - -class RequestType: + + +class RequestType(BaseBitFlags): """Consts indicating the type of a request""" Null = 0 @@ -383,7 +397,7 @@ Low = '4' -class RequestModified: +class RequestModified(BaseBitFlags): """Flags indicating what of a request has been modified @cvar Filename: the filename has been modified @cvar Identifier: the identifier has been moodified @@ -412,7 +426,7 @@ Redirect = 'redirect' -class Verbosity: +class Verbosity(BaseBitFlags): ReportCompletion = 0x0 ReportProgress = 0x1 ReportCompression = 0x200 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-09 09:35:18
|
Revision: 196 http://fclient.svn.sourceforge.net/fclient/?rev=196&view=rev Author: jurner Date: 2008-02-09 01:35:22 -0800 (Sat, 09 Feb 2008) Log Message: ----------- added request removed event Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_events.py Modified: trunk/sandbox/fcp/fcp2_0_events.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_events.py 2008-02-09 09:34:57 UTC (rev 195) +++ trunk/sandbox/fcp/fcp2_0_events.py 2008-02-09 09:35:22 UTC (rev 196) @@ -92,6 +92,9 @@ class RequestProgress(events.Event): """A request has made some progress""" + class RequestRemoved(events.Event): + """A request has been removed""" + class RequestRestored(events.Event): """A request has been restored""" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-09 09:34:51
|
Revision: 195 http://fclient.svn.sourceforge.net/fclient/?rev=195&view=rev Author: jurner Date: 2008-02-09 01:34:57 -0800 (Sat, 09 Feb 2008) Log Message: ----------- added plugin message test cases Modified Paths: -------------- trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py Modified: trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-09 09:34:37 UTC (rev 194) +++ trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-09 09:34:57 UTC (rev 195) @@ -483,7 +483,7 @@ 'arbitrary-uri', ) myRequest = self.fcpClient.getRequest(myIdentifier) - allRequests = self.fcpClient.getRequests() + requestsAll = self.fcpClient.getRequests() # respond to the file request self.sendResponseMessage( @@ -534,18 +534,17 @@ self.assertHasNextEvent( self.fcpClient.events.RequestCompleted, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Null | - consts.RequestStatus.Success | - consts.RequestStatus.RemovedFromQueue - ), + ('FcRequestStatus', consts.RequestStatus.Success | + consts.RequestStatus.RemovedFromQueue + ), data=data ) - self.failIf(myIdentifier in allRequests) + self.failIf(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) # cheat a bit to test peristence == Forever (client should not remove request) - allRequests[myIdentifier] =myRequest + requestsAll[myIdentifier] =myRequest myRequest['Persistence'] = consts.Persistence.Forever myRequest['FcRequestStatus'] &= ~(consts.RequestStatus.Success | consts.RequestStatus.Completed | @@ -563,11 +562,10 @@ self.assertHasNextEvent( self.fcpClient.events.RequestCompleted, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Null | - consts.RequestStatus.Success), + ('FcRequestStatus', consts.RequestStatus.Success), data=data ) - self.failUnless(myIdentifier in allRequests) + self.failUnless(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) @@ -579,7 +577,7 @@ 'arbitrary-uri', ) myRequest = self.fcpClient.getRequest(myIdentifier) - allRequests = self.fcpClient.getRequests() + requestsAll = self.fcpClient.getRequests() # respond to the file request self.sendResponseMessage( @@ -601,10 +599,9 @@ self.assertHasNextEvent( self.fcpClient.events.RequestFailed, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Null | - consts.RequestStatus.Error | - consts.RequestStatus.RemovedFromQueue - ) + ('FcRequestStatus', consts.RequestStatus.Error | + consts.RequestStatus.RemovedFromQueue + ), ) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) @@ -613,7 +610,7 @@ # cheat a bit to test peristence == Forever (client should not remove request) - allRequests[myIdentifier] =myRequest + requestsAll[myIdentifier] =myRequest myRequest['Persistence'] = consts.Persistence.Forever myRequest['FcRequestStatus'] &= ~(consts.RequestStatus.Error | consts.RequestStatus.Completed | @@ -631,11 +628,9 @@ self.assertHasNextEvent( self.fcpClient.events.RequestFailed, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Null | - consts.RequestStatus.Error - ), + ('FcRequestStatus', consts.RequestStatus.Error), ) - self.failUnless(myIdentifier in allRequests) + self.failUnless(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) @@ -648,7 +643,7 @@ 'arbitryry.txt' ) myRequest = self.fcpClient.getRequest(myIdentifier) - allRequests = self.fcpClient.getRequests() + requestsAll = self.fcpClient.getRequests() self.assertHasNextMessage(consts.Message.ClientGet) @@ -674,12 +669,11 @@ self.assertHasNextEvent( self.fcpClient.events.RequestCompleted, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Null | - consts.RequestStatus.Success | - consts.RequestStatus.RemovedFromQueue - ) + ('FcRequestStatus', consts.RequestStatus.Success | + consts.RequestStatus.RemovedFromQueue + ), ) - self.failIf(myIdentifier in allRequests) + self.failIf(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) @@ -692,7 +686,7 @@ 'arbitryry.txt' ) myRequest = self.fcpClient.getRequest(myIdentifier) - allRequests = self.fcpClient.getRequests() + requestsAll = self.fcpClient.getRequests() self.assertHasNextMessage(consts.Message.ClientGet) @@ -714,12 +708,11 @@ self.assertHasNextEvent( self.fcpClient.events.RequestFailed, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Null | - consts.RequestStatus.Error | - consts.RequestStatus.RemovedFromQueue - ) + ('FcRequestStatus', consts.RequestStatus.Error | + consts.RequestStatus.RemovedFromQueue + ), ) - self.failIf(myIdentifier in allRequests) + self.failIf(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) @@ -731,7 +724,7 @@ 'arbitrary-uri', ) myRequest = self.fcpClient.getRequest(myIdentifier) - allRequests = self.fcpClient.getRequests() + requestsAll = self.fcpClient.getRequests() self.assertHasNextMessage(consts.Message.ClientGet) @@ -757,12 +750,11 @@ self.assertHasNextEvent( self.fcpClient.events.RequestCompleted, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Null | - consts.RequestStatus.Success | - consts.RequestStatus.RemovedFromQueue - ) + ('FcRequestStatus', consts.RequestStatus.Success | + consts.RequestStatus.RemovedFromQueue + ), ) - self.failIf(myIdentifier in allRequests) + self.failIf(myIdentifier in requestsAll) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) @@ -775,7 +767,7 @@ 'arbitrary-uri', ) myRequest = self.fcpClient.getRequest(myIdentifier) - allRequests = self.fcpClient.getRequests() + requestsAll = self.fcpClient.getRequests() self.assertHasNextMessage(consts.Message.ClientGet) @@ -797,10 +789,9 @@ self.assertHasNextEvent( self.fcpClient.events.RequestCompleted, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Null | - consts.RequestStatus.Success | - consts.RequestStatus.RemovedFromQueue - ) + ('FcRequestStatus', consts.RequestStatus.Success | + consts.RequestStatus.RemovedFromQueue + ), ) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) @@ -834,10 +825,9 @@ self.assertHasNextEvent( self.fcpClient.events.RequestFailed, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Null | - consts.RequestStatus.Error | - consts.RequestStatus.RemovedFromQueue - ) + ('FcRequestStatus', consts.RequestStatus.Error | + consts.RequestStatus.RemovedFromQueue + ), ) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) self.assertHasNextEvent(None) @@ -850,10 +840,6 @@ #*********************************************************************************** # #*********************************************************************************** -#TODO: testGetRequest() -#TODO: testGetRequest() -#TODO: testResendRequest() - class TestRequests(BaseTestConnectedClient): @@ -919,14 +905,20 @@ self.fcpClient.removeRequest(myIdentifier) # of our request should be removed emidiately, - self.assertEqual(myRequest['FcRequestStatus'], consts.RequestStatus.Null | - consts.RequestStatus.Removed | + self.assertEqual(myRequest['FcRequestStatus'], consts.RequestStatus.Removed | consts.RequestStatus.Completed | consts.RequestStatus.RemovedFromQueue ) self.failIf(myIdentifier in self.fcpClient.getRequests()) # now the request should have been removed + self.assertHasNextEvent( + self.fcpClient.events.RequestRemoved, + consts.Message.ClientGet, + ('FcRequestStatus', consts.RequestStatus.Removed | + consts.RequestStatus.RemovedFromQueue + ), + ) self.failIf(self.fcpClient.getRequests()) self.assertHasNextEvent(None) @@ -957,9 +949,7 @@ # status of our request should be set to removed emidiately, but it should # not be removed from the client - self.assertEqual(myRequest['FcRequestStatus'], consts.RequestStatus.Null | - consts.RequestStatus.Removed - ) + self.assertEqual(myRequest['FcRequestStatus'], consts.RequestStatus.Removed) self.failUnless(myIdentifier in self.fcpClient.getRequests()) # client schould send a RemovePersistentRequest @@ -974,6 +964,14 @@ # now the request should have been removed self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.RemovedFromQueue) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + self.assertHasNextEvent( + self.fcpClient.events.RequestRemoved, + consts.Message.ClientGet, + ('FcRequestStatus', consts.RequestStatus.Removed | + consts.RequestStatus.RemovedFromQueue + ), + ) + self.failIf(self.fcpClient.getRequests()) self.assertHasNextEvent(None) @@ -983,30 +981,36 @@ myIdentifier = self.fcpClient.getData('any-key') myRequest = self.fcpClient.getRequest(myIdentifier) - allRequests = self.fcpClient.getRequests() + requestsAll = self.fcpClient.getRequests() self.assertHasNextMessage(consts.Message.ClientGet) newIdentifier = self.fcpClient.resendRequest(myRequest) # client should remove old request emidiately self.failIf(myIdentifier == newIdentifier) - self.failIf(myIdentifier in allRequests) - self.failUnless(newIdentifier in allRequests) - + self.failIf(myIdentifier in requestsAll) + self.failUnless(newIdentifier in requestsAll) + self.assertHasNextEvent( + self.fcpClient.events.RequestRemoved, + consts.Message.ClientGet, + ('FcRequestStatus', consts.RequestStatus.Removed | + consts.RequestStatus.RemovedFromQueue + ), + ) + self.assertHasNextMessage(consts.Message.ClientGet) - - + def testResendRequest_Persistent(self): myIdentifier = self.fcpClient.getData('any-key', persistence=consts.Persistence.Reboot) myRequest = self.fcpClient.getRequest(myIdentifier) - allRequests = self.fcpClient.getRequests() + requestsAll = self.fcpClient.getRequests() self.assertHasNextMessage(consts.Message.ClientGet) newIdentifier = self.fcpClient.resendRequest(myRequest) self.failIf(myIdentifier == newIdentifier) - self.failUnless(newIdentifier in allRequests) + self.failUnless(newIdentifier in requestsAll) # client should remove request from nodes queue self.assertHasNextMessage( @@ -1021,14 +1025,17 @@ 'PersistentRequestRemoved', Identifier=myIdentifier, ) + self.assertHasNextEvent( + self.fcpClient.events.RequestRemoved, + consts.Message.ClientGet, + ('FcRequestStatus', consts.RequestStatus.Removed | + consts.RequestStatus.RemovedFromQueue + ), + ) - self.failUnless(newIdentifier in allRequests) - self.failIf(myIdentifier in allRequests) + self.failUnless(newIdentifier in requestsAll) + self.failIf(myIdentifier in requestsAll) - - - - #*********************************************************************************** # @@ -1072,7 +1079,7 @@ 'arbitryry.txt' ) myRequest = self.fcpClient.getRequest(myIdentifier) - allRequests = self.fcpClient.getRequests() + requestsAll = self.fcpClient.getRequests() self.fcpClient.removeRequest(myIdentifier) self.sendResponseMessage( @@ -1102,7 +1109,7 @@ ('FcRequestStatus', consts.RequestStatus.Restored), # no RequestStatus.Pending flag should be set here ) - self.failUnless(myIdentifier in allRequests) + self.failUnless(myIdentifier in requestsAll) self.assertHasNextEvent(None) #*********************************************************************************** @@ -1342,15 +1349,154 @@ #*********************************************************************************** # #*********************************************************************************** -#TODO: class TestPlugins(BaseTestConnectedClient): +class TestPlugins(BaseTestConnectedClient): + + + def testGetPluginInfo_Success(self): + + myIdentifier = self.fcpClient.getPluginInfo('hi there') + myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + + self.failUnless(myIdentifier in requestsAll) + self.assertHasNextMessage( + consts.Message.GetPluginInfo, + ('Identifier', myIdentifier), + ('PluginName', 'hi there'), + ) + + self.sendResponseMessage( + consts.Message.PluginInfo, + PluginName='hi there', + Identifier=myIdentifier, + ) + + msg = self.assertHasNextEvent( + self.fcpClient.events.PluginInfo, + consts.Message.GetPluginInfo, + ('Identifier', myIdentifier), + ('PluginName', 'hi there'), + ('FcRequestStatus', consts.RequestStatus.Success | + consts.RequestStatus.RemovedFromQueue + ), + ) + + self.assertHasNextEvent(None) + self.failIf(myIdentifier in requestsAll) + self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + + def testGetPluginInfo_Failure(self): + myIdentifier = self.fcpClient.getPluginInfo('hi there') + myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + + self.failUnless(myIdentifier in requestsAll) + self.assertHasNextMessage( + consts.Message.GetPluginInfo, + ('Identifier', myIdentifier), + ('PluginName', 'hi there'), + ) + + self.sendResponseMessage( + consts.Message.ProtocolError, + Code=32, # No such plugin + Identifier=myIdentifier, + ) + + msg = self.assertHasNextEvent( + self.fcpClient.events.PluginInfoFailed, + consts.Message.GetPluginInfo, + #('PluginName', 'hi there'), + ('Identifier', myIdentifier), + ('FcRequestStatus', consts.RequestStatus.Error | + consts.RequestStatus.RemovedFromQueue + ), + ) + + self.assertHasNextEvent(None) + self.failIf(myIdentifier in requestsAll) + self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + + + def testSendPluginMessage_Success(self): + + myIdentifier = self.fcpClient.sendPluginMessage('hi there', {'foo': "bar"}) + myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + + self.failUnless(myIdentifier in requestsAll) + self.assertHasNextMessage( + consts.Message.FCPPluginMessage, + ('Identifier', myIdentifier), + ('PluginName', 'hi there'), + ('foo', 'bar'), + ) + + self.sendResponseMessage( + consts.Message.FCPPluginReply, + PluginName='hi there', + Identifier=myIdentifier, + baz='12345', + ) + + msg = self.assertHasNextEvent( + self.fcpClient.events.PluginMessage, + consts.Message.FCPPluginMessage, + ('PluginName', 'hi there'), + ('Identifier', myIdentifier), + ('FcRequestStatus', consts.RequestStatus.Success | + consts.RequestStatus.RemovedFromQueue + ), + ) + reply = msg['FcPluginReply'] + self.failUnless(reply.params.get('baz', None) == '12345') + + self.assertHasNextEvent(None) + self.failIf(myIdentifier in requestsAll) + self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + + + def testGetSendPluginMessage_Failure(self): + myIdentifier = self.fcpClient.sendPluginMessage('hi there', {'foo': "bar"}) + myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + + self.failUnless(myIdentifier in requestsAll) + self.assertHasNextMessage( + consts.Message.FCPPluginMessage, + ('Identifier', myIdentifier), + ('PluginName', 'hi there'), + ('foo', 'bar'), + ) + + self.sendResponseMessage( + consts.Message.ProtocolError, + Code=32, # No such plugin + Identifier=myIdentifier, + ) + + msg = self.assertHasNextEvent( + self.fcpClient.events.PluginMessageFailed, + consts.Message.FCPPluginMessage, + #('PluginName', 'hi there'), + ('Identifier', myIdentifier), + ('FcRequestStatus', consts.RequestStatus.Error | + consts.RequestStatus.RemovedFromQueue + ), + ) + + self.assertHasNextEvent(None) + self.failIf(myIdentifier in requestsAll) + self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + + #*********************************************************************************** #TODO: class TestConfig(BaseTestConnectedClient): #*********************************************************************************** # #*********************************************************************************** -#TODO: class TestSSKKeypair(BaseTestConnectedClient): class TestGenerateKeypair(BaseTestConnectedClient): def testGeberateSSKKeypair(self): @@ -1454,6 +1600,7 @@ TestDDA, TestCollisions, + TestPlugins, TestGenerateKeypair, TestSubscribeUSK, ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-09 09:34:35
|
Revision: 194 http://fclient.svn.sourceforge.net/fclient/?rev=194&view=rev Author: jurner Date: 2008-02-09 01:34:37 -0800 (Sat, 09 Feb 2008) Log Message: ----------- refactored removeRequest() and resendRequest() fixed bugs in plugin messages Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_client.py Modified: trunk/sandbox/fcp/fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_client.py 2008-02-08 23:41:20 UTC (rev 193) +++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-09 09:34:37 UTC (rev 194) @@ -8,6 +8,8 @@ @note: The client implementation never uses or watches the global queue. No implementation should ever do so. Global is evil. +@note: the client is not thread save, nor will it ever be. If you need that, create another client +and connect it to the node. Sample code. Connect to the freenet node:: @@ -389,6 +391,18 @@ 'FcPublicKey': 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': {}, + + 'FcPluginReply': None, + }) + + + else: msg.params.update({ 'FcRequestType': requestType, # identifies sub message types @@ -689,7 +703,7 @@ # handle plugin related request failures elif code == consts.ProtocolError.NoSuchPlugin: - if initialRequest.name == consts.Message.PluginInfo: + if initialRequest.name == consts.Message.GetPluginInfo: initialRequest['FcErrorMessage'] = msg initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error self._finalizeRequest(msg, initialRequest, self.events.PluginInfoFailed) @@ -962,12 +976,8 @@ if initialRequest is None: return False - initialRequest['FcRequestStatus'] |= (consts.RequestStatus.Removed | - consts.RequestStatus.Completed | - consts.RequestStatus.RemovedFromQueue - ) - - del self._requests[requestIdentifier] + initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed + self._finalizeRequest(msg, initialRequest, self.events.RequestRemoved) return True @@ -1125,6 +1135,7 @@ elif msg.name == consts.Message.PluginInfo: if initialRequest is None: return False + initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success self._finalizeRequest(msg, initialRequest, self.events.PluginInfo) return True @@ -1133,6 +1144,7 @@ if initialRequest is None: return False initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success + initialRequest['FcPluginReply'] = msg self._finalizeRequest(msg, initialRequest, self.events.PluginMessage) return True @@ -1819,12 +1831,12 @@ ## request related methods ## ######################################################## - def getRequest(self, identifier): + def getRequest(self, requestIdentifier): """Returns a (initial) message, given its identifier - @param identifier: identifier of the message + @param requestIdentifier: identifier of the message @return: L{Message} """ - return self._requests[identifier] + return self._requests[requestIdentifier] def getRequests(self): @@ -1871,11 +1883,10 @@ if initialRequest['FcRequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): # remove Persistence.Connection emidiately + #todo so we make up a PersistentRequestRemoved message if initialRequest['Persistence'] == consts.Persistence.Connection: - initialRequest['FcRequestStatus'] |= (consts.RequestStatus.Completed | - consts.RequestStatus.RemovedFromQueue - ) - del self._requests[requestIdentifier] + msg = self.Message(consts.Message.PersistentRequestRemoved, Identifier=requestIdentifier, Global=False) + self._finalizeRequest(msg, initialRequest, self.events.RequestRemoved) else: self.sendMessage( consts.Message.RemovePersistentRequest, @@ -1886,7 +1897,7 @@ del self._requests[requestIdentifier] #TODO: check how Fcp responds when the identifier is unknown or something else goes - # werong. Maybe a ProtocolError.NoSuchIdentifier ??? + # werong. Maybe a ProtocolError.NoSuchIdentifier ??? Naa ...never seen this def resendRequest(self, request): @@ -1896,29 +1907,35 @@ @note: you can use this method to resend get / put requests.All attempts to resend other requests will fail - @note: the request passed removed in the call if necessary. Except for FcInitTime is reseet, but - otherwise it is left unchanged + @note: actually a new request is created and registered. Todo so, the request passed is copied and removed from + the queue (if necessary). The new request will have FcInitTime reseet and FcUserData amd FcPersistentUserData + taken over from the old request """ requestType = request.get('FcRequestType', 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 + newRequest = copy.deepcopy(request) + # remove and cancel request - oldIdentifier = request['Identifier'] self._registerRequest( - request, + newRequest, requestType, - filenameCollision=request['FcFilenameCollision'] & consts.FilenameCollision.MaskHandle, + filenameCollision=newRequest['FcFilenameCollision'] & consts.FilenameCollision.MaskHandle, #initTime=time.time(), # TODO: reset init time or not? - persistentUserData=request['FcPersistentUserData'], - userData=request['FcUserData'], + persistentUserData=newRequest['FcPersistentUserData'], + userData=oldUserData, ) if oldIdentifier in self._requests: - self.removeRequest(oldIdentifier) + request['FcUserData'] = oldUserData + self.removeRequest(request['Identifier']) - self.sendMessageEx(request) - return request['Identifier'] + self.sendMessageEx(newRequest) + return newRequest['Identifier'] ######################################################## ## @@ -2040,14 +2057,14 @@ @param detailed: (bool) If True, detailed information is returned @return: (str) request identifier """ - identifier = self.FcParam.newUuid(uuids=self._requests) msg = self.Message( + consts.Message.GetPluginInfo, PluginName=pluginName, Detailed=detailed, ) - self._registerRequest(msg, consts.Message.GetPluginInfo) + self._registerRequest(msg, consts.RequestType.PluginInfo) self.sendMessageEx(msg) - return identifier + return msg['Identifier'] def sendPluginMessage(self, pluginName, params, data=None): @@ -2057,18 +2074,17 @@ @param data: (str) data to pass along with the messaage or None @return: (str) request identifier """ - identifier = self.FcParam.newUuid(uuids=self._requests) msg = self.Message( - consts.Message.GetPluginInfo, + consts.Message.FCPPluginMessage, PluginName=pluginName, **params ) if data is not None: msg['DataLength'] = len(data) msg.data = data - self._registerRequest(msg, onsts.RequestType.PluginMessage) + self._registerRequest(msg, consts.RequestType.PluginMessage) self.sendMessageEx(msg) - return identifier + 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-08 23:41:32
|
Revision: 193 http://fclient.svn.sourceforge.net/fclient/?rev=193&view=rev Author: jurner Date: 2008-02-08 15:41:20 -0800 (Fri, 08 Feb 2008) Log Message: ----------- added test for removeRequest() Modified Paths: -------------- trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py Modified: trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-08 23:41:00 UTC (rev 192) +++ trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-08 23:41:20 UTC (rev 193) @@ -856,6 +856,7 @@ class TestRequests(BaseTestConnectedClient): + def testModifyRequest(self): # request a arbitrary file @@ -894,7 +895,7 @@ self.assertHasNextEvent(None) - def testRemoveRequest(self): + def testRemoveRequest_NonPersistent(self): # request a file myIdentifier = self.fcpClient.getFile( @@ -917,6 +918,43 @@ # now cancel request self.fcpClient.removeRequest(myIdentifier) + # of our request should be removed emidiately, + self.assertEqual(myRequest['FcRequestStatus'], consts.RequestStatus.Null | + consts.RequestStatus.Removed | + consts.RequestStatus.Completed | + consts.RequestStatus.RemovedFromQueue + ) + self.failIf(myIdentifier in self.fcpClient.getRequests()) + + # now the request should have been removed + self.failIf(self.fcpClient.getRequests()) + self.assertHasNextEvent(None) + + + def testRemoveRequest_persistent(self): + + # request a file + myIdentifier = self.fcpClient.getFile( + 'arbitrary-uri', + 'arbitrary.txt', + persistence=consts.Persistence.Reboot, + ) + myRequest = self.fcpClient.getRequest(myIdentifier) + + # respond to the file request + self.sendResponseMessage( + 'PersistentGet', + Started='false', + **myRequest.params + ) + + # ignore events and messages so far + self.events = [] + self.messages = [] + + # now cancel request + self.fcpClient.removeRequest(myIdentifier) + # status of our request should be set to removed emidiately, but it should # not be removed from the client self.assertEqual(myRequest['FcRequestStatus'], consts.RequestStatus.Null | @@ -939,6 +977,59 @@ self.failIf(self.fcpClient.getRequests()) self.assertHasNextEvent(None) + + + def testResendRequest_NonPersistent(self): + + myIdentifier = self.fcpClient.getData('any-key') + myRequest = self.fcpClient.getRequest(myIdentifier) + allRequests = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.ClientGet) + + newIdentifier = self.fcpClient.resendRequest(myRequest) + + # client should remove old request emidiately + self.failIf(myIdentifier == newIdentifier) + self.failIf(myIdentifier in allRequests) + self.failUnless(newIdentifier in allRequests) + + self.assertHasNextMessage(consts.Message.ClientGet) + + + + def testResendRequest_Persistent(self): + + myIdentifier = self.fcpClient.getData('any-key', persistence=consts.Persistence.Reboot) + myRequest = self.fcpClient.getRequest(myIdentifier) + allRequests = self.fcpClient.getRequests() + self.assertHasNextMessage(consts.Message.ClientGet) + + newIdentifier = self.fcpClient.resendRequest(myRequest) + self.failIf(myIdentifier == newIdentifier) + self.failUnless(newIdentifier in allRequests) + + # client should remove request from nodes queue + self.assertHasNextMessage( + consts.Message.RemovePersistentRequest, + ('Identifier', myIdentifier) + ) + self.assertHasNextMessage( + consts.Message.ClientGet, + ('Identifier', newIdentifier) + ) + self.sendResponseMessage( + 'PersistentRequestRemoved', + Identifier=myIdentifier, + ) + + self.failUnless(newIdentifier in allRequests) + self.failIf(myIdentifier in allRequests) + + + + + + #*********************************************************************************** # #*********************************************************************************** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-08 23:41:06
|
Revision: 192 http://fclient.svn.sourceforge.net/fclient/?rev=192&view=rev Author: jurner Date: 2008-02-08 15:41:00 -0800 (Fri, 08 Feb 2008) Log Message: ----------- minor fixes Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_consts.py Modified: trunk/sandbox/fcp/fcp2_0_consts.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-08 23:40:33 UTC (rev 191) +++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-08 23:41:00 UTC (rev 192) @@ -77,8 +77,8 @@ FatalErrorInBlocks = 6 TooManyRetriesInBlock = 7 RouteReallyNotFound = 8 - Collision = '9' - Canceled = '10' + Collision = 9 + Canceled = 10 class ProtocolError(Exception): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-08 23:40:27
|
Revision: 191 http://fclient.svn.sourceforge.net/fclient/?rev=191&view=rev Author: jurner Date: 2008-02-08 15:40:33 -0800 (Fri, 08 Feb 2008) Log Message: ----------- what a bitch to implement .. Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_client.py Modified: trunk/sandbox/fcp/fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_client.py 2008-02-08 18:54:35 UTC (rev 190) +++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-08 23:40:33 UTC (rev 191) @@ -870,8 +870,11 @@ if initialRequest is None: return False + code = msg['Code'] + if code == consts.FetchError.Canceled: + return False + # check if it is one of our requests for key information - code = msg['Code'] if code == consts.FetchError.TooBig and initialRequest['FcRequestType'] == consts.RequestType.GetKeyInfo: initialRequest['FcMetadataContentType'] = msg.get('ExpectedMetadata.ContentType', '') initialRequest['FcDataLength'] = msg.get('ExpectedDataLength', -1) @@ -958,9 +961,13 @@ elif msg.name == consts.Message.PersistentRequestRemoved: if initialRequest is None: return False - #TODO: notify user? - initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed - self._finalizeRequest(msg, initialRequest, None) + + initialRequest['FcRequestStatus'] |= (consts.RequestStatus.Removed | + consts.RequestStatus.Completed | + consts.RequestStatus.RemovedFromQueue + ) + + del self._requests[requestIdentifier] return True @@ -1026,6 +1033,11 @@ elif msg.name == consts.Message.PutFailed: if initialRequest is None: return False + + code = msg['Code'] + if code == consts.InsertError.Canceled: + return False + initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error initialRequest['FcErrorMessage'] = msg self._finalizeRequest(msg, initialRequest, self.events.RequestFailed) @@ -1853,17 +1865,23 @@ def removeRequest(self, requestIdentifier): """Removes a request @param requestIdentifier: (str) identifier of the request to remove - - @note: you can use this method to remove get / put requests . All attempts to remove other requests will fail """ initialRequest = self._requests[requestIdentifier] initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed if initialRequest['FcRequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): - self.sendMessage( - consts.Message.RemovePersistentRequest, - Global=False, - Identifier=requestIdentifier, - ) + + # remove Persistence.Connection emidiately + if initialRequest['Persistence'] == consts.Persistence.Connection: + initialRequest['FcRequestStatus'] |= (consts.RequestStatus.Completed | + consts.RequestStatus.RemovedFromQueue + ) + del self._requests[requestIdentifier] + else: + self.sendMessage( + consts.Message.RemovePersistentRequest, + Global=False, + Identifier=requestIdentifier, + ) else: del self._requests[requestIdentifier] @@ -1871,36 +1889,37 @@ # werong. Maybe a ProtocolError.NoSuchIdentifier ??? - def resendRequest(self, requestMessage): + def resendRequest(self, request): """Resends a request - @param requestMessage: (L{fcp2_0_message.Message}) + @param request: (L{fcp2_0_message.Message}) @return: (str) request identifier - @note: you can use this method to resend get / put request, genarate keypair requests or - plugin messages. All attempts to resend other requests will fail - @note: the request passed is not removed in the call. Use L{removeRequest} if necessary + @note: you can use this method to resend get / put requests.All attempts to resend other requests + will fail + @note: the request passed removed in the call if necessary. Except for FcInitTime is reseet, but + otherwise it is left unchanged """ - requestType = requestMessage.get('FcRequestType', None) - if requestType is None: + requestType = request.get('FcRequestType', consts.RequestType.Null) + if not requestType & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): raise ValueError('Can not resend request: %s' % requestMessage.name) - - if requestType & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): - self._registerRequest( - requestMessage, - requestType, - filenameCollision=requestMessage['FcFilenameCollision'] & consts.FilenameCollision.MaskHandle, - #initTime=time.time(), # TODO: reset init time or not? - persistentUserData=requestMessage['FcPersistentUserData'], - userData=requestMessage['FcUserData'], - ) - elif requestType & (consts.RequestType.MaskGenerateKeypair | onsts.RequestType.MaskPlugin): - self._registerRequest(requestMessage, requestType) - else: - raise ValueError('Should not have ended here') + + # remove and cancel request + oldIdentifier = request['Identifier'] + self._registerRequest( + request, + requestType, + filenameCollision=request['FcFilenameCollision'] & consts.FilenameCollision.MaskHandle, + #initTime=time.time(), # TODO: reset init time or not? + persistentUserData=request['FcPersistentUserData'], + userData=request['FcUserData'], + ) + + if oldIdentifier in self._requests: + self.removeRequest(oldIdentifier) + + self.sendMessageEx(request) + return request['Identifier'] - self.sendMessageEx(msg) - return requestMessage['Identifier'] - ######################################################## ## ## Peer related methods @@ -2207,10 +2226,12 @@ def testUskPutData(): def cb(event, request): insertURI = request['FcPrivateKey'] - identifier = c.uskPutData( + myIdentifier = c.uskPutData( 'foo', insertURI + 'foo/0/', + persistence=consts.Persistence.Reboot, ) + c.removeRequest(myIdentifier) c.events.KeypairGenerated += cb c.generateKeypair(keypairType=consts.KeyType.USK) @@ -2219,10 +2240,10 @@ #'foo1', #'USK@dkbB9DSr6R2WWs0MFsB9BJvN2cRjNxSboanDQNMJVNc,uIi9-1JrCLZ~6MLa8UrxQCMLptu~PzL59hAtorUIStw,AQECAAE/foo/0/', #) - c.run() + #c.run() - #for i in xrange(500): - # c.next() + for i in xrange(700): + c.next() #testUskPutData() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-08 18:54:32
|
Revision: 190 http://fclient.svn.sourceforge.net/fclient/?rev=190&view=rev Author: jurner Date: 2008-02-08 10:54:35 -0800 (Fri, 08 Feb 2008) Log Message: ----------- added test for gen keypair and subscribe usk Modified Paths: -------------- trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py Modified: trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-08 18:53:33 UTC (rev 189) +++ trunk/sandbox/fcp/test_fcp/test_fcp2_0_client.py 2008-02-08 18:54:35 UTC (rev 190) @@ -473,7 +473,7 @@ self.failUnless(self.fcpClient.getRequests() ) myRequest = self.fcpClient.getRequest(myIdentifier) self.assertEqual(myIdentifier, myRequest['Identifier']) - self.assertEqual(myRequest['FcRequestStatus'], consts.RequestStatus.Pending) + self.assertEqual(myRequest['FcRequestStatus'], consts.RequestStatus.Null) def testGetData_Success(self): @@ -534,7 +534,7 @@ self.assertHasNextEvent( self.fcpClient.events.RequestCompleted, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Pending | + ('FcRequestStatus', consts.RequestStatus.Null | consts.RequestStatus.Success | consts.RequestStatus.RemovedFromQueue ), @@ -542,8 +542,7 @@ ) self.failIf(myIdentifier in allRequests) self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) - self.assertHasNextEvent(None) - + # cheat a bit to test peristence == Forever (client should not remove request) allRequests[myIdentifier] =myRequest @@ -564,7 +563,7 @@ self.assertHasNextEvent( self.fcpClient.events.RequestCompleted, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Pending | + ('FcRequestStatus', consts.RequestStatus.Null | consts.RequestStatus.Success), data=data ) @@ -602,7 +601,7 @@ self.assertHasNextEvent( self.fcpClient.events.RequestFailed, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Pending | + ('FcRequestStatus', consts.RequestStatus.Null | consts.RequestStatus.Error | consts.RequestStatus.RemovedFromQueue ) @@ -632,7 +631,7 @@ self.assertHasNextEvent( self.fcpClient.events.RequestFailed, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Pending | + ('FcRequestStatus', consts.RequestStatus.Null | consts.RequestStatus.Error ), ) @@ -675,7 +674,7 @@ self.assertHasNextEvent( self.fcpClient.events.RequestCompleted, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Pending | + ('FcRequestStatus', consts.RequestStatus.Null | consts.RequestStatus.Success | consts.RequestStatus.RemovedFromQueue ) @@ -715,7 +714,7 @@ self.assertHasNextEvent( self.fcpClient.events.RequestFailed, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Pending | + ('FcRequestStatus', consts.RequestStatus.Null | consts.RequestStatus.Error | consts.RequestStatus.RemovedFromQueue ) @@ -758,7 +757,7 @@ self.assertHasNextEvent( self.fcpClient.events.RequestCompleted, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Pending | + ('FcRequestStatus', consts.RequestStatus.Null | consts.RequestStatus.Success | consts.RequestStatus.RemovedFromQueue ) @@ -798,7 +797,7 @@ self.assertHasNextEvent( self.fcpClient.events.RequestCompleted, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Pending | + ('FcRequestStatus', consts.RequestStatus.Null | consts.RequestStatus.Success | consts.RequestStatus.RemovedFromQueue ) @@ -835,7 +834,7 @@ self.assertHasNextEvent( self.fcpClient.events.RequestFailed, consts.Message.ClientGet, - ('FcRequestStatus', consts.RequestStatus.Pending | + ('FcRequestStatus', consts.RequestStatus.Null | consts.RequestStatus.Error | consts.RequestStatus.RemovedFromQueue ) @@ -920,7 +919,7 @@ # status of our request should be set to removed emidiately, but it should # not be removed from the client - self.assertEqual(myRequest['FcRequestStatus'], consts.RequestStatus.Pending | + self.assertEqual(myRequest['FcRequestStatus'], consts.RequestStatus.Null | consts.RequestStatus.Removed ) self.failUnless(myIdentifier in self.fcpClient.getRequests()) @@ -1009,7 +1008,7 @@ self.fcpClient.events.RequestRestored, consts.Message.ClientGet, ('Identifier', myIdentifier), - ('FcRequestStatus', consts.RequestStatus.Null), # no RequestStatus.Pending flag should be set here + ('FcRequestStatus', consts.RequestStatus.Restored), # no RequestStatus.Pending flag should be set here ) self.failUnless(myIdentifier in allRequests) @@ -1260,14 +1259,95 @@ #*********************************************************************************** # #*********************************************************************************** -#TODO: class TestSSKKeypair(BaseTestConnectedClient): +#TODO: class TestSSKKeypair(BaseTestConnectedClient): +class TestGenerateKeypair(BaseTestConnectedClient): + + def testGeberateSSKKeypair(self): + myIdentifier = self.fcpClient.generateKeypair(consts.KeyType.SSK) + myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + + self.sendResponseMessage( + 'SSKKeypair', + Identifier=myIdentifier, + RequestURI='SSK@public', + InsertURI='SSK@private', + ) + + msg = self.assertHasNextEvent( + self.fcpClient.events.KeypairGenerated, + consts.Message.GenerateSSK, + ('Identifier', myIdentifier), + ('FcPublicKey','SSK@public'), + ('FcPrivateKey','SSK@private'), + ('FcRequestStatus', consts.RequestStatus.Success | + consts.RequestStatus.RemovedFromQueue + ), + ) + self.assertHasNextEvent(None) + self.failIf(myIdentifier in requestsAll) + self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + + + def testGeberateUSKKeypair(self): + myIdentifier = self.fcpClient.generateKeypair(consts.KeyType.USK) + myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + + self.sendResponseMessage( + 'SSKKeypair', + Identifier=myIdentifier, + RequestURI='SSK@public', + InsertURI='SSK@private', + ) + + msg = self.assertHasNextEvent( + self.fcpClient.events.KeypairGenerated, + consts.Message.GenerateSSK, + ('Identifier', myIdentifier), + ('FcPublicKey','USK@public'), + ('FcPrivateKey','USK@private'), + ('FcRequestStatus', consts.RequestStatus.Success | + consts.RequestStatus.RemovedFromQueue + ), + ) + self.assertHasNextEvent(None) + self.failIf(myIdentifier in requestsAll) + self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + #*********************************************************************************** # #*********************************************************************************** -#TODO: class TestSubscribeUSK(BaseTestConnectedClient): +class TestSubscribeUSK(BaseTestConnectedClient): + def testSubscribe(self): + + myIdentifier = self.fcpClient.subscribeUSK('arbitrary') + myRequest = self.fcpClient.getRequest(myIdentifier) + requestsAll = self.fcpClient.getRequests() + + self.failUnless(myIdentifier in requestsAll) + self.failUnless(myRequest['FcRequestStatus'] & consts.RequestStatus.Completed) + + self.sendResponseMessage( + 'SubscribedUSKUpdate', + Identifier=myIdentifier, + Edition=99, + URI='arbitryry/99/', + ) + + msg = self.assertHasNextEvent( + self.fcpClient.events.USKUpdated, + consts.Message.SubscribedUSKUpdate, + ('Identifier', myIdentifier), + ('Edition', 99), + ('URI', 'arbitryry/99/'), + ) + self.assertHasNextEvent(None) + + #********************************************************************************* # @@ -1282,6 +1362,9 @@ TestRestoreRequests, TestDDA, TestCollisions, + + TestGenerateKeypair, + TestSubscribeUSK, ) suite = unittest.TestSuite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-08 18:53:29
|
Revision: 189 http://fclient.svn.sourceforge.net/fclient/?rev=189&view=rev Author: jurner Date: 2008-02-08 10:53:33 -0800 (Fri, 08 Feb 2008) Log Message: ----------- fix Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_consts.py Modified: trunk/sandbox/fcp/fcp2_0_consts.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-08 18:53:10 UTC (rev 188) +++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-02-08 18:53:33 UTC (rev 189) @@ -294,7 +294,7 @@ class RequestStatus: """Request status flags @cvar Null: no status - @cvar Pending: the request was fed to the client (not set for restored requests) + @cvar Restored: the request was restored when the client was started @cvar Compressing: the request is about to be compressed @cvar Compressed: compressing is completed @cvar Success: the request has completed successfuly @@ -305,14 +305,11 @@ @cvar RemovedFromQueue: the request is no longer present in the nodes queue. The client will remove the request from its own queue as soon as all event listeners have been notified. - @cvar MaskProcessed: bitmask checking if a request is completely processed (either - successfuly completed or completed with an error or removed) - @note: the FcStatus member of the params dict of a request should contain one or more of the bitflags it picked up while running through the client. """ Null = 0x0 - Pending = 0x1 + Restored = 0x1 Compressing = 0x2 Compressed = 0x4 Success = 0x8 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-08 18:53:05
|
Revision: 188 http://fclient.svn.sourceforge.net/fclient/?rev=188&view=rev Author: jurner Date: 2008-02-08 10:53:10 -0800 (Fri, 08 Feb 2008) Log Message: ----------- more twiddling with request status flags ++ GenerateKeypair is now registered as request Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_client.py Modified: trunk/sandbox/fcp/fcp2_0_client.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_client.py 2008-02-08 13:45:43 UTC (rev 187) +++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-08 18:53:10 UTC (rev 188) @@ -348,7 +348,7 @@ 'FcPersistentUserData': persistentUserData, # any user defined persistent data # non persistent params - 'FcRequestStatus': consts.RequestStatus.Pending, + 'FcRequestStatus': consts.RequestStatus.Null, 'FcErrorMessage': None, # error message in case an error occured 'FcUserData': userData, # any user defined runtime data here @@ -381,7 +381,7 @@ elif requestType & consts.RequestType.MaskGenerateKeypair: msg.params.update({ 'FcRequestType': requestType, # identifies sub message types - 'FcRequestStatus': consts.RequestStatus.Pending, + 'FcRequestStatus': consts.RequestStatus.Null, 'FcInitTime': initTime, # when was the request started? 'FcModified': {}, @@ -392,12 +392,12 @@ else: msg.params.update({ 'FcRequestType': requestType, # identifies sub message types - 'FcRequestStatus': consts.RequestStatus.Pending, + 'FcRequestStatus': consts.RequestStatus.Null, 'FcInitTime': initTime, # when was the request started? 'FcModified': {}, }) - msg['FcRequestStatus'] |= consts.RequestStatus.Pending + msg['FcRequestStatus'] |= consts.RequestStatus.Null msg['Identifier'] = identifier self._requests[identifier] = msg @@ -916,7 +916,7 @@ #FIX: [0001965: Persistence vs PersistenceType] if 'PersistenceType' in initialRequest.params: initialRequest['Persistence'] = initialRequest.params.pop('PersistenceType') - initialRequest['FcRequestStatus'] = consts.RequestStatus.Null + initialRequest['FcRequestStatus'] |= consts.RequestStatus.Restored self.events.RequestRestored(initialRequest) return True @@ -1015,7 +1015,7 @@ #FIX: remove Started param from PersistentGet / Put del initialRequest.params['Started'] - initialRequest['FcRequestStatus'] = consts.RequestStatus.Null + initialRequest['FcRequestStatus'] |= consts.RequestStatus.Restored self.events.RequestRestored(initialRequest) return True @@ -1160,7 +1160,6 @@ elif msg.name == consts.Message.SubscribedUSKUpdate: if initialRequest is None: return False - self.events.USKUpdated(msg) return True @@ -1550,26 +1549,24 @@ #TODO: persists until connection is closed... can this request be removed? - # Anyway. It is not listed in consts.Message.ClientKeyRequestMessages, - # so any attempts will fail (wink) def subscribeUSK(self, uri, dontPoll=True): """Asks the node to notify the client when an USK is updated @param uri: uri of the USK to subscribe to @param dontPoll: if True, 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 """ - identifier = self.FcParams.newUuid(uuids=self._requests) - self.sendMessage( + msg = self.Message( consts.Message.SubscribeUSK, - FcModified={}, - FcRequestStatus=consts.RequestStatus.Pending, #TODO: status? - FcRequestType=consts.RequestType.SubscribeUSK, - - Identifier=identifier, URI=uri, DontPoll=dontPoll, ) - return identifier + self._registerRequest(msg, consts.RequestType.SubscribeUSK) + msg['FcRequestStatus'] |= consts.RequestStatus.Completed + self.sendMessageEx(msg) + return msg['Identifier'] ######################################################## ## @@ -1831,12 +1828,12 @@ @param persistentUserData: (str) persistent user data or None @param priorityClass: (L{consts.Priority}) new priority or None - @note: you can use this method to modify requests as listed in L{consts.Message.ClientKeyRequestMessages}. + @note: you can use this method to modify get / put related requests All attempts to modify other requests will fail @note: a RequestModified event is triggered as soon as the request has actually been modified """ initialRequest = self._requests[requestIdentifier] - if initialRequest.name not in consts.Message.ClientKeyRequestMessages: + if not initialRequest['FcRequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): raise ValueError('Can not modify request: %s' % initialRequest.name) msg = self.Message( @@ -1857,14 +1854,11 @@ """Removes a request @param requestIdentifier: (str) identifier of the request to remove - @note: you can use this method to remove requests as listed in L{consts.Message.ClientKeyRequestMessages} - or L{consts.Message.ClientPluginMessages}. All attempts to remove other requests will fail - @note: if the request is one the requests listed in L{consts.Message.ClientKeyRequestMessages} - a RequestRemoved event is triggered as soon as the request has actually been removed + @note: you can use this method to remove get / put requests . All attempts to remove other requests will fail """ initialRequest = self._requests[requestIdentifier] initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed - if initialRequest.name in consts.Message.ClientKeyRequestMessages: + if initialRequest['FcRequestType'] & (consts.RequestType.MaskGet | consts.RequestType.MaskPut): self.sendMessage( consts.Message.RemovePersistentRequest, Global=False, @@ -1882,8 +1876,8 @@ @param requestMessage: (L{fcp2_0_message.Message}) @return: (str) request identifier - @note: you can use this method to resend requests as listed in L{consts.Message.ClientKeyRequestMessages} - or L{consts.Message.ClientPluginMessages}. All attempts to resend other requests will fail + @note: you can use this method to resend get / put request, genarate keypair requests or + plugin messages. All attempts to resend other requests will fail @note: the request passed is not removed in the call. Use L{removeRequest} if necessary """ requestType = requestMessage.get('FcRequestType', None) @@ -2081,11 +2075,10 @@ 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 - identifier = self.FcParams.newUuid(uuids=self._requests) msg = self.Message(consts.Message.GenerateSSK) self._registerRequest(msg, requestType) self.sendMessageEx(msg) - return identifier + return msg['Identifier'] #***************************************************************************** @@ -2364,4 +2357,16 @@ for i in xrange(30): c.next() - #testListPeers() \ No newline at end of file + #testListPeers() + + + def testSubscribeUSK(): + myIdentifier = c.subscribeUSK('USK@zQyF2O1o8B4y40w7Twz8y2I9haW3d2DTlxjTHPu7zc8,h2mhQNNE9aQvF~2yKAmKV1uorr7141-QOroBf5hrlbw,AQACAAE/AnotherIndex/0/') + for i in xrange(10): + c.next() + + for i in xrange(10): + c.next() + + + #testSubscribeUSK() \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |