コード例 #1
0
def _make_tcp_handler():
    """
    :returns: a Foolscap default TCP handler
    """
    # this is always available
    from foolscap.connections.tcp import default
    return default()
コード例 #2
0
ファイル: node.py プロジェクト: tahoe-lafs/tahoe-lafs
def _make_tcp_handler():
    """
    :returns: a Foolscap default TCP handler
    """
    # this is always available
    from foolscap.connections.tcp import default
    return default()
コード例 #3
0
    def get_or_create_private_config(self, name, default=_None):
        """Try to get the (string) contents of a private config file (which
        is a config file that resides within the subdirectory named
        'private'), and return it. Any leading or trailing whitespace will be
        stripped from the data.

        If the file does not exist, and default is not given, report an error.
        If the file does not exist and a default is specified, try to create
        it using that default, and then return the value that was written.
        If 'default' is a string, use it as a default value. If not, treat it
        as a zero-argument callable that is expected to return a string.
        """
        privname = os.path.join(self._basedir, "private", name)
        try:
            value = fileutil.read(privname, mode="r")
        except EnvironmentError as e:
            if e.errno != errno.ENOENT:
                raise  # we only care about "file doesn't exist"
            if default is _None:
                raise MissingConfigEntry(
                    "The required configuration file %s is missing." %
                    (quote_output(privname), ))
            if isinstance(default, bytes):
                default = str(default, "utf-8")
            if isinstance(default, str):
                value = default
            else:
                value = default()
            fileutil.write(privname, value)
        return value.strip()
コード例 #4
0
ファイル: node.py プロジェクト: LeastAuthority/tahoe-lafs
    def get_or_create_private_config(self, name, default=_None):
        """Try to get the (string) contents of a private config file (which
        is a config file that resides within the subdirectory named
        'private'), and return it. Any leading or trailing whitespace will be
        stripped from the data.

        If the file does not exist, and default is not given, report an error.
        If the file does not exist and a default is specified, try to create
        it using that default, and then return the value that was written.
        If 'default' is a string, use it as a default value. If not, treat it
        as a zero-argument callable that is expected to return a string.
        """
        privname = os.path.join(self.basedir, "private", name)
        try:
            value = fileutil.read(privname)
        except EnvironmentError:
            if os.path.exists(privname):
                raise
            if default is _None:
                raise MissingConfigEntry("The required configuration file %s is missing."
                                         % (quote_output(privname),))
            if isinstance(default, basestring):
                value = default
            else:
                value = default()
            fileutil.write(privname, value)
        return value.strip()
コード例 #5
0
ファイル: test_connection.py プロジェクト: exarkun/foolscap
 def checkTCPEndpoint(self, hint, expected_host, expected_port):
     d = get_endpoint(hint, {"tcp": tcp.default()})
     (ep, host) = self.successResultOf(d)
     self.failUnless(isinstance(ep, endpoints.HostnameEndpoint), ep)
     # note: this is fragile, and will break when Twisted changes the
     # internals of HostnameEndpoint.
     self.failUnlessEqual(ep._host, expected_host)
     self.failUnlessEqual(ep._port, expected_port)
コード例 #6
0
 def checkTCPEndpoint(self, hint, expected_host, expected_port):
     with mock.patch("foolscap.connections.tcp.HostnameEndpoint",
                     side_effect=FakeHostnameEndpoint):
         d = get_endpoint(hint, {"tcp": tcp.default()}, ConnectionInfo())
     (ep, host) = self.successResultOf(d)
     self.assertTrue(isinstance(ep, FakeHostnameEndpoint), ep)
     self.assertIs(ep.reactor, reactor)
     self.assertEqual(ep.host, expected_host)
     self.assertEqual(ep.port, expected_port)
コード例 #7
0
ファイル: test_connection.py プロジェクト: exarkun/foolscap
 def hint_to_endpoint(self, hint, reactor):
     self.asked += 1
     if "bad" in hint:
         raise ipb.InvalidHintError
     self.accepted += 1
     pieces = hint.split(":")
     new_hint = "tcp:%s:%d" % (pieces[1], int(pieces[2])+0)
     ep = tcp.default().hint_to_endpoint(new_hint, reactor)
     if pieces[0] == "slow":
         d = defer.Deferred()
         reactor.callLater(0.01, d.callback, ep)
         return d
     return ep
コード例 #8
0
 def hint_to_endpoint(self, hint, reactor, update_status):
     self.asked += 1
     if "bad" in hint:
         raise ipb.InvalidHintError
     self.accepted += 1
     pieces = hint.split(":")
     new_hint = "tcp:%s:%d" % (pieces[1], int(pieces[2]) + 0)
     ep = tcp.default().hint_to_endpoint(new_hint, reactor, update_status)
     if pieces[0] == "slow":
         update_status("being slow")
         self._d = defer.Deferred()
         self._d.addCallback(lambda _: ep)
         return self._d
     return ep
コード例 #9
0
 def hint_to_endpoint(self, hint, reactor, update_status):
     self.asked += 1
     if "bad" in hint:
         raise ipb.InvalidHintError
     self.accepted += 1
     pieces = hint.split(":")
     new_hint = "tcp:%s:%d" % (pieces[1], int(pieces[2])+0)
     ep = tcp.default().hint_to_endpoint(new_hint, reactor, update_status)
     if pieces[0] == "slow":
         update_status("being slow")
         self._d = defer.Deferred()
         self._d.addCallback(lambda _: ep)
         return self._d
     return ep
コード例 #10
0
    def setup(self, _test_options):
        self._test_options = _test_options
        self.logger = flog.theLogger
        self.listeners = []
        self.locationHints = []

        # duplicate-connection management
        self.make_incarnation()

        # the master_table records the master-seqnum we used for the last
        # established connection with the given tubid. It only contains
        # entries for which we were the master.
        self.master_table = {}  # k:tubid, v:seqnum
        # the slave_table records the (master-IR,master-seqnum) pair for the
        # last established connection with the given tubid. It only contains
        # entries for which we were the slave.
        self.slave_table = {}  # k:tubid, v:(master-IR,seqnum)

        # local Referenceables
        self.nameToReference = weakref.WeakValueDictionary()
        self.referenceToName = weakref.WeakKeyDictionary()
        self.strongReferences = []
        self.nameLookupHandlers = []

        # remote stuff. Most of these use a TubRef as a dictionary key
        self.tubConnectors = {}  # maps TubRef to a TubConnector
        self.waitingForBrokers = {}  # maps TubRef to list of Deferreds
        self.brokers = {}  # maps TubRef to a Broker that connects to them
        self.reconnectors = []

        self._connectionHandlers = {"tcp": tcp.default()}
        self._activeConnectors = []

        self._pending_getReferences = []  # list of (d, furl) pairs

        self._logport = None
        self._logport_furl = None
        self._logport_furlfile = None

        self._log_gatherer_furls = []
        self._log_gatherer_furlfile = None
        self._log_gatherer_connectors = {}  # maps furl to reconnector

        self._handle_old_duplicate_connections = False
        self._expose_remote_exception_types = True
        self.accept_gifts = True
コード例 #11
0
ファイル: pb.py プロジェクト: david415/foolscap
    def setup(self, _test_options):
        self._test_options = _test_options
        self.logger = flog.theLogger
        self.listeners = []
        self.locationHints = []

        # duplicate-connection management
        self.make_incarnation()

        # the master_table records the master-seqnum we used for the last
        # established connection with the given tubid. It only contains
        # entries for which we were the master.
        self.master_table = {} # k:tubid, v:seqnum
        # the slave_table records the (master-IR,master-seqnum) pair for the
        # last established connection with the given tubid. It only contains
        # entries for which we were the slave.
        self.slave_table = {} # k:tubid, v:(master-IR,seqnum)

        # local Referenceables
        self.nameToReference = weakref.WeakValueDictionary()
        self.referenceToName = weakref.WeakKeyDictionary()
        self.strongReferences = []
        self.nameLookupHandlers = []

        # remote stuff. Most of these use a TubRef as a dictionary key
        self.tubConnectors = {} # maps TubRef to a TubConnector
        self.waitingForBrokers = {} # maps TubRef to list of Deferreds
        self.brokers = {} # maps TubRef to a Broker that connects to them
        self.reconnectors = []

        self._connectionHandlers = {"tcp": tcp.default()}
        self._activeConnectors = []

        self._pending_getReferences = [] # list of (d, furl) pairs

        self._logport = None
        self._logport_furl = None
        self._logport_furlfile = None

        self._log_gatherer_furls = []
        self._log_gatherer_furlfile = None
        self._log_gatherer_connectors = {} # maps furl to reconnector

        self._handle_old_duplicate_connections = False
        self._expose_remote_exception_types = True
        self.accept_gifts = True
コード例 #12
0
ファイル: node.py プロジェクト: testimx62/tahoe-lafs
 def _make_tcp_handler(self):
     # this is always available
     from foolscap.connections.tcp import default
     return default()
コード例 #13
0
ファイル: node.py プロジェクト: LeastAuthority/tahoe-lafs
 def _make_tcp_handler(self):
     # this is always available
     from foolscap.connections.tcp import default
     return default()
コード例 #14
0
 def checkUnknownEndpoint(self, hint):
     d = get_endpoint(hint, {"tcp": tcp.default()}, ConnectionInfo())
     self.failureResultOf(d, ipb.InvalidHintError)
コード例 #15
0
ファイル: test_connection.py プロジェクト: exarkun/foolscap
 def checkUnknownEndpoint(self, hint):
     d = get_endpoint(hint, {"tcp": tcp.default()})
     self.failureResultOf(d, ipb.InvalidHintError)
コード例 #16
0
 def checkBadTCPEndpoint(self, hint):
     d = get_endpoint(hint, {"tcp": tcp.default()}, ConnectionInfo())
     self.failureResultOf(d, ipb.InvalidHintError)