diff options
author | elie <elie> | 2011-02-11 21:38:19 +0000 |
---|---|---|
committer | elie <elie> | 2011-02-11 21:38:19 +0000 |
commit | edaec269890b5432590f81dd2e491898c855faf8 (patch) | |
tree | 7a04abdc92a002d34aa631679fa89eec81de3f34 | |
parent | 1438ad8dd32f378791d064b94f4d891cafb9ca55 (diff) | |
download | pysnmp-edaec269890b5432590f81dd2e491898c855faf8.tar.gz |
randomize initials in numeric sequences; grow serial number ranges
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | pysnmp/nextid.py | 6 | ||||
-rw-r--r-- | pysnmp/proto/api/v1.py | 2 | ||||
-rw-r--r-- | pysnmp/proto/rfc3412.py | 2 |
4 files changed, 8 insertions, 3 deletions
@@ -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 = {} |