2015-07-24 11:31:55 +00:00
|
|
|
"""
|
|
|
|
This module contains all valid messages layers can send to the underlying layers.
|
|
|
|
"""
|
2015-08-06 09:09:01 +00:00
|
|
|
from __future__ import (absolute_import, print_function, division)
|
2015-07-24 11:31:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
class _Message(object):
|
|
|
|
def __eq__(self, other):
|
|
|
|
# Allow message == Connect checks.
|
|
|
|
if isinstance(self, other):
|
|
|
|
return True
|
|
|
|
return self is other
|
|
|
|
|
2015-07-24 15:48:27 +00:00
|
|
|
def __ne__(self, other):
|
|
|
|
return not self.__eq__(other)
|
|
|
|
|
2015-07-24 11:31:55 +00:00
|
|
|
|
|
|
|
class Connect(_Message):
|
|
|
|
"""
|
|
|
|
Connect to the server
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class Reconnect(_Message):
|
|
|
|
"""
|
|
|
|
Re-establish the server connection
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeServer(_Message):
|
|
|
|
"""
|
|
|
|
Change the upstream server.
|
|
|
|
"""
|
|
|
|
|
2015-08-08 14:08:57 +00:00
|
|
|
def __init__(self, address, server_tls, sni, depth=1):
|
2015-07-24 11:31:55 +00:00
|
|
|
self.address = address
|
2015-08-08 14:08:57 +00:00
|
|
|
self.server_tls = server_tls
|
2015-07-24 11:31:55 +00:00
|
|
|
self.sni = sni
|
|
|
|
|
|
|
|
# upstream proxy scenario: you may want to change either the final target or the upstream proxy.
|
|
|
|
# We can express this neatly as the "nth-server-providing-layer"
|
|
|
|
# ServerConnection could get a `via` attribute.
|
|
|
|
self.depth = depth
|
2015-08-14 14:49:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Kill(_Message):
|
|
|
|
"""
|
|
|
|
Kill a connection.
|
|
|
|
"""
|