SF.net SVN: fclient: [83] trunk/sandbox/fcp/fcp2_0_consts.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-01-29 11:27:05
|
Revision: 83
http://fclient.svn.sourceforge.net/fclient/?rev=83&view=rev
Author: jurner
Date: 2008-01-29 03:27:08 -0800 (Tue, 29 Jan 2008)
Log Message:
-----------
Started implementing python <--> fcp value type mapping
Modified Paths:
--------------
trunk/sandbox/fcp/fcp2_0_consts.py
Modified: trunk/sandbox/fcp/fcp2_0_consts.py
===================================================================
--- trunk/sandbox/fcp/fcp2_0_consts.py 2008-01-28 11:22:27 UTC (rev 82)
+++ trunk/sandbox/fcp/fcp2_0_consts.py 2008-01-29 11:27:08 UTC (rev 83)
@@ -1,6 +1,6 @@
-"""Freennet Client Protocol consts"""
+"""Freennet Client Protocol consts and type mappings"""
-
+import base64
import logging
#************************************************************************
#
@@ -24,34 +24,34 @@
)
def __str__(self): return self.value
- MaxArchiveRecursionExceeded = '1'
- UnknownSplitfileMetadata = '2'
- UnknownMetadata = '3'
- InvalidMetadata = '4'
- ArchiveFailure = '5'
- BlockDecodeError = '6'
- MaxMetadataLevelsExceeded = '7'
- MaxArchiveRestartsExceeded = '8'
- MaxRecursionLevelExceeded = '9'
- NotAnArchve = '10'
- TooManyMetastrings = '11'
- BucketError = '12'
- DataNotFound = '13'
- RouteNotFound = '14'
- RejectedOverload = '15'
- TooManyRedirects = '16'
- InternalError = '17'
- TransferFailed = '18'
- SplitfileError = '19'
- InvalidUri = '20'
+ MaxArchiveRecursionExceeded = 1
+ UnknownSplitfileMetadata = 2
+ UnknownMetadata = 3
+ InvalidMetadata = 4
+ ArchiveFailure = 5
+ BlockDecodeError = 6
+ MaxMetadataLevelsExceeded = 7
+ MaxArchiveRestartsExceeded = 8
+ MaxRecursionLevelExceeded = 9
+ NotAnArchve = 10
+ TooManyMetastrings = 11
+ BucketError = 12
+ DataNotFound = 13
+ RouteNotFound = 14
+ RejectedOverload = 15
+ TooManyRedirects = 16
+ InternalError = 17
+ TransferFailed = 18
+ SplitfileError = 19
+ InvalidUri = 20
TooBig = '21'
- MetadataTooBig = '22'
- TooManyBlocks = '23'
- NotEnoughMetastrings = '24'
- Canceled = '25'
- ArchiveRestart = '26'
- PermanentRedirect = '27'
- NotAllDataFound = '28'
+ MetadataTooBig = 22
+ TooManyBlocks = 23
+ NotEnoughMetastrings = 24
+ Canceled = 25
+ ArchiveRestart = 26
+ PermanentRedirect = 27
+ NotAllDataFound = 28
class InsertError(Exception):
@@ -68,14 +68,14 @@
)
def __str__(self): return self.value
- InvalidUri = '1'
- BucketError = '2'
- InternalError = '3'
- RejectedOverload = '4'
- RouteNotFound = '5'
- FatalErrorInBlocks = '6'
- TooManyRetriesInBlock = '7'
- RouteReallyNotFound = '8'
+ InvalidUri = 1
+ BucketError = 2
+ InternalError = 3
+ RejectedOverload = 4
+ RouteNotFound = 5
+ FatalErrorInBlocks = 6
+ TooManyRetriesInBlock = 7
+ RouteReallyNotFound = 8
Collision = '9'
Canceled = '10'
@@ -94,37 +94,37 @@
)
def __str__(self): return self.value
- ClientHelloMustBeFirst = '1'
- NoLateClientHellos = '2'
- MessageParseError = '3'
- UriParseError = '4'
- MissingField = '5'
- ErrorParsingNumber = '6'
- InvalidMessage = '7'
- InvalidField = '8'
- FileNotFound = '9'
- DiskTargetExists = '10' # handled:
- SameDirectoryExpected = '11'
- CouldNotCreateFile = '12'
- CouldNotWriteFile = '13'
- CouldNotRenameFile = '14'
- NoSuchIdentifier = '15'
- NotSupported = '16'
- InternalError = '17'
- ShuttingDown = '18' # handled:
- NoSuchNodeIdentifier = '19' # Unused since 995
- UrlParseError = '20'
- ReferenceParseError = '21'
- FileParseError = '22'
- NotAFile = '23'
- AccessDenied = '24'
- DDADenied = '25' # handled:
- CouldNotReadFile = '26'
- ReferenceSignature = '27'
- CanNotPeerWithSelf = '28'
+ ClientHelloMustBeFirst = 1
+ NoLateClientHellos = 2
+ MessageParseError = 3
+ UriParseError = 4
+ MissingField = 5
+ ErrorParsingNumber = 6
+ InvalidMessage = 7
+ InvalidField = 8
+ FileNotFound = 9
+ DiskTargetExists = 10 # handled:
+ SameDirectoryExpected = 11
+ CouldNotCreateFile = 12
+ CouldNotWriteFile = 13
+ CouldNotRenameFile = 14
+ NoSuchIdentifier = 15
+ NotSupported = 16
+ InternalError = 17
+ ShuttingDown = 18 # handled:
+ NoSuchNodeIdentifier = 19 # Unused since 995
+ UrlParseError = 20
+ ReferenceParseError = 21
+ FileParseError = 22
+ NotAFile = 23
+ AccessDenied = 24
+ DDADenied = 25 # handled:
+ CouldNotReadFile = 26
+ ReferenceSignature = 27
+ CanNotPeerWithSelf = 28
PeerExists = '29'
- OpennetDisabled = '30'
- DarknetPeerOnly = '31'
+ OpennetDisabled = 30
+ DarknetPeerOnly = 31
# others
@@ -227,15 +227,320 @@
class Verbosity:
- ReportCompletion = '0'
- ReportProgress = '1'
- ReportProgressAndCompression = '513' # 1 | 512 # ClientPut only
+ ReportCompletion = 0x0
+ ReportProgress = 0x1
+ ReportCompression = 0x200
+#*************************************************************************************
+# python <--> fcp value mappings
+#*************************************************************************************
+#TODO: reqork Clss.validateFcpValue
+FcpTrue = 'true'
+FcpFalse = 'false'
+class FcpTypeBool(object):
+
+ @classmethod
+ def pythonToFcp(clss, value):
+ return FcpTrue if value else FcpFalse
+
+ @classmethod
+ def fcpToPython(clss, value):
+ return value == FcpTrue
+
+ @classmethod
+ def validateFcpValue(clss, value):
+ if value in ('true', 'false'):
+ return str(value)
+ return None
+class FcpTypeInt(object):
+
+ @classmethod
+ def pythonToFcp(clss, value):
+ return str(value)
+
+ @classmethod
+ def fcpToPython(clss, value):
+ return int(value)
+
+ @classmethod
+ def validateFcpValue(clss, value):
+ try:
+ return int(value)
+ except ValueError:
+ return None
+
+# GetFailed sets the ExpectedDataLenght field to '' (empty string). Fix this to show up as -1
+class FcpTypeInt_GetFailed_ExpectedDataLenght(object):
+
+ @classmethod
+ def pythonToFcp(clss, value):
+ return str(value)
+
+ @classmethod
+ def fcpToPython(clss, value):
+ if value == '':
+ return -1
+ return int(value)
+
+ @classmethod
+ def validateFcpValue(clss, value):
+ if value == '':
+ return -1
+ try:
+ return int(value)
+ except ValueError:
+ return None
+
+
+class FcpTypeIntWithBounds(object):
+
+ def __init__(self, lowerBound, upperBound):
+ self.lowerBound = lowerBound
+ self.upperBound = upperBound
+
+ def pythonToFcp(self, value):
+ return str(value)
+
+ def fcpToPython(self, value):
+ return int(value)
+
+ def validateFcpValue(self, value):
+ try:
+ n = int(value)
+ except ValueError:
+ return None
+
+ if self.lowerBound is not None:
+ if n >= self.lowerBound:
+ return n
+ if self.upperBound is not None:
+ if n <= self.upperBound:
+ return n
+
+ return None
+
+
+
+class FcpTypeBase64EncodedString(object):
+
+ @classmethod
+ def pythonToFcp(clss, value):
+ return base64.encode(value)
+
+ @classmethod
+ def fcpToPython(clss, value):
+ return base64.decode(value)
+
+ @classmethod
+ def validateFcpValue(clss, value):
+ pass
+ #TODO: no idea
+
+ # we add a few private params...
+ ParamPrefixPrivate = 'Fc'
+
+
+
+class FcpTypeTime(object):
+
+ @classmethod
+ def pythonToFcp(clss, value):
+ return str(value * 1000)
+
+ @classmethod
+ def fcpToPython(clss, value):
+ return int(value) / 1000
+
+ @classmethod
+ def validateFcpValue(clss, value):
+ try:
+ return self.fcpToPython(value)
+ except ValueEror:
+ return none
+
+#***************************************************************************************
+#
+# Mapping from message params to param types
+#
+# ...being lazy here, only types that are not strings are declared
+#
+#***************************************************************************************
+MessageParamTypes = {
+
+ # client messages
+
+ 'ListPeers': {
+ 'WithMetadata': FcpTypeBool,
+ 'WithVolantile': FcpTypeBool,
+ },
+
+ #'AddPeer': {}, # ??? check
+
+ 'ModifyPeer': {
+ 'AllowLocalAddresses': FcpTypeBool,
+ 'IsDisabled': FcpTypeBool,
+ 'ListenOnly': FcpTypeBool,
+ },
+
+ 'ModifyPeerNote': {
+ 'NoteText': FcpTypeBase64EncodedString,
+ },
+
+ 'GetNode': {
+ 'GiveOpennetRef': FcpTypeBool,
+ 'WithPrivate': FcpTypeBool,
+ 'WithVolatile': FcpTypeBool,
+ },
+ 'GetConfig': {
+ 'WithCurrent': FcpTypeBool,
+ 'WithDefaults': FcpTypeBool,
+ 'WithSortOrder': FcpTypeBool,
+ 'WithExpertFlag': FcpTypeBool,
+ 'WithForceWriteFlag': FcpTypeBool,
+ 'WithShortDescription': FcpTypeBool,
+ 'WithLongDescription': FcpTypeBool,
+ },
+
+ #'ModifyConfig': # ??? check
+
+ 'TestDDARequest': {
+ 'WantReadDirectory': FcpTypeBool,
+ 'WantWriteDirectory': FcpTypeBool,
+ },
+ 'ClientPut': {
+ 'BinaryBlob': FcpTypeBool,
+ 'DontCompress': FcpTypeBool,
+ 'EarlyEncode': FcpTypeBool,
+ 'GetCHKOnly': FcpTypeBool,
+ 'Global': FcpTypeBool,
+ 'MaxRetries': FcpTypeInt,
+ 'Verbosity': FcpTypeInt,
+ },
+ 'ClientGet': {
+ 'BinaryBlob': FcpTypeBool,
+ 'Global': FcpTypeBool,
+ 'IgnoreDS': FcpTypeBool,
+ 'DSOnly': FcpTypeBool,
+ 'MaxSize': FcpTypeInt,
+ 'MaxTempSize': FcpTypeInt,
+ 'Verbosity': FcpTypeInt,
+ },
+ 'SubscribeUSK': {
+ 'DontPoll': FcpTypeBool,
+ },
+ 'WatchGlobal': {
+ 'Enabled': FcpTypeBool,
+ 'VerbosityMask': FcpTypeInt,
+ },
+ 'GetRequestStatus': {
+ 'Global': FcpTypeBool,
+ 'OnlyData': FcpTypeBool,
+ },
+ 'RemopvePersistentRequest': {
+ 'Global': FcpTypeBool,
+ },
+ 'ModifyPersistentRequest': {
+ 'Global': FcpTypeBool,
+ },
+
+
+ # node messages
+
+ 'NodeHello': {
+ 'CompressionCodecs': FcpTypeInt,
+ 'Testnet': FcpTypeBool,
+
+ #TODO: ExtBuild et al. ???
+
+ },
+
+ #'Peer': {}, # ??? check
+
+ 'PeerNote': {
+ 'NoteText': FcpTypeBase64EncodedString,
+ },
+
+
+ #'NodeData': {}, # ??? check
+ #'ConfigData': {}, # ??? check
+
+ 'TestDDAComplete': {
+ 'ReadDirectoryAllowed': FcpTypeBool,
+ 'WriteDirectoryAllowed': FcpTypeBool,
+ },
+ 'PutFetchable': {
+ 'Global': FcpTypeBool,
+ },
+ 'DataFound': {
+ 'Global': FcpTypeBool,
+ 'DataLength': FcpTypeInt,
+ },
+ 'AllData': {
+ 'Global': FcpTypeBool,
+ #NOTE: we ignore startup and completion time here, as long as it is not passed in all messages
+
+ },
+ 'FinishedCompression': {
+ 'OriginalSize': FcpTypeInt,
+ 'CompressedSize': FcpTypeInt,
+ },
+ 'SimpleProgress': {
+ 'Total': FcpTypeInt,
+ 'Required': FcpTypeInt,
+ 'Failed': FcpTypeInt,
+ 'FatalyFailed': FcpTypeInt,
+ 'Succeeded': FcpTypeInt,
+ 'Finalized': FcpTypeBool,
+ },
+ 'PersistentRequestRemoved': {
+ 'Global': FcpTypeBool,
+ },
+ 'PersistentRequestModified': {
+ 'Global': FcpTypeBool,
+ },
+ 'PutFailed': {
+ 'Global': FcpTypeBool,
+ 'Code': FcpTypeInt,
+ },
+ 'GetFailed': {
+ 'Code': FcpTypeInt,
+ 'ExpectedDataLength': FcpTypeInt_GetFailed_ExpectedDataLenght,
+ 'Fatal': FcpTypeBool,
+ 'FinalizedExpected': FcpTypeBool,
+ 'Global': FcpTypeBool,
+ },
+ 'ProtocolError': {
+ 'Code': FcpTypeInt,
+ 'Global': FcpTypeBool,
+ },
+
+ 'IdentifierCollision': {
+ 'Global': FcpTypeBool,
+ },
+ 'SubscribedUSKUpdate': {
+ 'Edition': FcpTypeInt,
+ },
+
+
+
+ }
+
+MessageParamTypes['ClientPutDiskDir'] = MessageParamTypes['ClientPut']
+MessageParamTypes['ClientComplexDir'] = MessageParamTypes['ClientPut']
+
+# TODO: "Started" param? Think we simply ignore it
+MessageParamTypes['PersistentGet'] = MessageParamTypes['ClientGet']
+MessageParamTypes['PersistentPut'] = MessageParamTypes['ClientPut']
+
+
+
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|