36 from rosauth.srv
import Authentication
41 from functools
import partial, wraps
43 from tornado
import version_info
as tornado_version_info
44 from tornado.ioloop
import IOLoop
45 from tornado.websocket
import WebSocketHandler, WebSocketClosedError
46 from tornado.gen
import coroutine, BadYieldError
53 """Log the most recent exception to ROS.""" 54 exc = traceback.format_exception(*sys.exc_info())
55 rospy.logerr(
''.join(exc))
59 """Decorator for logging exceptions to ROS.""" 61 def wrapper(*args, **kwargs):
63 return f(*args, **kwargs)
74 use_compression =
False 78 fragment_timeout = 600
80 delay_between_messages = 0
81 max_message_size =
None 82 unregister_timeout = 10.0
83 bson_only_mode =
False 98 self.set_nodelay(
True)
104 if cls.client_manager:
105 cls.client_manager.add_client(self.
client_id, self.request.remote_ip)
106 except Exception
as exc:
107 rospy.logerr(
"Unable to accept incoming connection. Reason: %s", str(exc))
110 rospy.loginfo(
"Awaiting proper authentication...")
119 msg = bson.BSON(message).decode()
121 msg = json.loads(message)
123 if msg[
'op'] ==
'auth':
125 auth_srv = rospy.ServiceProxy(
'authenticate', Authentication)
126 resp = auth_srv(msg[
'mac'], msg[
'client'], msg[
'dest'],
127 msg[
'rand'], rospy.Time(msg[
't']), msg[
'level'],
128 rospy.Time(msg[
'end']))
131 rospy.loginfo(
"Client %d has authenticated.", self.protocol.client_id)
134 rospy.logwarn(
"Client %d did not authenticate. Closing connection.",
135 self.protocol.client_id)
139 self.protocol.incoming(message)
142 self.protocol.incoming(message)
148 self.protocol.finish()
149 if cls.client_manager:
150 cls.client_manager.remove_client(self.
client_id, self.request.remote_ip)
154 if type(message) == bson.BSON:
156 elif type(message) == bytearray:
158 message = bytes(message)
163 IOLoop.instance().add_callback(partial(self.
prewrite_message, message, binary))
170 yield self.write_message(message, binary)
171 except WebSocketClosedError:
172 rospy.logwarn(
'WebSocketClosedError: Tried to write to a closed websocket')
174 except BadYieldError:
177 if tornado_version_info < (4, 5, 0, 0):
def prewrite_message(self, message, binary)
def check_origin(self, origin)
int delay_between_messages
def get_compression_options(self)
def send_message(self, message)
def on_message(self, message)