summaryrefslogtreecommitdiff
path: root/pysnmp
diff options
context:
space:
mode:
authorelie <elie>2007-03-30 06:51:04 +0000
committerelie <elie>2007-03-30 06:51:04 +0000
commit91d0cbd541cf21036456bc57472cb2bc503ce35b (patch)
tree902d26eab6821d874e7ff5560b3904a90455ed79 /pysnmp
parent8a6a3e983f1c214b8effeaaed88d9da8ff8a257a (diff)
downloadpysnmp-git-91d0cbd541cf21036456bc57472cb2bc503ce35b.tar.gz
attempt to use process elapsed time (whenever available) for
timestamping timeframe, as elapsed time may not be affected by system clock reset.
Diffstat (limited to 'pysnmp')
-rw-r--r--pysnmp/proto/secmod/rfc3414/service.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/pysnmp/proto/secmod/rfc3414/service.py b/pysnmp/proto/secmod/rfc3414/service.py
index d9e01fc0..3392dce4 100644
--- a/pysnmp/proto/secmod/rfc3414/service.py
+++ b/pysnmp/proto/secmod/rfc3414/service.py
@@ -9,8 +9,16 @@ from pyasn1.type import univ, namedtype, constraint
from pyasn1.codec.ber import encoder, decoder
from pyasn1.error import PyAsn1Error
from pysnmp import debug
-import time
-
+import os
+
+if os.times()[-1]: # this is not affected by system clock reset
+ def _getTimestamp():
+ return abs(int(os.times()[-1]))
+else:
+ import time
+ def _getTimestamp():
+ return int(time.time())
+
# USM security params
class UsmSecurityParameters(rfc1155.TypeCoercionHackMixIn, univ.Sequence):
@@ -491,7 +499,7 @@ class SnmpUSMSecurityModel(AbstractSecurityModel):
securityParameters.getComponentByPosition(1),
securityParameters.getComponentByPosition(2),
securityParameters.getComponentByPosition(2),
- int(time.time())
+ _getTimestamp()
)
expireAt = self.__expirationTimer + 300
@@ -648,7 +656,7 @@ class SnmpUSMSecurityModel(AbstractSecurityModel):
msgAuthoritativeEngineID
]
# time passed since last talk with this SNMP engine
- idleTime = int(time.time())-latestUpdateTimestamp
+ idleTime = abs(_getTimestamp()-latestUpdateTimestamp)
debug.logger & debug.flagSM and debug.logger('processIncomingMsg: read timeline snmpEngineBoots %s snmpEngineTime %s for msgAuthoritativeEngineID %s, idle time %s secs' % (snmpEngineBoots, snmpEngineTime, msgAuthoritativeEngineID, idleTime))
else:
raise error.ProtocolError('Peer SNMP engine info missing')
@@ -684,7 +692,7 @@ class SnmpUSMSecurityModel(AbstractSecurityModel):
msgAuthoritativeEngineBoots,
msgAuthoritativeEngineTime,
msgAuthoritativeEngineTime,
- int(time.time())
+ _getTimestamp()
)
debug.logger & debug.flagSM and debug.logger('processIncomingMsg: stored timeline msgAuthoritativeEngineBoots %s msgAuthoritativeEngineTime %s for msgAuthoritativeEngineID %s' % (msgAuthoritativeEngineBoots, msgAuthoritativeEngineTime, msgAuthoritativeEngineID))