SF.net SVN: fclient: [21] trunk/fclient/fclient_lib/fcp/fcp2_0.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2007-10-28 22:44:18
|
Revision: 21
http://fclient.svn.sourceforge.net/fclient/?rev=21&view=rev
Author: jUrner
Date: 2007-10-28 15:44:22 -0700 (Sun, 28 Oct 2007)
Log Message:
-----------
added some fixed identifier prefixes to avoid collisions
Modified Paths:
--------------
trunk/fclient/fclient_lib/fcp/fcp2_0.py
Modified: trunk/fclient/fclient_lib/fcp/fcp2_0.py
===================================================================
--- trunk/fclient/fclient_lib/fcp/fcp2_0.py 2007-10-28 21:56:19 UTC (rev 20)
+++ trunk/fclient/fclient_lib/fcp/fcp2_0.py 2007-10-28 22:44:22 UTC (rev 21)
@@ -131,6 +131,9 @@
PriorityDefault = Bulk
+#TODO: no idea how fcp handles strings as in <Peer volatile.status=CONNECTED>
+# all I could find in the sources where these constants as in PEER_NODE_STATUS_CONNECTED
+# in --> freenet/node/PeerManager.java
class PeerNodeStatus:
Connected = 1
RoutingBackedOff = 2
@@ -147,6 +150,18 @@
Disconnecting = 13
+#TODO: see if we can get away with these to avoid collisions. TestDDA uses no prefix
+# cos ProtocolError 7 passes the directory as identifier and there is no other hint
+# that the error is related to TestDDA.
+class IdentifierPrefix:
+ """Identifier prefixes"""
+
+ ClientGet = 'ClientGet::'
+ #TestDDA = ''
+ PeerNote = 'PeerNote::'
+
+
+
#************************************************************************************
# exceptions
#************************************************************************************
@@ -656,7 +671,8 @@
def toString(self):
"""Returns the message as formated string ready to be send"""
- # TODO: "Data" not yet implemented
+
+ #TODO: just a guess, so maybe remove this check
if isinstance(self.name, (int, long)):
raise ValueError('You can not send client internal messages to the node')
out = [self.name, ]
@@ -841,7 +857,7 @@
Message.ListPeerNotes,
NodeIdentifier=identifier
)
- JobBase.__init__(self, fcpClient, identifier, message)
+ JobBase.__init__(self, fcpClient, IdentifierPrefix.PeerNote + identifier, message)
def handleStart(self):
@@ -906,7 +922,7 @@
string and size may not be accurate.
"""
- identifier = newIdentifier()
+ identifier = IdentifierPrefix.ClientGet + newIdentifier()
message = Message(
Message.ClientGet,
Identifier=identifier,
@@ -1158,8 +1174,6 @@
#TODO: no idea what happens on reconnect if socket died. What about running jobs?
#TODO: name as specified in NodeHello seems to be usable to keep jobs alive. Have to test this.
-#TODO: no idea if to add support for pending jobs and queue management here
-#
#TODO: do not mix directories as identifiers with identifiers (might lead to collisions)
#TODO: how to handle (ProtocolError code 18: Shutting down)?
class FcpClient(events.Events):
@@ -1290,6 +1304,8 @@
return self.jobDispatchMessage(FixedJobIdentifiers.ClientHello, msg)
elif code == ProtocolError.ShuttingDown:
+
+ #TODO: ??? why dispatch to ClientHello.. can't remember
if not self.jobDispatchMessage(FixedJobIdentifiers.ClientHello, msg):
# ########################################
@@ -1308,39 +1324,26 @@
else:
# check if the is something like an identifier in the message
- #TODO: we run into troubles when using directories and NodeIdentifiers as identifiers
- # have to maintain extra queues to prevent this. jobDispatchMessage(queue='directories')
if msg.name == Message.TestDDAReply:
identifier = msg['Directory']
elif msg.name == Message.TestDDAComplete:
identifier = msg['Directory']
elif msg.name == Message.PeerNote:
- identifier = msg['NodeIdentifier']
+ identifier = IdentifierPrefix.PeerNote + msg['NodeIdentifier']
elif msg.name == Message.EndListPeerNotes:
- identifier = msg['NodeIdentifier']
-
+ identifier = IdentifierPrefix.PeerNote + msg['NodeIdentifier']
else:
identifier = msg.get('Identifier', None)
# dispatch to jobs with fixed identifiers
if identifier is None:
-
if msg.name == Message.NodeHello:
return self.jobDispatchMessage(FixedJobIdentifiers.ClientHello, msg)
-
elif msg.name == Message.EndListPeers:
return self.jobDispatchMessage(FixedJobIdentifiers.ListPeers, msg)
-
elif msg.name == Message.Peer:
return self.jobDispatchMessage(FixedJobIdentifiers.ListPeers, msg)
- #elif msg.name == Message.PeerNote:
- # return self.jobDispatchMessage(FixedJobIdentifiers.ListPeerNotes, msg)
-
- #elif msg.name == Message.EndListPeerNotes:
- # return self.jobDispatchMessage(FixedJobIdentifiers.ListPeerNotes, msg)
-
-
# more here.....
else:
@@ -1349,7 +1352,7 @@
else:
return self.jobDispatchMessage(identifier, msg)
- raise RuntimeError('Should not have endet here: %s' % msg.name)
+ raise RuntimeError('We should not have gotten here: %s' % msg.name)
@@ -1670,14 +1673,8 @@
#foo()
- def foo():
- job = JobGenerateSSK(c)
- c.jobAdd(job, synchron=True)
- print job.jobResult
- #foo()
-
+
-
def foo():
d = os.path.dirname(os.path.abspath(__file__))
job2 = JobTestDDA(c, d)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|