SF.net SVN: fclient: [104] trunk/sandbox/fcp/fcp2_0_message.py
Status: Pre-Alpha
Brought to you by:
jurner
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. |