SF.net SVN: fclient: [474] trunk/fcp2/src/fcp2/client.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-01 18:41:11
|
Revision: 474
http://fclient.svn.sourceforge.net/fclient/?rev=474&view=rev
Author: jUrner
Date: 2008-07-01 11:39:17 -0700 (Tue, 01 Jul 2008)
Log Message:
-----------
_newUuid() is now newidentifier()
++ this and that
Modified Paths:
--------------
trunk/fcp2/src/fcp2/client.py
Modified: trunk/fcp2/src/fcp2/client.py
===================================================================
--- trunk/fcp2/src/fcp2/client.py 2008-07-01 18:36:31 UTC (rev 473)
+++ trunk/fcp2/src/fcp2/client.py 2008-07-01 18:39:17 UTC (rev 474)
@@ -202,6 +202,7 @@
import logging
import subprocess
import time
+import uuid
#--> rel import hack
@@ -220,12 +221,11 @@
from fcp2 import iohandler
from fcp2 import types
from fcp2 import key
+import random
from fcp2.fcp_lib import namespace
from fcp2.fcp_lib import tools
-from fcp2.fcp_lib import uuid
-
del hack, _RelImportHack
#<-- rel import hack
@@ -323,7 +323,6 @@
self.ioHandler.close()
- #TODO: check if this method is still needed
def _finalizeRequest(self, msg, request, event):
"""Finalzes a request
@param msg: message that is the reason for finalizing
@@ -350,21 +349,8 @@
if removeRequest:
del self._requests[request['Identifier']]
-
- def _newUuid(self, uuids=None):
- """Creates a new unique identifier
- @param uuids: if desired any iterable containing uuids to enshure the identifier is unique in the iterable
- @return: (str) uuid
-
- """
- uuid_ = uuid.uuid_time()
- if uuids is not None:
- while uuid_ in uuids:
- uuid_ = uuid_time()
- return uuid_
-
def _registerRequest(self,
msg,
requestType,
@@ -387,12 +373,12 @@
@return: (str) identifer of therequest
@note: the identifier returned is unique to the client but may not be unique to the node
"""
- identifier = self._newUuid(uuids=self._requests) if identifier is None else identifier
+ identifier = self.newIdentifier(identifiers=self._requests) if identifier is None else identifier
# equip requests with some additional params
#TODO: keep an eye on additional params, they may collide with Fcp parameters
- msg['Identifier'] = self._newUuid(uuids=self._requests) if identifier is None else identifier
+ msg['Identifier'] = self.newIdentifier(identifiers=self._requests) if identifier is None else identifier
msg['RequestType'] = requestType
msg['InitTime'] = time.time() if initTime is None else initTime
if requestType & consts.ConstRequestType.MaskGet:
@@ -459,9 +445,8 @@
@return: (bool) True if so, False otherwise
"""
return self.ioHandler.isOpen()
+
-
-
def iterConnect(self, host=DefaultFcpHost, port=DefaultFcpPort, duration=20, timeout=0.5):
"""Iterator to stablish a connection to a freenet node
@param host: (str) host of th node
@@ -537,7 +522,7 @@
@param connectionName: (str) connection name or None to use an arbitrary connection name
@return: (str) connection name
"""
- self._connectionName = self._newUuid() if connectionName is None else connectionName
+ self._connectionName = self.newIdentifier() if connectionName is None else connectionName
return self._connectionName
@@ -548,15 +533,26 @@
return consts.ConstLogger.Client.getEffectiveLevel()
-
def setDebugVerbosity(self, debugVerbosity):
"""Sets the verbosity level of the client
@param debugVerbosity: L{consts.ConstDebugVerbosity}
"""
consts.ConstLogger.Client.setLevel(debugVerbosity)
-
+
+ def newIdentifier(self, identifiers=None):
+ """Creates a new identifier to be used as request identifer or whatever
+ @param identifiersuuids: if desired any iterable containing identifiers to enshure the identifier is unique within the iterable
+ @return: (str) identifier
+
+ """
+ identifier = str(hex(random.getrandbits(128)))
+ if identifiers is not None:
+ while identifier in identifiers:
+ identifier = str(hex(random.getrandbits(128)))
+ return identifier
+
def startNode(self, cmdline):
"""Starts the freenet node
@param cmdline: commandline to start freenet (like '/freenet/run.sh start' or 'c:\freenet\start.bat')
@@ -612,7 +608,7 @@
return False
# resend request with new identifier
- newIdentifier = self._newUuid(uuids=self._requests)
+ newIdentifier = self.newIdentifier(identifiers=self._requests)
self._requests[newIdentifier] = initialRequest
del self._requests[requestIdentifier]
initialRequest['Identifier'] = newIdentifier
@@ -764,6 +760,7 @@
raise ValueError('No initial message found in TestDDAComplete')
# remove test and clean tmp data
+ #TODO: reset TestDDA params or not?
self._ddaTests.remove(initialRequest)
if initialRequest['TestDDA']['TmpFile'] is not None:
tools.saveRemoveFile(initialRequest['TestDDA']['TmpFile'])
@@ -847,7 +844,9 @@
code = msg['Code']
if code == consts.ConstFetchError.Canceled:
- initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Removed | consts.ConstRequestStatus.Completed | consts.ConstRequestStatus.RemovedFromQueue
+ initialRequest['RequestStatus'] |= consts.ConstRequestStatus.Removed | \
+ consts.ConstRequestStatus.Completed | \
+ consts.ConstRequestStatus.RemovedFromQueue
del self._requests[requestIdentifier]
self.events.RequestRemoved(initialRequest)
return True
@@ -897,7 +896,7 @@
self.events.RequestRestored(initialRequest)
return True
- # ignore
+ #TODO: ignore handshake?
return False
@@ -1196,8 +1195,8 @@
# Reminder to self:
#
- # if socket dies on sendall ther is no way to determine if and how much data was send
- # ...so assume data was send, cos there is no way to proove it was not send
+ # if socket dies on sendall there is no way to determine if and how much data was send
+ # ...so assume data was send
try:
self.ioHandler.sendMessage(msg)
except consts.ErrorIOBroken, details:
@@ -1237,9 +1236,8 @@
WithDataTypes=withDataTypes,
)
)
+
-
-
def modifyConfig(self, params):
"""Modifies node configuration values
@param params: (dict) containing parameters to modify
@@ -1286,7 +1284,6 @@
)
self.sendMessage(msg)
return msg['Identifier']
-
def getData(self,
@@ -1352,8 +1349,7 @@
ReturnType=consts.ConstReturnType.Direct,
Verbosity=consts.ConstVerbosity.ReportProgress,
)
-
-
+
def getFile(self,
uri,
@@ -1424,7 +1420,6 @@
)
-
def getKeyInfo(self,
uri,
@@ -1482,7 +1477,6 @@
)
-
def subscribeUSK(self, uri, dontPoll=True):
"""Asks the node to notify the client when an USK is updated
@param uri: (L{key.USK}) key to subscribe to
@@ -1868,7 +1862,6 @@
)
-
def putRedirect(self,
uri,
targetKey,
@@ -1984,8 +1977,7 @@
)
else:
del self._requests[requestIdentifier]
-
-
+
########################################################
##
## Peer related methods
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|