本文整理汇总了Python中neubot.state.STATE.update方法的典型用法代码示例。如果您正苦于以下问题:Python STATE.update方法的具体用法?Python STATE.update怎么用?Python STATE.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neubot.state.STATE
的用法示例。
在下文中一共展示了STATE.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: got_response_collecting
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def got_response_collecting(self, stream, request, response):
logging.info("BitTorrent: collecting ... done")
if self.success:
#
# Always measure at the receiver because there is more
# information at the receiver and also to make my friend
# Enrico happier :-P.
# The following is not a bug: it's just that the server
# returns a result using the point of view of the client,
# i.e. upload_speed is _our_ upload speed.
#
m = json.loads(response.body.read())
self.my_side["upload_speed"] = m["upload_speed"]
upload = utils.speed_formatter(m["upload_speed"])
STATE.update("test_progress", "100%", publish=False)
STATE.update("test_upload", upload)
logging.info('BitTorrent: upload speed: %s', upload)
if privacy.collect_allowed(self.my_side):
if DATABASE.readonly:
logging.warning('bittorrent_client: readonly database')
else:
table_bittorrent.insert(DATABASE.connection(), self.my_side)
# Update the upstream channel estimate
target_bytes = int(m["target_bytes"])
if target_bytes > 0:
estimate.UPLOAD = target_bytes
self.final_state = True
stream.close()
示例2: _schedule_after
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def _schedule_after(self, interval):
''' Schedule next rendezvous after interval seconds '''
logging.info('background_rendezvous: next rendezvous in %d seconds',
interval)
timestamp = POLLER.sched(interval, self.run)
STATE.update('idle', publish=False)
STATE.update('next_rendezvous', timestamp)
示例3: _start_collect
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def _start_collect(self, stream, result):
''' Start the COLLECT phase '''
STATE.update('collect')
logging.debug('raw_negotiate: collect in progress...')
context = stream.opaque
extra = context.extra
extra['local_result'] = result
body = six.b(json.dumps(result))
host_header = utils_net.format_epnt((extra['address'], extra['port']))
self.append_request(stream, 'POST', '/collect/raw', 'HTTP/1.1')
self.append_header(stream, 'Host', host_header)
self.append_header(stream, 'User-Agent', utils_version.HTTP_HEADER)
self.append_header(stream, 'Content-Type', 'application/json')
self.append_header(stream, 'Content-Length', str(len(body)))
self.append_header(stream, 'Cache-Control', 'no-cache')
self.append_header(stream, 'Pragma', 'no-cache')
self.append_header(stream, 'Connection', 'close')
if extra['authorization']:
self.append_header(stream, 'Authorization', extra['authorization'])
self.append_end_of_headers(stream)
self.append_bytes(stream, body)
http_utils.prettyprint_json(result, '>')
self.send_message(stream)
context.body = six.StringIO() # Want to save body
extra['requests'] += 1
示例4: _api_config
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def _api_config(self, stream, request, query):
response = Message()
indent, mimetype, sort_keys = None, "application/json", False
dictionary = cgi.parse_qs(query)
if "debug" in dictionary and utils.intify(dictionary["debug"][0]):
indent, mimetype, sort_keys = 4, "text/plain", True
if request.method == "POST":
s = request.body.read()
updates = qs_to_dictionary(s)
privacy.check(updates)
# Very low barrier to prevent damage from kiddies
if "agent.interval" in updates:
interval = int(updates["agent.interval"])
if interval < 1380 and interval != 0:
raise ConfigError("Bad agent.interval")
CONFIG.merge_api(updates, DATABASE.connection())
STATE.update("config", updates)
# Empty JSON b/c '204 No Content' is treated as an error
s = "{}"
else:
s = json.dumps(CONFIG.conf, sort_keys=sort_keys, indent=indent)
stringio = StringIO.StringIO(s)
response.compose(code="200", reason="Ok", body=stringio,
mimetype=mimetype)
stream.send_response(request, response)
示例5: got_response_negotiating
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def got_response_negotiating(self, stream, request, response):
m = json.loads(response.body.read())
PROPERTIES = ("authorization", "queue_pos", "real_address", "unchoked")
for k in PROPERTIES:
self.conf["_%s" % k] = m[k]
if not self.conf["_unchoked"]:
LOG.complete("done (queue_pos %d)" % m["queue_pos"])
STATE.update("negotiate", {"queue_pos": m["queue_pos"]})
self.connection_ready(stream)
else:
LOG.complete("done (unchoked)")
sha1 = hashlib.sha1()
sha1.update(m["authorization"])
self.conf["bittorrent.my_id"] = sha1.digest()
LOG.debug("* My ID: %s" % sha1.hexdigest())
self.http_stream = stream
self.negotiating = False
peer = PeerNeubot(self.poller)
peer.complete = self.peer_test_complete
peer.connection_lost = self.peer_connection_lost
peer.connection_failed = self.peer_connection_failed
peer.configure(self.conf)
peer.connect((self.http_stream.peername[0],
self.conf["bittorrent.port"]))
示例6: runner_api_done
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def runner_api_done(state):
''' Invoked when the test completes successfully '''
#
# State value should be 'idle'. This is needed otherwise the GUI stays
# on collect after a test is run on demand.
#
STATE.update(state)
示例7: __init__
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def __init__(self, poller):
ClientHTTP.__init__(self, poller)
STATE.update("test_name", "speedtest")
self.child = None
self.streams = collections.deque()
self.finished = False
self.state = None
示例8: _waiting_pingback
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def _waiting_pingback(self, stream, data):
''' Invoke when waiting for PINGBACK '''
#context = stream.opaque
#context.bufferise(data)
#tmp = context.pullup(len(PINGBACK))
#if not tmp:
stream.recv(len(PINGBACK), self._waiting_pingback)
return
if tmp[4:5] != PINGBACK_CODE:
raise RuntimeError('skype_clnt: received invalid message')
timediff = utils.ticks() - context.alrtt_ticks
context.state.setdefault('alrtt_list', []).append(timediff)
logging.debug('< PINGBACK')
logging.debug('skype_clnt: alrtt_sample: %f', timediff)
context.alrtt_cnt -= 1
if context.alrtt_cnt > 0:
self._send_ping(stream)
return
alrtt_list = context.state['alrtt_list']
alrtt_avg = sum(alrtt_list) / len(alrtt_list)
context.state['alrtt_avg'] = alrtt_avg
latency = utils.time_formatter(alrtt_avg)
logging.info('skype_clnt: alrtt_avg: %s', latency)
STATE.update('test_latency', latency)
logging.info('skype_clnt: estimating ALRTT... complete')
logging.info('skype_clnt: skype goodput test... in progress')
logging.debug('> RAWTEST')
stream.send(RAWTEST, self._skypetest_sent)
示例9: runner_api_done
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def runner_api_done():
''' Invoked when the test is done '''
#
# Needed otherwise the GUI stays on collect after a
# test is run on demand.
#
STATE.update('idle')
示例10: got_response_collecting
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def got_response_collecting(self, stream, request, response):
LOG.complete()
if self.success:
#
# Always measure at the receiver because there is more
# information at the receiver and also to make my friend
# Enrico happier :-P.
# The following is not a bug: it's just that the server
# returns a result using the point of view of the client,
# i.e. upload_speed is _our_ upload speed.
#
m = json.loads(response.body.read())
self.my_side["upload_speed"] = m["upload_speed"]
upload = utils.speed_formatter(m["upload_speed"])
STATE.update("test_upload", upload)
if privacy.collect_allowed(self.my_side):
table_bittorrent.insert(DATABASE.connection(), self.my_side)
# Update the upstream channel estimate
target_bytes = int(m["target_bytes"])
if target_bytes > 0:
estimate.UPLOAD = target_bytes
stream.close()
示例11: _waiting_pingback
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def _waiting_pingback(self, stream, data):
""" Invoke when waiting for PINGBACK """
context = stream.opaque
context.bufferise(data)
tmp = context.pullup(len(PINGBACK))
if not tmp:
stream.recv(len(PINGBACK), self._waiting_pingback)
return
if tmp[4:5] != PINGBACK_CODE:
raise RuntimeError("raw_clnt: received invalid message")
timediff = utils.ticks() - context.alrtt_ticks
context.state.setdefault("alrtt_list", []).append(timediff)
logging.debug("< PINGBACK")
logging.debug("raw_clnt: alrtt_sample: %f", timediff)
context.alrtt_cnt -= 1
if context.alrtt_cnt > 0:
self._send_ping(stream)
return
alrtt_list = context.state["alrtt_list"]
alrtt_avg = sum(alrtt_list) / len(alrtt_list)
context.state["alrtt_avg"] = alrtt_avg
latency = utils.time_formatter(alrtt_avg)
logging.info("raw_clnt: alrtt_avg: %s", latency)
STATE.update("test_progress", "50%", publish=False)
STATE.update("test_latency", latency)
logging.info("raw_clnt: estimating ALRTT... complete")
logging.info("raw_clnt: raw goodput test... in progress")
logging.debug("> RAWTEST")
stream.send(RAWTEST, self._rawtest_sent)
示例12: handle_connect
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def handle_connect(self, connector, sock, rtt, sslconfig, state):
logging.info("raw_clnt: connection established with %s", connector)
logging.info("raw_clnt: connect_time: %s", utils.time_formatter(rtt))
state["connect_time"] = rtt
Stream(sock, self._connection_ready, self._connection_lost, sslconfig, "", ClientContext(state))
STATE.update("test", "raw")
state["mss"] = sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG)
state["rcvr_data"] = []
示例13: handle_connect
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def handle_connect(self, connector, sock, rtt, sslconfig, state):
logging.info('raw_clnt: connection established with %s', connector)
logging.info('raw_clnt: connect_time: %s', utils.time_formatter(rtt))
state['connect_time'] = rtt
Stream(sock, self._connection_ready, self._connection_lost,
sslconfig, '', ClientContext(state))
STATE.update('test', 'raw')
state['mss'] = sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG)
state['rcvr_data'] = []
示例14: connect_uri
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def connect_uri(self, uri=None, count=None):
self._task = None
if not uri:
uri = "http://%s:9773/rendezvous" % CONFIG["agent.master"]
LOG.start("* Rendezvous with %s" % uri)
STATE.update("rendezvous")
# We need to make just one connection
ClientHTTP.connect_uri(self, uri, 1)
示例15: connection_ready
# 需要导入模块: from neubot.state import STATE [as 别名]
# 或者: from neubot.state.STATE import update [as 别名]
def connection_ready(self, stream):
LOG.complete()
STATE.update("negotiate")
LOG.start("BitTorrent: negotiating")
request = Message()
body = json.dumps({"target_bytes": self.conf["bittorrent.bytes.up"]})
request.compose(method="GET", pathquery="/negotiate/bittorrent",
host=self.host_header, body=body, mimetype="application/json")
request["authorization"] = self.conf.get("_authorization", "")
stream.send_request(request)