Thread: SF.net SVN: fclient: [167] trunk/sandbox/fcp/fcp2_0_client.py (Page 2)
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-02-07 23:47:18
|
Revision: 167
http://fclient.svn.sourceforge.net/fclient/?rev=167&view=rev
Author: jurner
Date: 2008-02-07 15:47:22 -0800 (Thu, 07 Feb 2008)
Log Message:
-----------
renames
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-06 14:57:28 UTC (rev 166)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-07 23:47:22 UTC (rev 167)
@@ -3,9 +3,9 @@
Compatibility: >= Freenet 0.7 Build #1107
-@newfield event: event, events
+@newfield event: Event, Events
+@newfield requestparam: RequestParam, RequestParams
-
@note: The client implementation never uses or watches the global queue. No implementation
should ever do so. Global is evil.
@@ -294,8 +294,7 @@
persistentUserData,
filenameCollision,
):
-
-
+
# add additional params to msg
msg.params.update({
@@ -306,7 +305,7 @@
'FcPersistentUserData': persistentUserData, # any user defined persistent data
# non persistent params
- 'FcStatus': consts.RequestStatus.Null,
+ 'FcRequestStatus': consts.RequestStatus.Null,
'FcErrorMessage': None, # error message in case an error occured
'FcUserData': userData, # any user defined runtime data here
@@ -353,12 +352,12 @@
#NOTE: non Get / Put related requests do not have a Persistence param
removeRequest = request.params.get('Persistence', consts.Persistence.Connection) == consts.Persistence.Connection
if removeRequest:
- request['FcStatus'] |= consts.RequestStatus.RemovedFromQueue
+ request['FcRequestStatus'] |= consts.RequestStatus.RemovedFromQueue
if event is not None:
event(request)
- request['FcStatus'] |= consts.RequestStatus.Completed
+ request['FcRequestStatus'] |= consts.RequestStatus.Completed
if removeRequest:
del self._requests[request['Identifier']]
@@ -371,8 +370,8 @@
persistentUserData,
filenameCollision=consts.FilenameCollision.HandleNever,
):
- """Registers a message
- @param msg: message to register for track keeping
+ """Registers a request
+ @param msg: message to register
@param userData: any user defined data
@param msgType: one of the message sub type consts
@param initTime: (python time)
@@ -395,7 +394,7 @@
)
msg['ClientToken'] = self.FcParams.messageToParams(msg)
- msg['FcStatus'] |= consts.RequestStatus.Pending
+ msg['FcRequestStatus'] |= consts.RequestStatus.Pending
msg['Identifier'] = identifier
self._requests[identifier] = msg
@@ -720,25 +719,25 @@
elif code == consts.ProtocolError.NoSuchPlugin:
if initialRequest.name == consts.Message.PluginInfo:
initialRequest['FcErrorMessage'] = msg
- initialRequest['FcStatus'] |= consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error
self._finalizeRequest(msg, initialRequest, self.events.PluginInfoFailed)
return True
elif initialRequest.name == consts.Message.FCPPluginMessage:
initialRequest['FcErrorMessage'] = msg
- initialRequest['FcStatus'] |= consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error
self._finalizeRequest(msg, initialRequest, self.events.PluginMessageFailed)
return True
elif code == consts.ProtocolError.AccessDenied:
if initialRequest.name == consts.Message.PluginInfo:
self.events.PluginInfoFailed(initialRequest)
- initialRequest['FcStatus'] |= consts.RequestStatus.Completed
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Completed
del self._requests[requestIdentifier]
return True
# TODO: just a guess that FCPPluginMessage can trigger an AccessDenied error
elif initialRequest.name == consts.Message.FCPPluginMessage:
self.events.PluginMessageFailed(initialRequest)
- initialRequest['FcStatus'] |= consts.RequestStatus.Completed
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Completed
del self._requests[requestIdentifier]
return True
@@ -747,7 +746,7 @@
# NOTE: Fcp already removed the request
initialRequest['FcErrorMessage'] = msg
- initialRequest['FcStatus'] = consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] = consts.RequestStatus.Error
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
@@ -827,7 +826,7 @@
if testFailed:
#TODO: check if errorMsg gives reasonable feedback
- initialRequest['FcStatus'] = consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] = consts.RequestStatus.Error
initialRequest['FcErrorMessage'] = initialRequest['FcTestDDA']['ErrorMsg']
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
@@ -861,7 +860,7 @@
if initialRequest is None:
return False
- initialRequest['FcStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
initialRequest.data = msg.data
self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
return True
@@ -870,7 +869,7 @@
if initialRequest is None:
return False
- initialRequest['FcStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
initialRequest['FcMetadataContentType'] = msg.get('Metadata.ContentType', '')
initialRequest['FcDataLength'] = msg.get('DataLength', '')
@@ -889,11 +888,11 @@
if code == consts.FetchError.TooBig and initialRequest['FcRequestType'] == consts.RequestType.GetKeyInfo:
initialRequest['FcMetadataContentType'] = msg.get('ExpectedMetadata.ContentType', '')
initialRequest['FcDataLength'] = msg.get('ExpectedDataLength', -1)
- initialRequest['FcStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
else:
initialRequest['FcErrorMessage'] = msg
- initialRequest['FcStatus'] |= consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
@@ -918,13 +917,13 @@
# restore request
self._requests[requestIdentifier] = restoredRequest
- restoredRequest['FcStatus'] |= consts.RequestStatus.Started
+ restoredRequest['FcRequestStatus'] |= consts.RequestStatus.Started
self.events.RequestRestored(restoredRequest)
return True
# known request... filter out multiple PersistentGets
- if not initialRequest['FcStatus'] & consts.RequestStatus.Started:
- initialRequest['FcStatus'] |= consts.RequestStatus.Started
+ if not initialRequest['FcRequestStatus'] & consts.RequestStatus.Started:
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Started
#TODO: update initialRequest with params from PersistentGet?
@@ -969,7 +968,7 @@
if initialRequest is None:
return False
#TODO: notify user?
- initialRequest['FcStatus'] |= consts.RequestStatus.Removed
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed
self._finalizeRequest(msg, initialRequest, None)
return True
@@ -1013,13 +1012,13 @@
# restore request
self._requests[requestIdentifier] = restoredRequest
- restoredRequest['FcStatus'] = consts.RequestStatus.Started
+ restoredRequest['FcRequestStatus'] = consts.RequestStatus.Started
self.events.RequestRestored(restoredRequest)
return True
# known request... filter out multiple PersistentGets
- if not initialRequest['FcStatus'] & consts.RequestStatus.Started:
- initialRequest['FcStatus'] |= consts.RequestStatus.Started
+ if not initialRequest['FcRequestStatus'] & consts.RequestStatus.Started:
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Started
#TODO: update initialRequest with params from PersistentPut?
@@ -1032,7 +1031,7 @@
elif msg.name == consts.Message.PutFailed:
if initialRequest is None:
return False
- initialRequest['FcStatus'] |= consts.RequestStatus.Error
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Error
initialRequest['FcErrorMessage'] = msg
self._finalizeRequest(msg, initialRequest, self.events.RequestFailed)
return True
@@ -1053,7 +1052,7 @@
# TODO: StartupTime and CompletionTime are passed, but
# as long as no corrosponding params are passed in DataFound
# we ignore them
- initialRequest['FcStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
initialRequest['URI'] = msg['URI']
self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
return True
@@ -1068,14 +1067,14 @@
elif msg.name == consts.Message.FinishedCompression:
if initialRequest is None:
return False
- initialRequest['FcStatus'] |= consts.RequestStatus.Compressed
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Compressed
self.events.RequestCompressionFinished(initialRequest)
return True
elif msg.name == consts.Message.StartedCompression:
if initialRequest is None:
return False
- initialRequest['FcStatus'] |= consts.RequestStatus.Compressing
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Compressing
self.events.RequestCompressionStarted(initialRequest)
return True
@@ -1116,14 +1115,14 @@
elif msg.name == consts.Message.PluginInfo:
if initialRequest is None:
return False
- initialRequest['FcStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
self._finalizeRequest(msg, initialRequest, self.events.PluginInfo)
return True
elif msg.name == consts.Message.FCPPluginReply:
if initialRequest is None:
return False
- initialRequest['FcStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
self._finalizeRequest(msg, initialRequest, self.events.PluginMessage)
return True
@@ -1154,9 +1153,9 @@
insertURI = insertURI.replace(consts.KeyType.SSK, consts.KeyType.USK, 1)
requestURI = requestURI.replace(consts.KeyType.SSK, consts.KeyType.USK, 1)
- initialRequest['InsertURI'] = insertURI
- initialRequest['RequestURI'] = requestURI
- initialRequest['FcStatus'] |= consts.RequestStatus.Success
+ initialRequest['FcPrivateKey'] = insertURI
+ initialRequest['FcPublicKey'] = requestURI
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Success
self._finalizeRequest(msg, initialRequest, self.events.KeypairGenerated)
return True
@@ -1213,7 +1212,7 @@
# check if we have running requests. Assert False
haveRunningRequests = False
for request in self._requests.values():
- if not request.params['FcStatus'] & consts.RequestStatus.Completed:
+ if not request.params['FcRequestStatus'] & consts.RequestStatus.Completed:
haveRunningRequests = True
break
@@ -1372,9 +1371,9 @@
userData=None,
persistentUserData='',
):
- """Requests a file from the node
+ """Requests datae from the node
- @param uri: uri of the file to request (may contain prefixes like 'freenet:' or 'http://')
+ @param uri: uri of the data to request (may contain prefixes like 'freenet:' or 'http://')
@param allowedMimeTypes: (str) list of allowed mime types
@param binaryBlob: (bool) if True, the file is retrieved as binary blob file
@@ -1389,12 +1388,14 @@
@return: (str) request identifier
- @event: RequestCompleted(event, message) triggered when the request is complete
- @event: RequestFailed(event, message) triggered when the request failes
- @event: RequestStarted(event, message) triggered when as the request is started
- @event: RequestModified(event, message) trigggered if the request identifier changes
+ @event: L{Events.RequestCompleted} triggered as soon as the request is complete
+ @event: L{Events.RequestFailed} triggered if the request failes
+ @event: L{Events.RequestStarted} triggered as soon as the request is started
+ @event: L{Events.RequestModified} trigggered if the request identifier changes
or the request is modified otherwise (see L{modifyRequest})
+ @note: the identifier of the request may change at any time. You should be prepaired to handle
+ this
@note: if persistence is L{consts.Persistence.Connection} the request is removed from the client
as soon as it completes or failes
"""
@@ -1563,6 +1564,10 @@
identifier = self.FcParams.newUuid(uuids=self._requests)
self.sendMessage(
consts.Message.SubscribeUSK,
+ FcModified={},
+ FcRequestStatus=consts.RequestStatus.Pending, #TODO: status?
+ FcRequestType=consts.RequestType.SubscribeUSK,
+
Identifier=identifier,
URI=uri,
DontPoll=dontPoll,
@@ -1574,6 +1579,37 @@
## CHK ClientPut related methods
##
########################################################
+ def putUpload(self, upload, userData=None, persistentUserData=''):
+
+ msg = upload.getMessage(self.Message)
+ if msg is None:
+ raise ValueError('Nothing to upload')
+
+ # determine SubType
+ if msg.name == consts.Message.ClientPut:
+ messageType = consts.RequestType.Put
+ elif msg.name == consts.Message.ClientPutDiskDir:
+ messageType = consts.RequestType.PutDiskDir
+ else:
+ messageType = consts.RequestType.PutComplexDir
+
+ self._registerRequest(
+ msg,
+ userData,
+ messageType,
+ time.time(),
+ persistentUserData,
+ #filenameCollision=filenameCollision,
+ )
+
+ if upload.keyType in (consts.KeyType.SSK, consts.KeyType.USK):
+ msg['FcInsertUri'] = upload.privateKey
+ #NOTE: the caller may use the 'FcInsertUri' member to store the private key
+
+
+ self.sendMessageEx(msg)
+ return msg['Identifier']
+
def clientPut(self,
uri,
messageSubType,
@@ -1590,7 +1626,7 @@
msg[paramName] = value
if data is not None:
msg.data = data
-
+
self._registerRequest(
msg,
userData,
@@ -1613,6 +1649,7 @@
contentType=None,
dontCompress=None,
+ filename=None,
maxRetries=None,
persistence=consts.Persistence.Connection,
priorityClass=consts.Priority.Medium,
@@ -1621,7 +1658,9 @@
userData=None,
persistentUserData='',
):
- """"""
+ """
+ @param data: ()
+ """
return self.clientPut(
consts.KeyType.CHK,
consts.RequestType.Put,
@@ -1650,10 +1689,9 @@
def chkPutFile(self,
- filename,
-
contentType=None,
dontCompress=None,
+ filename=None,
maxRetries=None,
persistence=consts.Persistence.Connection,
priorityClass=consts.Priority.Medium,
@@ -1663,6 +1701,10 @@
persistentUserData='',
):
+ """
+ @param filename: (str) filename to append to the CHK key or None (may not contain slashes)
+ """
+
return self.clientPut(
consts.KeyType.CHK,
consts.RequestType.Put,
@@ -1832,7 +1874,7 @@
a RequestRemoved event is triggered as soon as the request has actually been removed
"""
initialRequest = self._requests[requestIdentifier]
- initialRequest['FcStatus'] |= consts.RequestStatus.Removed
+ initialRequest['FcRequestStatus'] |= consts.RequestStatus.Removed
if initialRequest.name in consts.Message.ClientKeyRequestMessages:
self.sendMessage(
consts.Message.RemovePersistentRequest,
@@ -1997,7 +2039,7 @@
FcErrorMessage=None,
FcModified={},
FcRequestType=consts.RequestType.PluginInfo,
- FcStatus=consts.RequestStatus.Pending,
+ FcRequestStatus=consts.RequestStatus.Pending,
Identifier=identifier,
PluginName=pluginName,
@@ -2022,7 +2064,7 @@
FcErrorMessage=None,
FcModified={},
FcRequestType=consts.RequestType.PluginMessage,
- FcStatus=consts.RequestStatus.Pending,
+ FcRequestStatus=consts.RequestStatus.Pending,
Identifier=identifier,
PluginName=pluginName,
@@ -2042,12 +2084,20 @@
##
##########################################################
def generateKeypair(self, keypairType=consts.KeyType.SSK):
- """
+ """Generates a public / private keypair
+
@param keypairType: type of keypair to generate (either L{consts.KeyType.SSK} or L{consts.KeyType.SSK})
@return: identifier of the request
- @event: KeypairGenerated(event, params) is triggered when the request is complete
+
+ @event: L{Events.KeypairGenerated} triggered as soon as the request is complete
+
+ @requestparam: B{FcModified:} (dict)
+ @requestparam: B{FcPrivateKey:} None. Will contain the private key as soon as the key is generated
+ @requestparam: B{FcPublivcKey:} None. Will contain the public key as soon as the key is generated
+ @requestparam: B{FcRequestStatus:} one or more of the L{consts.RequestStatus} flags
+ @requestparam: B{FcRequestType:} one or more of the L{consts.RequestType} flags
+ @requestparam: B{Identifier:} identifier of the request
"""
-
if keypairType not in (consts.KeyType.SSK, consts.KeyType.USK):
raise ValueError('keypairType must be %s or %s' % (consts.KeyType.SSK, consts.KeyType.USK))
@@ -2056,7 +2106,9 @@
msg = self.Message(
consts.Message.GenerateSSK,
FcModified={},
- FcStatus=consts.RequestStatus.Pending,
+ FcPrivateKey= None,
+ FcPublicKey=None,
+ FcRequestStatus=consts.RequestStatus.Pending,
FcRequestType=requestType,
Identifier=identifier,
)
@@ -2159,8 +2211,6 @@
'test123',
#persistence=c.Persistence.Reboot,
)
-
-
for i in xrange(500):
c.next()
#c.removeRequest(myIdentifier)
@@ -2169,6 +2219,10 @@
#testChkPutData()
+
+
+
+
def testChkPutFile():
fpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.jpg')
@@ -2207,9 +2261,32 @@
# c.next()
#testUskPutData()
+
+
+ def testUskPutData():
+ def cb(event, request):
+ insertURI = request['InsertURI']
+ insertURI = 'USK@AKva7OolWsdAICB8ZE1hDgFqBJigJpYN2edJd6deiApU,dOitAHZSrt27Tl4wK7F-VHVShJVvzR7eNWKsXBolq8k,AQECAAE/'
+
+ u = c.Upload(consts.KeyType.USK, privateKey=insertURI)
+ u.addData('foo/0/', 'data here')
+ c.putUpload(u)
+
+
+ c.events.KeypairGenerated += cb
+ c.generateKeypair(keypairType=consts.KeyType.USK)
+
+ #identifier = c.uskPutData(
+ #'foo1',
+ #'USK@dkbB9DSr6R2WWs0MFsB9BJvN2cRjNxSboanDQNMJVNc,uIi9-1JrCLZ~6MLa8UrxQCMLptu~PzL59hAtorUIStw,AQECAAE/foo/0/',
+ #)
+ c.run()
+
+ #testUskPutData()
+
def testConfigData():
from fcp2_0_config import Config
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-08 08:36:54
|
Revision: 172
http://fclient.svn.sourceforge.net/fclient/?rev=172&view=rev
Author: jurner
Date: 2008-02-08 00:36:59 -0800 (Fri, 08 Feb 2008)
Log Message:
-----------
run() would hang when GetData[Persistence] is not connection. fixed
removed RequestStatus.Started and event.RequestStarted. We can not know that
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-07 23:49:44 UTC (rev 171)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-08 08:36:59 UTC (rev 172)
@@ -62,7 +62,6 @@
"""
-
#Bug reports filed and open:
#--------------------------------------------------------------------------------------------------------------------------------------------
# [0001931: Send EndListPersistentRequests following client connect]
@@ -167,7 +166,6 @@
from fcp2_0_requests import Upload
from fcp2_0_uri import Uri
-
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
#**********************************************************************
# helpers
@@ -874,8 +872,23 @@
initialRequest['FcDataLength'] = msg.get('DataLength', '')
# except from GetData all requests are complete here. Next GetData will run through AllData...
- if initialRequest['FcRequestType'] != consts.RequestType.GetData:
- self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
+
+ # For GetData with persistence != connection the node sends no All Data message
+ # whatever that is good for ..fix this here to get all GetData request to complete on
+ # All Data, too.
+ # Note: All other requests are completed here.
+ if initialRequest['FcRequestType'] == consts.RequestType.GetData:
+ if initialRequest['Persistence'] != consts.Persistence.Connection:
+ self.sendMessage(
+ consts.Message.GetRequestStatus,
+ Identifier=initialRequest['Identifier'],
+ Global=False,
+ OnlyData=True
+ )
+ else:
+ self._finalizeRequest(msg, initialRequest, self.events.RequestCompleted)
+
+
return True
@@ -917,22 +930,14 @@
# restore request
self._requests[requestIdentifier] = restoredRequest
- restoredRequest['FcRequestStatus'] |= consts.RequestStatus.Started
+ #restoredRequest['FcRequestStatus'] |= consts.RequestStatus.Null
self.events.RequestRestored(restoredRequest)
return True
- # known request... filter out multiple PersistentGets
- if not initialRequest['FcRequestStatus'] & consts.RequestStatus.Started:
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Started
-
- #TODO: update initialRequest with params from PersistentGet?
-
- self.events.RequestStarted(initialRequest)
- return True
+ # known request ..we don't handle that
+ return False
- return True
-
elif msg.name == consts.Message.PersistentRequestModified:
if initialRequest is None:
return False
@@ -1012,22 +1017,14 @@
# restore request
self._requests[requestIdentifier] = restoredRequest
- restoredRequest['FcRequestStatus'] = consts.RequestStatus.Started
+ #restoredRequest['FcRequestStatus'] = consts.RequestStatus.Null
self.events.RequestRestored(restoredRequest)
return True
- # known request... filter out multiple PersistentGets
- if not initialRequest['FcRequestStatus'] & consts.RequestStatus.Started:
- initialRequest['FcRequestStatus'] |= consts.RequestStatus.Started
-
- #TODO: update initialRequest with params from PersistentPut?
-
- self.events.RequestStarted(initialRequest)
- return True
-
- return True
+ # known request ..we don't handle that
+ return False
+
-
elif msg.name == consts.Message.PutFailed:
if initialRequest is None:
return False
@@ -1211,11 +1208,14 @@
# check if we have running requests. Assert False
haveRunningRequests = False
+ #print 'run'
for request in self._requests.values():
+ #print 'is completed', request.params['FcRequestStatus'] & consts.RequestStatus.Completed
if not request.params['FcRequestStatus'] & consts.RequestStatus.Completed:
haveRunningRequests = True
break
+ #print 'haveRunningRequest', haveRunningRequests
if not haveRunningRequests:
self._log.info(consts.LogMessages.AllRequestsCompleted)
break
@@ -2144,7 +2144,7 @@
identifier = c.getData(
'CHK@q4~2soHTd9SOINIoXmg~dn7LNUAOYzN1tHNHT3j4c9E,gcVRtoglEhgqN-DJolXPqJ4yX1f~1gBGh89HNWlFMWQ,AAIC--8/snow_002%20%2810%29.jpg',
- #persistence=consts.Persistence.Forever,
+ persistence=consts.Persistence.Connection,
#binaryBlob=True,
)
@@ -2242,7 +2242,7 @@
def testUskPutData():
def cb(event, request):
- insertURI = request['InsertURI']
+ insertURI = request['FcPrivateKey']
identifier = c.uskPutData(
'foo',
insertURI + 'foo/0/',
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-08 09:13:35
|
Revision: 180
http://fclient.svn.sourceforge.net/fclient/?rev=180&view=rev
Author: jurner
Date: 2008-02-08 01:13:40 -0800 (Fri, 08 Feb 2008)
Log Message:
-----------
combed a bit over Peer related stuff ++ UnknownPeerNoteType is handled now
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 09:11:42 UTC (rev 179)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-08 09:13:40 UTC (rev 180)
@@ -660,9 +660,9 @@
if requestIdentifier is None:
- #TODO: check how to handle this
- raise consts.ProtocolError(msg)
-
+ self.events.ProtocolError(msg)
+ return True
+
if initialRequest is None:
return False
@@ -1104,6 +1104,9 @@
self.events.PeerUnknown(msg)
return True
+ elif msg.name == consts.Message.UnknownPeerNoteType:
+ self.events.PeerNoteTypeUnknown(msg)
+ return True
####################################################
##
## plugins
@@ -1208,14 +1211,11 @@
# check if we have running requests. Assert False
haveRunningRequests = False
- #print 'run'
for request in self._requests.values():
- #print 'is completed', request.params['FcRequestStatus'] & consts.RequestStatus.Completed
if not request.params['FcRequestStatus'] & consts.RequestStatus.Completed:
haveRunningRequests = True
break
- #print 'haveRunningRequest', haveRunningRequests
if not haveRunningRequests:
self._log.info(consts.LogMessages.AllRequestsCompleted)
break
@@ -1939,9 +1939,9 @@
)
- def listPeer(self, nodeIdentity):
+ def listPeer(self, identity):
"""Requests information about a peer node
- @param nodeIdentity: identity of the peer to request information for
+ @param identity: identity of the peer to request information for
"""
self.sendMessage(
consts.Message.ListPeer,
@@ -1949,16 +1949,16 @@
)
- def listPeerNotes(self, nodeIdentity):
+ def listPeerNotes(self, identity):
"""Lists all text notes associated to a peer
- @param nodeIdentity: peer as returned in a call to L{listPeer}
+ @param identity: peer as returned in a call to L{listPeer}
@event: ListPeerNote(event, params)
@event: EndListPeerNotes(event, params)
@note: listPeerNotes() is only available for darknet nodes
"""
self.sendMessage(
consts.Message.ListPeerNotes,
- NodeIdentifier=nodeIdentity
+ NodeIdentifier=identity
)
@@ -1978,16 +1978,18 @@
- def modifyPeer(self, nodeIdentifier, allowLocalAddresses=None, isDisabled=None, isListenOnly=None):
+ def modifyPeer(self, identitty, allowLocalAddresses=None, isDisabled=None, isListenOnly=None):
"""Modifies a peer node
- @param nodeIdentifier: identitfier of the peer node to modify
+ @param identitty: identity of the peer node to modify
@param allowLocalAddresses: if True, whatever is done
@param isDisabled: if True, the peer is disabled
@param isListenOnly: if True, the peer is set to listen only status
+
+ @note: you can only modify darknet peers
"""
msg = Message(
consts.Message.ModifyPeer,
- NodeIdentifier=nodeidentifier,
+ NodeIdentifier=identity,
)
if allowLocalAddresses is not None:
msg['AllowLocalAddresses'] = allowLocalAddresses
@@ -1998,27 +2000,29 @@
self.sendMessageEx(msg)
- def modifyPeerNote(self, nodeIdentifier, note):
+ def modifyPeerNote(self, identity, note):
"""Modifies the note associated to a peer
- @param nodeIdentifier: identitifier of the peer node to modify
+ @param identity: identity of the peer node to modify
@param note: (str) new note to associate to the peer
+
+ @note: you can only modify notes of darknet peers
"""
self.sendMessage(
consts.Message.ModifyPeerNote,
- NodeIdentifier=nodeIdentifier,
+ NodeIdentifier=identity,
#NOTE: currently fcp supports only this one type
PeerNoteType=consts.PeerNoteType.Private,
NoteText=note
)
- def removePeer(self, nodeIdentifier):
+ def removePeer(self, identity):
"""Removes a peer
- @param nodeIdentifier: identitfier of the peer node to remove
+ @param identity: identity of the peer node to remove
"""
self.sendMessage(
consts.Message.RemovePeer,
- NodeIdentifier=nodeidentifier,
+ NodeIdentifier=identity,
)
##########################################################
@@ -2356,8 +2360,16 @@
def testListPeers():
+
+ def peerCb(event, msg):
+ c.listPeerNotes(msg['identity'])
+
+ c.events.Peer += peerCb
c.listPeers()
- for i in xrange(10):
+
+
+
+ for i in xrange(50):
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-08 13:34:36
|
Revision: 182
http://fclient.svn.sourceforge.net/fclient/?rev=182&view=rev
Author: jurner
Date: 2008-02-08 05:34:41 -0800 (Fri, 08 Feb 2008)
Log Message:
-----------
now all requests are registered via registerReques()
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 09:13:54 UTC (rev 181)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-08 13:34:41 UTC (rev 182)
@@ -10,22 +10,23 @@
should ever do so. Global is evil.
-Sample code, request data of a freenet key::
-
+Sample code. Connect to the freenet node::
client = FcpClient()
nodeHello = client.connect()
if nodeHello is None:
pass
# something went wrong ..could not connect to the freenet node
else:
- # request data associated to a freenet key
- myRequestIdentifier = client.getData('CHK@ABCDE.......')
- myRequest = c.getRequest(myIdentifier)
- c.run()
- print myRequest.data
+ pass
+ # everything went well ..we are connected now
-Usually you would connect handlers to client events to do processing or handle errors::
+Request data associated to a freenet key::
+ myRequestIdentifier = client.getData('CHK@ABCDE.......')
+ myRequest = c.getRequest(myIdentifier)
+ client.run()
+ print myRequest.data
+Usually you would connect handlers to client events to do processing or handle errors::
def handleSuccess(event, request):
print 'Here is the data:', request.data
@@ -40,7 +41,6 @@
Instead of calling run() you may run the client step by step::
-
client.getData('CHK@ABCDE.......')
for i in xrange(50):
client.next()
@@ -132,6 +132,7 @@
#------------------------------------------------------------------------------------------------------------------------------------------------
import atexit
+import copy
import cPickle
import logging
import os
@@ -284,54 +285,6 @@
## private methods
##
###############################################################
- def _addFcParamsToRequest(self,
- msg,
- userData,
- msgType,
- initTime,
- persistentUserData,
- filenameCollision,
- ):
-
- # add additional params to msg
- msg.params.update({
-
- # persistent params that will go into identifier
- 'FcRequestType': msgType, # identifies sub message types
- 'FcInitTime': initTime, # when was the request started?
- 'FcFilenameCollision': filenameCollision, # handle fielanem collisions?
- 'FcPersistentUserData': persistentUserData, # any user defined persistent data
-
- # non persistent params
- 'FcRequestStatus': consts.RequestStatus.Null,
- 'FcErrorMessage': None, # error message in case an error occured
- 'FcUserData': userData, # any user defined runtime data here
-
- # params for SSKKeypair
- 'FcInsertUri': None,
- 'FcRequestUri': None,
-
- # params from DataFound
- 'FcMetadataContentType': '', # contecnt type
- 'FcDataLength': '', # content size
-
- # params from PersistentRequestModified
- 'FcModified': {},
-
- # params for DDA test
- 'FcTestDDA': {},
-
- # params for SimpleProgress
- 'FcProgressTotal': '0',
- 'FcProgressRequired': '0',
- 'FcProgressFailed': '0',
- 'FcProgressFatalyFailed': '0',
- 'FcProgressSucceeeded': '0',
-
- })
- return msg
-
-
def _finalizeRequest(self, msg, request, event):
"""Finalzes a request
@param msg: message that is the reason for finalizing
@@ -362,71 +315,92 @@
def _registerRequest(self,
msg,
- userData,
- msgType,
- initTime,
- persistentUserData,
+ requestType,
+ userData=None,
+ identifier=None,
+ initTime=None,
+ persistentUserData='',
filenameCollision=consts.FilenameCollision.HandleNever,
):
"""Registers a request
@param msg: message to register
- @param userData: any user defined data
- @param msgType: one of the message sub type consts
- @param initTime: (python time)
- @param persistentUserData: (str) user defined persistent data
- @param filenameCollision: (bool)
-
- @return: (str) uuid
+ @param requestType: (L{consts.RequestType}) type of request to register
+ @param filenameCollision: (L{consts.FilenameCollision}) how to handle filename collisions.
+ Default is L{consts.FilenameCollision.HandleNever}
+ @param identifier: (str) identifier of the request or None to create a new one
+ @param initTime: (int) init time of the request or None to set it to now
+ @param persistentUserData: (str) anyuser defined persistent data
+ @param userData: (any) any user defined non persistent data
+
+ @return: (str) identifer of therequest
@note: the identifier returned is unique to the client but may not be unique to the node
"""
- identifier = self.FcParams.newUuid(uuids=self._requests)
+ identifier = self.FcParams.newUuid(uuids=self._requests) if identifier is None else identifier
- # add additional params to msg
- msg = self._addFcParamsToRequest(
- msg,
- userData,
- msgType,
- initTime,
- persistentUserData,
- filenameCollision,
- )
+ if requestType & (consts.RequestType.MaskGet | consts.RequestType.MaskPut):
+
+ msg.params.update({
- msg['ClientToken'] = self.FcParams.messageToParams(msg)
+ # persistent params that will go into identifier
+ 'FcRequestType': requestType, # identifies sub message types
+ 'FcInitTime': time.time() if initTime is None else initTime, # when was the request started?
+ 'FcFilenameCollision': filenameCollision, # handle fielanem collisions?
+ 'FcPersistentUserData': persistentUserData, # any user defined persistent data
+
+ # non persistent params
+ 'FcRequestStatus': consts.RequestStatus.Pending,
+ 'FcErrorMessage': None, # error message in case an error occured
+ 'FcUserData': userData, # any user defined runtime data here
+
+ # params for SSKKeypair
+ 'FcInsertUri': None,
+ 'FcRequestUri': None,
+
+ # params from DataFound
+ 'FcMetadataContentType': '', # contecnt type
+ 'FcDataLength': '', # content size
+
+ # params from PersistentRequestModified
+ 'FcModified': {},
+
+ # params for DDA test
+ 'FcTestDDA': {},
+
+ # params for SimpleProgress
+ 'FcProgressTotal': '0',
+ 'FcProgressRequired': '0',
+ 'FcProgressFailed': '0',
+ 'FcProgressFatalyFailed': '0',
+ 'FcProgressSucceeeded': '0',
+
+ })
+ # equip msg with some persistent pparams
+ if msg.get('ClientToken', None) is None:
+ msg['ClientToken'] = self.FcParams.messageToParams(msg)
+
+ elif requestType & consts.RequestType.MaskGenerateKeypair:
+ msg.params.update({
+ 'FcRequestType': requestType, # identifies sub message types
+ 'FcRequestStatus': consts.RequestStatus.Pending,
+ 'FcInitTime': initTime, # when was the request started?
+ 'FcModified': {},
+
+ 'FcPrivateKey': None,
+ 'FcPublicKey': None,
+ })
+
+ else:
+ msg.params.update({
+ 'FcRequestType': requestType, # identifies sub message types
+ 'FcRequestStatus': consts.RequestStatus.Pending,
+ 'FcInitTime': initTime, # when was the request started?
+ 'FcModified': {},
+ })
+
msg['FcRequestStatus'] |= consts.RequestStatus.Pending
msg['Identifier'] = identifier
self._requests[identifier] = msg
-
-
- def _restorePersistentRequestFromNode(self, msg):
- """Preps a message from node to be restored
- @return: the restored message if everything went well, None otherwise
- """
- fcParams = self.FcParams.paramsFromRequest(msg)
- if fcParams is None:
- return None
-
- # add additional params to msg
- msg = self._addFcParamsToRequest(
- msg,
- None, # userData,
- fcParams[self.FcParams.ISubType],
- fcParams[self.FcParams.IInitTime],
- fcParams[self.FcParams.IPersistentUserData],
- fcParams[self.FcParams.IFilenameCollision],
- )
-
- #FIX: remove Started param from PersistentGet / Put
- if msg.name == consts.Message.PersistentGet:
- del msg.params['Started']
- #FIX: [0001965: Persistence vs PersistenceType]
- if 'PersistenceType' in msg.params:
- msg['Persistence'] = msg.params.pop('PersistenceType')
- elif msg.name == consts.Message.PersistentPut:
- del msg.params['Started']
-
- return msg
-
###############################################################
##
## connection related methods
@@ -914,24 +888,36 @@
# unknown request... try to restore it
if initialRequest is None:
- restoredRequest = self._restorePersistentRequestFromNode(msg)
-
+ fcParams = self.FcParams.paramsFromRequest(msg)
+
# not one of our requests... so cancel it
- if restoredRequest is None or CancelPersistentRequests:
+ if fcParams is None or CancelPersistentRequests:
self.sendMessage(
consts.Message.RemovePersistentRequest,
- Identifier=msg['Identifier'],
+ Identifier=requestIdentifier,
Global=msg['Global'],
)
return True
- # determine initial message name
- restoredRequest.name = consts.Message.ClientGet
-
- # restore request
- self._requests[requestIdentifier] = restoredRequest
- #restoredRequest['FcRequestStatus'] |= consts.RequestStatus.Null
- self.events.RequestRestored(restoredRequest)
+ initialRequest = copy.deepcopy(msg)
+ self._registerRequest(
+ initialRequest,
+ fcParams[self.FcParams.IRequestType],
+ identifier=requestIdentifier,
+ initTime=fcParams[self.FcParams.IInitTime],
+ userData=None,
+ persistentUserData=fcParams[self.FcParams.IPersistentUserData],
+ filenameCollision=fcParams[self.FcParams.IFilenameCollision],
+ )
+
+ initialRequest.name = consts.Message.ClientGet
+ #FIX: remove Started param from PersistentGet / Put
+ del initialRequest.params['Started']
+ #FIX: [0001965: Persistence vs PersistenceType]
+ if 'PersistenceType' in initialRequest.params:
+ initialRequest['Persistence'] = initialRequest.params.pop('PersistenceType')
+ initialRequest['FcRequestStatus'] = consts.RequestStatus.Null
+ self.events.RequestRestored(initialRequest)
return True
# known request ..we don't handle that
@@ -996,29 +982,41 @@
# unknown request... try to restore it
if initialRequest is None:
- restoredRequest = self._restorePersistentRequestFromNode(msg)
-
+ fcParams = self.FcParams.paramsFromRequest(msg)
+
# not one of our requests... so cancel it
- if restoredRequest is None or CancelPersistentRequests:
+ if fcParams is None or CancelPersistentRequests:
self.sendMessage(
consts.Message.RemovePersistentRequest,
- Identifier=msg['Identifier'],
+ Identifier=requestIdentifier,
Global=msg['Global'],
)
return True
- # determine initial message name
- if restoredRequest['FcRequestType'] == consts.RequestType.Put:
- restoredRequest.name = consts.Message.ClientPut
- elif restoredRequest['FcRequestType'] == consts.RequestType.PutDiskDir:
- restoredRequest.name = consts.Message.ClientPutDiskDir
- elif restoredRequest['FcRequestType'] == consts.RequestType.PutComplexDir:
- restoredRequest.name = consts.Message.ClientPutComplexDir
+ initialRequest = copy.deepcopy(msg)
+ requestType = fcParams[self.FcParams.IRequestType]
+ self._registerRequest(
+ initialRequest,
+ requestType,
+ identifier=requestIdentifier,
+ initTime=fcParams[self.FcParams.IInitTime],
+ userData=None,
+ persistentUserData=fcParams[self.FcParams.IPersistentUserData],
+ filenameCollision=fcParams[self.FcParams.IFilenameCollision],
+ )
- # restore request
- self._requests[requestIdentifier] = restoredRequest
- #restoredRequest['FcRequestStatus'] = consts.RequestStatus.Null
- self.events.RequestRestored(restoredRequest)
+ # determine initial message name
+ if requestType == consts.RequestType.Put:
+ initialRequest.name = consts.Message.ClientPut
+ elif requestType == consts.RequestType.PutDiskDir:
+ initialRequest.name = consts.Message.ClientPutDiskDir
+ elif requestType == consts.RequestType.PutComplexDir:
+ initialRequest.name = consts.Message.ClientPutComplexDir
+
+ #FIX: remove Started param from PersistentGet / Put
+ del initialRequest.params['Started']
+ initialRequest['FcRequestStatus'] = consts.RequestStatus.Null
+ self.events.RequestRestored(initialRequest)
return True
# known request ..we don't handle that
@@ -1318,7 +1316,7 @@
########################################################
def clientGet(self,
uri,
- messageSubType,
+ requestType,
userData,
persistentUserData,
filenameCollision,
@@ -1326,7 +1324,7 @@
):
"""Requests a key from the node
@param uri: (str) uri of the file to request (may contain prefixes like 'freenet:' or 'http://')
- @param messageSubType: (L{consts.RequestType}) sub type of the message
+ @param requestType: (L{consts.RequestType}) sub type of the message
@param userData: any non persistent data to associate to the request or None
@param persistentUserData: any string to associate to the request as persistent data or None
@param filenameCollision: what to do if the disk target alreaady exists. One of the FilenameCollision.* consts
@@ -1345,11 +1343,10 @@
self._registerRequest(
msg,
- userData,
- messageSubType,
- time.time(),
- persistentUserData,
+ requestType,
filenameCollision=filenameCollision,
+ persistentUserData=persistentUserData,
+ userData=userData,
)
self.sendMessageEx(msg)
return msg['Identifier']
@@ -1595,11 +1592,9 @@
self._registerRequest(
msg,
- userData,
messageType,
- time.time(),
- persistentUserData,
- #filenameCollision=filenameCollision,
+ persistentUserData=persistentUserData,
+ userData=userData,
)
if upload.keyType in (consts.KeyType.SSK, consts.KeyType.USK):
@@ -1612,7 +1607,7 @@
def clientPut(self,
uri,
- messageSubType,
+ requestType,
userData,
persistentUserData,
data,
@@ -1629,21 +1624,15 @@
self._registerRequest(
msg,
- userData,
- messageSubType,
- time.time(),
- persistentUserData,
- #filenameCollision=filenameCollision,
+ requestType,
+ persistentUserData=persistentUserData,
+ userData=userData,
)
self.sendMessageEx(msg)
return msg['Identifier']
- #TODO: method names
-
#CHK
-
-
def chkPutData(self,
data,
@@ -1897,21 +1886,23 @@
or L{consts.Message.ClientPluginMessages}. All attempts to resend other requests will fail
@note: the request passed is not removed in the call. Use L{removeRequest} if necessary
"""
- if requestMessage.name in consts.Message.ClientKeyRequestMessages:
+ requestType = requestMessage.get('FcRequestType', None)
+ if requestType is None:
+ raise ValueError('Can not resend request: %s' % requestMessage.name)
+
+ if requestType & (consts.RequestType.MaskGet | consts.RequestType.MaskPut):
self._registerRequest(
requestMessage,
- requestMessage['FcUserData'],
- requestMessage['FcMessageSubType'],
- time.time(), # TOSO: reset init time?
- requestMessage['FcPersistentUserData'],
- requestMessage['FcFilenameCollision'] & consts.FilenameCollision.MaskHandle,
+ requestType,
+ filenameCollision=requestMessage['FcFilenameCollision'] & consts.FilenameCollision.MaskHandle,
+ #initTime=time.time(), # TODO: reset init time or not?
+ persistentUserData=requestMessage['FcPersistentUserData'],
+ userData=requestMessage['FcUserData'],
)
- elif requestMessage.name in consts.Message.ClientPluginMessages:
- identifier = self.FcParam.newUuid(uuids=self._requests)
- initialRequest['Identifier'] = identifier
- self._requests[identifier] = initialRequest
+ elif requestType & (consts.RequestType.MaskGenerateKeypair | onsts.RequestType.MaskPlugin):
+ self._registerRequest(requestMessage, requestType)
else:
- raise ValueError('Can not resend request: %s' % requestMessage.name)
+ raise ValueError('Should not have ended here')
self.sendMessageEx(msg)
return requestMessage['Identifier']
@@ -2038,18 +2029,10 @@
"""
identifier = self.FcParam.newUuid(uuids=self._requests)
msg = self.Message(
- consts.Message.GetPluginInfo,
-
- FcErrorMessage=None,
- FcModified={},
- FcRequestType=consts.RequestType.PluginInfo,
- FcRequestStatus=consts.RequestStatus.Pending,
-
- Identifier=identifier,
PluginName=pluginName,
Detailed=detailed,
)
- self._requests[identifier] = msg
+ self._registerRequest(msg, consts.Message.GetPluginInfo)
self.sendMessageEx(msg)
return identifier
@@ -2064,21 +2047,13 @@
identifier = self.FcParam.newUuid(uuids=self._requests)
msg = self.Message(
consts.Message.GetPluginInfo,
-
- FcErrorMessage=None,
- FcModified={},
- FcRequestType=consts.RequestType.PluginMessage,
- FcRequestStatus=consts.RequestStatus.Pending,
-
- Identifier=identifier,
PluginName=pluginName,
**params
)
if data is not None:
msg['DataLength'] = len(data)
msg.data = data
-
- self._requests[identifier] = msg
+ self._registerRequest(msg, onsts.RequestType.PluginMessage)
self.sendMessageEx(msg)
return identifier
@@ -2107,16 +2082,8 @@
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,
- FcModified={},
- FcPrivateKey= None,
- FcPublicKey=None,
- FcRequestStatus=consts.RequestStatus.Pending,
- FcRequestType=requestType,
- Identifier=identifier,
- )
- self._requests[identifier] = msg
+ msg = self.Message(consts.Message.GenerateSSK)
+ self._registerRequest(msg, requestType)
self.sendMessageEx(msg)
return identifier
@@ -2344,7 +2311,9 @@
def testGenerateKeypair():
def cb(event, msg):
- print msg.pprint()
+ print '--------------------------------'
+ print '>>>>privateKey:', msg['FcPrivateKey']
+ print '>>>>publicKey:', msg['FcPublicKey']
pass
c.events.KeypairGenerated += cb
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.
|
|
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-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-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-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 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-16 10:05:30
|
Revision: 213
http://fclient.svn.sourceforge.net/fclient/?rev=213&view=rev
Author: jurner
Date: 2008-02-16 02:05:34 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
bit more work on uploads. Still not decided how to process.
++ some fixes
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 15:59:48 UTC (rev 212)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-16 10:05:34 UTC (rev 213)
@@ -152,8 +152,16 @@
# x. Fcp seems to use kibibytes. Autoconvert to kilobytes?
#
#------------------------------------------------------------------------------------------------------------------------------------------------
+# logging
+#
+# x. should uris (...) always be visible in log output? Certainly in memory. Maybe a specialized
+# "save" logger could be useful (like for user feedback).
+#
+#------------------------------------------------------------------------------------------------------------------------------------------------
+
+
import atexit
import copy
import cPickle
@@ -266,7 +274,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 = 32768 #TODO: 32k
+ MaxSizeKeyInfo = 32768
SocketTimeout = 0.1
ExpectedFcpVersion = 2.0
ExpectedNodeBuild = 1107
@@ -293,7 +301,7 @@
self._ddaTests = [] # currently running DDA tests (request0, ... requestN)
self._requests = {} # currently running requests (requestIdentifier --> request)
- self._log = logging.getLogger(self.__class__.__name__)
+ self._log = logging.getLogger(consts.LoggerNames.Client)
self._nodeHelloMessage = None
self._socket = None
@@ -402,8 +410,8 @@
'FcUserData': userData, # any user defined runtime data here
# params for SSKKeypair
- 'FcInsertUri': None,
- 'FcRequestUri': None,
+ 'FcPrivateKey': None,
+ 'FcPublicKey': None,
# params from DataFound
'FcMetadataContentType': '', # contecnt type
@@ -1071,11 +1079,11 @@
)
# determine initial message name
- if requestType == consts.RequestType.Put:
+ if requestType in (consts.RequestType.PutData, consts.RequestType.PutFile):
initialRequest.name = consts.Message.ClientPut
- elif requestType == consts.RequestType.PutDiskDir:
+ elif requestType == consts.RequestType.PutDir:
initialRequest.name = consts.Message.ClientPutDiskDir
- elif requestType == consts.RequestType.PutComplexDir:
+ elif requestType == consts.RequestType.PutMultiple:
initialRequest.name = consts.Message.ClientPutComplexDir
#FIX: remove Started param from PersistentGet / Put
@@ -1344,7 +1352,6 @@
## config related methods
##
#########################################################
- #TODO: WithDefault never returns defaults
def getConfig(self,
withCurrent=True,
withDefaults=True,
@@ -1645,28 +1652,20 @@
########################################################
def putUpload(self, upload, userData=None, persistentUserData=''):
- msg = upload.getMessage(self.Message)
- if msg is None:
+ requestType, msg = upload.getMessage(self.Message)
+ if requestType is None:
raise ValueError('Nothing to upload')
- # determine SubType
- if msg.name == consts.Message.ClientPut:
- messageType = consts.RequestType.Put
- elif msg.name == consts.Message.ClientPutDiskDir:
- messageType = consts.RequestType.PutDiskDir
- else:
- messageType = consts.RequestType.PutComplexDir
-
self._registerRequest(
msg,
- messageType,
+ requestType,
persistentUserData=persistentUserData,
userData=userData,
)
if upload.keyType in (consts.KeyType.SSK, consts.KeyType.USK):
- msg['FcInsertUri'] = upload.privateKey
- #NOTE: the caller may use the 'FcInsertUri' member to store the private key
+ msg['FcPrivateKey'] = upload.privateKey
+ #NOTE: the caller may use the 'FcPrivateKey' member to store the private key
self.sendMessageEx(msg)
@@ -1678,11 +1677,18 @@
data=None,
persistentUserData='',
userData=None,
-
+ items=None,
**messageParams
):
- msg = self.Message(consts.Message.ClientPut, URI=uri)
+ if requestType in (consts.Message.ClientPutData, consts.Message.ClientPutFile):
+ msgName = consts.Message.ClientPut
+ elif requestType == consts.Message.ClientPutDir:
+ msgName = consts.Message.ClientPutDiskDir
+ else:
+ msgName = consts.Message.ClientPutComplexDir
+
+ msg = self.Message(msgName, URI=uri)
for paramName, value in messageParams.items():
if value is not None:
if paramName == 'ContentType':
@@ -1691,6 +1697,10 @@
if data is not None:
msg.data = data
+ if items:
+ pass
+
+
self._registerRequest(
msg,
requestType,
@@ -1720,7 +1730,7 @@
@param data: ()
"""
return self.clientPut(
- consts.RequestType.Put,
+ consts.RequestType.PutData,
consts.KeyType.CHK,
data=data,
@@ -1742,9 +1752,50 @@
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
- def chkPutDir(self):
+ def chkPutDir(self,
+ directory,
+ allowUnreadableFiles=False,
+ contentType=None,
+ defaultName=None,
+ dontCompress=None,
+ maxRetries=None,
+ persistence=consts.Persistence.Connection,
+ priorityClass=consts.Priority.Medium,
+ targetFilename=None,
+
+ userData=None,
+ persistentUserData='',
+
+ ):
+ """
+ @param TargetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
+ """
- pass
+ return self.clientPut(
+ consts.RequestType.PutDir,
+ consts.KeyType.CHK,
+
+ data=None,
+ persistentUserData=persistentUserData,
+ userData=userData,
+
+
+ # fcp params
+ Filename=directory,
+ AllowUnreadableFiles=allowUnreadableFiles,
+ ContentType=contentType,
+ DefaultName=defaultName,
+ #EarlyEncode='false',
+ #GetCHKOnly='false',
+ Global=False,
+ Identifier=None,
+ MaxRetries=maxRetries,
+ DontCompress=dontCompress,
+ Persistence=persistence,
+ TergetFilename=targetFilename,
+ UploadFrom=consts.UploadFrom.Disk,
+ Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
+ )
def chkPutFile(self,
@@ -1765,7 +1816,7 @@
"""
return self.clientPut(
- consts.RequestType.Put,
+ consts.RequestType.PutFile,
consts.KeyType.CHK,
data=None,
@@ -1790,21 +1841,52 @@
def chkPutMultiple(self,
+ directory,
items,
+
+ allowUnreadableFiles=False,
+ contentType=None,
defaultName=None,
- ):
+ dontCompress=None,
+ maxRetries=None,
+ persistence=consts.Persistence.Connection,
+ priorityClass=consts.Priority.Medium,
+ targetFilename=None,
+
+ userData=None,
+ persistentUserData='',
+
+ ):
+ """
+ @param TargetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
+ """
- msg = self.Message(
- consts.PutComplexDir,
- URI=consts.KeyType.CHK
+ return self.clientPut(
+ consts.RequestType.PutMultiple,
+ consts.KeyType.CHK,
+
+ data=None,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ items=items,
+
+ # fcp params
+ Filename=directory,
+ AllowUnreadableFiles=allowUnreadableFiles,
+ ContentType=contentType,
+ DefaultName=defaultName,
+ #EarlyEncode='false',
+ #GetCHKOnly='false',
+ Global=False,
+ Identifier=None,
+ MaxRetries=maxRetries,
+ DontCompress=dontCompress,
+ Persistence=persistence,
+ TergetFilename=targetFilename,
+ UploadFrom=consts.UploadFrom.Disk,
+ Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
-
- for n, item in enumerate(items):
-
- for paramName, value in item.items():
- pass
-
########################################################
##
## SSK ClientPut related methods
@@ -2200,7 +2282,7 @@
connectionName='test',
debugVerbosity=consts.DebugVerbosity.Debug
)
- log = c.getLogger()
+ #log = c.getLogger()
fpath = os.path.join(Dir, 'test.log')
handler = logging.FileHandler(fpath, 'w')
logging.getLogger('').addHandler(handler)
@@ -2291,12 +2373,12 @@
#c.sendMessage(c.consts.Message.GetRequestStatus, Identifier=identifier)
c.events.RequestCompleted += cb
- for i in xrange(55):
- c.next()
+ #for i in xrange(55):
+ # c.next()
#c.removeRequest(identifier)
#for i in xrange(5):
# c.next()
- c.events.RequestCompleted -= cb
+ c.run()
#testGetKeyInfo()
@@ -2390,6 +2472,9 @@
from fcp2_0_config import Config
def cb(event, msg):
+
+ #print msg['current.fcp.persistentDownloadsInterval']
+ #return
root=Config(configDataMsg=msg)
print
@@ -2420,7 +2505,31 @@
#testConfigData()
+ #testConfigData()
+
+ def testModifyConfig():
+
+ from fcp2_0_config import Config
+
+ def cb(event, msg):
+ print msg['current.logger.interval']
+ #print msg['current.fcp.persistentDownloadsInterval']
+
+ c.setDebugVerbosity(c.consts.DebugVerbosity.Warning)
+
+ c.events.ConfigData += cb
+ #c.modifyConfig({'fcp.persistentDownloadsInterval': '3000000h'})
+
+ c.modifyConfig({'logger.interval': '1'})
+
+ for i in xrange(10):
+ c.next()
+
+ #testModifyConfig()
+
+
+
def testNodeData():
def cb(event, msg):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 13:30:12
|
Revision: 229
http://fclient.svn.sourceforge.net/fclient/?rev=229&view=rev
Author: jurner
Date: 2008-02-18 05:30:13 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
added aome more loggers
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-18 13:28:30 UTC (rev 228)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-18 13:30:13 UTC (rev 229)
@@ -301,13 +301,16 @@
self._ddaTests = [] # currently running DDA tests (request0, ... requestN)
self._requests = {} # currently running requests (requestIdentifier --> request)
- self._log = logging.getLogger(consts.LoggerNames.Client)
+ self._logEvent = logging.getLogger(consts.LoggerNames.ClientEvents)
+ self._logMessage = logging.getLogger(consts.LoggerNames.ClientMessages)
+ self._logRuntime = logging.getLogger(consts.LoggerNames.ClientRuntime)
+
self._nodeHelloMessage = None
self._socket = None
-
+
self.events = Events()
for event in self.events:
- event += self._logEvent
+ event += self._captureEvent
self.setDebugVerbosity(consts.DebugVerbosity.Warning if debugVerbosity is None else debugVerbosity)
atexit.register(self.close)
@@ -322,7 +325,7 @@
"""Closes the client
@param msg: message to pass to the ClientDisconnected event or None to not inform listeners
"""
- self._log.info(consts.LogMessages.ClientClose)
+ self._logRuntime.info(consts.LogMessages.ClientClose)
# clean left over DDA test tmp files
for initialRequest in self._ddaTests:
@@ -471,9 +474,9 @@
self._requests[identifier] = msg
- def _logEvent(self, event, request):
+ def _captureEvent(self, event, request):
if event != self.events.Idle:
- self._log.debug(consts.LogMessages.EventTriggered + event.name)
+ self._logEvent.debug(consts.LogMessages.EventTriggered + event.name)
###############################################################
##
@@ -523,7 +526,7 @@
@event: ClientConnected(event, message) is triggered as soon as the client is connected
"""
- self._log.info(consts.LogMessages.Connecting)
+ self._logRuntime.info(consts.LogMessages.Connecting)
# try to Connect socket
if self._socket is not None:
@@ -543,7 +546,7 @@
except socket.error, d:
yield None
else:
- self._log.info(consts.LogMessages.Connected)
+ self._logRuntime.info(consts.LogMessages.Connected)
# send ClientHello and wait for NodeHello
#NOTE: thought I could leave ClientHelloing up to the caller
@@ -564,7 +567,7 @@
elif msg.name == consts.Message.NodeHello:
self._nodeHelloMessage = msg
- self._log.debug(consts.LogMessages.MessageReceived + msg.pprint())
+ self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
# check if version is ok
if self.versionCheckNodeHello(msg):
self.events.ClientConnected(msg)
@@ -579,16 +582,16 @@
raise StopIteration
else:
- self._log.debug(consts.LogMessages.MessageReceived + msg.pprint())
+ self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
break
break
# continue polling
- self._log.info(consts.LogMessages.ConnectionRetry)
+ self._logRuntime.info(consts.LogMessages.ConnectionRetry)
timeElapsed += timeout
time.sleep(timeout)
- self._log.info(consts.LogMessages.ConnectingFailed)
+ self._logRuntime.info(consts.LogMessages.ConnectingFailed)
disconnectMsg = self.Message(
consts.Message.ClientDisconnected,
DisconnectReason=consts.DisconnectReason.ConnectingFailed,
@@ -604,7 +607,7 @@
"""
return self._connectionName
-
+
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
@@ -618,7 +621,7 @@
"""Sets the verbosity level of the client
@note: see L{consts.DebugVerbosity}
"""
- self._log.setLevel(debugVerbosity)
+ self._logMessage.setLevel(debugVerbosity)
def startFreenet(self, cmdline):
@@ -663,7 +666,7 @@
if msg.name == consts.Message.ClientSocketTimeout:
return True
- self._log.debug(consts.LogMessages.MessageReceived + msg.pprint())
+ self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
# check if we have an initial request corrosponding to msg
requestIdentifier = msg.get('Identifier', None)
@@ -1253,7 +1256,7 @@
"""
msg = self.Message.fromSocket(self._socket)
if msg.name == consts.Message.ClientSocketDied:
- self._log.critical(consts.LogMessages.SocketDied)
+ self._logRuntime.critical(consts.LogMessages.SocketDied)
if dispatch:
disconnectMsg = self.Message(
consts.Message.ClientDisconnected,
@@ -1290,13 +1293,13 @@
break
if not haveRunningRequests:
- self._log.info(consts.LogMessages.AllRequestsCompleted)
+ self._logRuntime.info(consts.LogMessages.AllRequestsCompleted)
break
try:
msg = self.next()
except KeyboardInterrupt:
- self._log.info(consts.LogMessages.KeyboardInterrupt)
+ self._logRuntime.info(consts.LogMessages.KeyboardInterrupt)
break
if msg.name == consts.Message.ClientSocketDied:
@@ -1330,11 +1333,11 @@
@note: you can use this method to send a message to the node, bypassing all
track keeping methods of the client
"""
- self._log.debug(consts.LogMessages.MessageSend + msg.pprint())
+ self._logMessage.debug(consts.LogMessages.MessageSend + msg.pprint())
try:
msg.send(self._socket)
except socket.error, d:
- self._log.critical(consts.LogMessages.SocketDied)
+ self._logRuntime.critical(consts.LogMessages.SocketDied)
disconnectMsg = self.Message(
consts.Message.ClientDisconnected,
DisconnectReason=consts.DisconnectReason.SocketDied,
@@ -1642,6 +1645,41 @@
self.sendMessageEx(msg)
return msg['Identifier']
+
+ def putRedirect(self,
+ name,
+ targetURI,
+
+ maxRetries=None,
+ persistence=consts.Persistence.Connection,
+ priorityClass=consts.Priority.Medium,
+
+ userData=None,
+ persistentUserData='',
+ ):
+ """Uploads a redirect
+ @param name: name of the redirect
+ @param targetURI: (str) uri to redirect to
+ @return: (str) request identifier
+ """
+ msg = self.Message(
+ consts.Message.ClientPut,
+ URI=consts.KeyType.KSK + name,
+ Persistence=persistence,
+ PriorityClass=priorityClass,
+ TargetURI=targetURI,
+ UploadFrom=consts.UploadFrom.Redirect,
+ )
+ self._registerRequest(
+ msg,
+ consts.RequestType.PutRedirect,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ )
+ self.sendMessageEx(msg)
+ return msg['Identifier']
+
+
########################################################
##
## CHK ClientPut related methods
@@ -1678,9 +1716,9 @@
**messageParams
):
- if requestType in (consts.Message.ClientPutData, consts.Message.ClientPutFile):
+ if requestType in (consts.RequestType.PutData, consts.RequestType.PutFile):
msgName = consts.Message.ClientPut
- elif requestType == consts.Message.ClientPutDir:
+ elif requestType == consts.RequestType.PutDir:
msgName = consts.Message.ClientPutDiskDir
else:
msgName = consts.Message.ClientPutComplexDir
@@ -1744,6 +1782,7 @@
MaxRetries=maxRetries,
DontCompress=dontCompress,
Persistence=persistence,
+ PriorityClass=priorityClass,
TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Direct,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
@@ -1789,7 +1828,8 @@
MaxRetries=maxRetries,
DontCompress=dontCompress,
Persistence=persistence,
- TergetFilename=targetFilename,
+ PriorityClass=priorityClass,
+ TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Disk,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
@@ -1831,14 +1871,14 @@
MaxRetries=maxRetries,
DontCompress=dontCompress,
Persistence=persistence,
- TergetFilename=targetFilename,
+ PriorityClass=priorityClass,
+ TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Disk,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
def chkPutMultiple(self,
- directory,
items,
allowUnreadableFiles=False,
@@ -1854,8 +1894,14 @@
persistentUserData='',
):
- """
+ """Uploads multiple items at once
+
+ @param items:
+
@param TargetFilename: (str) filename to append to the CHK key or None (may not contain slashes)
+
+
+
"""
return self.clientPut(
@@ -1880,7 +1926,8 @@
MaxRetries=maxRetries,
DontCompress=dontCompress,
Persistence=persistence,
- TergetFilename=targetFilename,
+ PriorityClass=priorityClass,
+ TargetFilename=targetFilename,
UploadFrom=consts.UploadFrom.Disk,
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
@@ -1924,9 +1971,9 @@
):
return self.clientPut(
+ consts.RequestType.PutData,
insertURI,
#insertURI + 'foo/0/',
- consts.RequestType.Put,
userData,
persistentUserData,
data,
@@ -2279,10 +2326,12 @@
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)
+ #formatter = logging.Formatter('%(name)s:%(levelname)s:%(funcName)s:%(message)s')
+ #handler.setFormatter(formatter)
+ logging.getLogger('Fcp.Client').addHandler(handler)
nodeHello = c.connect()
@@ -2380,9 +2429,62 @@
#testGetKeyInfo()
+ def testPutRedirect():
+
+
+
+
+ def cb(event, msg):
+ if event == c.events.RequestCompleted:
+
+ identifier = c.putRedirect(
+ 'HaHaHa',
+ msg['URI']
+ )
+
+ pass
+ #c.sendMessage(c.consts.Message.GetRequestStatus, Identifier=identifier)
+ #print msg['FcErrorMessage']
+
+
+ c.events.RequestCompleted += cb
+ c.events.RequestFailed += cb
+
+ #c.chkPutData('HaHaHaHa')
+
+ #identifier = c.putRedirect(
+ # 'foo',
+ # 'USK@zQyF2O1o8B4y40w7Twz8y2I9haW3d2DTlxjTHPu7zc8,h2mhQNNE9aQvF~2yKAmKV1uorr7141-QOroBf5hrlbw,AQACAAE/AnotherIndex/0/',
+ #'foo/bar'
+ #persistence=c.consts.Persistence.Reboot,
+ # )
+
+ #c.sendMessage(
+ # consts.Message.ClientPut,
+ # Identifier='blah',
+ # URI='KSK@foo',
+ # TargetURI='USK@zQyF2O1o8B4y40w7Twz8y2I9haW3d2DTlxjTHPu7zc8,h2mhQNNE9aQvF~2yKAmKV1uorr7141-QOroBf5hrlbw,AQACAAE/AnotherIndex/0/',
+ # UploadFrom='redirect',
+ # )
+
+ c.chkPutData('arggggggggg!')
+
+ #for i in xrange(55):
+ # c.next()
+ #c.removeRequest(identifier)
+ #for i in xrange(5):
+ # c.next()
+ c.run()
+
+ #testPutRedirect()
+
+
+
+
+
def testChkPutData():
myIdentifier = c.chkPutData(
- 'test123',
+ 'test123hahaha',
#persistence=c.Persistence.Reboot,
)
@@ -2394,11 +2496,9 @@
# c.next()
#testChkPutData()
-
-
def testChkPutFile():
fpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.jpg')
@@ -2421,9 +2521,9 @@
myIdentifier = c.uskPutData(
'foo',
insertURI + 'foo/0/',
- persistence=consts.Persistence.Reboot,
+ #persistence=consts.Persistence.Reboot,
)
- c.removeRequest(myIdentifier)
+ #c.removeRequest(myIdentifier)
c.events.KeypairGenerated += cb
c.generateKeypair(keypairType=consts.KeyType.USK)
@@ -2432,10 +2532,10 @@
#'foo1',
#'USK@dkbB9DSr6R2WWs0MFsB9BJvN2cRjNxSboanDQNMJVNc,uIi9-1JrCLZ~6MLa8UrxQCMLptu~PzL59hAtorUIStw,AQECAAE/foo/0/',
#)
- #c.run()
+ c.run()
- for i in xrange(700):
- 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-18 13:44:20
|
Revision: 231
http://fclient.svn.sourceforge.net/fclient/?rev=231&view=rev
Author: jurner
Date: 2008-02-18 05:44:25 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
added a todo
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-18 13:37:05 UTC (rev 230)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-18 13:44:25 UTC (rev 231)
@@ -150,6 +150,7 @@
# Fcp types vs. Python types
#
# x. Fcp seems to use kibibytes. Autoconvert to kilobytes?
+# x. time intervals
#
#------------------------------------------------------------------------------------------------------------------------------------------------
# logging
@@ -158,10 +159,15 @@
# "save" logger could be useful (like for user feedback).
#
#------------------------------------------------------------------------------------------------------------------------------------------------
+# runtime
+#
+# x. if the socket dies the client disconnects automatically, clearing all requests.
+# No idea how to handle this. Would require at least an EndListPersistentRequest
+# from the node to check wich requests arrived at the node ..and an auto resend
+# requests the node does not know about.
+#
+#------------------------------------------------------------------------------------------------------------------------------------------------
-
-
-
import atexit
import copy
import cPickle
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-18 21:59:36
|
Revision: 232
http://fclient.svn.sourceforge.net/fclient/?rev=232&view=rev
Author: jurner
Date: 2008-02-18 13:59:40 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
a few fixes
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-18 13:44:25 UTC (rev 231)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-18 21:59:40 UTC (rev 232)
@@ -544,7 +544,7 @@
# try to Connect socket
if self._socket is not None:
- self.close()
+ self._close(None)
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._socket.settimeout(self.SocketTimeout)
try:
@@ -573,7 +573,6 @@
elif msg.name == consts.Message.NodeHello:
self._nodeHelloMessage = msg
- self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
# check if version is ok
if self.versionCheckNodeHello(msg):
self.events.ClientConnected(msg)
@@ -672,10 +671,6 @@
CancelPersistentRequests = 0 # for testing... if True, cancels all PersistentRequests
- if msg.name == consts.Message.ClientSocketTimeout:
- return True
- self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
-
# check if we have an initial request corrosponding to msg
requestIdentifier = msg.get('Identifier', None)
initialRequest = None if requestIdentifier is None else self._requests.get(requestIdentifier, None)
@@ -1278,6 +1273,7 @@
if dispatch:
self.events.Idle(msg)
else:
+ self._logMessage.debug(consts.LogMessages.MessageReceived + msg.pprint())
if dispatch:
self.handleMessage(msg)
return msg
@@ -1867,8 +1863,7 @@
data=None,
persistentUserData=persistentUserData,
userData=userData,
-
-
+
# fcp params
Filename=filename,
ContentType=contentType,
@@ -1982,9 +1977,9 @@
consts.RequestType.PutData,
insertURI,
#insertURI + 'foo/0/',
- userData,
- persistentUserData,
- data,
+ userData=userData,
+ persistentUserData=persistentUserData,
+ data=data,
# fcp params
ContentType=contentType,
@@ -2205,7 +2200,6 @@
)
-
def modifyPeer(self, identitty, allowLocalAddresses=None, isDisabled=None, isListenOnly=None):
"""Modifies a peer node
@param identitty: identity of the peer node to modify
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-20 17:48:44
|
Revision: 235
http://fclient.svn.sourceforge.net/fclient/?rev=235&view=rev
Author: jurner
Date: 2008-02-20 09:48:09 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
fix: run() method now waits a while to see if persistent requests are waiting
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-18 22:00:55 UTC (rev 234)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-20 17:48:09 UTC (rev 235)
@@ -281,6 +281,7 @@
# basic sizes of keys are: 1k for SSks and 32k for CHKs
# without MaxSize DataFound will have DataLength set to 0 (?!)
MaxSizeKeyInfo = 32768
+ MinimumRunTime = 1 # minimum time (seconds) the client will run when run() is called (FIX: 0001931)
SocketTimeout = 0.1
ExpectedFcpVersion = 2.0
ExpectedNodeBuild = 1107
@@ -923,7 +924,6 @@
# For GetData with persistence != connection the node sends no All Data message
# whatever that is good for ..fix this here to get all GetData request to complete on
# All Data, too.
- # Note: All other requests are completed here.
if initialRequest['FcRequestType'] == consts.RequestType.GetData:
if initialRequest['Persistence'] != consts.Persistence.Connection:
self.sendMessage(
@@ -1284,11 +1284,23 @@
@note: a KeyboardInterrupt will stop the client
"""
+ #FIX: 0001931
+ # poll a few times to see if there are persistent requests waiting
+ t0 = time.time()
+ while time.time() - t0 <= self.MinimumRunTime:
+ try:
+ msg = self.next()
+ except KeyboardInterrupt:
+ self._logRuntime.info(consts.LogMessages.KeyboardInterrupt)
+ return
+ if msg.name == consts.Message.ClientSocketDied:
+ return
+
#n = 0
while True:
#n += 1
#if n > 50: break
-
+
# check if we have running requests. Assert False
haveRunningRequests = False
for request in self._requests.values():
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-24 11:48:13
|
Revision: 244
http://fclient.svn.sourceforge.net/fclient/?rev=244&view=rev
Author: jurner
Date: 2008-02-24 03:48:04 -0800 (Sun, 24 Feb 2008)
Log Message:
-----------
continued working on uploads
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-23 08:18:18 UTC (rev 243)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-24 11:48:04 UTC (rev 244)
@@ -1661,67 +1661,12 @@
self.sendMessageEx(msg)
return msg['Identifier']
-
- def putRedirect(self,
- name,
- targetURI,
-
- maxRetries=None,
- persistence=consts.Persistence.Connection,
- priorityClass=consts.Priority.Medium,
-
- userData=None,
- persistentUserData='',
- ):
- """Uploads a redirect
- @param name: name of the redirect
- @param targetURI: (str) uri to redirect to
- @return: (str) request identifier
- """
- msg = self.Message(
- consts.Message.ClientPut,
- URI=consts.KeyType.KSK + name,
- Persistence=persistence,
- PriorityClass=priorityClass,
- TargetURI=targetURI,
- UploadFrom=consts.UploadFrom.Redirect,
- )
- self._registerRequest(
- msg,
- consts.RequestType.PutRedirect,
- persistentUserData=persistentUserData,
- userData=userData,
- )
- self.sendMessageEx(msg)
- return msg['Identifier']
-
########################################################
##
## CHK ClientPut related methods
##
########################################################
- def putUpload(self, upload, userData=None, persistentUserData=''):
-
- requestType, msg = upload.getMessage(self.Message)
- if requestType is None:
- raise ValueError('Nothing to upload')
-
- self._registerRequest(
- msg,
- requestType,
- persistentUserData=persistentUserData,
- userData=userData,
- )
-
- if upload.keyType in (consts.KeyType.SSK, consts.KeyType.USK):
- msg['FcPrivateKey'] = upload.privateKey
- #NOTE: the caller may use the 'FcPrivateKey' member to store the private key
-
-
- self.sendMessageEx(msg)
- return msg['Identifier']
-
def clientPut(self,
requestType,
uri,
@@ -1729,29 +1674,94 @@
persistentUserData='',
userData=None,
items=None,
- **messageParams
+ **msgParams
):
+ """Uploads to the node
+ @param requestType: (L{consts.RequestType}). Can be PutData, PutDir or PutMultiple
+ @param uri:
+ @param data: (str) for L{consts.RequestType.PutData} data to upload or None
+ @param persistentUserData: (str) persistent data to be assosiated to the request
+ @param userdata: (any) any data to be associated to the request at runtime
+ @param items: for L{consts.RequestType.PutMultiple}, items to upload
+ @param msgParams: (dict) Fcp parameters to pass along with the message
+ @note: the Fcp message parameter 'Metadata.ContentType' may be passed as 'ContentType'
+ to this method
+ @note: to upload multiple items at once (see: PutComplexDir) pass a dict for each item
+ containig the following members:
+
+ - FcRequestType: L{consts.RequestType.PutData}, L{consts.RequestType.PutFile} or L{consts.RequestType.PutRedirect}
+ - Data: if requestType is L{consts.RequestType.PutData}, data to upload
+ - Filename: if requestType is L{consts.RequestType.PutFile}, filepath of the file to upload
+ - TargetURI: if requestType is L{consts.RequestType.PutRedirect}, uri to redirect to
+ - Name: name under wich the item will be accesible via freenet
+ - Metadata.ContentType: (optional) may be passed as 'ContentType'
+
+ All items will be accessible under one single key as 'Uri/Name'. The default item (the item when
+ only 'Uri' is requested from freenet) is always the first item in the list.
+ """
if requestType in (consts.RequestType.PutData, consts.RequestType.PutFile):
msgName = consts.Message.ClientPut
elif requestType == consts.RequestType.PutDir:
msgName = consts.Message.ClientPutDiskDir
+ elif requestType == consts.RequestType.PutMultiple:
+ msgName = consts.Message.ClientPutComplexDir
else:
- msgName = consts.Message.ClientPutComplexDir
-
+ raise ValueError('Unsupported request type')
+
msg = self.Message(msgName, URI=uri)
- for paramName, value in messageParams.items():
+ contentType = msgParams.get('ContentType', None)
+ if contentType is not None:
+ del msgParams['ContentType']
+ msgParams['Metadata.ContentType'] = contentType
+ for param, value in msgParams.items():
if value is not None:
- if paramName == 'ContentType':
- param = 'Metadata.ContentType'
- msg[paramName] = value
+ msg[param] = value
+
if data is not None:
+ if requestType != consts.RequestType.PutData:
+ raise ValueError('Data can only be passed along with PutData uploads')
msg.data = data
- if items:
- pass
-
-
+ if items is not None:
+ mapping = {
+ consts.RequestType.PutData: consts.UploadFrom.Direct,
+ consts.RequestType.PutFile: consts.UploadFrom.Disk,
+ consts.RequestType.PutRedirect: consts.UploadFrom.Redirect,
+ }
+
+ if requestType != consts.RequestType.PutMultiple:
+ raise ValueError('Items can only be passed along with PutMultiple uploads')
+
+ data = ''
+ for n, item in enumerate(items):
+ requestType = item.get('FcRequestType', None)
+ if requestType is None:
+ raise ValueError('No request type specified for item: %s' % n)
+ uploadFrom = mapping.get(requestType, None)
+ if uploadFrom is None:
+ raise valueError('Unsupported request type for item %s: %s' % (n, requestType))
+
+ contentType = item.get('ContentType', None)
+ if conetntType is not None:
+ del msgParams['ContentType']
+ item['Metadata.ContentType'] = contentType
+
+ msg.params['Files.%s.UploadFrom' % n] = uploadFrom
+ for param, value in item.items():
+ if param.startswith('Fc'):
+ continue
+ elif param == 'Data':
+ data += data
+ msg.params['Files.%s.DataLength' % n] = len(data)
+ continue
+ msg.params['Files.%s.%s' % (n, param)] = value
+
+ msg['DefaultName'] = items[0].get('Name', '')
+ if data:
+ msg.data = data
+
+ #
self._registerRequest(
msg,
requestType,
@@ -1762,6 +1772,42 @@
return msg['Identifier']
+ def putRedirect(self,
+ name,
+ targetURI,
+ maxRetries=None,
+ persistence=consts.Persistence.Connection,
+ priorityClass=consts.Priority.Medium,
+ userData=None,
+ persistentUserData='',
+ ):
+ """Uploads a redirect to another key
+ @param name: name of the redirect
+ @param targetURI: (str) uri to redirect to
+ @param maxRetries: (int) maximum number of tretries or -1 to leave the decission up to the node
+ @param persistence: (L{consts.Persistence}) of the request
+ @param priority: (L{consts.Priority}) priority of the request
+ @param persistentUserData: (str) persistent data to be assosiated to the request
+ @param userdata: (any) any data to be associated to the request at runtime
+ @return: (str) request identifier
+ """
+ msg = self.Message(
+ consts.Message.ClientPut,
+ URI=consts.KeyType.KSK + name,
+ Persistence=persistence,
+ PriorityClass=priorityClass,
+ TargetURI=targetURI,
+ UploadFrom=consts.UploadFrom.Redirect,
+ )
+ self._registerRequest(
+ msg,
+ consts.RequestType.PutRedirect,
+ persistentUserData=persistentUserData,
+ userData=userData,
+ )
+ self.sendMessageEx(msg)
+ return msg['Identifier']
+
#CHK
def chkPutData(self,
data,
@@ -1970,8 +2016,8 @@
##
########################################################
def uskPutData(self,
+ insertURI,
data,
- insertURI,
contentType=None,
dontCompress=None,
@@ -1982,9 +2028,12 @@
userData=None,
persistentUserData=''
-
-
):
+ """Uploads data
+
+ """
+
+
return self.clientPut(
consts.RequestType.PutData,
insertURI,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ju...@us...> - 2008-02-26 09:07:35
|
Revision: 248
http://fclient.svn.sourceforge.net/fclient/?rev=248&view=rev
Author: jurner
Date: 2008-02-26 01:07:39 -0800 (Tue, 26 Feb 2008)
Log Message:
-----------
moved helpers to fcp_lib/tools module
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-24 11:52:23 UTC (rev 247)
+++ trunk/sandbox/fcp/fcp2_0_client.py 2008-02-26 09:07:39 UTC (rev 248)
@@ -214,65 +214,12 @@
from fcp2_0_config import Config
from fcp2_0_message import Message
import fcp2_0_params as FcParams
-from fcp2_0_requests import Upload
from fcp2_0_uri import Uri
-logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
-#**********************************************************************
-# helpers
-#**********************************************************************
-def saveReadFile(fpath):
- """Reads contents of a file in the savest manner possible
- @param fpath: file to write
- @return: contents of the file if successful, None otherwise
- """
- read = None
- try:
- fp = open(fpath, 'rb')
- except: pass
- else:
- try:
- read = fp.read()
- except: pass
- fp.close()
- return read
+from fcp_lib import tools
-def saveRemoveFile(fpath):
- """Savely removes a file
- @param fpath: filepath of the file to remove or None
- @return: True if the file was removed, False otherwise
- """
- if fpath is not None:
- if os.path.isfile(fpath):
- try:
- os.remove(fpath)
- except Exception, d:
- pass
- else:
- return True
- return False
-
-def saveWriteFile(fpath, data):
- """Writes data to a file in the savest manner possible
- @param fpath: file to write
- @param data: data to write to file
- @return: True if successful, False otherwise
- """
- written = False
- try:
- fp = open(fpath, 'wb')
- except: pass
- else:
- try:
- fp.write(data)
- written = True
- except:
- fp.Close()
- else:
- fp.close()
- return written
-
+logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
#*************************************************************************************************
#
#*************************************************************************************************
@@ -304,10 +251,8 @@
Message = Message
FcParams = FcParams
Uri = Uri
- Upload = Upload
+
-
-
def __init__(self,
connectionName=None,
debugVerbosity=None,
@@ -350,7 +295,7 @@
# 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'])
+ tools.saveRemoveFile(initialRequest['FcTestDDA']['TmpFile'])
self._ddaTests = []
self._requests = {}
@@ -738,8 +683,7 @@
ddaRequestMsg['WantReadDirectory'] = True
directory = os.path.dirname(initialRequest['Filename'])
ddaRequestMsg['Directory'] = directory
-
-
+
# add params required for testing
initialRequest['FcTestDDA'] = {
'Directory': directory,
@@ -824,16 +768,16 @@
fpathRead = msg.params.get('ReadFilename', None)
readContent = ''
if fpathRead is not None:
- readContent = saveReadFile(fpathRead)
+ readContent = tools.saveReadFile(fpathRead)
if readContent is None:
readContent = ''
# perform write test if necessary
fpathWrite = msg.params.get('WriteFilename', None)
if fpathWrite is not None:
- written = saveWriteFile(fpathWrite, msg['ContentToWrite'])
+ written = tools.saveWriteFile(fpathWrite, msg['ContentToWrite'])
if not written:
- saveRemoveFile(fpathWrite)
+ tools.saveRemoveFile(fpathWrite)
else:
initialRequest['FcTestDDA']['TmpFile'] = fpathWrite
@@ -861,7 +805,7 @@
# remove test and clean tmp data
self._ddaTests.remove(initialRequest)
if initialRequest['FcTestDDA']['TmpFile'] is not None:
- saveRemoveFile(initialRequest['FcTestDDA']['TmpFile'])
+ tools.saveRemoveFile(initialRequest['FcTestDDA']['TmpFile'])
wantWrite = initialRequest.params['FcTestDDA']['WantWrite']
# check if test was sucessful
@@ -881,9 +825,7 @@
# else: resend message
self.sendMessageEx(initialRequest)
return True
-
-
-
+
####################################################
##
## config related
@@ -896,8 +838,7 @@
elif msg.name == consts.Message.NodeData:
self.events.NodeData(msg)
return True
-
-
+
####################################################
##
## get / put related
@@ -1424,8 +1365,6 @@
If the value of a keyword is None, it is ignored.
@return: (str) identifier of the request
-
-
"""
uri = self.Uri(uri).uri
msg = self.Message(consts.Message.ClientGet, URI=uri)
@@ -1645,7 +1584,7 @@
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 ???
+ @param dontPoll: if True, does whatever ???
@return: (str) identifer of the request
@note: this request can not be removed or modified and the {consts.RequestStatus.Completed}
@@ -1681,7 +1620,7 @@
@param uri:
@param data: (str) for L{consts.RequestType.PutData} data to upload or None
@param persistentUserData: (str) persistent data to be assosiated to the request
- @param userdata: (any) any data to be associated to the request at runtime
+ @param userData: (any) any data to be associated to the request at runtime
@param items: for L{consts.RequestType.PutMultiple}, items to upload
@param msgParams: (dict) Fcp parameters to pass along with the message
@@ -1771,7 +1710,7 @@
self.sendMessageEx(msg)
return msg['Identifier']
-
+
def putRedirect(self,
name,
targetURI,
@@ -1786,9 +1725,9 @@
@param targetURI: (str) uri to redirect to
@param maxRetries: (int) maximum number of tretries or -1 to leave the decission up to the node
@param persistence: (L{consts.Persistence}) of the request
- @param priority: (L{consts.Priority}) priority of the request
+ @param priorityClass: (L{consts.Priority}) priority of the request
@param persistentUserData: (str) persistent data to be assosiated to the request
- @param userdata: (any) any data to be associated to the request at runtime
+ @param userData: (any) any data to be associated to the request at runtime
@return: (str) request identifier
"""
msg = self.Message(
@@ -1850,6 +1789,7 @@
Verbosity=consts.Verbosity.ReportProgress | consts.Verbosity.ReportCompression,
)
+
def chkPutDir(self,
directory,
allowUnreadableFiles=False,
@@ -1866,9 +1806,8 @@
):
"""
- @param TargetFilename: (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.PutDir,
consts.KeyType.CHK,
@@ -1876,8 +1815,7 @@
data=None,
persistentUserData=persistentUserData,
userData=userData,
-
-
+
# fcp params
Filename=directory,
AllowUnreadableFiles=allowUnreadableFiles,
@@ -1911,7 +1849,7 @@
):
"""
- @param TargetFilename: (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(
@@ -1959,12 +1897,11 @@
@param items:
- @param TargetFilename: (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.PutMultiple,
consts.KeyType.CHK,
@@ -1973,8 +1910,7 @@
persistentUserData=persistentUserData,
userData=userData,
items=items,
-
-
+
# fcp params
Filename=directory,
AllowUnreadableFiles=allowUnreadableFiles,
@@ -2097,7 +2033,7 @@
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.
+ All attempts to do so are ignored. Too bad, but doing so is not implemented in the client protocol.
"""
initialRequest = self._requests[requestIdentifier]
@@ -2169,8 +2105,8 @@
@note: you can use this method to resend get / put requests.All attempts to resend other requests
will fail
- @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
+ @note: actually a new request is created and registered. Todo so, the request passed is copied. If it is a persistent
+ request, it will be removed. The new request will have FcInitTime reset and FcUserData amd FcPersistentUserData
taken over from the old request
"""
requestType = request.get('FcRequestType', consts.RequestType.Null)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|