summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2011-02-11 21:38:19 +0000
committerelie <elie>2011-02-11 21:38:19 +0000
commitedaec269890b5432590f81dd2e491898c855faf8 (patch)
tree7a04abdc92a002d34aa631679fa89eec81de3f34
parent1438ad8dd32f378791d064b94f4d891cafb9ca55 (diff)
downloadpysnmp-edaec269890b5432590f81dd2e491898c855faf8.tar.gz
randomize initials in numeric sequences; grow serial number ranges
-rw-r--r--CHANGES1
-rw-r--r--pysnmp/nextid.py6
-rw-r--r--pysnmp/proto/api/v1.py2
-rw-r--r--pysnmp/proto/rfc3412.py2
4 files changed, 8 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 11c6d70..1b95a66 100644
--- a/CHANGES
+++ b/CHANGES
@@ -9,6 +9,7 @@ Revision 4.1.16a
position.
- Internal caches structure improved.
- Sync versions of oneliner apps split off async implementation for clarity.
+- Randomize initial in various numeric sequences.
- Changes towards performance improvement:
+ all dict.has_key() & dict.get() invocations replaced with modern syntax
(this breaks compatibility with Python 2.1 and older).
diff --git a/pysnmp/nextid.py b/pysnmp/nextid.py
index 8a0c4e1..3e60a4f 100644
--- a/pysnmp/nextid.py
+++ b/pysnmp/nextid.py
@@ -1,4 +1,7 @@
# Return a next value in a reasonably MT-safe manner
+import random
+
+random.seed()
class Integer:
def __init__(self, maximum, increment=256):
@@ -7,7 +10,8 @@ class Integer:
increment = maximum
self.__increment = increment
self.__threshold = increment/2
- self.__bank = range(self.__increment)
+ e = random.randrange(self.__maximum - self.__increment)
+ self.__bank = range(e, e+self.__increment)
def __repr__(self):
return '%s(%d, %d)' % (
diff --git a/pysnmp/proto/api/v1.py b/pysnmp/proto/api/v1.py
index 1e9ae5d..9223645 100644
--- a/pysnmp/proto/api/v1.py
+++ b/pysnmp/proto/api/v1.py
@@ -38,7 +38,7 @@ class VarBindAPI:
apiVarBind = VarBindAPI()
-getNextRequestID = nextid.Integer(0xffff)
+getNextRequestID = nextid.Integer(0xffffff)
class PDUAPI:
_null = Null('')
diff --git a/pysnmp/proto/rfc3412.py b/pysnmp/proto/rfc3412.py
index 8b1c2dc..c2db84a 100644
--- a/pysnmp/proto/rfc3412.py
+++ b/pysnmp/proto/rfc3412.py
@@ -30,7 +30,7 @@ class MsgAndPduDispatcher:
self.__appsRegistration = {}
# Source of sendPduHandle and cache of requesting apps
- self.__sendPduHandle = nextid.Integer(0xffffffff)
+ self.__sendPduHandle = nextid.Integer(0xffffff)
# To pass transport info to app
self.__transportInfo = {}