本文整理汇总了Python中txtorcon.router.Router类的典型用法代码示例。如果您正苦于以下问题:Python Router类的具体用法?Python Router怎么用?Python Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Router类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_policy_not_set_error
def test_policy_not_set_error(self):
router = Router(object())
try:
router.accepts_port(123)
self.fail()
except Exception, e:
self.assertTrue("policy" in str(e))
开发者ID:arlolra,项目名称:txtorcon,代码行数:7,代码来源:test_router.py
示例2: test_policy_error
def test_policy_error(self):
router = Router(object())
try:
router.policy = 'foo 123'
self.fail()
except Exception, e:
self.assertTrue("Don't understand" in str(e))
开发者ID:arlolra,项目名称:txtorcon,代码行数:7,代码来源:test_router.py
示例3: test_countrycode
def test_countrycode(self):
controller = FakeController()
router = Router(controller)
router.update("foo",
"AHhuQ8zFQJdT8l42Axxc6m6kNwI",
"MAANkj30tnFvmoh7FsjVFr+cmcs",
"2011-12-16 15:11:34",
"127.0.0.1",
"24051", "24052")
开发者ID:gsathya,项目名称:txtorcon,代码行数:9,代码来源:test_router.py
示例4: test_repr
def test_repr(self):
router = Router(FakeController())
router.update("foo",
"AHhuQ8zFQJdT8l42Axxc6m6kNwI",
"MAANkj30tnFvmoh7FsjVFr+cmcs",
"2011-12-16 15:11:34",
"1.2.3.4",
"24051", "24052")
router.flags = ['Named']
repr(router)
开发者ID:arlolra,项目名称:txtorcon,代码行数:10,代码来源:test_router.py
示例5: test_ctor
def test_ctor(self):
controller = object()
router = Router(controller)
router.update("foo",
"AHhuQ8zFQJdT8l42Axxc6m6kNwI",
"MAANkj30tnFvmoh7FsjVFr+cmcs",
"2011-12-16 15:11:34",
"77.183.225.114",
"24051", "24052")
self.assertEqual(router.id_hex, "$00786E43CCC5409753F25E36031C5CEA6EA43702")
self.assertEqual(router.policy, '')
开发者ID:arlolra,项目名称:txtorcon,代码行数:11,代码来源:test_router.py
示例6: test_flags_from_string
def test_flags_from_string(self):
controller = object()
router = Router(controller)
router.update("foo",
"AHhuQ8zFQJdT8l42Axxc6m6kNwI",
"MAANkj30tnFvmoh7FsjVFr+cmcs",
"2011-12-16 15:11:34",
"77.183.225.114",
"24051", "24052")
router.flags = "Exit Fast Named Running V2Dir Valid"
self.assertEqual(router.name_is_unique, True)
开发者ID:arlolra,项目名称:txtorcon,代码行数:11,代码来源:test_router.py
示例7: test_get_location_unknown
def test_get_location_unknown(self):
class CountryCodeController(object):
def get_info_raw(self, i):
raise RuntimeError("shouldn't happen")
controller = CountryCodeController()
r = Router(controller)
loc = yield r.get_location()
self.assertEqual(loc.countrycode, None)
开发者ID:meejah,项目名称:txtorcon,代码行数:11,代码来源:test_router.py
示例8: test_unique_name
def test_unique_name(self):
controller = object()
router = Router(controller)
router.update("foo",
"AHhuQ8zFQJdT8l42Axxc6m6kNwI",
"MAANkj30tnFvmoh7FsjVFr+cmcs",
"2011-12-16 15:11:34",
"77.183.225.114",
"24051", "24052")
self.assertTrue(router.id_hex == "$00786E43CCC5409753F25E36031C5CEA6EA43702")
self.assertTrue(router.unique_name == "$00786E43CCC5409753F25E36031C5CEA6EA43702")
router.flags = ['Named']
self.assertTrue(router.unique_name == "foo")
开发者ID:gsathya,项目名称:txtorcon,代码行数:13,代码来源:test_router.py
示例9: test_get_location_something
def test_get_location_something(self):
class CountryCodeController(object):
def get_info_raw(self, i):
return defer.succeed(
'250-ip-to-country/8.8.8.8=US\r\n250 OK'
)
controller = CountryCodeController()
r = Router(controller)
r.update('routername', 'deadbeef', 'orhash', 'modified', '8.8.8.8', '', '')
loc = yield r.get_location()
self.assertNotEqual(loc.countrycode, None)
开发者ID:meejah,项目名称:txtorcon,代码行数:13,代码来源:test_router.py
示例10: test_countrycode
def test_countrycode(self):
class CountryCodeController(object):
def get_info_raw(self, i):
return defer.succeed('250-ip-to-country/127.1.2.3=ZZ\r\n250 OK')
controller = CountryCodeController()
router = Router(controller)
router.update("foo",
"AHhuQ8zFQJdT8l42Axxc6m6kNwI",
"MAANkj30tnFvmoh7FsjVFr+cmcs",
"2011-12-16 15:11:34",
"127.1.2.3",
"24051", "24052")
self.assertEqual(router.location.countrycode, 'ZZ')
开发者ID:arlolra,项目名称:txtorcon,代码行数:14,代码来源:test_router.py
示例11: test_get_location_private
def test_get_location_private(self):
class CountryCodeController(object):
def get_info_raw(self, i):
return defer.succeed(
'250-ip-to-country/192.168.0.1=ZZ\r\n250 OK'
)
controller = CountryCodeController()
r = Router(controller)
r.update('routername', 'deadbeef', 'orhash', 'modified', '192.168.0.1', '', '')
loc0 = yield r.get_location()
loc1 = yield r.get_location()
self.assertEqual(loc0.countrycode, 'ZZ')
self.assertEqual(loc1.countrycode, 'ZZ')
开发者ID:meejah,项目名称:txtorcon,代码行数:15,代码来源:test_router.py
示例12: _router_begin
def _router_begin(self, data):
args = data.split()
self._router = Router(self.protocol)
self._router.from_consensus = True
self._router.update(args[1], # nickname
args[2], # idhash
args[3], # orhash
datetime.datetime.strptime(args[4] + args[5], '%Y-%m-%f%H:%M:%S'),
args[6], # ip address
args[7], # ORPort
args[8]) # DirPort
if self._router.id_hex in self.routers:
## FIXME should I do an update() on this one??
self._router = self.routers[self._router.id_hex]
return
if self._router.name in self.routers_by_name:
self.routers_by_name[self._router.name].append(self._router)
else:
self.routers_by_name[self._router.name] = [self._router]
if self._router.name in self.routers:
self.routers[self._router.name] = None
else:
self.routers[self._router.name] = self._router
self.routers[self._router.id_hex] = self._router
开发者ID:enriquefynn,项目名称:txtorcon,代码行数:29,代码来源:torstate.py
示例13: test_ctor
def test_ctor(self):
controller = object()
router = Router(controller)
router.update("foo",
"AHhuQ8zFQJdT8l42Axxc6m6kNwI",
"MAANkj30tnFvmoh7FsjVFr+cmcs",
"2011-12-16 15:11:34",
"77.183.225.114",
"24051", "24052")
self.assertEqual(
router.id_hex,
"$00786E43CCC5409753F25E36031C5CEA6EA43702"
)
# we assert this twice to cover the cached + uncached cases
self.assertTrue(isinstance(router.modified, datetime))
self.assertTrue(isinstance(router.modified, datetime))
self.assertEqual(router.policy, '')
开发者ID:felipedau,项目名称:txtorcon,代码行数:18,代码来源:test_router.py
示例14: setUp
def setUp(self):
self.router = Router(FakeController())
self.router.update(
"foo",
"AHhuQ8zFQJdT8l42Axxc6m6kNwI",
"MAANkj30tnFvmoh7FsjVFr+cmcs",
"2011-12-16 15:11:34",
"1.2.3.4",
"24051", "24052"
)
开发者ID:felipedau,项目名称:txtorcon,代码行数:10,代码来源:test_router.py
示例15: router_from_id
def router_from_id(self, routerid):
"""IRouterContainer API"""
try:
return self.routers[routerid]
except KeyError:
router = Router(self.protocol)
if routerid[0] != '$':
raise # just re-raise the KeyError
idhash = routerid[1:41]
nick = ''
is_named = False
if len(routerid) > 41:
nick = routerid[42:]
is_named = routerid[42] is '='
router.update(nick, hashFromHexId(idhash), '0'*27, 'unknown', 'unknown', '0', '0')
return router
开发者ID:narastabbocchi,项目名称:txtorcon,代码行数:19,代码来源:torstate.py
示例16: router_from_id
def router_from_id(self, routerid):
"""IRouterContainer API"""
try:
return self.routers[routerid]
except KeyError:
router = Router(self.protocol)
if routerid[0] != "$":
raise # just re-raise the KeyError
idhash = routerid[1:41]
nick = ""
is_named = False
if len(routerid) > 41:
nick = routerid[42:]
is_named = routerid[41] is "="
router.update(nick, hashFromHexId(idhash), "0" * 27, "unknown", "unknown", "0", "0")
router.name_is_unique = is_named
return router
开发者ID:aagbsn,项目名称:txtorcon,代码行数:20,代码来源:torstate.py
示例17: test_policy_accept
def test_policy_accept(self):
controller = object()
router = Router(controller)
router.update("foo",
"AHhuQ8zFQJdT8l42Axxc6m6kNwI",
"MAANkj30tnFvmoh7FsjVFr+cmcs",
"2011-12-16 15:11:34",
"77.183.225.114",
"24051", "24052")
router.policy = "accept 25,128-256".split()
self.assertTrue(router.accepts_port(25))
for x in range(128, 256):
self.assertTrue(router.accepts_port(x))
self.assertTrue(not router.accepts_port(26))
self.assertEqual(router.policy, 'accept 25,128-256')
开发者ID:arlolra,项目名称:txtorcon,代码行数:15,代码来源:test_router.py
示例18: test_policy_reject
def test_policy_reject(self):
controller = object()
router = Router(controller)
router.update("foo",
"AHhuQ8zFQJdT8l42Axxc6m6kNwI",
"MAANkj30tnFvmoh7FsjVFr+cmcs",
"2011-12-16 15:11:34",
"77.183.225.114",
"24051", "24052")
router.policy = "reject 500-600,655,7766".split()
for x in range(1, 500):
self.assertTrue(router.accepts_port(x))
for x in range(500, 601):
self.assertTrue(not router.accepts_port(x))
self.assertEqual(router.policy, 'reject 500-600,655,7766')
开发者ID:arlolra,项目名称:txtorcon,代码行数:16,代码来源:test_router.py
示例19: _create_router
def _create_router(self, **kw):
id_hex = hexIdFromHash(kw['idhash'])
try:
router = self.routers[id_hex]
except KeyError:
router = Router(self.protocol)
self.routers[router.id_hex] = router
router.from_consensus = True
router.update(
kw['nickname'],
kw['idhash'],
kw['orhash'],
kw['modified'],
kw['ip'],
kw['orport'],
kw['dirport'],
)
router.flags = kw.get('flags', [])
if 'bandwidth' in kw:
router.bandwidth = kw['bandwidth']
if 'ip_v6' in kw:
router.ip_v6.extend(kw['ip_v6'])
if 'guard' in router.flags:
self.guards[router.id_hex] = router
if 'authority' in router.flags:
self.authorities[router.name] = router
if router.id_hex in self.routers:
# FIXME should I do an update() on this one??
router = self.routers[router.id_hex]
else:
if router.name in self.routers:
self.routers[router.name] = None
else:
self.routers[router.name] = router
if router.name in self.routers_by_name:
self.routers_by_name[router.name].append(router)
else:
self.routers_by_name[router.name] = [router]
self.routers[router.id_hex] = router
self.routers_by_hash[router.id_hex] = router
self.all_routers.add(router)
开发者ID:felipedau,项目名称:txtorcon,代码行数:47,代码来源:torstate.py
示例20: TorState
class TorState(object):
"""
This tracks the current state of Tor using a TorControlProtocol.
On setup it first queries the initial state of streams and
circuits. It then asks for updates via the listeners. It requires
an ITorControlProtocol instance. The control protocol doesn't need
to be bootstrapped yet. The Deferred .post_boostrap is driggered
when the TorState instance is fully ready to go. The easiest way
is to use the helper method
:func:`txtorcon.build_tor_connection`. For details, see the
implementation of that.
You may add an :class:`txtorcon.interface.IStreamAttacher` to
provide a custom mapping for Strams to Circuits (by default Tor
picks by itself).
This is also a good example of the various listeners, and acts as
an :class:`txtorcon.interface.ICircuitContainer` and
:class:`txtorcon.interface.IRouterContainer`.
"""
implements(ICircuitListener, ICircuitContainer, IRouterContainer,
IStreamListener)
def __init__(self, protocol, bootstrap=True, write_state_diagram=False):
self.protocol = ITorControlProtocol(protocol)
## fixme could use protocol.on_disconnect to re-connect; see issue #3
## could override these to get your own Circuit/Stream subclasses
## to track these things
self.circuit_factory = Circuit
self.stream_factory = Stream
self.attacher = None
"""If set, provides
:class:`txtorcon.interface.IStreamAttacher` to attach new
streams we hear about."""
self.tor_binary = 'tor'
self.circuit_listeners = []
self.stream_listeners = []
self.addrmap = AddrMap()
self.circuits = {} # keys on id (integer)
self.streams = {} # keys on id (integer)
self.routers = {} # keys by hexid (string) and by unique names
self.routers_by_name = {} # keys on name, value always list (many duplicate "Unnamed" routers, for example)
self.guards = {} # potentially-usable as entry guards, I think? (any router with 'Guard' flag)
self.entry_guards = {} # from GETINFO entry-guards, our current entry guards
self.unusable_entry_guards = [] # list of entry guards we didn't parse out
self.authorities = {} # keys by name
self.cleanup = None # see set_attacher
class die(object):
__name__ = 'die' # FIXME? just to ease spagetti.py:82's pain
def __init__(self, msg):
self.msg = msg
def __call__(self, *args):
raise RuntimeError(self.msg % tuple(args))
def nothing(*args):
pass
waiting_r = State("waiting_r")
waiting_w = State("waiting_w")
waiting_p = State("waiting_p")
waiting_s = State("waiting_s")
def ignorable_line(x):
return x.strip() == '.' or x.strip() == 'OK' or x[:3] == 'ns/' or x.strip() == ''
waiting_r.add_transition(Transition(waiting_r, ignorable_line, nothing))
waiting_r.add_transition(Transition(waiting_s, lambda x: x[:2] == 'r ', self._router_begin))
## FIXME use better method/func than die!!
waiting_r.add_transition(Transition(waiting_r, lambda x: x[:2] != 'r ', die('Expected "r " while parsing routers not "%s"')))
waiting_s.add_transition(Transition(waiting_w, lambda x: x[:2] == 's ', self._router_flags))
waiting_s.add_transition(Transition(waiting_s, lambda x: x[:2] == 'a ', self._router_address))
waiting_s.add_transition(Transition(waiting_r, ignorable_line, nothing))
waiting_s.add_transition(Transition(waiting_r, lambda x: x[:2] != 's ' and x[:2] != 'a ', die('Expected "s " while parsing routers not "%s"')))
waiting_s.add_transition(Transition(waiting_r, lambda x: x.strip() == '.', nothing))
waiting_w.add_transition(Transition(waiting_p, lambda x: x[:2] == 'w ', self._router_bandwidth))
waiting_w.add_transition(Transition(waiting_r, ignorable_line, nothing))
waiting_w.add_transition(Transition(waiting_s, lambda x: x[:2] == 'r ', self._router_begin)) # "w" lines are optional
waiting_w.add_transition(Transition(waiting_r, lambda x: x[:2] != 'w ', die('Expected "w " while parsing routers not "%s"')))
waiting_w.add_transition(Transition(waiting_r, lambda x: x.strip() == '.', nothing))
waiting_p.add_transition(Transition(waiting_r, lambda x: x[:2] == 'p ', self._router_policy))
waiting_p.add_transition(Transition(waiting_r, ignorable_line, nothing))
waiting_p.add_transition(Transition(waiting_s, lambda x: x[:2] == 'r ', self._router_begin)) # "p" lines are optional
waiting_p.add_transition(Transition(waiting_r, lambda x: x[:2] != 'p ', die('Expected "p " while parsing routers not "%s"')))
waiting_p.add_transition(Transition(waiting_r, lambda x: x.strip() == '.', nothing))
#.........这里部分代码省略.........
开发者ID:enriquefynn,项目名称:txtorcon,代码行数:101,代码来源:torstate.py
注:本文中的txtorcon.router.Router类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论