本文整理汇总了Python中mixminion.Common.LOG.debug方法的典型用法代码示例。如果您正苦于以下问题:Python LOG.debug方法的具体用法?Python LOG.debug怎么用?Python LOG.debug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mixminion.Common.LOG
的用法示例。
在下文中一共展示了LOG.debug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: processMessage
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def processMessage(self, packet):
assert packet.getExitType() == 0xFFFE
exitInfo = packet.getAddress()
if exitInfo == 'fail':
return DELIVER_FAIL_RETRY
elif exitInfo == 'FAIL!':
return DELIVER_FAIL_NORETRY
LOG.debug("Delivering test message")
m = _escapeMessageForEmail(packet)
if m is None:
# Ordinarily, we'd drop corrupt messages, but this module is
# meant for debugging.
m = """\
==========CORRUPT OR UNDECODABLE MESSAGE
Decoding handle: %s%s==========MESSAGE ENDS""" % (
base64.encodestring(packet.getTag()),
base64.encodestring(packet.getContents()))
f = open(os.path.join(self.loc, str(self.next)), 'w')
self.next += 1
f.write(m)
f.close()
return DELIVER_OK
示例2: run
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def run(self):
"""Thread body: pull questions from the DNS thread queue and
answer them."""
queue = self.dnscache.queue
_lookupDone = self.dnscache._lookupDone
_adjBusyThreads = self.dnscache._adjBusyThreads
_adjLiveThreads = self.dnscache._adjLiveThreads
try:
_adjLiveThreads(1)
try:
while 1:
# Get a question from the queue, but don't wait more than
# MAX_THREAD_IDLE seconds
hostname = queue.get(timeout=MAX_THREAD_IDLE)
# If the question is None, shutdown.
if hostname is None:
return
# Else, resolve the IP and send the answer to the dnscache
_adjBusyThreads(1)
result = mixminion.NetUtils.getIP(hostname)
_lookupDone(hostname, result)
_adjBusyThreads(-1)
except QueueEmpty:
LOG.debug("DNS thread shutting down: idle for %s seconds.",
MAX_THREAD_IDLE)
except:
LOG.error_exc(sys.exc_info(),
"Exception in DNS thread; shutting down.")
finally:
_adjLiveThreads(-1)
示例3: process
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def process(self, r, w, x, cap):
#XXXX007 do something with x
try:
con, addr = self.sock.accept()
LOG.debug("Accepted connection from %s", addr)
self.connectionFactory(con)
except socket.error, e:
LOG.warn("Socket error while accepting connection: %s", e)
示例4: onProtocolWritten
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def onProtocolWritten(self,n):
if self.outbuf:
# Not done writing outgoing data.
return
LOG.debug("Sent MMTP protocol string to %s", self.address)
self.stopWriting()
self.beginReading()
self.onRead = self.onProtocolRead
示例5: onConnected
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def onConnected(self):
LOG.debug("Completed MMTP client connection to %s",self.address)
# Is the certificate correct?
try:
self.certCache.check(self.tls, self.targetKeyID, self.address)
except MixProtocolBadAuth, e:
LOG.warn("Certificate error: %s. Shutting down connection.", e)
self._failPendingPackets()
self.startShutdown()
return
示例6: checkKeys
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def checkKeys(self):
"""Internal method: read information about all this server's
currently-prepared keys from disk.
May raise ConfigError if any of the server descriptors on disk
are invalid.
"""
self.keySets = []
badKeySets = []
firstKey = sys.maxint
lastKey = 0
LOG.debug("Scanning server keystore at %s", self.keyDir)
if not os.path.exists(self.keyDir):
LOG.info("Creating server keystore at %s", self.keyDir)
createPrivateDir(self.keyDir)
# Iterate over the entires in HOME/keys
for dirname in os.listdir(self.keyDir):
# Skip any that aren't directories named "key_INT"
if not os.path.isdir(os.path.join(self.keyDir,dirname)):
continue
if not dirname.startswith('key_'):
LOG.warn("Unexpected directory %s under %s",
dirname, self.keyDir)
continue
keysetname = dirname[4:]
try:
setNum = int(keysetname)
# keep trace of the first and last used key number
if setNum < firstKey: firstKey = setNum
if setNum > lastKey: lastKey = setNum
except ValueError:
LOG.warn("Unexpected directory %s under %s",
dirname, self.keyDir)
continue
# Find the server descriptor...
keyset = ServerKeyset(self.keyDir, keysetname, self.hashDir)
ok = 1
try:
keyset.checkKeys()
except MixError, e:
LOG.warn("Error checking private keys in keyset %s: %s",
keysetname, str(e))
ok = 0
try:
if ok:
keyset.getServerDescriptor()
except (ConfigError, IOError), e:
LOG.warn("Key set %s has invalid/missing descriptor: %s",
keysetname, str(e))
ok = 0
示例7: rescan
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def rescan(self):
"""Check all fragment metadata objects on disk, and reconstruct our
internal view of message states.
"""
# Delete all internal state; reload FragmentMetadatas from disk.
self.store.loadAllMetadata(lambda: None)
meta = self.store._metadata_cache
self.states = {}
badMessageIDs = {} # map from bad messageID to 1
unneededHandles = [] # list of handles that aren't needed.
for h, fm in meta.items():
if not fm:
LOG.debug("Removing fragment %s with missing metadata", h)
self.store.removeMessage(h)
continue
try:
mid = fm.messageid
if badMessageIDs.has_key(mid):
# We've already decided to reject fragments with this ID.
pass
else:
# All is well; try to register the fragment/chunk. If it's
# redundant or inconsistent, raise an exception.
state = self._getState(fm)
if fm.isChunk:
state.addChunk(h, fm)
else:
state.addFragment(h, fm)
except MismatchedFragment:
# Mark the message ID for this fragment as inconsistent.
badMessageIDs[mid] = 1
except UnneededFragment:
LOG.warn("Found redundant fragment %s in pool", h)
# Remember that this message is unneeded.
unneededHandles.append(h)
# Check for fragments superseded by chunks -- those are unneeded too.
for s in self.states.values():
unneededHandles.extend(s.getUnneededFragmentHandles())
# Delete unneeded fragments.
for h in unneededHandles:
try:
fm = meta[h]
except KeyError:
continue
LOG.debug("Removing unneeded fragment %s from message ID %r",
fm.idx, fm.messageid)
self.store.removeMessage(h)
# Now nuke inconsistent messages.
self._deleteMessageIDs(badMessageIDs, "REJECTED")
示例8: _save
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def _save(self, now=None):
"""Implements 'save' method. For internal use. Must hold self._lock
to invoke."""
LOG.debug("Syncing statistics to disk")
if not now: now = time()
tmpfile = self.filename + "_tmp"
tryUnlink(tmpfile)
self.accumulatedTime += int(now-self.lastSave)
self.lastSave = now
writePickled(self.filename, { 'count' : self.count,
'lastRotation' : self.lastRotation,
'accumulatedTime' : self.accumulatedTime,
})
示例9: onDataRead
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def onDataRead(self):
while self.inbuflen >= self.MESSAGE_LEN:
data = self.getInbuf(self.MESSAGE_LEN, clear=1)
control = data[:SEND_CONTROL_LEN]
pkt = data[SEND_CONTROL_LEN:-DIGEST_LEN]
digest = data[-DIGEST_LEN:]
if control == JUNK_CONTROL:
expectedDigest = sha1(pkt+"JUNK")
replyDigest = sha1(pkt+"RECEIVED JUNK")
replyControl = RECEIVED_CONTROL
isJunk = 1
elif control == SEND_CONTROL:
expectedDigest = sha1(pkt+"SEND")
if self.rejectPackets:
replyDigest = sha1(pkt+"REJECTED")
replyControl = REJECTED_CONTROL
else:
replyDigest = sha1(pkt+"RECEIVED")
replyControl = RECEIVED_CONTROL
isJunk = 0
else:
LOG.warn("Unrecognized command (%r) from %s. Closing connection.",
control, self.address)
#failed
self.startShutdown()
return
if expectedDigest != digest:
LOG.warn("Invalid checksum from %s. Closing connection.",
self.address)
#failed
self.startShutdown()
return
else:
if isJunk:
LOG.debug("Link padding received from %s; Checksum valid.",
self.address)
else:
LOG.debug("Packet received from %s; Checksum valid.",
self.address)
# Make sure we process the packet before we queue the ack.
if isJunk:
self.junkCallback()
elif self.rejectPackets:
self.rejectCallback()
else:
self.packetConsumer(pkt)
# Queue the ack.
self.beginWriting(replyControl+replyDigest)
示例10: _buildReplyBlockImpl
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def _buildReplyBlockImpl(path, exitType, exitInfo, expiryTime=0,
secretPRNG=None, tag=None):
"""Helper function: makes a reply block, given a tag and a PRNG to
generate secrets. Returns a 3-tuple containing (1) a
newly-constructed reply block, (2) a list of secrets used to
make it, (3) a tag.
path: A list of ServerInfo
exitType: Routing type to use for the final node
exitInfo: Routing info for the final node, not including tag.
expiryTime: The time at which this block should expire.
secretPRNG: A PRNG to use for generating secrets. If not
provided, uses an AES counter-mode stream seeded from our
entropy source. Note: the secrets are generated so that they
will be used to encrypt the message in reverse order.
tag: If provided, a 159-bit tag. If not provided, a new one
is generated.
"""
if secretPRNG is None:
secretPRNG = Crypto.getCommonPRNG()
if expiryTime is None:
# XXXX This is dangerous, and should go away; the user should
# XXXX *always* specify an expiry time.
LOG.warn("Inferring expiry time for reply block")
expiryTime = min([s.getValidUntil() for s in path])
checkPathLength(None, path, exitType, exitInfo, explicitSwap=0)
LOG.debug("Building reply block for path %s",
[s.getNickname() for s in path])
LOG.debug(" Delivering to %04x:%r", exitType, exitInfo)
# The message is encrypted first by the end-to-end key, then by
# each of the path keys in order. We need to reverse these steps, so we
# generate the path keys back-to-front, followed by the end-to-end key.
secrets = [ secretPRNG.getBytes(SECRET_LEN) for _ in range(len(path)+1) ]
headerSecrets = secrets[:-1]
headerSecrets.reverse()
sharedKey = secrets[-1]
# (This will go away when we deprecate 'stateful' reply blocks
if tag is None:
tag = _getRandomTag(secretPRNG)
header = _buildHeader(path, headerSecrets, exitType, tag+exitInfo,
paddingPRNG=Crypto.getCommonPRNG())
return ReplyBlock(header, expiryTime,
SWAP_FWD_HOST_TYPE,
path[0].getMMTPHostInfo().pack(), sharedKey), secrets, tag
示例11: _sendPackets
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def _sendPackets(self, family, ip, port, keyID, deliverable, serverName):
"""Begin sending a set of packets to a given server.
'deliverable' is a list of objects obeying the DeliverableMessage
interface.
"""
try:
# Is there an existing connection open to the right server?
con = self.clientConByAddr[(ip,port,keyID)]
except KeyError:
pass
else:
# No exception: There is an existing connection. But is that
# connection currently sending packets?
if con.isActive():
LOG.debug("Queueing %s packets on open connection to %s",
len(deliverable), con.address)
for d in deliverable:
con.addPacket(d)
return
if len(self.clientConByAddr) >= self.maxClientConnections:
LOG.debug("We already have %s open client connections; delaying %s packets for %s",
len(self.clientConByAddr), len(deliverable), serverName)
self.pendingPackets.append((family,ip,port,keyID,deliverable,serverName))
return
try:
# There isn't any connection to the right server. Open one...
addr = (ip, port, keyID)
finished = lambda addr=addr, self=self: self.__clientFinished(addr)
con = _ClientCon(
family, ip, port, keyID, serverName=serverName,
context=self.clientContext, certCache=self.certificateCache)
nickname = mixminion.ServerInfo.getNicknameByKeyID(keyID)
if nickname is not None:
# If we recognize this server, then we'll want to tell
# the ping log what happens to our connection attempt.
con.configurePingLog(self.pingLog, keyID)
#con.allPacketsSent = finished #XXXX007 wrong!
con.onClosed = finished
except (socket.error, MixProtocolError), e:
LOG.error("Unexpected socket error connecting to %s: %s",
serverName, e)
EventStats.log.failedConnect() #FFFF addr
for m in deliverable:
try:
m.failed(1)
except AttributeError:
pass
示例12: _getDHFile
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def _getDHFile(self):
"""Return the filename for the diffie-helman parameters for the
server. Creates the file if it doesn't yet exist."""
dhdir = os.path.split(self.dhFile)[0]
createPrivateDir(dhdir)
if not os.path.exists(self.dhFile):
# ???? This is only using 512-bit Diffie-Hellman! That isn't
# ???? remotely enough.
LOG.info("Generating Diffie-Helman parameters for TLS...")
mixminion._minionlib.generate_dh_parameters(self.dhFile, verbose=0)
LOG.info("...done")
else:
LOG.debug("Using existing Diffie-Helman parameter from %s",
self.dhFile)
return self.dhFile
示例13: _sendQueuedPackets
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def _sendQueuedPackets(self):
"""Helper function: Find all DNS lookup results and packets in
self.msgQueue, and begin sending packets to the resulting servers.
This function should only be called from the main thread.
"""
while len(self.clientConByAddr) < self.maxClientConnections and self.pendingPackets:
args = self.pendingPackets.pop(0)
LOG.debug("Sending %s delayed packets...",len(args[5]))
self._sendPackets(*args)
while 1:
try:
family,addr,port,keyID,deliverable,serverName = \
self.msgQueue.get(block=0)
except QueueEmpty:
return
self._sendPackets(family,addr,port,keyID,deliverable,serverName)
示例14: _updateRWState
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def _updateRWState(self):
"""Helper: if we have any queued packets that haven't been sent yet,
and we aren't waiting for WRITEAHEAD acks, and we're connected,
start sending the pending packets.
"""
if not self._isConnected: return
while self.nPacketsSent < self.nPacketsAcked + self.WRITEAHEAD:
if not self.packets:
break
LOG.trace("Queueing new packet for %s",self.address)
self._startSendingNextPacket()
if self.nPacketsAcked == self.nPacketsSent:
LOG.debug("Successfully relayed all packets to %s",self.address)
self.allPacketsSent()
self._isConnected = 0
self._isAlive = 0
self.startShutdown()
示例15: buildReplyPacket
# 需要导入模块: from mixminion.Common import LOG [as 别名]
# 或者: from mixminion.Common.LOG import debug [as 别名]
def buildReplyPacket(payload, path1, replyBlock, paddingPRNG=None):
"""Build a message using a reply block. 'path1' is a sequence of
ServerInfo for the nodes on the first leg of the path. 'payload'
must be exactly 28K long.
"""
if paddingPRNG is None:
paddingPRNG = Crypto.getCommonPRNG()
LOG.debug("Encoding reply message for %s-byte payload", len(payload))
LOG.debug(" Using path %s/??", [s.getNickname() for s in path1])
assert len(payload) == PAYLOAD_LEN
# Encrypt the payload so that it won't appear as plaintext to the
# crossover note. (We use 'decrypt' so that the message recipient can
# simply use 'encrypt' to reverse _all_ the steps of the reply path.)
k = Crypto.Keyset(replyBlock.encryptionKey).getLionessKeys(Crypto.PAYLOAD_ENCRYPT_MODE)
payload = Crypto.lioness_decrypt(payload, k)
return _buildPacket(payload, None, None, path1=path1, path2=replyBlock)