Skip to content

Commit

Permalink
Private keys
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelchang committed Feb 16, 2016
1 parent 0f83551 commit 5495677
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.8.3)
project(roscloud)
project(roscloud_client)

find_package(catkin REQUIRED COMPONENTS
rospy
Expand Down
20 changes: 8 additions & 12 deletions launch/example.launch
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
<?xml version="1.0"?>
<launch>
<node pkg="roscloud" type="client_node.py" name="foo_client_node" output="screen">
<node pkg="roscloud_client" type="client_node.py" name="foo_client_node" output="screen">
<param name="name" value="foo"/>
<!-- <param name="host" value="localhost"/> -->
<!-- <param name="port" value="9000"/> -->
<param name="host" value="wallar.me"/>
<param name="port" value="8080"/>
<param name="private_key" value="MIICXAIBAAKBgQCTUQ49FJUCVvU5tIag" />
</node>

<node pkg="roscloud" type="client_node.py" name="bar_client_node" output="screen">
<node pkg="roscloud_client" type="client_node.py" name="bar_client_node" output="screen">
<param name="name" value="bar"/>
<!-- <param name="host" value="localhost"/> -->
<!-- <param name="port" value="9000"/> -->
<param name="host" value="wallar.me"/>
<param name="port" value="8080"/>
<param name="private_key" value="MIICXAIBAAKBgQCTUQ49FJUCVvU5tIag" />
</node>

<node pkg="roscloud" type="client_node.py" name="baz_client_node" output="screen">
<node pkg="roscloud_client" type="client_node.py" name="baz_client_node" output="screen">
<param name="name" value="baz"/>
<!-- <param name="host" value="localhost"/> -->
<!-- <param name="port" value="9000"/> -->
<param name="host" value="wallar.me"/>
<param name="port" value="8080"/>
<param name="private_key" value="MIICXAIBAAKBgQCTUQ49FJUCVvU5tIag" />
</node>

<node pkg="roscloud" type="client_node.py" name="qux_client_node" output="screen">
<node pkg="roscloud_client" type="client_node.py" name="qux_client_node" output="screen">
<param name="name" value="qux"/>
<!-- <param name="host" value="localhost"/> -->
<!-- <param name="port" value="9000"/> -->
<param name="host" value="wallar.me"/>
<param name="port" value="8080"/>
<param name="private_key" value="MIICXAIBAAKBgQCTUQ49FJUCVvU5tIag" />
<rosparam>
publishing:
- /state
Expand Down
6 changes: 3 additions & 3 deletions launch/video_chat_demo.launch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<launch>
<node pkg="roscloud" type="client_node.py" name="alex_client_node" output="screen">
<param name="name" value="alex"/>
<node pkg="roscloud" type="client_node.py" name="raphael_client_node" output="screen">
<param name="name" value="raphael"/>
<param name="host" value="wallar.me"/>
<param name="port" value="8080"/>
<rosparam>
Expand All @@ -10,7 +10,7 @@
types:
- sensor_msgs/CompressedImage
trusted:
- raphael
- alex
</rosparam>

</node>
Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<package>
<name>roscloud</name>
<name>roscloud_client</name>
<version>0.0.1</version>
<description>ROS Cloud Robotics Framework</description>
<maintainer email="[email protected]">Alex Wallar</maintainer>
Expand Down
11 changes: 7 additions & 4 deletions src/client_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@

class ROSCloudNode(object):

def __init__(self, host, port, name, broadcasting):
def __init__(self, host, port, name, broadcasting, private_key):
self.host = host
self.port = port
self.name = name
self.conn = dict()
self.receiver = None
self.subs = dict()
self.broadcasting = broadcasting
self.private_key = private_key
self.pub_man = pm.PublisherManager()

def run(self):
Expand All @@ -30,10 +31,10 @@ def run(self):
self.name))
continue
self.conn[topic] = Connection(host, port, "{}{}".format(
self.name, topic))
self.name, topic), private_key)
self.conn[topic].start()
self.receiver = Connection(host, port, "{}{}".format(
self.name, "/receiving"))
self.name, "/receiving"), private_key)
self.receiver.start()
while not rospy.is_shutdown():
#for key, conn in self.conn.iteritems():
Expand Down Expand Up @@ -61,6 +62,7 @@ def callback(msg):
data["Topic"] = "/{}{}".format(self.name, topic)
data["Type"] = msg_type
data["Stamp"] = time.time()
data["Private_key"] = self.private_key
data["Msg"] = mc.convert_ros_message_to_dictionary(msg)
self.conn[topic].send_message(data)
return callback
Expand All @@ -74,6 +76,7 @@ def callback(msg):
trusted = rospy.get_param("~trusted", [])
host = rospy.get_param("~host")
port = rospy.get_param("~port")
private_key = rospy.get_param("~private_key")
broadcasting = zip(topics, types, trusted)
rcn = ROSCloudNode(host, port, name, broadcasting)
rcn = ROSCloudNode(host, port, name, broadcasting, private_key)
rcn.run()
12 changes: 8 additions & 4 deletions src/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

class Connection(threading.Thread):

def __init__(self, host, port, name):
def __init__(self, host, port, name, private_key):
super(Connection, self).__init__()
self.host = host
self.port = port
self.name = name
self.url = "ws://{}:{}/{}".format(host, port, name)
self.url = "ws://{}:{}/{}/{}".format(host, port, private_key, name)
self.ioloop = None
self.connection = None
self.values = dict()
Expand Down Expand Up @@ -60,7 +60,8 @@ def send_message_cb(self, data):
self.timer.start()

def send_message(self, data):
self.ioloop.add_callback(self.send_message_cb, data)
if not self.ioloop is None:
self.ioloop.add_callback(self.send_message_cb, data)

def updates(self):
payloads = copy.copy(self.values)
Expand Down Expand Up @@ -88,7 +89,10 @@ def on_connected(self, res):
def on_message(self, payload):
if len(payload) == 1:
self.acknowledged = True
self.timer.cancel()
try:
self.timer.cancel()
except:
pass
else:
decompressed = zlib.decompress(payload)
size = struct.unpack('=I', decompressed[:4])
Expand Down

0 comments on commit 5495677

Please sign in to comment.