本文整理汇总了Python中network.Network.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Network.stop方法的具体用法?Python Network.stop怎么用?Python Network.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.Network
的用法示例。
在下文中一共展示了Network.stop方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NetworkServer
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
class NetworkServer(util.DaemonThread):
def __init__(self, config):
util.DaemonThread.__init__(self)
self.debug = False
self.config = config
self.pipe = util.QueuePipe()
self.network = Network(self.pipe, config)
self.lock = threading.RLock()
# each GUI is a client of the daemon
self.clients = []
self.request_id = 0
self.requests = {}
def add_client(self, client):
for key in ['status', 'banner', 'updated', 'servers', 'interfaces']:
value = self.network.get_status_value(key)
client.response_queue.put({'method':'network.status', 'params':[key, value]})
with self.lock:
self.clients.append(client)
print_error("new client:", len(self.clients))
def remove_client(self, client):
with self.lock:
self.clients.remove(client)
print_error("client quit:", len(self.clients))
def send_request(self, client, request):
with self.lock:
self.request_id += 1
self.requests[self.request_id] = (request['id'], client)
request['id'] = self.request_id
if self.debug:
print_error("-->", request)
self.pipe.send(request)
def run(self):
self.network.start()
while self.is_running():
try:
response = self.pipe.get()
except util.timeout:
continue
if self.debug:
print_error("<--", response)
response_id = response.get('id')
if response_id:
with self.lock:
client_id, client = self.requests.pop(response_id)
response['id'] = client_id
client.response_queue.put(response)
else:
# notification
m = response.get('method')
v = response.get('params')
for client in self.clients:
if m == 'network.status' or v in client.subscriptions.get(m, []):
client.response_queue.put(response)
self.network.stop()
print_error("server exiting")
示例2: NetworkServer
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
class NetworkServer(threading.Thread):
def __init__(self, config):
threading.Thread.__init__(self)
self.daemon = True
self.config = config
self.network = Network(config)
# network sends responses on that queue
self.network_queue = Queue.Queue()
self.running = False
self.lock = threading.RLock()
# each GUI is a client of the daemon
self.clients = []
# todo: the daemon needs to know which client subscribed to which address
def is_running(self):
with self.lock:
return self.running
def stop(self):
with self.lock:
self.running = False
def start(self):
self.running = True
threading.Thread.start(self)
def add_client(self, client):
for key in ['status','banner','updated','servers','interfaces']:
value = self.network.get_status_value(key)
client.daemon_pipe.get_queue.put({'method':'network.status', 'params':[key, value]})
with self.lock:
self.clients.append(client)
def remove_client(self, client):
with self.lock:
self.clients.remove(client)
print_error("client quit:", len(self.clients))
def run(self):
self.network.start(self.network_queue)
while self.is_running():
try:
response = self.network_queue.get(timeout=0.1)
except Queue.Empty:
continue
for client in self.clients:
client.daemon_pipe.get_queue.put(response)
self.network.stop()
print_error("server exiting")
示例3: test_connect
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
def test_connect(self):
port1 = random.randint(20000, 30000)
port2 = random.randint(20000, 30000)
n1 = Network(port1)
n2 = Network(port2)
n1.start()
n2.start()
time.sleep(WAIT_TIME)
m = 'hasdgbaeswbjf'
n2.set_clipboard(m)
time.sleep(WAIT_TIME)
n1.connect('localhost', port2)
time.sleep(WAIT_TIME)
self.assertEqual(m, n1.get_clipboard())
n1.stop()
n2.stop()
示例4: NetworkServer
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
class NetworkServer(threading.Thread):
def __init__(self, config):
threading.Thread.__init__(self)
self.daemon = True
self.debug = False
self.config = config
self.network = Network(config)
# network sends responses on that queue
self.network_queue = Queue.Queue()
self.running = False
self.lock = threading.RLock()
# each GUI is a client of the daemon
self.clients = []
self.request_id = 0
self.requests = {}
def is_running(self):
with self.lock:
return self.running
def stop(self):
with self.lock:
self.running = False
def start(self):
self.running = True
threading.Thread.start(self)
def add_client(self, client):
for key in ['status','banner','updated','servers','interfaces']:
value = self.network.get_status_value(key)
client.response_queue.put({'method':'network.status', 'params':[key, value]})
with self.lock:
self.clients.append(client)
print_error("new client:", len(self.clients))
def remove_client(self, client):
with self.lock:
self.clients.remove(client)
print_error("client quit:", len(self.clients))
def send_request(self, client, request):
with self.lock:
self.request_id += 1
self.requests[self.request_id] = (request['id'], client)
request['id'] = self.request_id
if self.debug:
print_error("-->", request)
self.network.requests_queue.put(request)
def run(self):
self.network.start(self.network_queue)
while self.is_running():
try:
response = self.network_queue.get(timeout=0.1)
except Queue.Empty:
continue
if self.debug:
print_error("<--", response)
response_id = response.get('id')
if response_id:
with self.lock:
client_id, client = self.requests.pop(response_id)
response['id'] = client_id
client.response_queue.put(response)
else:
# notification
for client in self.clients:
client.response_queue.put(response)
self.network.stop()
print_error("server exiting")
示例5: NetworkProxy
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
class NetworkProxy(threading.Thread):
def __init__(self, socket, config=None):
if config is None:
config = {} # Do not use mutables as default arguments!
threading.Thread.__init__(self)
self.config = SimpleConfig(config) if type(config) == type({}) else config
self.message_id = 0
self.unanswered_requests = {}
self.subscriptions = {}
self.debug = False
self.lock = threading.Lock()
self.pending_transactions_for_notifications = []
self.callbacks = {}
self.running = True
self.daemon = True
if socket:
self.pipe = util.SocketPipe(socket)
self.network = None
else:
self.network = Network(config)
self.pipe = util.QueuePipe(send_queue=self.network.requests_queue)
self.network.start(self.pipe.get_queue)
for key in ['status', 'banner', 'updated', 'servers', 'interfaces']:
value = self.network.get_status_value(key)
self.pipe.get_queue.put({'method': 'network.status', 'params': [key, value]})
# status variables
self.status = 'connecting'
self.servers = {}
self.banner = ''
self.blockchain_height = 0
self.server_height = 0
self.interfaces = []
def is_running(self):
return self.running
def run(self):
while self.is_running():
try:
response = self.pipe.get()
except util.timeout:
continue
if response is None:
break
self.process(response)
self.trigger_callback('stop')
if self.network:
self.network.stop()
print_error("NetworkProxy: terminating")
def process(self, response):
if self.debug:
print_error("<--", response)
if response.get('method') == 'network.status':
key, value = response.get('params')
if key == 'status':
self.status = value
elif key == 'banner':
self.banner = value
elif key == 'updated':
self.blockchain_height, self.server_height = value
elif key == 'servers':
self.servers = value
elif key == 'interfaces':
self.interfaces = value
self.trigger_callback(key)
return
msg_id = response.get('id')
result = response.get('result')
error = response.get('error')
if msg_id is not None:
with self.lock:
method, params, callback = self.unanswered_requests.pop(msg_id)
else:
method = response.get('method')
params = response.get('params')
with self.lock:
for k, v in self.subscriptions.items():
if (method, params) in v:
callback = k
break
else:
print_error("received unexpected notification", method, params)
return
r = {'method':method, 'params':params, 'result':result, 'id':msg_id, 'error':error}
callback(r)
def send(self, messages, callback):
"""return the ids of the requests that we sent"""
# detect subscriptions
sub = []
#.........这里部分代码省略.........
示例6: NetworkProxy
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
class NetworkProxy(util.DaemonThread):
def __init__(self, socket, config=None):
if config is None:
config = {} # Do not use mutables as default arguments!
util.DaemonThread.__init__(self)
self.config = SimpleConfig(config) if type(config) == type({}) else config
self.message_id = 0
self.unanswered_requests = {}
self.subscriptions = {}
self.debug = False
self.lock = threading.Lock()
self.callbacks = {}
if socket:
self.pipe = util.SocketPipe(socket)
self.network = None
else:
self.pipe = util.QueuePipe()
self.network = Network(self.pipe, config)
self.network.start()
for key in ['fee','status','banner','updated','servers','interfaces']:
value = self.network.get_status_value(key)
self.pipe.get_queue.put({'method':'network.status', 'params':[key, value]})
# status variables
self.status = 'unknown'
self.servers = {}
self.banner = ''
self.blockchain_height = 0
self.server_height = 0
self.interfaces = []
# value returned by estimatefee
self.fee = None
def run(self):
while self.is_running():
self.run_jobs() # Synchronizer and Verifier
try:
response = self.pipe.get()
except util.timeout:
continue
if response is None:
break
# Protect against ill-formed or malicious server responses
try:
self.process(response)
except:
traceback.print_exc(file=sys.stderr)
self.trigger_callback('stop')
if self.network:
self.network.stop()
self.print_error("stopped")
def process(self, response):
if self.debug:
self.print_error("<--", response)
if response.get('method') == 'network.status':
key, value = response.get('params')
if key == 'status':
self.status = value
elif key == 'banner':
self.banner = value
elif key == 'fee':
self.fee = value
elif key == 'updated':
self.blockchain_height, self.server_height = value
elif key == 'servers':
self.servers = value
elif key == 'interfaces':
self.interfaces = value
if key in ['status', 'updated']:
self.trigger_callback(key)
else:
self.trigger_callback(key, (value,))
return
msg_id = response.get('id')
result = response.get('result')
error = response.get('error')
if msg_id is not None:
with self.lock:
method, params, callback = self.unanswered_requests.pop(msg_id)
else:
method = response.get('method')
params = response.get('params')
with self.lock:
for k,v in self.subscriptions.items():
if (method, params) in v:
callback = k
break
else:
self.print_error("received unexpected notification",
method, params)
return
r = {'method':method, 'params':params, 'result':result,
#.........这里部分代码省略.........
示例7: bind_layers
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
# scapy basic configuration...
bind_layers(UDP,BOOTP,sport=BOOTPS)
conf.verb = 0
startTime = time.time()
print "Simulation Start Time : ", time.ctime()
simulator = Simulator()
network = Network(simQueue=signalQueue)
network.launch()
#timerEvent.run()
simulator.run()
simuTime = time.time() - startTime
print "Time Elapsed while Simulation :%.3f " % (simuTime)
print "Stopping network...."
network.stop()
sys.exit(0)
示例8: NetworkProxy
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
class NetworkProxy(util.DaemonThread):
def __init__(self, socket, config=None):
if config is None:
config = {} # Do not use mutables as default arguments!
util.DaemonThread.__init__(self)
self.config = SimpleConfig(config) if type(config) == type({}) else config
self.message_id = 0
self.unanswered_requests = {}
self.subscriptions = {}
self.debug = False
self.lock = threading.Lock()
self.callbacks = {}
if socket:
self.pipe = util.SocketPipe(socket)
self.network = None
else:
self.pipe = util.QueuePipe()
self.network = Network(self.pipe, config)
self.network.start()
for key in ["fee", "status", "banner", "updated", "servers", "interfaces"]:
value = self.network.get_status_value(key)
self.pipe.get_queue.put({"method": "network.status", "params": [key, value]})
# status variables
self.status = "unknown"
self.servers = {}
self.banner = ""
self.blockchain_height = 0
self.server_height = 0
self.interfaces = []
self.jobs = []
# value returned by estimatefee
self.fee = None
def run(self):
while self.is_running():
for job in self.jobs:
job()
try:
response = self.pipe.get()
except util.timeout:
continue
if response is None:
break
self.process(response)
self.trigger_callback("stop")
if self.network:
self.network.stop()
self.print_error("stopped")
def process(self, response):
if self.debug:
print_error("<--", response)
if response.get("method") == "network.status":
key, value = response.get("params")
if key == "status":
self.status = value
elif key == "banner":
self.banner = value
elif key == "fee":
self.fee = value
elif key == "updated":
self.blockchain_height, self.server_height = value
elif key == "servers":
self.servers = value
elif key == "interfaces":
self.interfaces = value
if key in ["status", "updated"]:
self.trigger_callback(key)
else:
self.trigger_callback(key, (value,))
return
msg_id = response.get("id")
result = response.get("result")
error = response.get("error")
if msg_id is not None:
with self.lock:
method, params, callback = self.unanswered_requests.pop(msg_id)
else:
method = response.get("method")
params = response.get("params")
with self.lock:
for k, v in self.subscriptions.items():
if (method, params) in v:
callback = k
break
else:
print_error("received unexpected notification", method, params)
return
r = {"method": method, "params": params, "result": result, "id": msg_id, "error": error}
callback(r)
def send(self, messages, callback):
"""return the ids of the requests that we sent"""
#.........这里部分代码省略.........
示例9: TestSimple
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
class TestSimple(unittest.TestCase):
def setUp(self):
self.port1 = random.randint(20000, 30000)
self.port2 = random.randint(20000, 30000)
self.n1 = Network(self.port1)
self.n2 = Network(self.port2)
self.n1.start()
self.n2.start()
# give everything time to get going
time.sleep(WAIT_TIME)
# establish connection
self.n2.connect('localhost', self.port1)
time.sleep(WAIT_TIME)
# test simple clipboard syncing
def test_simple(self):
m1 = 'test 1'
self.n2.set_clipboard(m1)
time.sleep(WAIT_TIME)
self.assertEqual(self.n1.get_clipboard(), m1)
m2 = 'test 2'
self.n1.set_clipboard(m2)
time.sleep(WAIT_TIME)
self.assertEqual(self.n2.get_clipboard(), m2)
def test_disconnect_from_client(self):
self.n2.set_clipboard('test')
time.sleep(WAIT_TIME)
self.assertEqual(self.n1.get_clipboard(), 'test')
self.n2.disconnect('localhost')
time.sleep(WAIT_TIME)
m = "test %d" % random.randint(0, 1000)
self.n2.set_clipboard(m)
time.sleep(WAIT_TIME)
self.assertNotEqual(self.n1.get_clipboard(), m)
def test_disconnect_from_server(self):
self.n2.set_clipboard('test')
time.sleep(WAIT_TIME)
self.assertEqual(self.n1.get_clipboard(), 'test')
self.n1.disconnect('localhost')
time.sleep(WAIT_TIME)
m = "test %d" % random.randint(0, 1000)
self.n2.set_clipboard(m)
time.sleep(WAIT_TIME)
self.assertNotEqual(self.n1.get_clipboard(), m)
def test_reconnect(self):
self.n2.disconnect('localhost')
time.sleep(WAIT_TIME)
self.n1.connect('localhost', self.port2)
time.sleep(WAIT_TIME)
self.n1.set_clipboard('asdf 5')
time.sleep(WAIT_TIME)
self.assertEqual(self.n2.get_clipboard(), 'asdf 5')
def tearDown(self):
# give it enough time to execute before tearing down
time.sleep(WAIT_TIME)
self.n1.stop()
self.n2.stop()
示例10: Daemon
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
class Daemon(DaemonThread):
def __init__(self, config, fd):
DaemonThread.__init__(self)
self.config = config
if config.get("offline"):
self.network = None
else:
self.network = Network(config)
self.network.start()
self.gui = None
self.wallets = {}
# Setup server
cmd_runner = Commands(self.config, None, self.network)
host = config.get("rpchost", "localhost")
port = config.get("rpcport", 0)
server = SimpleJSONRPCServer((host, port), logRequests=False, requestHandler=RequestHandler)
os.write(fd, repr((server.socket.getsockname(), time.time())))
os.close(fd)
server.timeout = 0.1
for cmdname in known_commands:
server.register_function(getattr(cmd_runner, cmdname), cmdname)
server.register_function(self.run_cmdline, "run_cmdline")
server.register_function(self.ping, "ping")
server.register_function(self.run_daemon, "daemon")
server.register_function(self.run_gui, "gui")
self.server = server
def ping(self):
return True
def run_daemon(self, config):
sub = config.get("subcommand")
assert sub in ["start", "stop", "status"]
if sub == "start":
response = "Daemon already running"
elif sub == "status":
if self.network:
p = self.network.get_parameters()
response = {
"path": self.network.config.path,
"server": p[0],
"blockchain_height": self.network.get_local_height(),
"server_height": self.network.get_server_height(),
"nodes": self.network.get_interfaces(),
"connected": self.network.is_connected(),
"auto_connect": p[4],
"wallets": {k: w.is_up_to_date() for k, w in self.wallets.items()},
}
else:
response = "Daemon offline"
elif sub == "stop":
self.stop()
response = "Daemon stopped"
return response
def run_gui(self, config_options):
config = SimpleConfig(config_options)
if self.gui:
if hasattr(self.gui, "new_window"):
path = config.get_wallet_path()
self.gui.new_window(path, config.get("url"))
response = "ok"
else:
response = "error: current GUI does not support multiple windows"
else:
response = "Error: Electrum is running in daemon mode. Please stop the daemon first."
return response
def load_wallet(self, path, get_wizard=None):
if path in self.wallets:
wallet = self.wallets[path]
else:
storage = WalletStorage(path)
if get_wizard:
if storage.file_exists:
wallet = Wallet(storage)
action = wallet.get_action()
else:
action = "new"
if action:
wizard = get_wizard()
wallet = wizard.run(self.network, storage)
else:
wallet.start_threads(self.network)
else:
wallet = Wallet(storage)
wallet.start_threads(self.network)
if wallet:
self.wallets[path] = wallet
return wallet
def run_cmdline(self, config_options):
config = SimpleConfig(config_options)
cmdname = config.get("cmd")
cmd = known_commands[cmdname]
path = config.get_wallet_path()
wallet = self.load_wallet(path) if cmd.requires_wallet else None
# arguments passed to function
args = map(lambda x: config.get(x), cmd.params)
#.........这里部分代码省略.........
示例11: NetworkProxy
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
class NetworkProxy(util.DaemonThread):
"""Proxy for communicating with the daemon or Network.
If the daemon is running when this is initialized,
this will create a socket pipe.
Otherwise, this will create a new Network instance."""
def __init__(self, socket, config=None):
if config is None:
config = {} # Do not use mutables as default arguments!
util.DaemonThread.__init__(self)
self.config = SimpleConfig(config) if type(config) == type({}) else config
self.message_id = 0
self.unanswered_requests = {}
self.subscriptions = {}
self.debug = False
self.lock = threading.Lock()
self.pending_transactions_for_notifications = []
self.callbacks = {}
if socket:
self.pipe = util.SocketPipe(socket)
self.network = None
else:
self.pipe = util.QueuePipe()
self.network = Network(self.pipe, config)
self.network.start()
for key in ['status','banner','updated','servers','interfaces']:
value = self.network.get_status_value(key)
self.pipe.get_queue.put({'method':'network.status', 'params':[key, value]})
# status variables
self.status = 'connecting'
self.servers = {}
self.banner = ''
self.blockchain_height = 0
self.server_height = 0
self.interfaces = []
def switch_to_active_chain(self):
"""Create a new Network instance or send message to daemon."""
with self.lock:
# for the network.switch_chains request
message_id = self.message_id
self.message_id = 0
self.unanswered_requests = {}
self.subscriptions = {}
self.pending_transactions_for_notifications = []
self.callbacks = {}
self.status = 'connecting'
self.servers = {}
self.banner = ''
self.blockchain_height = 0
self.server_height = 0
self.interfaces = []
# Not daemon, probably running GUI
if self.network:
self.network.switch_chains()
for key in ['status','banner','updated','servers','interfaces']:
value = self.network.get_status_value(key)
self.pipe.get_queue.put({'method':'network.status', 'params':[key, value]})
# Daemon is running
else:
req = {'id': message_id, 'method': 'network.switch_chains', 'params':[chainparams.get_active_chain().code]}
self.pipe.send(req)
def run(self):
while self.is_running():
try:
response = self.pipe.get()
except util.timeout:
continue
if response is None:
break
self.process(response)
self.trigger_callback('stop')
if self.network:
self.network.stop()
self.print_error("stopped")
def process(self, response):
if self.debug:
print_error("<--", response)
if response.get('method') == 'network.status':
key, value = response.get('params')
if key == 'status':
self.status = value
elif key == 'banner':
self.banner = value
elif key == 'updated':
self.blockchain_height, self.server_height = value
elif key == 'servers':
#.........这里部分代码省略.........
示例12: NetworkServer
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
class NetworkServer(util.DaemonThread):
"""Server that the daemon sends connections to.
Handles requests/responses to/from the Network
from ClientThreads. Also handles notifying
ClientThreads of responses to their subscriptions."""
def __init__(self, config):
util.DaemonThread.__init__(self)
self.debug = False
self.config = config
self.pipe = util.QueuePipe()
self.network = Network(self.pipe, config)
self.lock = threading.RLock()
# each GUI is a client of the daemon
self.clients = []
self.request_id = 0
# dict of {request_id: client}
self.requests = {}
def add_client(self, client):
for key in ['status', 'banner', 'updated', 'servers', 'interfaces']:
value = self.network.get_status_value(key)
client.response_queue.put({'method':'network.status', 'params':[key, value]})
with self.lock:
self.clients.append(client)
print_error("new client:", len(self.clients))
def remove_client(self, client):
with self.lock:
self.clients.remove(client)
print_error("client quit:", len(self.clients))
def send_request(self, client, request):
with self.lock:
self.request_id += 1
self.requests[self.request_id] = (request['id'], client)
request['id'] = self.request_id
if self.debug:
print_error("-->", request)
self.pipe.send(request)
def run(self):
self.network.start()
while self.is_running():
try:
response = self.pipe.get()
except util.timeout:
continue
if self.debug:
print_error("<--", response)
response_id = response.get('id')
if response_id:
with self.lock:
client_id, client = self.requests.pop(response_id)
response['id'] = client_id
client.response_queue.put(response)
else:
# responses with no id are notifications (e.g. to subscriptions)
# and are sent to whichever clients have the subscription.
m = response.get('method')
v = response.get('params')
for client in self.clients:
if repr((m, v)) in client.subscriptions or m == 'network.status':
client.response_queue.put(response)
self.network.stop()
print_error("server exiting")
示例13: __init__
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import stop [as 别名]
#.........这里部分代码省略.........
Conneciton on other end status: CONNECTED
"""
conn = self.get_connection(address)
if conn:
print "Connection from %s accepted" % address
conn.status = Connection.CONNECTED
else:
print "Error: no connection from %s exists" % address
def request_connection(self, address):
"""
This is like new_connection except in this case the Connection
with the given address already existed and had status NOT_CONNECTED.
Before this is called:
Connection on this end status: NOT_CONNECTED
Conneciton on other end status: NOT_CONNECTED
After this has executed:
Connection on this end status: PENDING
Conneciton on other end status: REQUEST
"""
self._network.connect(address)
conn = self.get_connection(address)
if conn:
print "Request to connect to %s sent" % address
#conn.status = Connection.PENDING
conn.status = Connection.CONNECTED
else:
print "Error: no connection to %s exists" % address
def disconnect(self, address):
"""
This is called when the user has an open connection to the given
address and wants to close the connection.
Before this is called:
Connection on this end status: CONNECTED
Conneciton on other end status: CONNECTED
After this has executed:
Connection on this end status: NOT_CONNECTED
Conneciton on other end status: NOT_CONNECTED
"""
self._network.disconnect(address)
conn = self.get_connection(address)
if conn:
print "Disconnected from %s" % address
conn.status = Connection.NOT_CONNECTED
else:
print "Error: no connection to %s exists" % address
def cancel_request(self, address):
"""
This is called when the user has requested a connection to the given
address and the request is still pending but the user wants to
cancel the request.
Before this is called:
Connection on this end status: PENDING
Conneciton on other end status: REQUEST
After this has executed:
Connection on this end status: NOT_CONNECTED
Conneciton on other end status: NOT_CONNECTED
"""
conn = self.get_connection(address)
if conn:
print "Request to %s canceled" % address
conn.status = Connection.NOT_CONNECTED
else:
print "Error: no connection to %s exists" % address
def del_connection(self, address):
"""
Removes the Connection with the given address from the list of
connections.
"""
conn = self.get_connection(address)
if conn:
if conn.status == Connection.CONNECTED:
self.disconnect(address)
self._con_mgr.del_connection(address)
else:
print "Error: no connection to %s exists" % address
def update_alias(self, address, new_alias):
"""
Changes the alias of the Connection with the given address to be
new_alias.
"""
conn = self.get_connection(address)
if conn:
print "Updated alias of %s to %s" % (address, new_alias)
conn.alias = new_alias
else:
print "Error: no connection to %s exists" % address
def close(self):
self._network.stop()