Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
vocab_index = 0
check_inrange(self.initialVocabTableRange[0],
self.initialVocabTableRange[1],
vocab_index, "initial vocab table index")
our_hash = vocab.hashVocabTable(vocab_index)
if vocab_index > 0 and our_hash != vocab_hash:
msg = ("Our hash for vocab-table-index %d (%s) does not match "
"your hash (%s)" % (vocab_index, our_hash, vocab_hash))
raise NegotiationError(msg)
if self.theirTubRef in self.tub.brokers:
# we're the slave, so we need to drop our existing connection and
# use the one picked by the master
self.log("master told us to use a new connection, "
"so we must drop the existing one", level=UNUSUAL)
err = DeadReferenceError("replaced by a new connection")
why = Failure(err)
self.tub.brokers[self.theirTubRef].shutdown(why)
current_connection = decision.get('current-connection')
if current_connection:
tubID = self.theirTubRef.getTubID()
if tubID != "":
self.tub.slave_table[tubID] = tuple(current_connection.split())
else:
self.log("no current-connection in decision from %s" %
self.theirTubRef, level=UNUSUAL)
params = { 'banana-decision-version': ver,
'initial-vocab-table-index': vocab_index,
}
return params
def abandonAllRequests(self, why):
for req in list(self.waitingForAnswers.values()):
if why.check(*LOST_CONNECTION_ERRORS):
# map all connection-lost errors to DeadReferenceError, so
# application code only needs to check for one exception type
tubid = None
# since we're creating a new exception object for each call,
# let's add more information to it
if self.remote_tubref:
tubid = self.remote_tubref.getShortTubID()
e = DeadReferenceError("Connection was lost", tubid, req)
why = failure.Failure(e)
eventually(req.fail, why)
# itself. Leave them alone, and assume that users will see the warnings for
# Tub and Referenceable and the more common symols.
SturdyRef = referenceable.SturdyRef
from foolscap import copyable
Copyable = copyable.Copyable
RemoteCopy = copyable.RemoteCopy
registerRemoteCopy = _wrap_function(copyable.registerRemoteCopy,
"registerRemoteCopy")
registerCopier = _wrap_function(copyable.registerCopier,
"registerCopier")
registerRemoteCopyFactory = _wrap_function(copyable.registerRemoteCopyFactory,
"registerRemoteCopyFactory")
import foolscap.ipb
DeadReferenceError = _wrap_class(foolscap.ipb.DeadReferenceError, "DeadReferenceError")
import foolscap.tokens
BananaError = _wrap_class(foolscap.tokens.BananaError, "BananaError")
import foolscap.schema
schema = foolscap.schema
import foolscap.storage
serialize = _wrap_function(foolscap.storage.serialize, "serialize")
unserialize = _wrap_function(foolscap.storage.unserialize, "unserialize")
def _dead_reference(self, fail, event_uri, node):
"""
Errback for DeadReference exception handling
@param fail: twisted failure object
@type fail: twisted.failure.Falure
@param node: node object
@type node: L{Node}
"""
fail.trap(DeadReferenceError)
log.msg("dead reference %s, drop it" % node, logLevel=logging.WARNING)
self.routing.remove(event_uri, node)
node.monitor = None
self.heartbeat.remove(node)
if theirTubRef and theirTubRef in self.tub.brokers:
# there is an existing connection.. we might want to prefer
# this new offer, because the old connection might be stale
# (NAT boxes and laptops that disconnect abruptly are two
# ways for a single process to disappear silently and then
# reappear with a different IP address).
lp = self.log("got offer for an existing connection",
level=UNUSUAL)
existing = self.tub.brokers[theirTubRef]
acceptOffer = self.compareOfferAndExisting(offer, existing, lp)
if acceptOffer:
# drop the old one
self.log("accepting new offer, dropping existing connection",
parent=lp)
err = DeadReferenceError("[%s] replaced by a new connection"
% theirTubRef.getShortTubID())
why = Failure(err)
existing.shutdown(why)
else:
# reject the new one
self.log("rejecting the offer: we already have one",
parent=lp)
raise NegotiationError("Duplicate connection")
if theirTubRef:
# generate a new seqnum, one higher than the last one we've
# used. Note that UnauthenticatedTubs all share the same
# index, so we leak certain information about how many
# connections we've established.
old_seqnum = self.tub.master_table.get(theirTubRef.getTubID(),
0)
def _ignore_loss(f):
f.trap(DeadReferenceError, *LOST_CONNECTION_ERRORS)
return None
d.addErrback(_ignore_loss)
from foolscap.schema import StringConstraint, IntegerConstraint, \
ListOf, TupleOf, SetOf, DictOf, ChoiceOf, Any
from foolscap.storage import serialize, unserialize
from foolscap.tokens import Violation, RemoteException
from foolscap.eventual import eventually, fireEventually, flushEventualQueue
from foolscap.logging import app_versions
# hush pyflakes
_unused = [
__version__,
Tub,
RemoteInterface,
Referenceable, SturdyRef,
Copyable, RemoteCopy, registerRemoteCopy,
registerCopier, registerRemoteCopyFactory,
DeadReferenceError,
BananaError,
StringConstraint, IntegerConstraint,
ListOf, TupleOf, SetOf, DictOf, ChoiceOf, Any,
serialize, unserialize,
Violation, RemoteException,
eventually, fireEventually, flushEventualQueue,
app_versions,
]
del _unused