Alljoyn 概述(2)
AllJoyn 基本概念
• 总线(Bus)
– 实现P2P通信的基础
– AllJoyn 的底层协议类似于D-Bus,相当于是跨设备分布式的 D-Bus
• 总线附件(Bus Attachment)
– 每一个连接到总线上的Alljoyn应用程序被称为总线附件,可用C++或Java编写
– 每个总线附件有独一的名称(unique name),当每次连接到总线时自动分配
– 每个总线附件可以有一个易读的名称(well-known name),用于标识服务,例如“org.alljoyn.bus.addressbook”
• 总线接口(Bus Interfaces)
– 类似于Java中的接口,定义了方法、信号处理函数和属性
– 所有总线方法(Bus Methods)可使用简单或复杂的数据类型(数组、结构等)作为参数 和返回值
• 总线对象(Bus Objects)
– 用于实现总线接口,每个总线对象实现一个或多个总线接口
– 处理远程方法调用(Remote Method Calls)和发出信号(signals)、消息(messages) – 总线对象通过总线附件注册到总线上
– 每个总线对象有一个类似于文件路径的路径名,例如/org/AllJoyn/Games/chess,用于远程方法调用
• 代理总线对象(Proxy Bus Object)
– 一旦总线附件之间建立连接,应用程序创建一个代理总线对象,实现远程方法调用(Remote Method Calls)并准备好从总线上接收信号(signals)
– 远程方法调用是同步的,信号则是异步的且可以一对多(广播)或一对一
• service 和 client
– P2P 应用中提供服务的一方称为 service,使用服务的一方称为 client
– 一个应用程序可以同时是 service 和 client(例如chat)
• session
– 在宣告服务后,service 需创建一个或多个 session,client 发现服务后加入 session
– 每个 session 有一个 session port,类似于 socket 通信中的 port
– session 的两种情形:
point-to-point session:两个 peer 之间交互
multipoint session:多个 peer 加入同一个 session,组成一个 group
• AllJoyn daemon——实现P2P通信的核心
– daemon通过进程间通信(IPC)与应用程序通信,应用程序只与 daemon打交道
– daemon提供一个抽象层处理所有的网络传输、消息路由、命名空间管理等
– 整个AllJoyn系统相当于一个虚拟总线,连接多个AllJoyn daemons和总线附件
– daemon是用 C++编写的 native程序,运行在不同操作系统上的 daemons可实现互联
– 在应用程序启动之前必须先启动daemon
• AllJoyn daemon 在 Android 上的三种实现形式
– 第一种:Android app(AllJoyn.apk)
只支持 WiFi/TCP 传输
无需 root 权限
– 第二种:纯C++编写的可执行程序,在 adb shell 下运行(alljoyn-daemon)
若使用 WiFi 传输无需 root 权限
若使用 Bluetooth 传输需 root 权限,且蓝牙协议栈限定用 bluez
可在 init.rc 中自动加载
– 第三种:与应用程序捆绑在一起(bundle),不需要单独启动daemon
适用于发布基于AllJoyn开发的应用程序
• 设备发现和建立连接的过程
– 注册(Register): 连接在总线上的对象为自身进行注册
– 宣告(Advertise): 连接在总线上的对象通过IP组播(multicast)宣告自身的存在
– 发现(Discover): 发现其他对象的存在
• 在使用蓝牙时借助蓝牙本身的 SDP 进行发现
• 设备连接过程示意图:
• 设备之间通信的方式
– 远程方法调用(同步)
– Signal(异步)
– Raw session(直接 socket 通信,应用程序可选择基于 TCP 或 UDP )
简单应用程序代码示例——echo
总线接口定义:
import org.alljoyn.bus.BusException;
import org.alljoyn.bus.annotation.BusInterface;
import org.alljoyn.bus.annotation.BusMethod;
/*
* This interface implements a simple echo method that returns the same string * that is receives.
*/
@BusInterface
public interface EchoInterface {
/*
* Echo a string.
*
* inStr is the string to be echoed by the service, returns the echoed string. */
@BusMethod(signature="s", replySignature="s")
public String Echo(String inStr) throws BusException;
}
Service端:
public class Service implements SimpleInterface, BusObject {
public static void main(String[] args) {
/* Create a bus connection and connect to the bus */
BusAttachment bus = new BusAttachment(Service.class.getName());
bus.connect();
/* Register the service */
Service service = new Service();
bus.registerBusObject(service, "/myobject");
/* Request a well-known name */
try {
bus.RequestName("org.alljoyn.echo", REQUEST_NAME_NO_FLAGS);
} catch (BusException ex) {
return;
}
/* Echo until told to stop */
while (!stop) { Thread.sleep(10000); }
}
/* Implementation of the echo method */
public String Echo(String inStr) {
return inStr;
}
}
Client端:
public class Client {
public static void main(String[] args) {
/* Create a bus connection and connect to the bus */
BusAttachment bus = new BusAttachment(Client.class.getName());
bus.connect();
/* Get a remote object */
Class[] ifaces = { EchoInterface.class };
ProxyBusObject proxyObj = bus.getProxyBusObject("org.alljoyn.echo", "/myobject", ifaces);
SimpleInterface proxy = proxyObj.getInterface(EchoInterface.class);
/* Call the ping method on the remote object */
try {
String ret = proxy.Echo("Hello World");
System.out.println("Echo returned: " + ret);
} catch (BusException ex) {
return;
}
}
}
AllJoyn应用程序典型API调用流程示意
AllJoyn的安全机制
• AllJoyn的安全模型——认证和加密(Authentication and encryption)
• 认证和加解密是基于应用程序实现的,总线只负责传输和路由而并 不参与认证和加解密
• 每个应用程序维护各自的 key store并采用密码保护
• AllJoyn支持 3种安全机制,基于Transport Layer Security (TLS) 协议,应用开发者根据应用程序的类型和所传输数据的种类来选择 3种机制之一:
– PIN-code
– logon
– certificate-based
• 安全和非安全应用程序的差别:
– 前者在定义总线接口时需使用@Secure注释符,后者无
– 前者需定义一个class实现AuthListener 接口,在该类中实现两个方法:requested 和completed
安全机制工作原理:
加入安全机制的应用程序代码示例
总线接口定义:
import org.alljoyn.bus.BusException;
import org.alljoyn.bus.annotation.BusInterface;
import org.alljoyn.bus.annotation.BusMethod;
import org.alljoyn.bus.annotation.Secure; @BusInterface(name = "org.alljoyn.bus.samples.secure.SecureInterface")
/*
* The @Secure annotation marks requests any method calls on this interface to first authenticate
* then encrypt the data between the AllJoyn peers.
@Secure
public interface SecureInterface {
@BusMethod
String Ping(String inStr) throws BusException;
}
Service端:
......
/*
* The main differences between a secure application and a plain application, besides the
* @Secure annotations of the interfaces, are encapsulated in the AuthListener. The
* BusAttachment calls the listener with various authentication requests in the process of
* authenticating a peer. The requests made are dependent on the specific authentication
* mechanism negotiated between the peers.
*
* mechanisms.
*/
class AuthListeners implements AuthListener {
/*
* Authentication requests are being made. Contained in this call are the mechanism in use,
* the number of attempts made so far, the desired user name for the requests, and the
* specific credentials being requested in the form of AuthRequests.
*
* A true return value tells the BusAttachment that the requests have been handled.
*
*/
public boolean requested(String mechanism, String peer, int count, String userName, AuthRequest[] requests) {
....
....
}
/*
* An authentication attempt has completed, either successfully or unsuccessfully.
* This simply defers to the specific listener based on the mechanism in use.
*/
public void completed(String mechanism, String authPeer, boolean authenticated) {
....
....
}
}
......
Alljoyn 概述(2)的更多相关文章
- Alljoyn 概述(3)
开发工具 • scons:一个 Python写的自动化构建工具,是对 gnu make 改进的替代工具 • D-Feet:一个D-Bus调试工具 • C++ Code Generator Tool ( ...
- Alljoyn 概述(1)
Alljoyn Overview Feb. 2012- AllJoyn 是什么? • 2011年2月9日发布,由 QuiC(高通创新中心)开发维护的开源软 件项目,采用 Apache license ...
- AllJoyn 了解
AllJoyn是一个中性平台系统,旨在简化邻近异构分布式移动通信网络系统.这里的异构性不仅表示不同的设备,而且可以是具有不同操作系统和不同类型的设备(例如个人电脑.手机.平板电脑和消费性电子产品),并 ...
- 【AR实验室】ARToolKit之概述篇
0x00 - 前言 我从去年就开始对AR(Augmented Reality)技术比较关注,但是去年AR行业一直处于偶尔发声的状态,丝毫没有其"异姓同名"的兄弟VR(Virtual ...
- Recurrent Neural Network系列1--RNN(循环神经网络)概述
作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 本文翻译自 RECURRENT NEURAL NETWORKS T ...
- Swift3.0服务端开发(一) 完整示例概述及Perfect环境搭建与配置(服务端+iOS端)
本篇博客算是一个开头,接下来会持续更新使用Swift3.0开发服务端相关的博客.当然,我们使用目前使用Swift开发服务端较为成熟的框架Perfect来实现.Perfect框架是加拿大一个创业团队开发 ...
- .Net 大型分布式基础服务架构横向演变概述
一. 业务背景 构建具备高可用,高扩展性,高性能,能承载高并发,大流量的分布式电子商务平台,支持用户,订单,采购,物流,配送,财务等多个项目的协作,便于后续运营报表,分析,便于运维及监控. 二. 基础 ...
- [C#] 进阶 - LINQ 标准查询操作概述
LINQ 标准查询操作概述 序 “标准查询运算符”是组成语言集成查询 (LINQ) 模式的方法.大多数这些方法都在序列上运行,其中的序列是一个对象,其类型实现了IEnumerable<T> ...
- 【基于WinForm+Access局域网共享数据库的项目总结】之篇一:WinForm开发总体概述与技术实现
篇一:WinForm开发总体概述与技术实现 篇二:WinForm开发扇形图统计和Excel数据导出 篇三:Access远程连接数据库和窗体打包部署 [小记]:最近基于WinForm+Access数据库 ...
随机推荐
- vs2008 提示msdbg.dll未正确安装的解决办法
开始-->运行-->输入: regsvr32.exe "%ProgramFiles(x86)%\Common Files\Microsoft Shared\VS7Debug\ms ...
- 【转】SendMessage及WPRAME、LPARAME
原文网址:http://www.cnblogs.com/renyuan/archive/2012/11/26/2789103.html SendMessage及WPRAME.LPARAME typed ...
- 数据结构(莫队算法):HH的项链
问题描述: HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步 完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH不断地收集新的贝壳,因此, 他的项链变得越来越长. ...
- iOS 多线程学习笔记 —— NSOperation
本文复制.参考自文章:iOS多线程编程之NSOperation和NSOperationQueue的使用 ,主要为了加强个人对知识的理解和记忆,不做他用.原作者声明: 著作权声明:本文由http://b ...
- java多线程编程(1) 线程的基本知识
在前面研究过多线程与进程的区别. 这里在稍微总结一下: 进程:程序动态的一次执行过程. 线程:可以只是程序员的一部分的执行过程 每个进程有多个线程组成,在java程序中,至少两个线程一个是垃圾回收线程 ...
- JavaScript高级程序设计20.pdf
用户代理检测 为了不在全局作用域中添加多余的变量,我们使用模块增强模式来封装检测脚本 以下是完整的用户代理字符串检测脚本,包括检测呈现引擎.平台.Window操作系统.移动设备和游戏系统 var cl ...
- JavaScript XML 兼容处理,序列化和反序列化以及回调事件
浏览器中XML DOM的支持 IE中通过ActiveXObject实现了XML的支持,存在一下几个版本:Microsoft.XmlDom,MSXML2.DOMDocument,MSXML2.DOMDo ...
- Delphi 对象的创建(create)与释放(free/destory)
Delphi 对象的创建(create)与释放(free/destory) 1.Create参数为:nil/self/application的区别,最好能看到实际效果的区别 例如: My := TMy ...
- 《A First Course in Probability》-chape1-组合分析-二项式定理
二项式系数的概念给人最直观的概念就是,这里有n个物品,分成两组,其中一组的数量是i的所有组合情况. 它的证明过程既可以从组合分析的角度,也可以从数学归纳的角度,由于数学归纳涉及到计算比较困难,我们这里 ...
- freepbx 安装和配置
首先参见 asterisk manager api 的配置,然后根据freepbx的官方文档: http://wiki.freepbx.org/display/HTGS/Installing+Fr ...