Thread: SF.net SVN: fclient: [80] trunk/sandbox/fcp/fcp2_0_message.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <ju...@us...> - 2008-01-28 11:20:55
|
Revision: 80 http://fclient.svn.sourceforge.net/fclient/?rev=80&view=rev Author: jurner Date: 2008-01-28 03:20:59 -0800 (Mon, 28 Jan 2008) Log Message: ----------- ... Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-01-27 02:16:50 UTC (rev 79) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-01-28 11:20:59 UTC (rev 80) @@ -82,10 +82,10 @@ # some additional consts SubTypeNone = 0 - SubTypeGetKeyInfo = 1 + SubTypeGetData = 1 SubTypeGetFile = 2 - SubTypeGetData = 3 - SubTypePutFile = 4 + SubTypeGetKeyInfo = 3 + SubTypePutData = 4 SubTypePutDiskDir = 5 SubTypePutComplexDir = 6 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-01-29 11:27:27
|
Revision: 84 http://fclient.svn.sourceforge.net/fclient/?rev=84&view=rev Author: jurner Date: 2008-01-29 03:27:31 -0800 (Tue, 29 Jan 2008) Log Message: ----------- Started implementing python <--> fcp value type mapping Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-01-29 11:27:08 UTC (rev 83) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-01-29 11:27:31 UTC (rev 84) @@ -1,6 +1,8 @@ """Freennet Client Protocol message""" import socket + +from fcp2_0_consts import MessageParamTypes #******************************************************************************** # #******************************************************************************** @@ -151,6 +153,7 @@ msg = clss(None) buf = [] + paramTypes = None #TODO: to buffer or not to buffer? while True: @@ -176,6 +179,8 @@ # first line == message name if msg.name is None: msg.name = line + paramTypes = MessageParamTypes.get(line, None) + # get data member elif line == 'Data': @@ -192,6 +197,13 @@ # get next paramater else: head, sep, tail = line.partition('=') + + # covert fcp to python value if necessary + if paramTypes is not None: + paramType = paramTypes.get(head, None) + if paramType is not None: + tail = paramType.fcpToPython(tail) + msg.params[head] = tail # TODO: errorchek params? #if not sep: pass @@ -217,9 +229,18 @@ def pprint(self): """Returns the message as nicely formated human readable string""" out = ['', '>>' + self.name, ] + paramTypes = MessageParamTypes.get(self.name, None) + for param, value in self.params.items(): if param.startswith(self.ParamPrefixPrivate): continue + + # convert python to fcp value if necessary + if paramTypes is not None: + paramType = paramTypes.get(param, None) + if paramType is not None: + value = paramType.pythonToFcp(value) + out.append('>> %s=%s' % (param, value)) out.append('>>EndMessage') return '\n'.join(out) @@ -235,9 +256,18 @@ def toString(self): """Returns the message as formated string ready to be send""" out = [self.name, ] + paramTypes = MessageParamTypes.get(self.name, None) + for param, value in self.params.items(): if param.startswith(self.ParamPrefixPrivate): continue + + # convert python to fcp value if necessary + if paramTypes is not None: + paramType = paramTypes.get(param, None) + if paramType is not None: + value = paramType.pythonToFcp(value) + out.append('%s=%s' % (param, value)) if self.data: assert 'DataLength' in self.params, 'DataLength member required' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-01 14:43:33
|
Revision: 99 http://fclient.svn.sourceforge.net/fclient/?rev=99&view=rev Author: jurner Date: 2008-02-01 06:43:34 -0800 (Fri, 01 Feb 2008) Log Message: ----------- added a few message Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-01 14:43:03 UTC (rev 98) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-01 14:43:34 UTC (rev 99) @@ -11,7 +11,7 @@ # we add a few private params... - ParamPrefixPrivate = 'Fc' + ParamPrefixPrivate = 'Fc' # params prefixed with this are skipped when generating the message # client messages @@ -33,6 +33,8 @@ MessageClientPutDiskDir = 'ClientPutDiskDir' MessageClientPutComplexDir = 'ClientPutComplexDir' MessageClientGet = 'ClientGet' + MessageGetPluginInfo = 'GetPluginInfo' + MessageFCPPluginMessage = 'FCPPluginMessage' MessageSubscribeUSK = 'SubscribeUSK' MessageWatchGlobal = 'WatchGlobal' MessageGetRequestStatus = 'GetRequestStatus' @@ -75,6 +77,8 @@ MessageUnknownNodeIdentifier = 'UnknownNodeIdentifier' MessageUnknownPeerNoteType = 'UnknownPeerNoteType' MessageSubscribedUSKUpdate = 'SubscribedUSKUpdate' + MessagePluginInfo = 'PluginInfo' + MessageFCPPluginReply = 'FCPPluginReply' # client messages (internal use only) MessageClientSocketTimeout = 1 @@ -87,7 +91,7 @@ SubTypeGetData = 1 SubTypeGetFile = 2 SubTypeGetKeyInfo = 3 - SubTypePutData = 4 + SubTypePut = 4 SubTypePutDiskDir = 5 SubTypePutComplexDir = 6 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-02 05:12:11
|
Revision: 104 http://fclient.svn.sourceforge.net/fclient/?rev=104&view=rev Author: jurner Date: 2008-02-01 21:12:17 -0800 (Fri, 01 Feb 2008) Log Message: ----------- moved consts to consts module Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-02 05:11:43 UTC (rev 103) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-02 05:12:17 UTC (rev 104) @@ -1,114 +1,41 @@ -"""Freennet Client Protocol message""" +"""Freennet Client Protocol message +""" + import socket -from fcp2_0_consts import MessageParamTypes +import fcp2_0_consts as consts +import fcp2_0_types as types #******************************************************************************** # #******************************************************************************** class Message(object): - """Class wrapping a freenet message""" + """Class wrapping a Fcp message + + Sample use:: + + msg = Messsage( + consts.Message.ClientHello, + ExpectedVersion='2.0', + Name='MyConnectionName' + ) + msg['Name'] = 'another' + msg['Name'] + >> 'another' + + msg.send(mySocket) + @ivar data: data carried along with the message or None + @ivar name: message name + @ivar params: message params + """ + + # we add a few private params... ParamPrefixPrivate = 'Fc' # params prefixed with this are skipped when generating the message - - # client messages - MessageClientHello = 'ClientHello' - MessageListPeer = 'ListPeer' # (since 1045) - MessageListPeers = 'ListPeers' - MessageListPeerNotes = 'ListPeerNotes' - MessageAddPeer = 'AddPeer' - MessageModifyPeer = 'ModifyPeer' - MessageModifyPeerNote = 'ModifyPeerNote' - MessageRemovePeer = 'RemovePeer' - MessageGetNode = 'GetNode' - MessageGetConfig = 'GetConfig' # (since 1027) - MessageModifyConfig = 'ModifyConfig' # (since 1027) - MessageTestDDARequest = 'TestDDARequest' # (since 1027) - MessageTestDDAResponse = 'TestDDAResponse' # (since 1027) - MessageGenerateSSK = 'GenerateSSK' - MessageClientPut = 'ClientPut' - MessageClientPutDiskDir = 'ClientPutDiskDir' - MessageClientPutComplexDir = 'ClientPutComplexDir' - MessageClientGet = 'ClientGet' - MessageGetPluginInfo = 'GetPluginInfo' - MessageFCPPluginMessage = 'FCPPluginMessage' - MessageSubscribeUSK = 'SubscribeUSK' - MessageWatchGlobal = 'WatchGlobal' - MessageGetRequestStatus = 'GetRequestStatus' - MessageListPersistentRequests = 'ListPersistentRequests' - MessageRemovePersistentRequest = 'RemovePersistentRequest' - MessageModifyPersistentRequest = 'ModifyPersistentRequest' - MessageShutdown = 'Shutdown' - - # node messages - MessageNodeHello = 'NodeHello' - MessageCloseConnectionDuplicateClientName = 'CloseConnectionDuplicateClientName' - MessagePeer = 'Peer' - MessagePeerNote = 'PeerNote' - MessageEndListPeers = 'EndListPeers' - MessageEndListPeerNotes = 'EndListPeerNotes' - MessagePeerRemoved = 'PeerRemoved' - MessageNodeData = 'NodeData' - MessageConfigData = 'ConfigData' # (since 1027) - MessageTestDDAReply = 'TestDDAReply' # (since 1027) - MessageTestDDAComplete = 'TestDDAComplete' # (since 1027) - MessageSSKKeypair = 'SSKKeypair' - MessagePersistentGet = 'PersistentGet' - MessagePersistentPut = 'PersistentPut' - MessagePersistentPutDir = 'PersistentPutDir' - MessageURIGenerated = 'URIGenerated' - MessagePutSuccessful = 'PutSuccessful' - MessagePutFetchable = 'PutFetchable' - MessageDataFound = 'DataFound' - MessageAllData = 'AllData' - MessageStartedCompression = 'StartedCompression' - MessageFinishedCompression = 'FinishedCompression' - MessageSimpleProgress = 'SimpleProgress' - MessageEndListPersistentRequests = 'EndListPersistentRequests' - MessagePersistentRequestRemoved = 'PersistentRequestRemoved' # (since 1016) - MessagePersistentRequestModified = 'PersistentRequestModified' # (since 1016) - MessagePutFailed = 'PutFailed' - MessageGetFailed = 'GetFailed' - MessageProtocolError = 'ProtocolError' - MessageIdentifierCollision = 'IdentifierCollision' - MessageUnknownNodeIdentifier = 'UnknownNodeIdentifier' - MessageUnknownPeerNoteType = 'UnknownPeerNoteType' - MessageSubscribedUSKUpdate = 'SubscribedUSKUpdate' - MessagePluginInfo = 'PluginInfo' - MessageFCPPluginReply = 'FCPPluginReply' - # client messages (internal use only) - MessageClientSocketTimeout = 1 - MessageClientSocketDied = 2 - MessageClientDisconnected = 3 - - - # some additional consts - SubTypeNone = 0 - SubTypeGetData = 1 - SubTypeGetFile = 2 - SubTypeGetKeyInfo = 3 - SubTypePut = 4 - SubTypePutDiskDir = 5 - SubTypePutComplexDir = 6 - - StatusPending = 0x1 - StatusCompressing = 0x2 - StatusStarted = 0x4 - StatusComplete = 0x8 - StatusError = 0x10 - StatusRemoved = 0x20 - StatusRestoreFailed = 0x40 - - ModifiedRequestPersistentUserData = 0x1 - ModifiedRequestPriorityClass = 0x2 - ModifiedRequestIdentifier = 0x4 - ModifiedRequestFilename = 0x8 - - def __init__(self, name, data=None, **params): """ @param name: messge name @@ -126,8 +53,7 @@ """Reads n bytes from socket @param socketObj: socket to read bytes from @param n: (int) number of bytes to read - @return: (tuple) (error-message or None, bytes read or None) if an error occured - or no bytes could be read + @return: (tuple) (error-message, bytes-read). If no error was encountered, error-message will be None """ error = p = None try: @@ -136,9 +62,9 @@ p = None raise socket.error('Socket shut down by node') except socket.timeout, d: # nothing in the queue - error = clss(clss.MessageClientSocketTimeout) + error = clss(consts.Message.ClientSocketTimeout) except socket.error, d: - error = clss(clss.MessageClientSocketDied, Exception=socket.error, Details=d) + error = clss(consts.Message.ClientSocketDied, Exception=socket.error, Details=d) return error, p @@ -147,9 +73,8 @@ """Reads a message from a socket @param socketObj: socket to read a message from @return: L{Message} next message from the socket. If the socket dies - unexpectedly a L{ClientSocketDied} message is returned containing the parameters - 'Exception' and 'Details'. If the socket times out a L{MessageClientSocketTimout} - message is returned. + unexpectedly a L{consts.Message.ClientSocketDied} message is returned containing the parameters + 'Exception' and 'Details'. If the socket times out a L{consts.Message.ClientSocketTimeout} message is returned. @note: SocketObj can be any object that supports a sockets recv() and sendall() methods and raises the appropriate socket errors @@ -183,7 +108,7 @@ # first line == message name if msg.name is None: msg.name = line - paramTypes = MessageParamTypes.get(line, None) + paramTypes = types.MessageParamTypes.get(line, None) # get data member @@ -233,7 +158,7 @@ def pprint(self): """Returns the message as nicely formated human readable string""" out = ['', '>>' + self.name, ] - paramTypes = MessageParamTypes.get(self.name, None) + paramTypes = types.MessageParamTypes.get(self.name, None) for param, value in self.params.items(): if param.startswith(self.ParamPrefixPrivate): @@ -260,7 +185,7 @@ def toString(self): """Returns the message as formated string ready to be send""" out = [self.name, ] - paramTypes = MessageParamTypes.get(self.name, None) + paramTypes = consts.MessageParamTypes.get(self.name, None) for param, value in self.params.items(): if param.startswith(self.ParamPrefixPrivate): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-02 11:24:50
|
Revision: 109 http://fclient.svn.sourceforge.net/fclient/?rev=109&view=rev Author: jurner Date: 2008-02-02 03:24:50 -0800 (Sat, 02 Feb 2008) Log Message: ----------- typo Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-02 05:14:24 UTC (rev 108) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-02 11:24:50 UTC (rev 109) @@ -185,7 +185,7 @@ def toString(self): """Returns the message as formated string ready to be send""" out = [self.name, ] - paramTypes = consts.MessageParamTypes.get(self.name, None) + paramTypes = types.MessageParamTypes.get(self.name, None) for param, value in self.params.items(): if param.startswith(self.ParamPrefixPrivate): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-04 11:53:19
|
Revision: 137 http://fclient.svn.sourceforge.net/fclient/?rev=137&view=rev Author: jurner Date: 2008-02-04 03:53:08 -0800 (Mon, 04 Feb 2008) Log Message: ----------- remove3d checks... ClientPutComplexDir does not like them Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-04 11:51:16 UTC (rev 136) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-04 11:53:08 UTC (rev 137) @@ -199,13 +199,6 @@ out.append('%s=%s' % (param, value)) if self.data: - assert 'DataLength' in self.params, 'DataLength member required' - n = None - try: - n = int(self['DataLength']) - except ValueError: pass - assert n is not None, 'DataLength member must be an integer' - assert n == len(self.data), 'DataLength member must corrospond to lenght of data' out.append('Data') out.append(self.data) else: @@ -214,3 +207,5 @@ + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-12 15:57:04
|
Revision: 211 http://fclient.svn.sourceforge.net/fclient/?rev=211&view=rev Author: jurner Date: 2008-02-12 07:57:09 -0800 (Tue, 12 Feb 2008) Log Message: ----------- pprint now print python types not Fcp types Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-12 15:56:20 UTC (rev 210) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-12 15:57:09 UTC (rev 211) @@ -165,10 +165,10 @@ continue # convert python to fcp value if necessary - if paramTypes is not None: - paramType = paramTypes.get(param, None) - if paramType is not None: - value = paramType.pythonToFcp(value) + #if paramTypes is not None: + # paramType = paramTypes.get(param, None) + # if paramType is not None: + # value = paramType.pythonToFcp(value) out.append('>> %s=%s' % (param, value)) out.append('>>EndMessage') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-18 00:31:36
|
Revision: 225 http://fclient.svn.sourceforge.net/fclient/?rev=225&view=rev Author: jurner Date: 2008-02-17 16:31:25 -0800 (Sun, 17 Feb 2008) Log Message: ----------- fix: always end messages with 'EndMessage\n' Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-17 09:21:42 UTC (rev 224) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-18 00:31:25 UTC (rev 225) @@ -46,7 +46,7 @@ self.data = data self.name = name self.params = params - + @classmethod def bytesFromSocket(clss, socketObj, n): @@ -198,14 +198,8 @@ value = paramType.pythonToFcp(value) out.append('%s=%s' % (param, value)) - if self.data: - out.append('Data') - out.append(self.data) - else: - out.append('EndMessage\n') + + out.append('EndMessage') + out.append(self.data if self.data is not None else '') return '\n'.join(out) - - - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-18 22:00:17
|
Revision: 233 http://fclient.svn.sourceforge.net/fclient/?rev=233&view=rev Author: jurner Date: 2008-02-18 14:00:15 -0800 (Mon, 18 Feb 2008) Log Message: ----------- beautifications Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-18 21:59:40 UTC (rev 232) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-18 22:00:15 UTC (rev 233) @@ -171,6 +171,8 @@ # value = paramType.pythonToFcp(value) out.append('>> %s=%s' % (param, value)) + + #TODO: append data? out.append('>>EndMessage') return '\n'.join(out) @@ -200,6 +202,7 @@ out.append('%s=%s' % (param, value)) out.append('EndMessage') - out.append(self.data if self.data is not None else '') + out.append('' if self.data is None else self.data) return '\n'.join(out) - + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-02-21 13:14:20
|
Revision: 240 http://fclient.svn.sourceforge.net/fclient/?rev=240&view=rev Author: jurner Date: 2008-02-21 05:13:53 -0800 (Thu, 21 Feb 2008) Log Message: ----------- fix: messages containing data always use terminating 'Data'. Hmm ..Fcp seems to accept both... Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-21 13:12:03 UTC (rev 239) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-21 13:13:53 UTC (rev 240) @@ -29,9 +29,7 @@ @ivar name: message name @ivar params: message params """ - - - + # we add a few private params... ParamPrefixPrivate = 'Fc' # params prefixed with this are skipped when generating the message @@ -67,7 +65,7 @@ error = clss(consts.Message.ClientSocketDied, Exception=socket.error, Details=d) return error, p - + @classmethod def fromSocket(clss, socketObj): """Reads a message from a socket @@ -102,6 +100,13 @@ line = ''.join(buf) buf = [] + + + #NOTE: messages carying data may end with 'EndMessage' or 'Data'. + # This is a bit messed up in Fcp. We assume here all messages from the + # node end with Data if data is passed. Alternative would be to check for both + # and rely on the 'DataLength' member to indicate if data is included. This + # should work for all messages except 'DataFound' if line == 'EndMessage': break @@ -172,8 +177,11 @@ out.append('>> %s=%s' % (param, value)) - #TODO: append data? - out.append('>>EndMessage') + if self.data is None: + out.append('>>EndMessage') + else: + out.append('>>Data') + out.append(self.data) return '\n'.join(out) @@ -201,8 +209,14 @@ out.append('%s=%s' % (param, value)) - out.append('EndMessage') - out.append('' if self.data is None else self.data) + if self.data is None: + out.append('EndMessage\n') + else: + out.append('Data') + out.append(self.data) return '\n'.join(out) + + + 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:08:25
|
Revision: 250 http://fclient.svn.sourceforge.net/fclient/?rev=250&view=rev Author: jurner Date: 2008-02-26 01:08:23 -0800 (Tue, 26 Feb 2008) Log Message: ----------- documentation fix Modified Paths: -------------- trunk/sandbox/fcp/fcp2_0_message.py Modified: trunk/sandbox/fcp/fcp2_0_message.py =================================================================== --- trunk/sandbox/fcp/fcp2_0_message.py 2008-02-26 09:07:59 UTC (rev 249) +++ trunk/sandbox/fcp/fcp2_0_message.py 2008-02-26 09:08:23 UTC (rev 250) @@ -70,7 +70,7 @@ def fromSocket(clss, socketObj): """Reads a message from a socket @param socketObj: socket to read a message from - @return: L{Message} next message from the socket. If the socket dies + @return: (Message) next message from the socket. If the socket dies unexpectedly a L{consts.Message.ClientSocketDied} message is returned containing the parameters 'Exception' and 'Details'. If the socket times out a L{consts.Message.ClientSocketTimeout} message is returned. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |